Repository navigation
fix(record): write request headers by allowlist (#1466) - #1469
Conversation
The recorder dropped a header only when its name was on a denylist. A credential under another name (X-Passwd, X-Signature, a gateway session header) reached the .wire.jsonl file. - record.AllowedHeaders and wireHeaders keep only listed names. - The proxy copies only listed names when it queues an event. - Tests: end to end through the proxy, credmask gaps, target and Dispatcher serialization, CONTEXT_GURU_CAPTURE. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 4 | a9fa5b882d23 |
blocking |
Verdict: blocking
Findings
- internal/record/wire.go:96-104 — the allowlist names one client's headers outside
agent.Identifyand the agent packages- What fails: the allowlist hardcodes a second copy of the client header names that package
agentowns:x-claude-code-agent-id(agent/claudecode/claudecode.go:18),session-id,thread-id,x-codex-parent-thread-id(agent/codex/codex.go:48-50),x-opencode-session-id,x-opencode-parent-session-id(agent/opencode/identify.go:22-23),x-task-id(agent/bob/bob.go:34). The copy can drift. When a client renames its session header, or a new client joins,agentis updated and the recorder is not: the wire file silently loses that client's correlation ids. No test fails, because nothing ties the two lists together. The drift exists already:x-claude-code-session-id(wire.go:97) is on the list, but no code in this repo reads it — agent/identify.go:50 says Claude Code names its session in the body. The PR body calls the list "the id headers packageagentreads", which is not true for that entry. CLAUDE.md, Client-specific code: "if a rule names one client, it lives inagent.Identify, and nowhere else"; a header of one client outside the agent packages is a blocking finding. A PR that adds a client rule also updatesdocs/client-coverage.md; this one does not. - Proof:
grep -rn "x-claude-code-session-id"hits onlyinternal/record/wire.go:97andinternal/record/wire_test.go:105.grep -rn "x-task-id"inagent/hits onlyagent/bob/bob.go:34. Each allowlisted id header duplicates a constant or literal in an agent package. - Fix: export the correlation header names from package
agent(one list, built from the same constants theIdentifyparsers use), and build the id part ofallowedHeadersfrom it ininternal/record. Keep only the generic names (content-type, accept, accept-encoding, user-agent, the version and beta flags,x-stainless-) local torecord. Cite the source and version forx-claude-code-session-id, or drop it if nothing sends it. Updatedocs/client-coverage.mdif the row changes.
- What fails: the allowlist hardcodes a second copy of the client header names that package
Non-blocking
internal/record/wire.go:51— theWireCall.Headerscomment still says "Wire removes credentials".proxy/recctx.go:28says "credentials are removed when written". Both describe the old denylist. Say "allowlisted" instead.internal/record/wire.go:110— thex-stainless-prefix match accepts any suffix an SDK adds later. Safe today: the values still passContent, and the SDK's telemetry names carry no credential. Worth a line in the comment that the prefix is trusted because Stainless telemetry is fixed-shape.proxy/recordheaders_test.goruns only under-tags cg_record. CI runs that tag (ci.yaml line 259), so the coverage is real. The untaggedinternal/recordtests also pin the allowlist.
What I checked
- The full diff
f9ec697c..a9fa5b88, and the code around each change:internal/record/wire.go,proxy/proxy.go(serve's record defer),proxy/sessionrec.go,proxy/recctx.go,proxy/credmask.go,proxy/dispatcher.go. - Every allowlisted name against its reader. Generic names: content-type, accept, accept-encoding, user-agent, anthropic-version, anthropic-beta, openai-beta, x-stainless-. Client id names: see finding 1. Credential names (authorization, x-api-key, x-goog-api-key, cookies, x-context-guru-) are all excluded.
- The redaction chain:
AllowedHeadersfilters at the queue (proxy.go:1947),wireHeadersfilters again and passes each value throughContent(wire.go:141). The second guard is real:Contentruns identity,internal/redact, extra shapes and a base64 pass (redact.go:117-127). - Other request-header sinks: the OTLP path (
record.TurnFromCall,ProxiedCall) carries no headers; the dashboard content capture andstorehold no request headers;CONTEXT_GURU_CAPTUREwrites provider, model and body only. The wire file was the only sink, and it is fixed. - Replay impact: the wire loader in this repo reads no header; the Inference-Perf converter is external and the PR states it reads none. The loader-relevant fields (path, bodies, status, times, model) are unchanged.
- Tests: the new
internal/recordtests and both newproxytest files compile against the current helpers (newTestRecorder,wireLines,testSSE,ccBodyin sessionrec_test.go;heldAuth,maskHeaders,credMask,zeroHeaders,captureRequest,NewDispatcherin untagged files).credmask_test.gois correctly untagged;recordheaders_test.gois correctly taggedcg_record. Notime.Sleep; the timingguard rule is met. - Data dependence: the row file
docs/data-dependence/features/trace-recording.mdand the generated page carry the same new text;datadep.Buildjoins the row body with single spaces, which matches the page diff.TestGeneratedPageIsUpToDateenforces it. The change lowers what the feature stores and the row says so. - Behavior change: named at the top of the PR (who, old, new, no off switch). The PR author is the row's "Decided by" owner.
- Host boundary: the filter lives in
internal/record(a library package); the proxy change is one call. No business logic was added to a host package. - Fail-open:
AllowedHeaderscannot fail or panic on any input, including nil. The record path keeps its own recover. - Commit: DCO sign-off present,
Assisted-By:used, no binaries, nogo.modchange.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 4 | a9fa5b882d23 |
blocking |
Verdict: blocking
Findings
- internal/record/wire.go:96-104 — the allowlist hardcodes one-client headers outside the agent packages, and its justification is false for two entries
- What fails: CLAUDE.md says a header that only one client sends lives in
agent.Identifyand the agent packages, nowhere else. This allowlist copies eight such names intointernal/record. The comment (wire.go:83-84) says they are "correlation ids that package agent reads". Package agent does not read two of them:x-claude-code-session-id(wire.go:97): no reader in any Go package.agent/identify.go:50says Claude Code names its session in the body, not in a header.x-task-id(wire.go:104): Bob's route id. Its readers areapply/apply.go:387andproxy/recctx.go:83, not package agent.
The PR body repeats the false claim: "the id headers packageagentreads", and "The agent package reads it [x-task-id] as a session id".
- Why it matters: the names duplicate knowledge the agent packages own (
agent/claudecode/claudecode.go:18,agent/codex/codex.go:48-50,agent/opencode/identify.go:22-23). When a client renames or adds an id header, the agent packages update and the recorder silently drops the new header from traces. No test fails. The comment then goes stale in the way CLAUDE.md bans. Also, the allowlist's own rule is "add it here on purpose, and only when it can never carry a credential". Two entries sit on the list with a reason that is not true, so that rule was not applied to them. - Fix: export the id-header names from package agent as one list, next to
Identify. Build the record allowlist from that list plus the generic names (content-type,accept,accept-encoding,user-agent, the version and beta flags). Correct or drop thex-claude-code-session-idandx-task-identries, or justify them with their real readers. Updatedocs/client-coverage.mdfor the client entries that stay in record.
- What fails: CLAUDE.md says a header that only one client sends lives in
Non-blocking
internal/record/wire_test.go:80-81: the test comment still describes the old design ("A credential in a header nobody expected is still caught, by redacting every value"). Now such a header is dropped, not redacted.proxy/recctx.go:28says "credentials are removed when written"; the filter now runs at queue time inproxy/proxy.go:1947.- The
x-stainless-prefix match (wire.go:110) admits any future header of that family without a list entry. The comment explains why it is safe today. It is a small exception to "add it here on purpose". Acceptable, but it weakens the guarantee the file comment promises. - The PR names the behavior change at the top, as required. Round 1 rules stopped me from reading PR comments, so I could not verify that the human's yes, and the confirm from the trace-recording row's "Decided by" (David Amid), are recorded. The integrator must check both before merge.
What I checked
- The full diff of the head against the base, and the code around each change.
- The old
dropHeaderdenylist:X-PasswdandX-Signaturepassed it, so the leak the PR fixes was real. Values went throughContent, which redacts by key shape only, so a non-key-shaped credential survived. - Every caller:
record.Wirehas one caller (proxy/sessionrec.go:288),AllowedHeadershas one caller (proxy/proxy.go:1947). No other host writes request headers.captureRequestwrites provider, model and body only. r.Headeris never mutated in place duringserve(copyHeaderscopies onto the outgoing request;scrubTokenworks on a copy), so the recorded headers are the client's own.- The OTLP path (
buildTurn) passes no headers, so only the wire file is affected. - Test compile level:
heldAuth,maskHeaders,credMask,zeroHeaders,heldHeader,target,Dispatcher.held,dispatch.Ref,captureRequest,newTestRecorder,wireLines,testSSEandccBodyall exist with matching signatures.scrubTokendoes not drop the test values (sk-is not thecg_live_prefix). - Build tags: the new end-to-end test carries
cg_record. CI runsgo test -race -tags cg_recordon./proxy/...(ci.yaml:259), so it runs. - No golden file or existing test asserts a now-dropped header.
- Data dependence: the row file
docs/data-dependence/features/trace-recording.mdand the generated page carry the same new text. The PR lowers what the feature stores and says so. docs/client-coverage.mdwas not updated; see finding 1.
Round 1 review. The recorder allowlist copied 8 one-client header names. Now agent.CorrelationHeaders lists them, built from the same constants the parsers use. internal/record keeps only generic names. - x-claude-code-session-id is dropped: nothing reads it. - A test checks the allowlist holds every agent name. - Comments say "allowlisted"; x-stainless- prefix is explained. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Replies to round 1 (both reviewers blocked)
Both reviewers, finding 1: one-client header names outside package
Non-blocking notes: the stale comments in Tests (macOS, Go 1.27.4): Local tests: waived (owner rule) |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 4 | b178da63a3b5 |
approve |
Verdict: approve
Findings
None.
Round 1 findings
-
Allowlist hardcoded one-client headers outside package agent, with a false justification for two entries — fixed. I verified each part of the fix in
b178da63:agent.CorrelationHeaders()(agent/identify.go:231-240) is built from the constants the parsers use:claudecode.AgentHeader, the newcodex.SessionHeader/ThreadHeader/ParentThreadHeader, the newopencode.SessionHeader/ParentSessionHeader, andagent.TaskIDHeader. The parsers now read the same constants (agent/codex/codex.go:55-57, agent/opencode/identify.go:28-29, agent/bob/bob.go:34). One source of truth; no copy left ininternal/record.x-claude-code-session-idis dropped. Nothing in the repo reads it. The wire test now usesx-claude-code-agent-id.x-task-idlives inagentasTaskIDHeader, with its real readers named:agent/bob(SessionID),apply/apply.go,proxy/recctx.go. The placement reason (bob imports agent, so the constant cannot live in bob) is documented and correct.TestAllowlistHoldsEveryAgentCorrelationHeader(internal/record/wire_test.go:152) fails if the two lists drift.- The PR body now separates the generic names from the correlation ids and states the readers correctly.
docs/client-coverage.mdstays unchanged. I accept the author's reason: no client row changed. The record allowlist no longer names a client, andTaskIDHeaderis a constant for a literalagent/bobalready used.
Non-blocking notes from round 1 are fixed too:
wire_test.go:80-82,wire.go:51andproxy/recctx.go:28now say "allowlisted", andstainlessPrefix(wire.go:104-106) states why the prefix is trusted.
Non-blocking
- The behavior change at the top of the PR still says "needs a human yes", and no comment on the PR records the yes. The PR author is the row's "Decided by" owner. The integrator should record the yes before the merge, per CLAUDE.md.
scripts/tooldefer-accuracy/tap.py:51still readsX-Claude-Code-Session-Idfrom live traffic. It does not read wire files, so the dropped allowlist entry does not affect it. Noted only so nobody mistakes it for a reader of the record.
What I checked
- Last review: round 1, a9fa5b8, 2026-11-26T14:30:31Z.
- New commits read: 2 —
0937ff80(merge origin/main) andb178da63(refactor(record): take client header names from package agent). - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review:
- Reviewer 2's round-1 review (14:29:02Z, before my posting time). Same finding 1 as mine, same non-blocking notes. I checked its proof lines myself in round 1; nothing new to add.
- The author's comment (14:42:35Z) describing the fixes. Each claim checked against the diff; all hold.
- Merge
0937ff80: it brings mainebd659bb(accountant v0.10.0, PR #1464). The merge diff againstebd659bbtouches only this PR's own files, so no manual edit rode in with it. - Fix
b178da63: the full diff ofagent/,internal/record/andproxy/recctx.go, plus the code around each change.
- Import graph:
internal/recordnow importsagent. Noagentpackage importsinternal/record, so there is no cycle.agentimports no host package. - The allowlist at init (wire.go:88-101) lowercases every agent name before adding it. All seven names are already lowercase.
- The drift test covers the agent-to-record direction. The other direction is structural: the allowlist is built from
agent.CorrelationHeaders(), so a name removed from agent leaves the allowlist with it. - Recorded behaviour change versus round 1: Claude Code traces lose
x-claude-code-session-id, which no code reads. Nothing else changed in what is written. - Data dependence: the row text ("the client's session ids") stays true for the names now sourced from agent. No row change needed for the fix commit.
- Round-1 checks that still hold at the new head: single caller each for
record.WireandAllowedHeaders;r.Headernot mutated in place; the OTLP path writes no headers; the end-to-end test runs under-tags cg_recordin CI (ci.yaml:259).
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 4 | b178da63a3b5 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Round 1, mine, finding 1 (one-client header names outside package
agent) — fixed inb178da63.agent.CorrelationHeaders()(agent/identify.go:235-242) now owns the list. It is built from the same constants the parsers use:claudecode.AgentHeader, the newcodex.SessionHeader/ThreadHeader/ParentThreadHeader, the newopencode.SessionHeader/ParentSessionHeader, andagent.TaskIDHeader. The parsers were changed to read those constants (agent/codex/codex.go:55-57, agent/opencode/identify.go:28-29, agent/bob/bob.go:34), so there is one copy.internal/recordkeeps only the generic names and thex-stainless-prefix, and adds the agent list when it builds the map (wire.go:89-103). No client name is spelled inrecordany more.TestAllowlistHoldsEveryAgentCorrelationHeader(wire_test.go:150-160) fails if a name is added toagentand not to the allowlist. The other direction cannot drift, because the map is built from the list.x-claude-code-session-idis dropped. Nothing in the repo reads it. Correct.- The PR body now states the real readers.
docs/client-coverage.mdstays unchanged; no client row changed. Correct. - No import cycle:
agent/bobimportsagent;agentdoes not importagent/boborinternal/record;internal/recordimportingagentis a library-to-library import.
- Round 1, reviewer 1, finding 1 — the same defect. Fixed by the same change. I checked it myself; my proof is above. Reviewer 1's extra point, that
x-task-id's readers areapplyandproxy/recctxrather than package agent, is also answered:agent/bob.SessionIDreads it throughagent.TaskIDHeader, andapply/proxy/recctxreach it through that method, so the name now lives inagentwith its direct reader. - Round 1 non-blocking notes (both reviewers) — fixed.
WireCall.Headers(wire.go:51) andproxy/recctx.go:28say "allowlisted".stainlessPrefix(wire.go:105-108) carries the reason the prefix is trusted. Thewire_test.gocomment describes the allowlist design.
Non-blocking
agent/identify.go:225-227— theTaskIDHeaderdoc namesapplyandproxy/recctx.goas readers. Both read the header indirectly, throughagent/bob.SessionIDandapply.ExplicitSessionFor. The direct reader isagent/bob. A precision point in a comment only.
What I checked
- Last review: round 1, a9fa5b8, 2026-11-26T14:29:02Z.
- New commits read: 2 on the PR plus 1 from main inside the merge.
0937ff80merge origin/main. Bringsebd659bb(accountant v0.10.0 bump, from main, not this PR's change). The merge touchesdocs/data-dependence.mdon two different rows (Trace recording from this branch, Metrics push from main); git resolves both, and the result keeps each side's row. No conflict was resolved by hand. The row files and the page stay in sync.b178da63refactor(record): take client header names from package agent. The fix commit. Read in full, plus every changed file around the change:agent/identify.go,agent/bob/bob.go,agent/codex/codex.go,agent/opencode/identify.go,internal/record/wire.go,internal/record/wire_test.go,proxy/recctx.go.
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review:
- Reviewer 1's round-1 review (14:30:31Z). Finding 1 matches mine. I checked its extra claim (
x-task-idreaders) myself; see finding 2. - The author's comment (14:42:35Z) describing the fixes. I verified each claim against the code: the constants exist and are used by the parsers; the allowlist map is built from
agent.CorrelationHeaders; the drift test exists;x-claude-code-session-idis gone; the PR body's reader list matches the code.
- Reviewer 1's round-1 review (14:30:31Z). Finding 1 matches mine. I checked its extra claim (
- The fix commit changes no behavior on the wire: the allowlist holds the same seven id names as before plus the six it always had, minus
x-claude-code-session-id(dropped, nothing reads it). The generic names and thex-stainless-prefix are unchanged. Fail-open paths are unchanged. headerAllowedlowercases before the map lookup, and every constant inCorrelationHeadersis lowercase, so casing cannot drop a name.- Data dependence: the fix commit touches no docs. The row text from round 1 ("the client's session ids") is still true. The generated page is unchanged and in sync.
- Commit: DCO sign-off present,
Assisted-By:used, no binaries, nogo.modlines added by this PR.
agent/bob reads x-task-id directly. apply and proxy/recctx.go read it through bob.SessionID. Only the comment changes. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Round 2: both approve. One comment fix.Reviewer 2 noted that the Local tests: waived (owner rule) |
…signal (#1470) The test const fakeSecret clashed with #1469. The startup line now reads tenants != nil, the same signal the proxy decides on. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…signal (#1470) The test const fakeSecret clashed with #1469. The startup line now reads tenants != nil, the same signal the proxy decides on. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
feat(keepalive): the audit-sink rule applies in hosted mode only (#1457) A single-tenant proxy holds only its own user's credential, in memory. It now holds a thread and pings with no dashboard. A hosted proxy with no recorder still holds nothing. - keepalive.MayHoldCredentials decides; the proxy calls it from keeper.mayHold (hosted = Options.Tenants != nil). - The gate covers recordTouch, canPing, session arming and the Ping route. - With no dashboard the Ping route reads the cold gate from the keeper (Keeper.WarmFacts), and the route stays mounted. - The credential stays in memory: no new file, log or metric. Fixes #1457 fix(keepalive): round 1 of #1470 - WarmFacts uses the entry's cacheTTL; a 1-hour-tier test pins it. - Test for the header hold with no dashboard. - Fix the route-table and Ping-route comments. - body-stash row: the in-memory copies now exist with no dashboard too. test(keepalive): the 1-hour press must return 200 and send one ping (#1470) fix(keepalive): rename the test key; log hosted mode by the decision signal (#1470) The test const fakeSecret clashed with #1469. The startup line now reads tenants != nil, the same signal the proxy decides on. Behavior change (the audit-sink rule applies in hosted mode only: a single-tenant proxy without --dashboard holds the user's own credential in memory only and pings) approved by the owner in the integrator session: "1470 yes". Approvals at b2472bd carried over (SAME CHANGE: re-signed merge commit). Proxy-boundary and credential checks passed. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Behavior change (needs a human yes)
--record, and any replay or analysis that reads theheadersfield of a.wire.jsonlfile.Summary
A credential under an unexpected header name reached the wire file. Now only an allowlist of safe names is written. Fixes #1466.
What changed
internal/record/wire.go:dropHeader(name denylist) is gone.allowedHeadersandheaderAllowedreplace it.AllowedHeadersis the one shared filter.wireHeadersstill redacts each value.proxy/proxy.go: the proxy copies only allowed names (record.AllowedHeaders), notr.Header.Clone().internal/record): content-type, accept, accept-encoding, user-agent, anthropic-version, anthropic-beta, openai-beta, and thex-stainless-prefix. The prefix is trusted because Stainless telemetry has a fixed shape.agent.CorrelationHeaders): the list lives in packageagentand uses the constants the client parsers use. It holdsx-claude-code-agent-id(agent/claudecode),session-id,thread-id,x-codex-parent-thread-id(agent/codex),x-opencode-session-id,x-opencode-parent-session-id(agent/opencode) andx-task-id. A test checks the record allowlist holds every name in that list.agent.Identifyreads the claudecode, codex and opencode ids.x-task-idis read byagent/bob(SessionID),apply/apply.go(the host id of a route) andproxy/recctx.go(the recorder's session key).x-claude-code-session-id. Nothing in the repo reads it. Claude Code names its session in the body.How it was tested
macOS, Go 1.27.4.
--recordon:X-Passwd,X-Signature,X-Bob-Session,AuthorizationandX-Api-Keycarrysk-test-SECRET-123. The whole record directory has no secret.anthropic-versionis kept.proxy/credmask_test.go:heldAuthkeeps only auth headers.maskHeadersdiffers from the plaintext and unmasks back.targetandDispatchershow no secret underencoding/json,%+v,%vand%#v.CONTEXT_GURU_CAPTUREthrough the handler and directly: no header, no secret in the file.headerAllowedfailsTestRecordWritesHeadersByAllowlist,TestWireHeadersDropCredentialsandTestAllowedHeadersCopiesOnlyListedNames.go build ./...and-tags cg_record,go vet, plaingo testofinternal/record,proxyandcomponents/all, and-race -runon the new tests: all pass.Local tests: waived (owner rule)
Data dependence
Trace recording stays a content feature. This PR lowers what it stores. It adds no data dependence. The row in
docs/data-dependence/features/trace-recording.mdhas a new note, andgen-datadepis run.Open questions
x-task-id(Bob) fine to keep? The agent package reads it as a session id.