Compare commits

...
Author SHA1 Message Date
poli0981andClaude Opus 5 7889720ba9 fix(app): bug bundles no longer carry the user's name in log paths, as the privacy policy already promised
legal/PRIVACY_POLICY.md section 3 says logs are redacted (user directory paths removed) before bundling, and
10_LOGGING named a RedactingEnricher. Neither existed: BugBundleBuilder copied ui-*.log, agent-*.log and
overlay-*.log verbatim, on the ground that they carry no paths beyond the data directory, which is itself under the
user's profile. On the dev box the profile path appeared 8 times in the UI log, 7 in the Agent's and in 175 overlay
headers.

LogRedactor rewrites every log copy in the zip: the name in each X:\Users\<name> path becomes <user>, and so does a
profile directory's last segment elsewhere, in backslash, doubled-backslash (Serilog's JSON), forward-slash, any-case
and ANSI-question-mark spellings. The file is read through Latin-1, so UTF-8 and ANSI logs come out byte for byte
except the names. The files on disk keep their paths, and the policy's sentence is now true unchanged. The enricher
claim is struck in 10_LOGGING with where the rule is enforced instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 20:39:42 +07:00
7 changed files with 224 additions and 8 deletions

No files matched your search

+12
View File
@@ -241,6 +241,18 @@ under a `## [x.y.z] - date` heading in the same commit that bumps `VERSION`, the
### Fixed
- **Bug bundles no longer carry the user's name in log paths, which the privacy policy already promised
(2026-09-15).** `legal/PRIVACY_POLICY.md` §3 says "logs are redacted (user directory paths removed) before
bundling" and `10_LOGGING` named a `RedactingEnricher`; neither existed, and `BugBundleBuilder` copied `ui-*.log`,
`agent-*.log` and `overlay-*.log` verbatim on the stated ground that they carry no paths beyond the data directory,
which is itself under the user's profile. On the dev box the profile path appeared 8 times in the UI log, 7 in the
Agent's and in 175 overlay headers. `App/Services/LogRedactor` now rewrites every log copy in the zip: the name in
each `X:\Users\<name>` path becomes `<user>`, and so does a profile directory's last segment elsewhere, in
backslash, doubled-backslash (Serilog's JSON), forward-slash, any-case and ANSI-`?` spellings, byte for byte
otherwise (Latin-1 round trip, so UTF-8 and ANSI logs both survive). The files on disk keep their paths; the policy's
sentence is now true without a word of it changing. Tests: `LogRedactorTests`, `BugBundleBuilderTests`. Docs:
`10_LOGGING` §Serilog configuration (the enricher claim struck, with where the rule is enforced) and §Bug report
flow step 2.
- **Test runs stop filling the real data folder with hook-harness logs (2026-09-15).** The injection tests inject the
shipped Overlay, whose log goes to `%LOCALAPPDATA%\FrameLedger\logs` by design (§S21: not the environment, and no
switch in the injected DLL), so the owner's folder held 2506 overlay logs, 2492 of them hook-harness's from test
+17 -3
View File
@@ -6,7 +6,7 @@
- Minimum level `Information` (`Debug` toggle in Settings → applies live via `LoggingLevelSwitch`).
- Enrichers: process name, version, `SessionGuid` and `GamePid` scoped properties during capture (`LogContext.PushProperty`).
- Template: `[{Timestamp:HH:mm:ss.fff} {Level:u3}] {SourceContext} {Message:lj} {Properties:j}{NewLine}{Exception}`.
- **Never log:** full user paths outside `%LOCALAPPDATA%\FrameLedger` (redact to `<user>`), machine name, any exe arguments of games. A `RedactingEnricher` enforces the path rule.
- **Never log:** full user paths outside `%LOCALAPPDATA%\FrameLedger` (redact to `<user>`), machine name, any exe arguments of games. ~~A `RedactingEnricher` enforces the path rule.~~ *(No such enricher was ever written: found 2026-09-15, checking `legal/PRIVACY_POLICY.md` §3's "logs are redacted (user directory paths removed) before bundling" against the bundle, which copied the logs verbatim. An enricher could not have kept the rule anyway: exception text and the Overlay's native log never pass through one, and the data directory itself sits under the user's profile, so every run logs a user name. The rule is enforced where a log leaves the machine instead: `App/Services/LogRedactor` over every log copy in the bug bundle, §Bug report flow step 2. The files in `logs\` keep their full paths; they leave the PC only if the user copies them.)*
- Capture hot path logs nothing per-frame; counters summarized at finalize.
## Crash handling (the app's own crashes)
@@ -67,8 +67,9 @@ Tails the active files (shared read), level filter, text search, pause autoscrol
> **Step 2 built 2026-09-14 (P3 PR-8a), narrower than this list; steps 1 (Help menu, crash dialog), 3, 4 and 5
> are P4's.** `App/Services/BugBundleBuilder` writes the zip where the Logs page's save dialog says
> (`FrameLedger-bugreport-YYYYMMDD-HHmm.zip`): `logs/` = every `ui-*.log` and `agent-*.log` modified in the last
> seven days, **copied verbatim, not redacted** — the files carry no paths beyond the data directory and no
> game data, and a redaction pass that nobody has specified would be a claim; `overlay/` = the five newest
> seven days, ~~**copied verbatim, not redacted** — the files carry no paths beyond the data directory and no
> game data, and a redaction pass that nobody has specified would be a claim~~ **redacted since 2026-09-15, note
> below** (the data directory is under the user's profile, so the claim was false on every machine); `overlay/` = the five newest
> `overlay-<pid>-*.log` (the ring's counters and the `FAULT`/`UNHOOK_*` lines are in those files, not
> separately); `sysinfo.json` = app version, and from the Agent's `HelloAck` when connected its version, the
> overlay build id, telemetry source, Vulkan layer state, elevation, CPU-temperature availability (the
@@ -92,6 +93,19 @@ Tails the active files (shared read), level filter, text search, pause autoscrol
> ~~Still open from this list: the **crash dialog and the minidump** (§Crash handling, step 1's third entry point)
> and the optional session-metadata / dump checkboxes of step 2.~~ PR-9 below; the session-metadata checkbox is open.
>
> **The log copies are redacted since 2026-09-15.** `App/Services/LogRedactor` is what the list's "redacted copies"
> and `legal/PRIVACY_POLICY.md` §3 promised: in every `logs/` and `overlay/` entry the name in each
> `X:\Users\<name>` path becomes `<user>`, and so does the last segment of this user's profile directory when it
> lives elsewhere (`D:\Profiles\<name>`). Every spelling a log carries is covered: backslashes, the doubled
> backslashes of Serilog's JSON properties, forward slashes, any case, a name with spaces, and the `?` the Overlay's
> ANSI image path writes for a letter its code page lacks. The file is read as bytes through Latin-1, so a UTF-8
> log and an ANSI one both come out byte for byte except the names. Over-redaction is the chosen failure:
> `C:\Users\Public` reads `<user>` too. The measured need on the dev box: the profile path appeared 8 times in
> `ui-*.log`, 7 in `agent-*.log` and in 175 overlay headers; no machine name or bare user name did. A crash dump is
> memory and cannot be redacted, which its checkbox says. Tests: `LogRedactorTests` (fifteen cases, both
> directions, UTF-8 and ANSI bytes), `BugBundleBuilderTests` (the copies carry no user name, the file on disk is
> untouched).
>
> **The crash dump's checkbox and step 1's third entry point built 2026-09-15 (P4 PR-9).** When
> `BugBundleBuilder.LatestCrashDump` finds a `*.dmp` written in the last seven days under `crashdumps\` (either
> process's), the flow shows **Optional items** before the save dialog (`BugReportPreviewPrompt.AskCrashDumpAsync` →
+1 -1
View File
@@ -280,7 +280,7 @@ public partial class App : System.Windows.Application
services.AddSingleton<IRunAtLogon, RunAtLogonRegistry>();
services.AddSingleton<SafetyNotices>();
services.AddSingleton(static _ => new LogTail(UiPaths.Logs));
services.AddSingleton(static sp => new BugBundleBuilder(UiPaths.Logs, sp.GetRequiredService<RegisteredSettings>(), crashDumpDirectory: UiPaths.CrashDumps));
services.AddSingleton(static sp => new BugBundleBuilder(UiPaths.Logs, sp.GetRequiredService<RegisteredSettings>(), crashDumpDirectory: UiPaths.CrashDumps, redactor: LogRedactor.ForCurrentUser()));
// The bug report's steps 3-4 and the shell's Export (P4 PR-3): the preview dialog, the browser, the clipboard,
// the flow over them, the session the shell exports, and the CSV/JSON service the summary window's writers serve.
@@ -11,7 +11,8 @@ namespace FrameLedger.App.Services;
/// <summary>
/// <c>10_LOGGING</c> §Bug report flow, step 2 — the bundle: <c>logs/</c> (this app's and the Agent's files of the
/// last seven days), the last <c>overlay-*.log</c> files, <c>sysinfo.json</c> (app, agent, overlay build id, OS,
/// last seven days) and the last <c>overlay-*.log</c> files, both as copies with every user name in a path replaced
/// (<see cref="LogRedactor"/>), <c>sysinfo.json</c> (app, agent, overlay build id, OS,
/// locale, telemetry source, Vulkan layer state, elevation), <c>settings.json</c> (the registry's keys and values —
/// no paths), and <c>crashdumps/</c> with one minidump only when the user ticked it (P4 PR-9). We ship our files only,
/// never a game's; nothing is sent anywhere (<see cref="BugReportFlow"/> is steps 3 and 4).
@@ -24,18 +25,21 @@ public sealed class BugBundleBuilder
private readonly RegisteredSettings _settings;
private readonly TimeProvider _clock;
private readonly string? _crashDumps;
private readonly LogRedactor _redactor;
/// <summary>A builder over the logs directory, the settings registry and, when given, the crash dump directory.</summary>
/// <param name="logsDirectory">The logs directory: ours and the Overlay's.</param>
/// <param name="settings">The registry the bundle's <c>settings.json</c> reads.</param>
/// <param name="clock">The seven-day cut's clock.</param>
/// <param name="crashDumpDirectory">The minidumps' directory (P4 PR-9); null offers none.</param>
public BugBundleBuilder(string logsDirectory, RegisteredSettings settings, TimeProvider? clock = null, string? crashDumpDirectory = null)
/// <param name="redactor">What the log copies pass through; the current user's by default.</param>
public BugBundleBuilder(string logsDirectory, RegisteredSettings settings, TimeProvider? clock = null, string? crashDumpDirectory = null, LogRedactor? redactor = null)
{
_logs = logsDirectory ?? throw new ArgumentNullException(nameof(logsDirectory));
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
_clock = clock ?? TimeProvider.System;
_crashDumps = crashDumpDirectory;
_redactor = redactor ?? LogRedactor.ForCurrentUser();
}
/// <summary>
@@ -77,12 +81,12 @@ public sealed class BugBundleBuilder
{
foreach (string log in Directory.EnumerateFiles(_logs, "*.log").Where(f => IsOurs(f) && File.GetLastWriteTimeUtc(f) >= cutoff))
{
AddFile(zip, log, "logs/" + Path.GetFileName(log), written);
AddRedactedFile(zip, log, "logs/" + Path.GetFileName(log), written);
}
foreach (string overlay in Directory.EnumerateFiles(_logs, "overlay-*.log").OrderByDescending(File.GetLastWriteTimeUtc).Take(OverlayLogsKept))
{
AddFile(zip, overlay, "overlay/" + Path.GetFileName(overlay), written);
AddRedactedFile(zip, overlay, "overlay/" + Path.GetFileName(overlay), written);
}
}
@@ -121,6 +125,25 @@ public sealed class BugBundleBuilder
written.Add(entryName);
}
// legal/PRIVACY_POLICY.md §3: a log leaves this machine only as a copy with the user names in its paths replaced. A log is
// at most 10 MB (Serilog's roll size), so it is read whole; a crash dump is memory and goes in as it is, behind its box.
private void AddRedactedFile(ZipArchive zip, string source, string entryName, List<string> written)
{
byte[] bytes;
using (var stream = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
using (var buffer = new MemoryStream())
{
stream.CopyTo(buffer);
bytes = buffer.ToArray();
}
byte[] redacted = _redactor.Redact(bytes);
ZipArchiveEntry entry = zip.CreateEntry(entryName, CompressionLevel.Optimal);
using Stream target = entry.Open();
target.Write(redacted, 0, redacted.Length);
written.Add(entryName);
}
private static void AddText(ZipArchive zip, string entryName, string text, List<string> written)
{
ZipArchiveEntry entry = zip.CreateEntry(entryName, CompressionLevel.Optimal);
@@ -0,0 +1,77 @@
using System.Text;
using System.Text.RegularExpressions;
namespace FrameLedger.App.Services;
/// <summary>
/// The "redacted copies" of <c>10_LOGGING</c> §Bug report flow step 2, and what makes <c>legal/PRIVACY_POLICY.md</c> §3's
/// "logs are redacted (user directory paths removed) before bundling" true: the name in every <c>X:\Users\&lt;name&gt;</c>
/// path becomes <c>&lt;user&gt;</c>, and so does the last segment of this user's own profile directory when it lives
/// somewhere else. Applied to the bundle's copies only; the files in <c>logs\</c> keep their paths.
/// </summary>
/// <remarks>
/// Every spelling a log carries: backslashes, the doubled backslashes of Serilog's JSON properties, forward slashes, any
/// case, a name with spaces, and a name the Overlay's ANSI header could only spell with <c>?</c>. Files are read as bytes
/// through Latin-1, which maps each byte to one character and back, so a UTF-8 log (Serilog) and an ANSI one (the Overlay's
/// image path) both come out byte for byte except the names. Over-redaction is the failure direction chosen: another
/// account's folder, or <c>C:\Users\Public</c>, reads <c>&lt;user&gt;</c> too.
/// </remarks>
public sealed partial class LogRedactor
{
/// <summary>What a user name in a path becomes.</summary>
public const string Placeholder = "<user>";
private const string _separator = @"(?:\\{1,2}|/)";
private const string _end = @"(?=[\\/""'<>|\r\n\t]|\z)";
private readonly Regex? _profile;
/// <summary>A redactor for <paramref name="profileDirectory"/>'s owner; null or empty redacts <c>X:\Users\&lt;name&gt;</c> paths only.</summary>
public LogRedactor(string? profileDirectory)
{
_profile = ProfilePattern(profileDirectory);
}
/// <summary>The redactor for the user running FrameLedger.</summary>
public static LogRedactor ForCurrentUser() => new(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
/// <summary>The text with every user name in a path replaced by <see cref="Placeholder"/>.</summary>
public string Redact(string text)
{
ArgumentNullException.ThrowIfNull(text);
string result = UsersPath().Replace(text, "${prefix}" + Placeholder);
return _profile is null ? result : _profile.Replace(result, "${prefix}" + Placeholder);
}
/// <summary>A log file's bytes, redacted, and otherwise byte for byte what was read.</summary>
public byte[] Redact(byte[] bytes)
{
ArgumentNullException.ThrowIfNull(bytes);
return Encoding.Latin1.GetBytes(Redact(Encoding.Latin1.GetString(bytes)));
}
[GeneratedRegex(@"(?<prefix>\b[A-Za-z]:" + _separator + "Users" + _separator + @")(?<name>[^\\/""'<>|\r\n\t]+?)" + _end, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, matchTimeoutMilliseconds: 2000)]
private static partial Regex UsersPath();
// A profile outside X:\Users (a redirected or a domain-managed one): its own parent, then its name. The name is matched
// as its UTF-8 bytes read through Latin-1, which is how Redact(byte[]) sees a Serilog log.
private static Regex? ProfilePattern(string? profileDirectory)
{
if (string.IsNullOrWhiteSpace(profileDirectory))
{
return null;
}
string[] segments = profileDirectory.Split(['\\', '/'], StringSplitOptions.RemoveEmptyEntries);
if (segments.Length < 2 || segments[0].Length != 2 || segments[0][1] != ':'
|| (segments.Length == 3 && string.Equals(segments[1], "Users", StringComparison.OrdinalIgnoreCase)))
{
return null;
}
static string Escaped(string segment) => Regex.Escape(Encoding.Latin1.GetString(Encoding.UTF8.GetBytes(segment)));
string parent = string.Join(_separator, segments[..^1].Select(Escaped));
string pattern = @"(?<prefix>\b" + parent + _separator + ")" + Escaped(segments[^1]) + _end;
return new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(2));
}
}
@@ -80,6 +80,29 @@ public sealed class BugBundleBuilderTests : IDisposable
sysinfo["telemetry_source"].Should().Be("l3");
}
[Fact]
public async Task TheLogCopiesCarryNoUserNameAndTheFilesOnDiskAreUntouched()
{
await using ScratchLedger s = await ScratchLedger.OpenAsync();
var clock = new FixedClock(new DateTimeOffset(2026, 9, 15, 12, 0, 0, TimeSpan.Zero));
DateTime now = clock.GetUtcNow().UtcDateTime;
string ui = Path.Combine(_dir, "ui-20260915.log");
await File.WriteAllTextAsync(ui, "[12:00:00.000 INF] ui: started (0.1.0), ledger C:\\Users\\tester\\AppData\\Local\\FrameLedger\\ledger.db {\"Path\":\"C:\\\\Users\\\\tester\\\\AppData\"}\r\n", Ct);
File.SetLastWriteTimeUtc(ui, now);
string overlay = Path.Combine(_dir, "overlay-4242-20260915-120000.log");
await File.WriteAllTextAsync(overlay, "# FrameLedger.Overlay build x pid 4242 layout v9 image C:\\Users\\tester\\Games\\title.exe\nSTOP\n", Ct);
File.SetLastWriteTimeUtc(overlay, now);
string zip = Path.Combine(_dir, "bundle.zip");
await new BugBundleBuilder(_dir, new RegisteredSettings(new SqliteSettingsStore(s.Db)), clock, redactor: new LogRedactor(@"C:\Users\tester")).WriteAsync(zip, agent: null, ct: Ct);
string uiCopy = ReadEntry(zip, "logs/ui-20260915.log");
string overlayCopy = ReadEntry(zip, "overlay/overlay-4242-20260915-120000.log");
uiCopy.Should().NotContain("tester").And.Contain(@"C:\Users\<user>\AppData\Local\FrameLedger\ledger.db").And.Contain(@"C:\\Users\\<user>\\AppData");
overlayCopy.Should().NotContain("tester").And.StartWith(@"# FrameLedger.Overlay build x pid 4242 layout v9 image C:\Users\<user>\Games\title.exe");
(await File.ReadAllTextAsync(ui, Ct)).Should().Contain("tester", "the redaction is the bundle's copy, never the log on disk");
}
[Fact]
public void TheSuggestedNameIsTheDocsFormat()
{
@@ -143,6 +166,13 @@ public sealed class BugBundleBuilderTests : IDisposable
return path;
}
private static string ReadEntry(string zip, string entry)
{
using ZipArchive archive = ZipFile.OpenRead(zip);
using var reader = new StreamReader(archive.GetEntry(entry)!.Open());
return reader.ReadToEnd();
}
private static Dictionary<string, string> ReadJson(string zip, string entry)
{
using ZipArchive archive = ZipFile.OpenRead(zip);
@@ -0,0 +1,60 @@
using System.Text;
using FluentAssertions;
using FrameLedger.App.Services;
namespace FrameLedger.App.Tests;
/// <summary>
/// <c>legal/PRIVACY_POLICY.md</c> §3 (P4 follow-up, 2026-09-15): a user name in a path never leaves the machine in a log
/// copy, in any spelling a log carries, and nothing else in the file changes.
/// </summary>
public sealed class LogRedactorTests
{
private static readonly LogRedactor _redactor = new(@"C:\Users\kuujo");
[Theory]
[InlineData(@"ledger C:\Users\kuujo\AppData\Local\FrameLedger\ledger.db", @"ledger C:\Users\<user>\AppData\Local\FrameLedger\ledger.db")]
[InlineData(@"{""Path"":""C:\\Users\\kuujo\\AppData\\Local""}", @"{""Path"":""C:\\Users\\<user>\\AppData\\Local""}")]
[InlineData("file:///c:/users/KUUJO/Documents/x.txt", "file:///c:/users/<user>/Documents/x.txt")]
[InlineData(@"C:\Users\John Smith\Documents", @"C:\Users\<user>\Documents")]
[InlineData(@"'C:\Users\kuujo'", @"'C:\Users\<user>'")]
[InlineData("profile C:\\Users\\kuujo\r\nnext", "profile C:\\Users\\<user>\r\nnext")]
[InlineData(@"image C:\Users\Nguy?n\Games\title.exe", @"image C:\Users\<user>\Games\title.exe")]
[InlineData(@"two C:\Users\a\x and D:\Users\b\y", @"two C:\Users\<user>\x and D:\Users\<user>\y")]
public void TheNameInAUsersPathBecomesThePlaceholderInEverySpelling(string log, string expected)
{
_redactor.Redact(log).Should().Be(expected);
_redactor.Redact(_redactor.Redact(log)).Should().Be(expected, "redacting a copy twice changes nothing more");
}
[Theory]
[InlineData(@"C:\Program Files\FrameLedger\FrameLedger.exe")]
[InlineData(@"D:\Games\Users\title.exe")]
[InlineData(@"C:\Userspace\x")]
[InlineData("Users: 3, sessions: 12")]
[InlineData(@"C:\Users\")]
public void TextThatNamesNoUserIsUnchanged(string log) => _redactor.Redact(log).Should().Be(log);
[Fact]
public void AProfileOutsideTheUsersFolderIsRedactedByItsOwnPath()
{
var redirected = new LogRedactor(@"D:\Profiles\kuujo");
redirected.Redact(@"ledger D:\Profiles\kuujo\AppData\Local\FrameLedger\ledger.db").Should().Be(@"ledger D:\Profiles\<user>\AppData\Local\FrameLedger\ledger.db");
redirected.Redact(@"{""P"":""d:\\profiles\\KUUJO\\x""}").Should().Be(@"{""P"":""d:\\profiles\\<user>\\x""}");
redirected.Redact(@"D:\Profiles\kuujo2\x").Should().Be(@"D:\Profiles\kuujo2\x", "another folder that merely starts with the name");
new LogRedactor(null).Redact(@"D:\Profiles\kuujo\x").Should().Be(@"D:\Profiles\kuujo\x", "without a profile only X:\\Users paths are known");
}
[Fact]
public void BytesOutsideTheNamesAreKeptExactlyInUtf8AndInAnsi()
{
byte[] utf8 = Encoding.UTF8.GetBytes("[12:00:00.000 INF] Thiết lập đã lưu C:\\Users\\Nguyễn\\AppData\r\n");
byte[] expectedUtf8 = Encoding.UTF8.GetBytes("[12:00:00.000 INF] Thiết lập đã lưu C:\\Users\\<user>\\AppData\r\n");
byte[] ansi = [.. Encoding.ASCII.GetBytes("# image C:\\Users\\Jos"), 0xE9, .. Encoding.ASCII.GetBytes("\\Games\\t.exe\n")];
byte[] expectedAnsi = Encoding.ASCII.GetBytes("# image C:\\Users\\<user>\\Games\\t.exe\n");
_redactor.Redact(utf8).Should().Equal(expectedUtf8);
_redactor.Redact(ansi).Should().Equal(expectedAnsi);
}
}