Skip to content

fix(trueforge): match the redaction sentinel exactly and publish less of a secret - #463

Closed
ethanstoner wants to merge 1 commit into
truefoundry:mainfrom
ethanstoner:fix/secret-redaction-sentinel
Closed

ethanstoner wants to merge 1 commit into
truefoundry:mainfrom
ethanstoner:fix/secret-redaction-sentinel

Conversation

@ethanstoner

@ethanstoner ethanstoner commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #423.

Both defects, and one correction to the proposed fix

Defect 1 — sentinel matched by substring. isRedactedSecretValue used .includes(), so any real secret containing ***REDACTED*** anywhere was read as "keep the stored one". The value the user typed was discarded with nothing saying so: the old secret survived an update, and a create failed with a message about a missing key. It is now a whole-value test.

One correction. The issue proposes value === SECRET_REDACTION, on the grounds that "the redaction function only ever emits that exact standalone string". It does not — that is only the short-secret branch. A secret at or above the threshold masks to the sentinel plus a suffix, and a client round-tripping an unedited form sends that back. Exact-equality-only would classify it as a real value and store the mask as the secret, which is a worse bug than the one being fixed. So the test matches the two shapes toRedactedSecretValue actually emits, anchored to the whole value, and nothing else.

A secret whose entire content is exactly one of those two shapes remains indistinguishable from a mask. Nothing in-band can separate them — only a separate keep field beside the value could, which is an API change rather than a fix. Left alone, and documented in the module so the next reader does not have to rediscover it.

Defect 2 — prefix/suffix leak. Any secret of ten characters or more came back as first three + last three, so a ten-character key published six of its ten to every viewer of a settings response, screen share, or captured log. Now: last four only, and only for secrets of at least twelve, so eight characters stay unknown at the threshold. Shorter secrets are masked completely. Suffix-only matches what other providers publish, as the issue suggests.

before   toRedactedSecretValue('sk-ant-01234')  ->  sk-***REDACTED***-234
after    toRedactedSecretValue('sk-ant-01234')  ->  ***REDACTED***-1234

Two existing tests asserted the defect

mcpServers.test.ts and sandboxProviders.test.ts each sent a redacted-looking value that was not the stored secret's mask (oth-***REDACTED***-xxx) and asserted the stored secret survived, with the comment:

// Any value containing ***REDACTED*** is treated as keep, not only the exact GET mask.

That is defect 1 written down as intended behaviour, so both now assert the opposite: a value that merely contains the sentinel is stored like any other rotation. Flagging it explicitly since inverting an existing assertion deserves a look rather than a skim.

The MCP tests also hardcoded the wire form ('Bea-***REDACTED***-ken'). That is now derived from toRedactedSecretValue, so the mask has one definition and the tests cannot drift from it again.

Verified

  • tests/unit/apis/ + tests/unit/utils/ — 146 passed, 15 suites, including 11 new cases covering both defects, the round-trip keep, the create-with-mask refusal, and rotation.
  • tsc --noEmit clean for src and for tests/unit/tsconfig.json.
  • prettier --check and eslint clean on the files touched.
  • Six failures elsewhere in the package (LocalSandboxProvider, Code Mode UDS) are a Windows host — unix sockets and symlink paths — and fail identically on a clean checkout with this branch stashed, so they are not from this change.

Notes

  • .changeset/secret-redaction-exact-mask.md added, per the packages/trueforge rule in AGENTS.md.
  • No wire-shape or schema change: the mask is a string field either way, so packages/trueforge-sdk and the OpenAPI spec are untouched.
  • Defect 2b in the issue — the round-trip relying on the substring check — is closed by the same change, since the emitted mask is now what the keep test recognises.
  • Unrelated, in case it is useful: pnpm --filter @truefoundry/trueforge test cannot run on a Windows host, because the script uses a NODE_OPTIONS='…' node … inline env prefix and cmd.exe has no such syntax. I ran jest directly to get around it. That looks like the same family as npx @truefoundry/trueforge command fails to start the server on Windows Terminal (PS, CMD, and Git Bash) #427 and Feat: add cross platform support #374, so I have not touched it here.

Note

Medium Risk
Changes secret persistence and response masking for settings APIs (MCP headers, sandbox/model providers); clients may see a different mask string on GET, but round-trip keep still works for the new shapes.

Overview
Tightens settings secret redaction so GET masks leak less and PUT “keep existing secret” only applies to the exact mask shapes the API returns—not any string that happens to contain ***REDACTED***.

Response masking no longer publishes the first three characters. Long secrets (≥12 chars) now appear as ***REDACTED***- plus the last four characters; shorter secrets are fully redacted.

Write-back detection in isRedactedSecretValue switches from a substring check to whole-value matching: bare sentinel or the fixed suffix-mask form from toRedactedSecretValue. Real secrets that embed the sentinel are stored as typed instead of silently keeping the old value. MCP header auth and sandbox provider API tests are inverted accordingly; dedicated unit tests cover masking, recognition, and resolveStoredSecretValue.

Reviewed by Cursor Bugbot for commit 2fe3696. Bugbot is set up for automated code reviews on this repo. Configure here.

… of a secret

Settings secrets are masked on the way out and the mask is sent back on the next PUT to mean "keep
what you already have". Two things were wrong with that exchange.

The keep test was a substring test. Any real secret containing ***REDACTED*** anywhere in it was
read as a mask, so the value the user typed was discarded without an error saying so: the old secret
stayed on an update, and a create failed with a message about a missing key. It is now a whole-value
test against the shapes the redaction function actually emits.

Exact equality with the bare sentinel alone would not do, because that is not the only shape emitted
— a long secret masks to the sentinel plus a suffix, and a client round-tripping an unedited form
sends that back. Treating it as a real value would store the mask as the secret. Both shapes are
recognised, and nothing else is.

A value whose entire content is one of those two shapes is still indistinguishable from a mask.
Nothing in-band can separate them; only a separate field meaning "keep" could, which is an API
change rather than a fix, so it is left alone and the residual case is documented.

The mask also published too much. Any secret of ten characters or more came back as its first three
and last three characters, so a ten-character key showed six of its ten to every viewer of a settings
response, a screen share, or a captured log. It is now the last four characters and only for secrets
of at least twelve, so eight remain unknown at the threshold; shorter ones are masked completely.
Suffix-only matches what other providers publish.

Two existing cases asserted the substring behaviour deliberately, one for MCP header auth and one
for the sandbox provider api_key, each sending a redacted-looking value that was not the stored
secret's mask and expecting the stored secret to survive. Those pinned the defect, so they now
assert the opposite: a value that merely contains the sentinel is stored like any other rotation.
The hardcoded wire form in the MCP tests is derived from the redaction function instead of written
out, so the mask has one definition and the tests cannot drift from it again.

Verified: unit suites for apis/ and utils/ pass, 146 tests across 15 suites. tsc clean for src and
for tests/unit. Six failures elsewhere in the package are a Windows host — unix sockets and symlink
paths under LocalSandboxProvider — and fail identically on a clean checkout.
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2fe3696

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@truefoundry/trueforge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chiragjn

Copy link
Copy Markdown
Member

Thank you for contributing but we have decided not to go ahead with this issue. Please see #423 (comment)

We would recommend getting maintainer approval on an issue before starting any implementation work.

@chiragjn chiragjn closed this Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secret redaction: sentinel matched by substring (real keys containing ***REDACTED*** silently dropped) and 3+3 char prefix/suffix leak for short secrets

2 participants