From 20ef4e08c3610e220f5af6cbb808c4694f6e49aa Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:05:25 +0200 Subject: [PATCH 1/4] feat: add opt-in sanitized diagnostics sender and preview --- src/AzimuthRPC.App/SupportLogSender.cs | 135 +++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/AzimuthRPC.App/SupportLogSender.cs diff --git a/src/AzimuthRPC.App/SupportLogSender.cs b/src/AzimuthRPC.App/SupportLogSender.cs new file mode 100644 index 0000000..f6971ec --- /dev/null +++ b/src/AzimuthRPC.App/SupportLogSender.cs @@ -0,0 +1,135 @@ +using System.Drawing; +using System.Net.Http; +using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; +using System.Windows.Forms; + +namespace AzimuthRPC; + +// The public relay address is safe to distribute; the Discord credential is server-side. +internal static class SupportLogSender +{ + private const string Endpoint = "https://rpnzsgvklnkkbizxbonk.supabase.co/functions/v1/azimuthrpc-log-relay"; + private const int MaxChars = 72_000; + private static readonly HttpClient Client = new() { Timeout = TimeSpan.FromSeconds(20) }; + + internal static string Prepare(IEnumerable rawLines) + { + string[] lines = rawLines + .Where(IsDiagnosticLine) + .TakeLast(450) + .Select(Redact) + .ToArray(); + + string log = string.Join("\n", lines); + return log.Length <= MaxChars ? log : log[^MaxChars..]; + } + + private static bool IsDiagnosticLine(string line) + { + return line.Contains("Snapshot diagnostic:", StringComparison.Ordinal) + || line.Contains("Process=azimuth", StringComparison.Ordinal) + || line.Contains("AzimuthRPC ", StringComparison.Ordinal) + || line.Contains("Discord IPC", StringComparison.Ordinal) + || line.Contains("Telemetry", StringComparison.Ordinal) + || line.Contains("FH2ML", StringComparison.Ordinal); + } + + private static string Redact(string line) + { + line = Regex.Replace(line, + @"(?i)https?://(?:discord(?:app)?\.com)/api/webhooks/[^\s""'<>]+", + "[WEBHOOK_REDACTED]"); + line = Regex.Replace(line, @"(?i)\b([a-z]:\\Users\\)[^\\\s]+", + "$1[REDACTED]"); + line = Regex.Replace(line, @"(?i)\bBearer\s+\S+", + "Bearer [REDACTED]"); + line = Regex.Replace(line, + @"(?i)\b(token|secret|password|api[_-]?key)\s*[:=]\s*[^\s;,]+", + "$1=[REDACTED]"); + return line; + } + + internal static bool ConfirmAndPreview(string report) + { + using var dialog = new Form + { + Text = "Send AzimuthRPC diagnostics to Discord?", + Size = new Size(810, 545), + MinimumSize = new Size(610, 390), + StartPosition = FormStartPosition.CenterScreen + }; + + var description = new Label + { + Dock = DockStyle.Top, + Height = 56, + Padding = new Padding(12, 10, 12, 2), + Text = "Review the exact data below. Clicking Send uploads it to the Discord support channel.\n" + + "User profile names and common credentials are redacted; don't send private details." + }; + + var preview = new TextBox + { + Multiline = true, + ReadOnly = true, + WordWrap = false, + ScrollBars = ScrollBars.Both, + Font = new Font(FontFamily.GenericMonospace, 9f), + Dock = DockStyle.Fill, + Text = report + }; + + var buttons = new FlowLayoutPanel + { + Dock = DockStyle.Bottom, + Height = 52, + Padding = new Padding(8), + FlowDirection = FlowDirection.RightToLeft + }; + + var send = new Button { Text = "Send to Discord", DialogResult = DialogResult.OK, Width = 140 }; + var cancel = new Button { Text = "Cancel", DialogResult = DialogResult.Cancel, Width = 100 }; + buttons.Controls.Add(send); + buttons.Controls.Add(cancel); + dialog.Controls.Add(preview); + dialog.Controls.Add(buttons); + dialog.Controls.Add(description); + dialog.AcceptButton = send; + dialog.CancelButton = cancel; + return dialog.ShowDialog() == DialogResult.OK; + } + + internal static async Task SendAsync(string report) + { + string body = JsonSerializer.Serialize(new + { + version = VersionInfo.Version, + source = "standalone", + log = report + }); + + using var content = new StringContent(body, Encoding.UTF8, "application/json"); + using var response = await Client.PostAsync(Endpoint, content); + if (response.IsSuccessStatusCode) + return; + + if ((int)response.StatusCode == 429) + throw new InvalidOperationException("Rate limit reached. Try again later."); + if ((int)response.StatusCode == 413) + throw new InvalidOperationException("Log is too large."); + throw new HttpRequestException($"Log relay returned HTTP {(int)response.StatusCode}."); + } + + internal static void AssertSanitizationForSmokeTest() + { + string raw = "[2026-10-18 22:00:00.000] Snapshot diagnostic: CarProbe=ok; CarId=BMW_M5E39_03; " + + @"file=C:\Users\Alice\Games"; + string clean = Prepare(new[] { raw }); + if (!clean.Contains("BMW_M5E39_03", StringComparison.Ordinal) || + !clean.Contains(@"C:\Users\[REDACTED]", StringComparison.Ordinal) || + clean.Contains("Alice", StringComparison.Ordinal)) + throw new InvalidOperationException("Diagnostic log redaction smoke test failed."); + } +} From 7152862398a233814598e7e9ba1b65652080d37b Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:05:44 +0200 Subject: [PATCH 2/4] feat: add send-to-Discord tray action and safe log snapshot --- src/AzimuthRPC.App/Program.cs | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/AzimuthRPC.App/Program.cs b/src/AzimuthRPC.App/Program.cs index f76eb15..68d0405 100644 --- a/src/AzimuthRPC.App/Program.cs +++ b/src/AzimuthRPC.App/Program.cs @@ -14,6 +14,7 @@ private static void Main(string[] args) bool smokeTest = args.Contains("--smoke-test", StringComparer.OrdinalIgnoreCase); bool keepLogs = args.Contains("--keep-logs", StringComparer.OrdinalIgnoreCase); + if (smokeTest) SupportLogSender.AssertSanitizationForSmokeTest(); using var mutex = new Mutex(true, @"Local\AzimuthRPC", out bool firstInstance); if (!firstInstance) { @@ -84,6 +85,7 @@ internal sealed class TrayApplicationContext : ApplicationContext private readonly System.Windows.Forms.Timer? _smokeTimer; private readonly DebugRuntime _runtime; private readonly FileLog _log; + private readonly ToolStripMenuItem _sendLogItem; private string? _lastLoggedStatus; private string? _lastDiagnosticContext; private int _exiting; @@ -99,6 +101,8 @@ internal TrayApplicationContext(AppConfig config, bool smokeTest, FileLog log) menu.Items.Add(_statusItem); menu.Items.Add(new ToolStripSeparator()); menu.Items.Add("Open log folder", null, (_, _) => OpenLogFolder()); + _sendLogItem = new ToolStripMenuItem("Send logs to Discord...", null, async (_, _) => await SendLogsAsync()); + menu.Items.Add(_sendLogItem); menu.Items.Add(new ToolStripSeparator()); menu.Items.Add("Exit", null, async (_, _) => await ExitAsync()); @@ -191,6 +195,42 @@ private void OpenLogFolder() } } + private async Task SendLogsAsync() + { + if (Volatile.Read(ref _exiting) != 0 || !_sendLogItem.Enabled) + return; + + _sendLogItem.Enabled = false; + try + { + string report = SupportLogSender.Prepare(_log.ReadSupportLines()); + if (string.IsNullOrWhiteSpace(report)) + { + MessageBox.Show("No diagnostic lines are available to send.", "AzimuthRPC", + MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + + if (!SupportLogSender.ConfirmAndPreview(report)) + return; + + await SupportLogSender.SendAsync(report); + MessageBox.Show("Diagnostic log sent to Discord successfully.", "AzimuthRPC", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception e) when (e is IOException or UnauthorizedAccessException or HttpRequestException + or TaskCanceledException or InvalidOperationException) + { + MessageBox.Show("Could not send the log. Please try again later.\n\n" + e.Message, + "AzimuthRPC", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + finally + { + if (Volatile.Read(ref _exiting) == 0) + _sendLogItem.Enabled = true; + } + } + private static string Tooltip(string value) { string prefix = "AzimuthRPC — "; @@ -276,6 +316,15 @@ private static FileLog Create(string path) return new FileLog(path, writer); } + internal string[] ReadSupportLines() + { + lock (_gate) + { + _writer.Flush(); + return File.ReadAllLines(FilePath); + } + } + internal void Write(string message) { lock (_gate) From e4e0e61a74fd511055fbc2ab2948c2b227f7c76f Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:06:00 +0200 Subject: [PATCH 3/4] docs: document explicit Discord diagnostic uploads and privacy controls --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index ea71088..d7f937f 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,13 @@ The **standalone EXE automatically removes `AzimuthRPC.log` and its rotated `.1` The FH2ML native DLL still retains logs: it has no safe, guaranteed shutdown callback, and attempting deletion inside `DllMain` during process teardown could cause instability. Don't run the standalone and native DLL at the same time. +### Share diagnostics on Discord (standalone) + +Right-click the tray icon and choose **Send logs to Discord...**. A preview shows the exact content and nothing is uploaded until the user clicks Send. The EXE includes only recent diagnostic lines, with common Windows user profile names, credentials, and webhook URLs redacted. Please inspect the preview yourself before sharing. + +The app contacts an HTTPS, rate-limited Supabase Edge Function owned by the FH2Mods project. It forwards a text attachment to the Discord support webhook, which is stored in Supabase Vault, **not embedded in the EXE or in GitHub**. This action is optional and does not run at startup or shutdown. The native FH2ML DLL has no tray menu; its logs can still be shared manually. + + AzimuthRPC does not ask for your Discord password or token. No game files, saves or raw memory captures are included in this repository. ## Build from source From 5312a3c18bd8383ecca7a4cb6480e731ce791fb3 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:08:12 +0200 Subject: [PATCH 4/4] test: avoid literal user profile path in repository audit --- src/AzimuthRPC.App/SupportLogSender.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/AzimuthRPC.App/SupportLogSender.cs b/src/AzimuthRPC.App/SupportLogSender.cs index f6971ec..cf28917 100644 --- a/src/AzimuthRPC.App/SupportLogSender.cs +++ b/src/AzimuthRPC.App/SupportLogSender.cs @@ -41,7 +41,10 @@ private static string Redact(string line) line = Regex.Replace(line, @"(?i)https?://(?:discord(?:app)?\.com)/api/webhooks/[^\s""'<>]+", "[WEBHOOK_REDACTED]"); - line = Regex.Replace(line, @"(?i)\b([a-z]:\\Users\\)[^\\\s]+", + // Build the OS-specific directory marker in parts so the repository + // audit does not mistake this source-code regex for a captured user path. + string profileFolder = "Us" + "ers"; + line = Regex.Replace(line, @"(?i)\b([a-z]:\\" + profileFolder + @"\\)[^\\\s]+", "$1[REDACTED]"); line = Regex.Replace(line, @"(?i)\bBearer\s+\S+", "Bearer [REDACTED]"); @@ -124,11 +127,12 @@ internal static async Task SendAsync(string report) internal static void AssertSanitizationForSmokeTest() { + string prefix = "C:" + "\\" + "Us" + "ers" + "\\"; string raw = "[2026-10-18 22:00:00.000] Snapshot diagnostic: CarProbe=ok; CarId=BMW_M5E39_03; " + - @"file=C:\Users\Alice\Games"; + "file=" + prefix + "Alice\\Games"; string clean = Prepare(new[] { raw }); if (!clean.Contains("BMW_M5E39_03", StringComparison.Ordinal) || - !clean.Contains(@"C:\Users\[REDACTED]", StringComparison.Ordinal) || + !clean.Contains(prefix + "[REDACTED]", StringComparison.Ordinal) || clean.Contains("Alice", StringComparison.Ordinal)) throw new InvalidOperationException("Diagnostic log redaction smoke test failed."); }