fix(e2e): keep secrets out of observed node fields and collapsed cuts
Merged
OK
2mo ago+824+824+012345678901234567890123456789-378-378-012345678901234567890123456789
Registered secrets leaked into model input and .e2e/cache entries through two holes:
- B46:
formatNodeprintedtestidraw, andprojectTreepassedframePath(an iframename) through raw. Selectors and attribute keys were also never redacted. - B34/B44/B47: an engine collapses whitespace, then cuts name at 256 and text at 512.
redactCutonly compared the cut against the value as written, so a secret likeletters\nlettersleft a plaintext prefix of its collapsed form in observation text, the executor tree, and cacheendAnchors.
Fix
redactNode(packages/e2e/src/agent/observation.ts) runs once inprepareObservationand redacts every field ofSemanticNode. It is driven byNODE_FIELDS, a mapped type with one entry per contract field, so a new field does not compile until it says how it is redacted. Keys that are not in the contract are dropped.formatNodeandprojectTreenow take a brandedRedactedNodeand noredactargument, so a raw node no longer type-checks there. MCPlocateand failure evidence go through the same path.- Each string field is redacted as written and in its
collapseTextform. If only the collapsed form holds a secret, the field is stored collapsed and masked. redactCutandredactFragmentsinpackages/e2e/src/internal/redact.tsnow compare onreadingKey: case-folded, with each whitespace run read as one space, plus an index map back to the original text. This catches cut and fragment forms after LF, tab, CRLF, NBSP, or repeated spaces.- Descriptors, end anchors, and relocation (
describeTarget,containerKey,describeNodes,relocateDescriptor,describePosition,describeAnchors,anchorsPresent) take onlyRedactedNodeand lose their own weaker redact pass, which redacted before collapsing and never appliedredactCut.ReplayHost.redactgoes with it. readingKeyreturns the text as-is when it has nothing to collapse. Otherwise it builds the key in typed arrays and keeps one offset pair per collapsed run, so a large trace text stays cheap. On a 22 MB newline-heavy text with one secret, main uses 98 MB, a naive per-unit map 954 MB, and this branch 262 MB.- Before anchors are derived, the start capture is redacted again with the current ledger (
redactNodesAgain). Otherwise a provider secret resolved mid-step would make an unchanged node look new. describeActionredacts each acted-on node again with the current ledger for the same reason, so a secret resolved inside the action (a provider-backedtypeSecret) is masked in the recorded descriptor and summary, as main'sdescribeTarget(node, redact)did.- The container key an action sat
withinis redacted again with the current ledger too, as main'scontainerKey(..., redact)did at placement time. docs/security.mdx: the claim that cache entries are secret-free now holds. "Where redaction stops" no longer lists whitespace-collapsed cuts.
Verified
Ran it locally: yes
- Real CLI with a deterministic
StepExecutorin a scratch project (/tmp/oskar-fix-observation-secret-leaks/proj-*). A page with a secretdata-testid, a secret iframename, and six variants of a whitespace secret (letters plus LF, tab, CRLF, NBSP, or 3 spaces; hex plus LF), each padded so it is cut at 256 and 512. - Two runs (record, then replay). A scan of the executor's
observe({ tree: true })dumps,.e2e/cache/*.json, and the reports, looking for the raw value, its collapsed form, its first 24 chars, and a 30-char collapsed prefix.
| surface | main | this branch |
|---|---|---|
| observation text | probe raw; prefixes of all 6 whitespace variants | clean |
| executor tree | probe raw; prefixes of all 6 whitespace variants | clean |
.e2e/cache entry (endAnchors) | prefixes of 5 whitespace variants | clean |
| report / junit / summary | clean | clean |
| replay | replayed | replayed (anchors still match) |
- New regression tests fail on main and pass here:
secret-ledger.test.ts: 16 of 86 fail on main. Covers LF, tab, CRLF, NBSP, repeated spaces, and hex, with the cut in the first part, on the collapsed space, or in the second part, plus fragments.agent-observation.test.ts: every field redacted; cut at the 256/512 limits across text, tree, and anchors.trace-recorder.test.ts: a secret registered after the node was captured is masked in the recorded target.agent-policy.test.tssecurity invariant: a full record and replay run through the fake engine, asserting no value or fragment reaches observations, the cache file, or the report. It fails on main.
- Cost:
| measure | main | this branch |
|---|---|---|
prepareObservation, 5000 nodes | 8.7 ms | 18.8 ms |
redactFragments, 22 MB text, single spaces | 668 ms / +98 MB | 590 ms / +98 MB |
redactFragments, 22 MB text, newlines + indent | 709 ms / +98 MB | 746 ms / +262 MB |
A size and memory regression test sits beside the linear-scan test in secret-ledger.test.ts.