Skip to content

fix(logredact): keep signed stream and download tokens out of logs - #3137

Merged
Quick104 merged 3 commits into
mainfrom
fix/sec-download-log-token
Oct 27, 2026
Merged

Quick104 merged 3 commits into
mainfrom
fix/sec-download-log-token

Conversation

@Quick104

@Quick104 Quick104 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

When a download goes through a proxy node, the API server first sends a HEAD to 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.SanitizeURL would 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 with logredact kept those tokens too.

Approach

Signed stream and download tokens are JWTs. logredact now treats a path segment shaped like a JWT as a credential: two base64url parts that each start with eyJ, then a signature. SanitizeURL and SanitizeRequestURL replace it with [REDACTED]. Three places decided whether a URL needed sanitizing by looking only for @, ? or #: the requested-URL scrub in SanitizeURLError, URL strings inside SanitizeJSON, and the operational log's free-text URL pass. They now share one rule, logredact.URLMayHoldCredential.

Two log lines change at the call site:

  • The download preflight debug log runs its error through logredact.SanitizeURLError.
  • The proxy's "proxy to transcode node" error log is the node-side copy of the relay log fix(playback): keep the account token out of transcode relay logs #3126 fixed. It logged the raw URL and error, and the forwarded query can carry the player's account token. It now uses SanitizeURL and SanitizeURLError, as the API relay does.

Requests and responses are unchanged.

Validation

  • make embed-stub, go build ./..., gofmt -l . (empty), go vet ./...: pass
  • make lint-changed, make lint-router-recovery: 0 issues
  • Focused go test for logredact, opslog, proxy and api/handlers: pass
  • make test-go: every touched package passes. The remaining failures also occur on main on 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.
  • A new logredact test checks that SanitizeURL, SanitizeURLError (direct and wrapped), SanitizeRequestURL and SanitizeJSON mask a token path segment, and that an ordinary segment starting with eyJ is kept. It fails on main.

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 from main and 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

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: T3 Code (Claude Code)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; no human has reviewed the diff yet
  • Adversarial review: automated security scan finding, independently re-verified against the code by a separate agent

🤖 Generated with Claude Code

Note

Fix logredact sanitizers to mask signed tokens in URL paths

  • Signed download/stream tokens carried in URL paths were previously kept in logs. logredact.redactTokenSegments in 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, and logredact.sanitizeDiagnosticValue all use the updated logredact.URLMayHoldCredential check, so URLs with token path segments are now sanitized everywhere.
  • Error and URL logging in the proxy and download handlers (server.go, downloads.go) is sanitized before it reaches logs.
  • Operation-log URLs in handler.go now also sanitize tokens in paths, and an exclamation mark is trimmed along with existing trailing punctuation.
  • Behavioral Change: URL-like strings with no detected credential-bearing part (userinfo, query, fragment, or token segment) are left unchanged, as before. Paths whose segments merely look like JWTs are redacted even if they are not credentials.

Macroscope summarized 40cb774.

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-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 27, 2026
@silo-kody

silo-kody Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

URL sanitization now masks JWT-shaped path segments, including percent-encoded token prefixes. Diagnostic and operational logging use the expanded credential check. Proxy preflight and transcode-node failure logs now sanitize errors and target URLs.

Changes: Credential URL log redaction

Layer / File(s) Summary
Detect and redact credential-bearing URL paths
internal/logredact/url.go, internal/logredact/diagnostic.go, internal/logredact/url_test.go, internal/opslog/handler.go
URL sanitization detects and masks JWT-shaped path segments. Diagnostic and operational logging use the shared credential check. Tests cover URLs, errors, request URLs, JSON, percent-encoded prefixes, and ordinary media paths.
Sanitize proxy failure logs
internal/api/handlers/downloads.go, internal/proxy/server.go
Download preflight failures continue to fall back to local serving, but their errors are sanitized before logging. Transcode-node failures log a sanitized error and target URL.

Priority: Pending latest changes

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: dannyshafer, rangodj, neurekadev

Merge Risk: Low · up to eb322

Signed tokens are now masked in URL logs and in the proxy failure logs. One narrow gap remains: an operational-log error whose URL ends in a JWT followed by "!" may still log the token. Fix this small trim-list issue before or shortly after merge.

Security architecture risk: Low · up to eb322

The change strengthens protection against signed URLs appearing in logs. Two redaction gaps remain, but comparison with the PR base shows that the same URL forms were already exposed. No increased access or broader credential exposure was established. Whether crafted encoded separators can reach redeemable routes remains unresolved.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A disclosed valid signed URL can expose its readable claims and permit replay within the capability's validity and route authorization constraints. Exploitation requires access to the emitted token and a reachable serving endpoint. The inspected changes do not grant signing authority or broaden the token's authorized resources.

Security Findings and Attack Paths

  • observed — The retained punctuation finding remains: an exclamation mark attached to a JWT-bearing URL survives free-text trimming and prevents the whole-segment JWT match. Subsequent assignment and userinfo controls do not mask that bare token. This is a residual disclosure condition, not an introduced PR architecture concern: the base also retained that URL, with the same error-text capture path.
  • observed — The retained encoded-separator finding also remains: splitting before unescaping leaves a segment such as file%2F followed by a JWT unmatched after decoding. The base likewise retained its token. Inspected generated URLs use literal separators, but that does not establish how client-crafted encoded separators are routed or whether their escaped representation reaches a diagnostic sink. Those exploitability questions remain unresolved.

Trust Boundaries and Controls

  • observed — The relevant boundary is credential-bearing runtime data entering lower-trust diagnostics. Whole-segment JWT recognition adds a control at that boundary, but it is heuristic rather than a general proof that an arbitrary URL is credential-free. Key-based logging redaction separately protects secret-named attributes and does not scan every free-text value.

Hardening Proposals

  • proposed — Define a shared diagnostic normalization policy for encoded separators and prose punctuation, then validate it against actual routing behavior. Treat JWT-shape detection as a supported-format heuristic rather than a universal credential-free guarantee.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely states the primary change: keeping signed stream and download tokens out of logs.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description directly explains the changes to redact signed tokens from URL paths and sanitize related log and diagnostic output.
Full details: Docstring Coverage

Explanation

Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T02:43:29.843425Z 40cb774 New commits
🔒 Security Review ✅ Completed 2026-10-27T02:45:09.767304Z 40cb774 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

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 Evidence: none, no user-visible change.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 27, 2026
Comment thread internal/logredact/url.go Outdated
Comment on lines +35 to +41
if !strings.Contains(escaped, "eyJ") {
return escaped, false
}
segments := strings.Split(escaped, "/")
found := false
for i, segment := range segments {
if tokenSegment.MatchString(segment) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Security high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between 073a5c4 and eb322aa.

Files selected for processing: 6
  • internal/api/handlers/downloads.go
  • internal/logredact/diagnostic.go
  • internal/logredact/url.go
  • internal/logredact/url_test.go
  • internal/opslog/handler.go
  • internal/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.

Comment thread internal/opslog/handler.go Resolved
…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

silo-kody Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

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

@Quick104

Copy link
Copy Markdown
Contributor Author

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 main and from this branch. A screenshot would show the same strings, and the "before" one would show a signed token. I added the Admin Logs surface to the Evidence section instead.

@Quick104
Quick104 merged commit ff448b4 into main Oct 27, 2026
25 checks passed
@Quick104
Quick104 deleted the fix/sec-download-log-token branch October 27, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant