fix(secrets): redact plain-string secret values from traces and text downloads

Merged
OK
2mo ago
+149-129

What and why

  • A registered secret a test passes as a plain string (app.open('/?token=' + KEY), fill(KEY)) was redacted from titles, labels, and agent input since #727, but stayed verbatim in trace.zip. #727 left this out on purpose: trace rewriting was gated on the session's exposure level, which only a secret fill or an engine-held secret (basic auth) raises. A plain string raises neither, so the trace was kept as recorded and labeled not-required.
  • The gate assumed the runner sees every way a value reaches the app. It does not: a URL, a fill, or the app's own config never touch the exposure model. Traces and text downloads are now rewritten whenever the session's ledger holds a value (every static secret, and a provider's once resolved), the same way reports and observations already are. redactsRecordings in packages/e2e/src/run/secrecy.ts is the one place that decides.
  • The engine exposure level only fed that gate, so it is removed. Exposure now decides pixels and saved-session taint only. Screencast frames are still dropped only after a secret fill: a plain string is protected as text only, like an engine-held secret.
  • Labels: a trace from a session that knows a secret value is now complete (scanned) instead of not-required, and a scanned text download complete instead of incomplete. not-required stays for runs with no secret value.
  • tests/integration/plain-string-secrets.test.ts now records a trace (trace: 'on'), adds a plain-string fill, inflates every zip entry, and asserts no plain, base64, or base64url form of the value (any case) remains. It fails on main on trace.zip!trace.trace.
  • Docs: security.mdx (Redaction, Where redaction stops, the artifacts table), debugging.mdx, reference/engine.mdx, reference/errors.mdx (TRACE_WITHHELD), and the AGENTS.md invariant.
export function redactsRecordings(secrecy: SessionSecrecy): boolean {
  return !secrecy.ledger.isEmpty;
}

Cost

Every trace in a project with a secret is now scanned, not just traces after a fill. A trace with nothing to redact is still not rewritten (bytes untouched). Testbed (has credentials), full suite with --trace on, 70 traces, 9.4 MB:

mainthis branch
wall15.4s, 15.9s16.4s, 16.5s
user CPU17.6s, 18.8s21.6s, 22.1s
trace labels67 not-required, 3 complete70 complete

Roughly 55 ms CPU per trace. The scan is the existing redactFragments pass from #663; I did not add a prefilter, for the reason #663 gives (it would duplicate the spelling rules).

Verified

Ran it locally: yes

  • testbed, scratch config (trace: 'on', secrets: { probe: 'plain-Zr8Kq2Wm5Tx9' }) and one test: app.open('/forms?token=' + S), screen.getByLabel('Full name').fill(S), toHaveValue(S). Ran node node_modules/e2e/dist/cli/bin.js run --config e2e.plainsecret.config.ts on a main build and on this branch, then inflated every zip entry under .e2e and counted the plain, base64, and base64url forms of the value (case-insensitive).
mainthis branch
trace.zip!trace.trace200
trace.zip!trace.network20
trace redactionnot-requiredcomplete
  • Mutation check: putting the old gate back (return secrecy.exposure.withholdsPixels) and rebuilding fails the integration test on trace.zip!trace.trace.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.