fix(diagnostics): scrub whole passwords; unique bundle names; no temporary files left behind

- A secret value runs to the next ';' or the end of the line unless quoted
  (backslash and doubled-quote escapes), so passwords with spaces, commas or
  quotes never leak in part; URL passwords run to the last '@' before the path.
- Desktop bundles get " (2)", " (3)"… instead of overwriting one made in the
  same minute, and a bundle that fails half-way deletes its .tmp file.
- The server builds its bundle in a temporary file that no crash leaves behind
  (DeleteOnClose on Windows, unlinked at once elsewhere).
- Tests: passwords with spaces, commas, quotes and '@'; a DbConnectionString in
  the server bundle; bundle name collisions and failure cleanup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 10:05:45 +00:00
1 parent ffa05d9f69
commit 03da77277c
6 files changed
+95 -27

No files matched your search

@@ -18,10 +18,23 @@ public sealed class SecretScrubberTests
[Case("Cookie: titano_session=" + Secret + "; titano_csrf=x", "Cookie: [removed]")]
[Case("git clone https://x-access-token:" + Secret + "@github.com/o/r.git", "git clone https://x-access-token:[removed]@github.com/o/r.git")]
[Case("GET /api/v1/events?token=" + Secret + "&x=1", "GET /api/v1/events?token=[removed]&x=1")]
[Case("client_secret=" + Secret + " refresh_token='" + Secret + "'", "client_secret=[removed] refresh_token=[removed]")]
[Case("refresh_token='" + Secret + "' client_secret=" + Secret, "refresh_token=[removed] client_secret=[removed]")]
[Case("pushed with ghp_0123456789abcdefghijABCDEFGHIJ012345", "pushed with [removed]")]
public void SecretsInTextAreRemoved(string line, string expected) => Assert.Equal(expected, SecretScrubber.ScrubLine(line));
[Theory]
[Case("Host=db;Password=correct horse battery;SslMode=prefer", "Host=db;Password=[removed];SslMode=prefer")]
[Case("Host=db;Password=ab,cd;Port=5432", "Host=db;Password=[removed];Port=5432")]
[Case("Server=db;PWD='semi;colon and space';User ID=sa", "Server=db;PWD=[removed];User ID=sa")]
[Case("Host=db;Password=\"quoted, \"\" pw\";Port=5432", "Host=db;Password=[removed];Port=5432")]
[Case("TITANO_ADMIN_PASSWORD=Very Secret phrase", "TITANO_ADMIN_PASSWORD=[removed]")]
[Case("DbPassword: it's a, secret", "DbPassword: [removed]")]
[Case("login body {\"password\":\"a \\\"quoted\\\" pass, word\",\"user\":\"bob\"}", "login body {\"password\":[removed],\"user\":\"bob\"}")]
[Case("postgres://titano:p@ss@db:5432/titano", "postgres://titano:[removed]@db:5432/titano")]
[Case("https://alice:pa:ss@nas.local/api", "https://alice:[removed]@nas.local/api")]
public void PasswordsWithSpacesCommasQuotesOrAtSignsLeaveNothingBehind(string line, string expected) =>
Assert.Equal(expected, SecretScrubber.ScrubLine(line));
[Theory]
[Case("2026-10-02T09:00:00Z Info archive: Scan of /archive found 1,204 frames in 12 sequences")]
[Case("Index open (schema 3) at C:\\Users\\alice\\AppData\\Local\\Titano\\titano.db")]
@@ -45,7 +58,7 @@ public sealed class SecretScrubberTests
"ServerName": "NAS",
"AdminPassword": "{{Secret}}",
"DbPassword": null,
"DbConnectionString": "Host=db;Password={{Secret}}",
"DbConnectionString": "Host=db;Username=titano;Password=correct horse, battery;SslMode=prefer",
"TokenLifetimeDays": 30,
"ProtectedToken": "AQAAANCMnd8BFdERjHoAwE",
"TrustedCertificates": [ { "Fingerprint": "AB:CD:EF", "Server": "nas" } ],
@@ -61,7 +74,8 @@ public sealed class SecretScrubberTests
Assert.Equal("NAS", root.GetProperty("ServerName").GetString());
Assert.Equal(SecretScrubber.Removed, root.GetProperty("AdminPassword").GetString());
Assert.Equal(JsonValueKind.Null, root.GetProperty("DbPassword").ValueKind);
Assert.Equal("Host=db;Password=[removed]", root.GetProperty("DbConnectionString").GetString());
Assert.Equal("Host=db;Username=titano;Password=[removed];SslMode=prefer", root.GetProperty("DbConnectionString").GetString());
Assert.False(scrubbed.Contains("horse", StringComparison.Ordinal), scrubbed);
Assert.Equal(30, root.GetProperty("TokenLifetimeDays").GetInt32());
Assert.Equal("AB:CD:EF", root.GetProperty("TrustedCertificates")[0].GetProperty("Fingerprint").GetString());
Assert.Equal(SecretScrubber.Removed, root.GetProperty("Nested").GetProperty("Credentials").GetProperty("User").GetString());
@@ -69,7 +83,7 @@ public sealed class SecretScrubberTests
[Test]
public void TextThatIsNotJsonIsScrubbedAsText() =>
Assert.Equal("password=[removed] {", SecretScrubber.ScrubJson("password=" + Secret + " {"));
Assert.Equal("password=[removed]\n{ \"kept\": 1", SecretScrubber.ScrubJson("password=" + Secret + "\r\n{ \"kept\": 1"));
[Theory]
[Case("DbPassword", true)]