fix(run): redact run-level errors with the run's secrets
What and why
A run-level error could carry a secret into report.json, the GitHub reporter, and the terminal in the clear. serializeError (packages/e2e/src/internal/errors.ts) takes an optional redact and falls back to identity when a call site gives none, and several run-level paths gave none: a suite hook failure (packages/e2e/src/run/realm.ts:222), engine disposal and collection errors (packages/e2e/src/run/execute.ts:339, :405), a worker's fatal error (packages/e2e/src/run/worker/entry.ts:123), an in-memory run's fatal (packages/e2e/src/run/in-process.ts:71), model preflight (packages/e2e/src/run/standalone.ts:204), the runner's failure sink (packages/e2e/src/run/runner.ts:368), and the scheduler's own protocol errors (packages/e2e/src/run/scheduler.ts:633, :694, :771, :792). Sibling calls on the same objects already passed a redactor, so the omission was easy to miss.
The gap matters because a hook or an engine can quote a value the app echoed back. A beforeAll that signs in and fails with the response body in its message is the common shape: by the time the message reaches the reporter it is a plain string, and the report renders run.errors verbatim (packages/e2e/src/report/build.ts:746). docs/security.mdx already says the runner replaces every occurrence of a registered secret value with <secret:name> in reports, so these paths were breaking a promise the rest of the runner keeps.
The fix installs the process's live secret ledger (processSecrets in packages/e2e/src/run/secrecy.ts) as the default redactor, so serializeError uses it when a call site gives none:
// packages/e2e/src/internal/errors.ts
const redact = extras.redact ?? redactorSlot.get(globalThis) ?? ((text: string): string => text);
The slot is a globalThis value (internal/realm-slot.ts, the same mechanism secrets.ts uses for its registry). internal/ cannot import run/, where the ledger lives, and a project can load a second copy of e2e, so a module-local variable would not be shared. An explicit per-call redactor still wins, and the slot clears to identity when no runner is active.
flowchart LR
A[error thrown] --> B["serializeError(error, options)"]
B --> C{"options.redact?"}
C -- yes --> D[use it]
C -- no --> E{"process ledger installed?"}
E -- yes --> F["redact with processSecrets"]
E -- no --> G[identity]
Verified
Ran it locally: yes
A scratch project with one secret (secrets: { probe: 'plain-secret-value-1234' }), a fake engine, and a beforeAll that throws the value in its message. Ran the built CLI (packages/e2e/dist/cli/bin.js run) from a main worktree and from this branch.
| main | this branch |
|---|---|
beforeAll failed: sign-in failed for plain-secret-value-1234 | beforeAll failed: sign-in failed for <secret:probe> |
The same value in run.errors of report.json:
"run": { "errors": [{
"code": "HOOK_FAILED",
- "message": "beforeAll failed: sign-in failed for plain-secret-value-1234",
+ "message": "beforeAll failed: sign-in failed for <secret:probe>",
packages/e2e/tests/unit/errors.test.tscovers the resolution order: the installed redactor is used when none is given, a per-call one wins, and no redactor means identity.packages/e2e/tests/unit/session-secrecy.test.tscovers the wiring, that importing the run layer installs the ledger so a serialized error carries no secret. Both fail on the pre-fix code and pass here.pnpm --filter e2e run build,pnpm --filter e2e run typecheck, andoxlinton the changed files exit 0.pnpm --filter e2e run test:unitfails the same files as a clean tree (17, all Windows path and CRLF cases), so nothing here regresses.
Checklist
- Changeset added (
pnpm changeset):.changeset/error-default-redactor.md, a patch bump fore2e. - Breaking change: no.
serializeErroris internal, the default only adds redaction where there was none, and an explicit per-call redactor keeps winning. - Docs updated in the same PR:
docs/security.mdxalready documents this behavior for reports, so there is no prose to fix, and noskills/e2e/page covers the error-serialization path. - Contract change: none.
serializeErroris not indist/index.d.tsordist/engine/index.d.ts, and no wire schema is touched. - Engine contract (
e2e/engine): not touched, so no engine changesets are needed.