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:
6 files changed
+95
-27
No files matched your search
@@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Titano.App.Settings;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Windows.Codecs;
|
||||
using Titano.Data;
|
||||
@@ -22,7 +23,8 @@ public static class DiagnosticsBundle
|
||||
public const int FailedJobs = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Writes "Titano diagnostics yyyy-MM-dd HHmm.zip" into <paramref name="folder"/> and returns its path. Call on the UI
|
||||
/// Writes "Titano diagnostics yyyy-MM-dd HHmm.zip" (" (2)", " (3)"… when that name is taken) into
|
||||
/// <paramref name="folder"/> and returns its path; a bundle that fails half-way leaves no file behind. Call on the UI
|
||||
/// thread: the settings are captured there; detection and writing run in the background.
|
||||
/// </summary>
|
||||
public static Task<string> CreateAsync(AppServices services, string folder, IEnumerable<string>? extraLines = null, CancellationToken ct = default)
|
||||
@@ -33,19 +35,27 @@ public static class DiagnosticsBundle
|
||||
{
|
||||
var failures = services.Database is { } db ? (await db.Jobs.ListAsync(JobState.Failed, FailedJobs, null, ct).ConfigureAwait(false)).Items : [];
|
||||
var codecs = Codecs(services.Encoders);
|
||||
var path = Path.Combine(folder, $"Titano diagnostics {DateTime.Now.ToString("yyyy-MM-dd HHmm", CultureInfo.InvariantCulture)}.zip");
|
||||
var path = ExportNaming.Unique(folder, $"Titano diagnostics {DateTime.Now.ToString("yyyy-MM-dd HHmm", CultureInfo.InvariantCulture)}", ".zip");
|
||||
var temp = path + ".tmp";
|
||||
await using (var file = new FileStream(temp, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
using (var bundle = new DiagnosticsArchive(file))
|
||||
try
|
||||
{
|
||||
bundle.AddText("environment.txt", report);
|
||||
bundle.AddText("codecs.txt", codecs);
|
||||
bundle.AddJson("settings.json", settings);
|
||||
bundle.AddJobs("jobs-failed.json", failures);
|
||||
bundle.AddLogs(services.Environment.LogDirectory, cancellationToken: ct);
|
||||
await using (var file = new FileStream(temp, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
using (var bundle = new DiagnosticsArchive(file))
|
||||
{
|
||||
bundle.AddText("environment.txt", report);
|
||||
bundle.AddText("codecs.txt", codecs);
|
||||
bundle.AddJson("settings.json", settings);
|
||||
bundle.AddJobs("jobs-failed.json", failures);
|
||||
bundle.AddLogs(services.Environment.LogDirectory, cancellationToken: ct);
|
||||
}
|
||||
File.Move(temp, path);
|
||||
return path;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Gone after a successful move; after a failure a half-written zip helps nobody.
|
||||
if (File.Exists(temp)) File.Delete(temp);
|
||||
}
|
||||
File.Move(temp, path, overwrite: true);
|
||||
return path;
|
||||
}, ct);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user