fix(e2e): rewrite downloads with the full ledger pass, the way traces are
What and why
The runner labels a redacted text download redaction: "complete", and docs/security.mdx tells users a download is "rewritten the way trace text is". The code behind that label only matched whole secret values, so anything the whole-value pass cannot see sat inside a file that the report and an ArtifactStore export both treat as clean.
The trace path does more. redactFragments (packages/e2e/src/internal/redact.ts:129) runs three passes over the text: whole values, sliding 8-character windows of every registered value, and each base64 or base64url run decoded from all four offsets. trace-redaction.ts:94 calls it for every text entry in an archive. The download path called ledger.redact (packages/e2e/src/run/artifacts.ts:285), which is the first pass only, and it still stamped the record complete.
Where the gap shows up in practice:
- An observation cut. The screen reader clips a filled secret to
ad-secret-Qx7-, the app serves that string later in a CSV export, and the fragment matches no whole value. The file keeps it and getscompleteanyway. - A base64 copy. The scenario #663 fixed for traces, but served as a download instead of recorded in one: an
Authorization: Basic <base64>line in a served text export walks through untouched. - The label is what makes it hurt. #561 made the label honest by scanning before stamping, and a store that exports only
completefiles trusts that stamp, so a fragment under it ships.
The fix is one line: redactDownload now calls secrecy.ledger.redactFragments(text). The doc comment above the function already claimed trace parity, so it stays as it is. docs/security.mdx does not change either. It documented the behavior this PR restores, and CONTRIBUTING.md says that where docs and code disagree, the code is the bug.
flowchart LR
A[download lands] --> B{secret reached the session?}
B -- no --> C[kept as served · incomplete]
B -- yes --> D{text-like?}
D -- no --> C
D -- yes --> E["ledger.redactFragments: whole + fragments + base64"]
E --> F[rewritten · complete]
The change itself:
// packages/e2e/src/run/artifacts.ts, redactDownload
- const redacted = secrecy.ledger.redact(text);
+ const redacted = secrecy.ledger.redactFragments(text);
And the test that pins the behavior, run through the real artifact sink (createAttemptArtifacts) rather than the ledger in isolation:
const cut = SECRET.slice(6, 20);
const encoded = Buffer.from(SECRET).toString('base64');
writeFileSync(path.join(artifacts.dir, 'downloads', 'export.txt'), `cut=${cut}\nencoded=${encoded}\n`);
artifacts.sink.register('download', 'downloads/export.txt');
The record says complete on both builds. What changes is the bytes on disk.
Verified
Ran it locally: yes
On the old code the test fails with the fragment and the base64 run still sitting in the saved file while the record already claims complete:
- cut=<secret:api-key>
- encoded=<secret:api-key>
+ cut=ad-secret-Qx7-
+ encoded=ZG93bmxvYWQtc2VjcmV0LVF4Ny0yNzE4
| main | this branch |
|---|---|
cut=ad-secret-Qx7- left in the saved download | cut=<secret:api-key> |
encoded=ZG93bmxvYWQtc2VjcmV0LVF4Ny0yNzE4 left in the saved download | encoded=<secret:api-key> |
record says redaction: "complete" | record says redaction: "complete", and now the file earns it |
- After the change,
pnpm --filter e2e exec vitest run tests/unit/artifact-store.test.tsreports17 passed, andpnpm --filter e2e run buildpluspnpm --filter e2e run typecheckboth exit 0. - End to end through the real runner:
pnpm --filter e2e exec vitest run --project integration tests/integration/trace-secrets.test.tspasses 9 of 9, includingdownloads after a fill: a text download is rewritten, labelled complete, and stored cleananddownloads without a fill: the file is kept as served and labelled incomplete. pnpm bench:ab --suite testbed -- tests/browser.e2e.tsagainst the merge baseb5dc0f8, 14 pairs in random order:Every test ran the same steps with the same outcome on every run of both builds.and every counter matched. Timings resolve tosame.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 10.81 s (10.58 s-11.13 s) | 10.61 s (10.08 s-11.00 s) | -2.0% (-4.1% to +1.9%) | same |
| suite (sum of attempts) | 3.74 s (3.61 s-3.83 s) | 3.67 s (3.63 s-3.78 s) | -0.7% (-4.0% to +3.3%) | same |
Checklist
- Changeset added (
pnpm changeset):.changeset/download-full-ledger-pass.md, a patch bump fore2e. - Breaking change: no.
redactionkeeps its values and their meaning, the label semantics do not move, so the title carries no!. - Docs updated in the same PR:
docs/security.mdxalready describes this exact behavior ("rewritten the way trace text is"), so there is no prose to fix, and noskills/e2e/page covers the redaction passes. - Contract change: none. No emitted
.d.tschanges and no wire schema touched, sincecompleteandincompletealready exist in report-1. - Engine contract (
e2e/engine): not touched, so no engine changesets are needed.