Repository navigation
Description
Problem
ErrorReportService.Record redacts Bearer tokens out of the string it returns to the UI, but hands
the raw exception to the two sinks that actually persist and transmit:
var summary = $"{context}: {ex.Message}";
var details = $"{context}{Environment.NewLine}{ex}";
summary = Redact(summary); // computed, redacted... then never used
details = Redact(details); // redacted, returned to the caller
_logger.LogError(ex, "{Context}", context); // RAW exception -> file log + logcat
SentrySdk.CaptureException(ex); // RAW exception -> off-device
return details;So redaction covers the on-screen error panel — the least sensitive sink, on the user's own device —
while the rotating file log and Sentry receive the unredacted text.
summary being computed, redacted and then discarded suggests this was wiring that got lost rather
than a deliberate choice.
The vector is live
AniListClient embeds up to 500 characters of the raw HTTP response body into the exception message:
// src/AniSprinkles.Core/Services/AniListClient.cs:864
var fallback = content?.Length > 500 ? content[..500] + "..." : content;
throw new AniListApiException(
kind,
apiMessage ?? $"AniList request failed ({(int)response.StatusCode}) for {operationName}. {fallback}");An auth-failure body that echoes the credential (Invalid token: Bearer eyJ...) therefore lands in
AniListApiException.Message, and from there in both the log file and Sentry.
The redaction regex — Bearer\s+[A-Za-z0-9\-\._~\+\/]+=* — is written to match exactly that shape in
free text, which suggests this response-body path is the case it was added for.
Two things that are not the problem, checked while investigating:
LoggingHandlerlogs method and URI only, never headers.SendDefaultPii = falseinMauiProgramgoverns IP/username, not exception message content.
Why this matters more than it looks
#112 proposes a button that lets a user share the diagnostic log file. If tokens can reach that file
unredacted, that feature turns a passive gap into active exfiltration. This should land before
#112 does.
Proposal
Redact at the source rather than at each sink, so the token never enters the exception and every
downstream consumer is safe by construction:
- Redact the server-derived text in
AniListClientbefore constructingAniListApiException, at
all three sites:apiMessage(:856),fallback(:864), andgraphQl.Errors[0].Message
(:879) — the last is the HTTP-200 GraphQL error path, missed in the original write-up. Move the
regex somewhere both it andErrorReportServicecan share.
Classification must run on the raw text and redaction only on the message that gets stored:
AniListErrorClassifiermatches on "Invalid token" / outage markers, none of which the Bearer
regex touches, but keeping the order explicit means a future pattern cannot silently break it. - Add a Sentry
BeforeSendscrubber as defence in depth, for anything that reaches Sentry by a path
that does not go throughErrorReportService. - Delete the dead
summarylocal, or use it — whichever the redesign settles on.
Sink-by-sink sanitising was considered and is worse: it means remembering to redact at every future
LogError(ex, ...) call site, and redacting the exception before handing it to Sentry costs the
stack trace that makes Sentry grouping work.
Acceptance
- A response body containing
Bearer <token>cannot reach the file log, logcat, or Sentry. - Regression tests for both server-message paths — the 4xx-with-token-in-body path and the
200-with-GraphQL-error path — asserting the thrown exception'sMessagecarries no raw token and
itsKindis unchanged. ErrorReportServicehas no unused redaction result.- Stack traces and Sentry grouping are unaffected.
Notes
Pre-existing; not introduced by #123, where ErrorReportService.cs moved as a 100%-similarity rename
with no content change. Found while triaging a Copilot review comment on that PR.
Activity
zhollis21 commentedon Aug 23, 2026
Verification notes (checked against
origin/main@ 57d4506):src/AniSprinkles.Core/Services/ErrorReportService.cs:20-30—summaryisbuilt, redacted, and never read;
_logger.LogError(ex, "{Context}", context)andSentrySdk.CaptureException(ex)both receive the raw exception.AniListClient.cs:879builds theexception message from
graphQl.Errors[0].Messageon an HTTP-200 GraphQL error response. Thatreaches
AniListApiException.Messageby the same route as the 4xxapiMessage(:856) andfallback(:864), so redaction at the source needs all three sites, not two.ErrorReportService.Recordis the onlySentrySdk.CaptureExceptioncall site undersrc/; theother 27
SentrySdk.*calls are allAddBreadcrumb.LoggingHandlerlogs method + URI only(
LoggingHandler.cs:18,35,54), and its Sentry breadcrumbs useGetLeftPart(UriPartial.Path).AuthServicenever puts a token in a log message or an exception.AGENTS.md:133currently reads "ErrorReportService redacts Bearer tokens from all error outputbefore logging or Sentry capture", which the code does not do. That line needs correcting with
the fix.
zhollis21 commentedon Aug 23, 2026
Updated during planning: the proposal and acceptance now cover the third server-derived message site,
graphQl.Errors[0].MessageatAniListClient.cs:879(the HTTP-200 GraphQL error path), which the original write-up missed. Also noted that classification has to run on the raw text with redaction applied only to the stored message, soAniListErrorClassifierkeeps matching "Invalid token" and the outage markers.Adult-content commit timing, token redaction, AppSettings seam, and C…
Adult-content commit timing, token redaction, AppSettings seam, and C…