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

@@ -45,12 +45,44 @@ public sealed class DiagnosticsBundleTests(TestContext context)
}
}
private sealed class OneEncoder : IEncoderInventory
[Test]
public async Task BundlesNeverOverwriteEachOtherAndAFailedOneLeavesNothing()
{
var environment = AppEnvironment.ForCapture();
try
{
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs()) { Encoders = new OneEncoder() };
await File.WriteAllTextAsync(Path.Combine(environment.LogDirectory, "titano-20261002.log"), "started\n");
var folder = context.CreateTempDirectory();
var first = await DiagnosticsBundle.CreateAsync(services, folder);
var second = await DiagnosticsBundle.CreateAsync(services, folder);
Assert.NotEqual(first, second);
Assert.SequenceEqual(new[] { first, second }.Order(StringComparer.Ordinal), Directory.GetFiles(folder).Order(StringComparer.Ordinal));
// The encoder inventory runs after the job query and before the zip is written: cancelling there fails the
// bundle half-way, once its temporary file exists.
using var cts = new CancellationTokenSource();
services.Encoders = new OneEncoder(cts.Cancel);
var empty = context.CreateTempDirectory();
await Assert.ThrowsAsync<OperationCanceledException>(() => DiagnosticsBundle.CreateAsync(services, empty, ct: cts.Token));
Assert.Empty(Directory.GetFiles(empty));
}
finally
{
environment.DeleteCaptureData();
}
}
private sealed class OneEncoder(Action? onDetect = null) : IEncoderInventory
{
public string? Adapter() => "Test adapter";
public IReadOnlyList<EncoderRow> Detect() =>
[new EncoderRow("H.264", "Test encoder", null, EncoderSource.MediaFoundation, true, false, 4096, 2304, VideoCodec.H264)];
public IReadOnlyList<EncoderRow> Detect()
{
onDetect?.Invoke();
return [new EncoderRow("H.264", "Test encoder", null, EncoderSource.MediaFoundation, true, false, 4096, 2304, VideoCodec.H264)];
}
public Task<SelfTestResult> SelfTestAsync(EncoderRow row, CancellationToken ct) => Task.FromResult(new SelfTestResult(true, 100, null));
}