Strip credentials from every emitted log line - #431
Merged
Conversation
EngineLog logs whole URLs on purpose: host, path and query are what a playback report is diagnosed from. Media servers routinely put the access token in that same query, Jellyfin's `api_key=` being the case at hand, so `[AetherEngine] load url=`, `[NativeAVPlayerHost] load url=` and `asset.url=` carried a live credential into every sink at once. Emission is `.public` privacy, so a Console.app capture or a sysdiagnose held it in clear text, and the host handler passed it to whatever in-app log a consumer built on it. That makes it the engine's problem rather than each consumer's: the engine composes the line, it reaches three sinks a consumer does not control, and a host-side scrub only ever covers the one sink that host owns. Sodalite had just turned its diagnostic log on for App Store users so reporters can hand logs over, which is exactly the situation where this ships a token. Both public emit overloads now funnel through one private deliver(), which runs the line through LogRedaction first. Redacting at the funnel rather than at the call sites is the point: a URL logged by code added later is covered without its author knowing the redactor exists. Covered names are generic rather than Jellyfin-specific: api_key, apikey, access_token, token, secret, password, signature, x-emby-token, x-mediabrowser-token, connect.sid, in the query form, both header forms and the cookie form. Values go whole, never as a prefix. Public API is unchanged and the redactor is internal, so docs/api.md needs no entry. The redactor works on UTF-8 bytes and allocates its output only once something matches. That is not premature. The first version compared Characters and built a lowercased String per position, which cost enough on this path to shift request timing in ServedFromMemoryProgressTests: emit is called from the demuxer and the segment producer, so anything per-line here is per-line everywhere. That test is what caught it, and it passes again. 11 tests cover the forms, the boundary rule that keeps `hasToken=true` and `[SWDiag] enq=…` intact, and that the host handler never sees the raw token. Full suite: 2125 tests in 299 suites pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RbWZLwBVLGM1xUVXa9NeJ1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EngineLoglogs whole URLs on purpose: host, path and query are what a playback report is diagnosed from. Media servers routinely put the access token in that same query (Jellyfin'sapi_key=is the case at hand), so[AetherEngine] load url=,[NativeAVPlayerHost] load url=andasset.url=carried a live credential into every sink at once. Emission uses.publicprivacy, so a Console.app capture or a sysdiagnose held it in clear text, and the host handler passed it to whatever in-app log a consumer built on it.This belongs in the engine rather than in each consumer: the engine composes the line, it reaches three sinks a consumer does not control, and a host-side scrub only ever covers the one sink that host owns. Sodalite had just enabled its diagnostic log for App Store users so reporters can hand logs over, which is precisely the situation where an unredacted line ships a token.
What changed
emitoverloads funnel through one privatedeliver(), which runs the line throughLogRedactionbefore OSLog and before the handler. Public API is unchanged; the redactor isinternal, sodocs/api.mdneeds no entry.api_key,apikey,access_token,token,secret,password,signature,x-emby-token,x-mediabrowser-token,connect.sid, in the query form, both header forms (Token="…",X-Emby-Token: …) and the cookie form. Values are replaced whole, never truncated to a prefix.Performance
The redactor works on UTF-8 bytes and allocates its output only once something matches. That is not premature. The first version compared
Characters and built a lowercasedStringper position, which cost enough on this path to shift request timing inServedFromMemoryProgressTests:emitis called from the demuxer and the segment producer, so anything per-line here is per-line everywhere. That test caught it and passes again.Verification
11 new tests cover the forms, the boundary rule that keeps
hasToken=trueand[SWDiag] enq=…intact, and that the host handler never receives the raw token. Full suite: 2125 tests in 299 suites pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01RbWZLwBVLGM1xUVXa9NeJ1