Repository navigation
fix(logredact): keep signed stream and download tokens out of logs - #3137
Conversation
When the download preflight to a proxy node failed, a debug log wrote the HTTP client's error, which repeats the probe URL with the signed download token in its path. logredact.SanitizeURL only dropped userinfo, query and fragment, so routing the error through it would not have helped, and the same gap applied to every signed stream URL (/stream/direct/, /stream/remux/, /stream/transcode/<token>/...). Signed stream and download tokens are JWTs, so logredact now treats a JWT-shaped path segment as a credential: SanitizeURL and SanitizeRequestURL mask it, and the checks that decide whether a URL needs sanitizing (SanitizeURLError's requested-URL scrub, SanitizeJSON and the operational log's free-text URL pass) share one rule, URLMayHoldCredential. The preflight log now uses SanitizeURLError. The proxy's "proxy to transcode node" error log, the node-side copy of the relay log fixed in #3126, also logged its raw URL and error, whose query can carry the player's account token. It now uses SanitizeURL and SanitizeURLError like the API relay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Walkthrough
Merge Risk:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This PR changes server-side log output only, so it is not user-visible. Please replace the log-capture text in the Evidence section with Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
| if !strings.Contains(escaped, "eyJ") { | ||
| return escaped, false | ||
| } | ||
| segments := strings.Split(escaped, "/") | ||
| found := false | ||
| for i, segment := range segments { | ||
| if tokenSegment.MatchString(segment) { |
There was a problem hiding this comment.
Credential disclosure occurs because redactURLPath passes u.EscapedPath() to redactTokenSegments, whose matcher examines escaped text: replacing a JWT's initial eyJ with %65yJ preserves the entire credential in SanitizeURL/SanitizeRequestURL output and makes URLMayHoldCredential return false, allowing log readers to URL-decode and reuse the token until expiration. Unescape each segment before matching and remove the literal eyJ fast-path check so encoded prefixes cannot bypass redaction.
func redactTokenSegments(escaped string) (string, bool) {
segments := strings.Split(escaped, "/")
found := false
for i, segment := range segments {
decoded, err := url.PathUnescape(segment)
if err == nil && tokenSegment.MatchString(decoded) {
segments[i] = Placeholder
found = true
}
}
return strings.Join(segments, "/"), found
}Prompt for LLM
File internal/logredact/url.go:
Line 35 to 41:
Credential disclosure occurs because redactURLPath passes u.EscapedPath() to redactTokenSegments, whose matcher examines escaped text: replacing a JWT's initial `eyJ` with `%65yJ` preserves the entire credential in SanitizeURL/SanitizeRequestURL output and makes URLMayHoldCredential return false, allowing log readers to URL-decode and reuse the token until expiration. Unescape each segment before matching and remove the literal `eyJ` fast-path check so encoded prefixes cannot bypass redaction.
Suggested Code:
func redactTokenSegments(escaped string) (string, bool) {
segments := strings.Split(escaped, "/")
found := false
for i, segment := range segments {
decoded, err := url.PathUnescape(segment)
if err == nil && tokenSegment.MatchString(decoded) {
segments[i] = Placeholder
found = true
}
}
return strings.Join(segments, "/"), found
}
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in eb322aa. Each segment is now matched after unescaping, and a new test row checks that a token starting with %65yJ is masked. I kept a fast path that skips the split when the string has neither eyJ nor %, because any encoded token must contain one of them, and URLMayHoldCredential runs on every URL in operational log text.
There was a problem hiding this comment.
That addresses the reported bypass. Matching each segment after unescaping catches %65yJ, and the regression test covers that case.
The retained fast path is safe for this matcher: a matching token either contains literal eyJ or uses percent encoding, which necessarily contains %. Skipping only when both are absent won’t miss an encoded match and keeps the inexpensive check for ordinary URLs.
Based on the described change, the original suggestion is addressed; removing the fast path entirely isn’t necessary.
A token whose characters were percent-encoded in the path, such as a leading %65 for e, slipped past the redaction and decodes back to a working token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
9d447a98-fc8e-4998-b676-59640249ec4f
Files selected for processing: 6-
internal/api/handlers/downloads.gointernal/logredact/diagnostic.gointernal/logredact/url.gointernal/logredact/url_test.gointernal/opslog/handler.gointernal/proxy/server.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
…d URL An exclamation mark ending a sentence was taken into the URL, so a signed token in its last path segment no longer matched and stayed in the log. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Operational-log errors are sanitized before storage and are shown in the Admin Logs entry details, so this changes what administrators see. The linked evidence is described as before-and-after log-line captures, not captures of that screen. Please add before-and-after screenshots of the same Admin Logs entry detail from the base and PR head, and identify the surface and builds. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
The Admin Logs entry detail shows the stored operational-log message as written, and the evidence page has that stored text for both log lines from |
Problem
Related issue: N/A
Validation tasks: none
When a download goes through a proxy node, the API server first sends a
HEADto the proxy's/downloads/file/<token>URL. If that probe fails, a debug log writes the HTTP client's error, and that error repeats the URL along with the signed download token. With debug logging on, anyone who can read the server logs can copy the token and fetch the file from the proxy until the token expires. The token's claims also show the media path and user. An automated security scan found this as a follow-up to #3126.Running the error through
logredact.SanitizeURLwould not have been enough: it drops userinfo, query and fragment, and this token is in the path. Every signed stream and download URL carries its token the same way (/stream/direct/,/stream/remux/,/stream/transcode/<token>/…,/downloads/file/), so the other logs that already sanitize URLs withlogredactkept those tokens too.Approach
Signed stream and download tokens are JWTs.
logredactnow treats a path segment shaped like a JWT as a credential: two base64url parts that each start witheyJ, then a signature.SanitizeURLandSanitizeRequestURLreplace it with[REDACTED]. Three places decided whether a URL needed sanitizing by looking only for@,?or#: the requested-URL scrub inSanitizeURLError, URL strings insideSanitizeJSON, and the operational log's free-text URL pass. They now share one rule,logredact.URLMayHoldCredential.Two log lines change at the call site:
logredact.SanitizeURLError.token. It now usesSanitizeURLandSanitizeURLError, as the API relay does.Requests and responses are unchanged.
Validation
make embed-stub,go build ./...,gofmt -l .(empty),go vet ./...: passmake lint-changed,make lint-router-recovery: 0 issuesgo testforlogredact,opslog,proxyandapi/handlers: passmake test-go: every touched package passes. The remaining failures also occur onmainon the test Mac: jellycompat DV-strip PlaybackInfo, metadata/nfo and scanner (case-insensitive filesystem), subtitles/subsync (non-UTF-8 file names), and the playback real-FFmpeg remux timeout.logredacttest checks thatSanitizeURL,SanitizeURLError(direct and wrapped),SanitizeRequestURLandSanitizeJSONmask a token path segment, and that an ordinary segment starting witheyJis kept. It fails onmain.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3137/
Only log text changes, and only when a logged URL carries a credential. If the download preflight to a proxy fails while debug logging is on, the logged error now reads
Head "http://<proxy>/downloads/file/[REDACTED]": …and no longer contains the token. If a proxy cannot reach a transcode node, its error log shows the node URL without the query. The evidence page has both log lines captured frommainand from this branch. The Admin Logs entry details show this stored operational-log text as written, so the same masked string appears there. No other UI and no API response changes.Risks
Low; only log and diagnostic text changes. A path segment that is not a token but happens to look like a JWT would also be masked in logs. Media and route segments do not have that shape.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix
logredactsanitizers to mask signed tokens in URL pathslogredact.redactTokenSegmentsin url.go now detects JWT-shaped path segments (including percent-encoded ones) and replaces them with the redaction placeholder, while keeping other path parts.logredact.SanitizeURL,logredact.SanitizeRequestURL,logredact.scrubRequestedURLs, andlogredact.sanitizeDiagnosticValueall use the updatedlogredact.URLMayHoldCredentialcheck, so URLs with token path segments are now sanitized everywhere.Macroscope summarized 40cb774.