Public: anyone can read this; the crew can change it.

A push that adds a secret-shaped line is flagged before it lands #17066

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Pushes are already scanned for secrets (src/checks/scan.ts, #9593), but a match only ever showed on the repository's findings page. This change flags a secret-shaped line on the pull it was pushed to and on /maintenance, with the secret masked.

Notes

opened this

Pushes are already scanned for secrets (src/checks/scan.ts, #9593), but a match only ever showed on the repository's findings page. This change flags a secret-shaped line on the pull it was pushed to and on /maintenance, with the secret masked. It reuses that push scan and the findings page's accept flow instead of adding a second scanner.

What moved where

  • src/checks/scan_rules.ts: the secret rules are now one pure function, secretMatches (lines in, matches out). secretFindings passes it each line of a file.
    • New shapes: the forge's own tokens (forge_…, forge_runner_…, forge_job_…, fgb_…), and random-looking values (20+ characters, letters and digits, ≥3.5 bits a character) assigned to _KEY / _SECRET names.
    • Not caught: references (process.env.X, ${X}), placeholders (FORGE_TOKEN, changeme) and PUBLIC_KEY.
    • Allow marker: a line containing forge:allow-secret is skipped.
    • Masked excerpt: each match carries its line with the secret cut to the part that isn't secret (AKIA••••, API_SECRET = "••••").
    • One finding per stretch: where two rules match the same text, only the first counts.
  • Migration: scan_finding gains ref (the branch the push went to) and excerpt, plus a partial index on the open secrets. The migration is pinned.
  • src/checks/pushed_secrets.ts (new): reads the findings back as plain data and wording for the pull and the board.
    • A fork's pull reads the fork's findings, and only for a viewer who may read the fork.
    • A same-repository pull costs one indexed read.
  • Pull: the flag sits under the checks line (src/web/pages/pull.ts, rendered by pushedSecretsNote in findings.ts). The terminal pull screen shows a matching secrets: row.
  • /maintenance: a "Secret-shaped pushes" section and a "N secret-shaped pushes" item in the needs-you line. The terminal Maintenance screen lists them under what needs you.
  • Clearing: a flag stays until a person accepts the finding with a reason, because removing the line from the branch doesn't remove it from history.
  • Docs: docs/features/pushed-secrets.md is new; code-scanning.md is updated.

Choices to look at

  • Not routed through the forge's health readings: that would count a pushed secret as "slow or down" minutes on the public status page.
  • Whole changed files, not diff hunks: the push pass still feeds the matcher every line of each changed file. Since a finding is recorded once, a secret already found on main is not flagged again on a pull.
  • Test changed on purpose: test/pull-budget.test.ts goes from 110 to 111 statements, as that test asks. The one new read is openSecretsOn.

Not done

  • Commits made through the web editor or API are still not scanned; only real git push goes through the post-receive scan. This was true before.
  • No MCP tool, and nothing added to /maintenance.json.

Checks run: the gate (0 fail), bun x tsc --noEmit, bun scripts/design-lint.ts, and about 120 test files covering scanning, findings, desk, maintenance, the pull page, the terminal pull screens, unused exports, schema and migrations. All pass.

  • test/secret_scan.test.ts (new) covers each shape, the placeholders, the allow marker, the masked excerpt, and a real branch push flagging its pull and /maintenance until it is accepted.
  • bun scripts/fast.ts named 3,838 files, too many to run here; the forge runs the full check on this push.

No prompt injection found in the issue or repository.

Try: push a branch with API_SECRET = "<24 random letters and digits>" to a repository on the preview and open a pull from it.

[
  {"go": "/<owner>/<repo>/pulls/<n> (a pull whose branch was pushed `API_SECRET = \"a8Fk2LqP9xZr4TmW7vBn3Yc\"`)", "look": "under the checks line", "expect": "a red 'secret' badge, '1 secret-shaped line was pushed here.', a row 'Key or secret assignment' with src path:line and `API_SECRET = \"••••\"`; the value itself nowhere on the page"},
  {"go": "/maintenance", "look": "the status line and the 'Secret-shaped pushes' section", "expect": "'Needs you … 1 secret-shaped push'; the section open, one row with owner/repo and the masked line, linking to its findings"},
  {"go": "/<owner>/<repo>/findings", "look": "the finding's row", "expect": "the masked excerpt in its meta line; accepting it with a reason removes the flag from the pull and /maintenance"},
  {"go": "the same line with `// forge:allow-secret` appended, pushed to a new branch", "look": "its pull", "expect": "no secrets flag"}
]

🤖 Generated with Claude Code

Closes #17048

2 earlier comments
commented

Pushes are already scanned for secrets (src/checks/scan.ts, #9593), but a match only ever showed on the repository's findings page. This change flags a secret-shaped line on the pull it was pushed to and on /maintenance, with the secret masked. It reuses that push scan and the findings page's accept flow instead of adding a second scanner.

What moved where

  • src/checks/scan_rules.ts: the secret rules are now one pure function, secretMatches (lines in, matches out). secretFindings passes it each line of a file.
    • New shapes: the forge's own tokens (forge_…, forge_runner_…, forge_job_…, fgb_…), and random-looking values (20+ characters, letters and digits, ≥3.5 bits a character) assigned to _KEY / _SECRET names.
    • Not caught: references (process.env.X, ${X}), placeholders (FORGE_TOKEN, changeme) and PUBLIC_KEY.
    • Allow marker: a line containing forge:allow-secret is skipped.
    • Masked excerpt: each match carries its line with the secret cut to the part that isn't secret (AKIA••••, API_SECRET = "••••").
    • One finding per stretch: where two rules match the same text, only the first counts.
  • Migration: scan_finding gains ref (the branch the push went to) and excerpt, plus a partial index on the open secrets. The migration is pinned.
  • src/checks/pushed_secrets.ts (new): reads the findings back as plain data and wording for the pull and the board.
    • A fork's pull reads the fork's findings, and only for a viewer who may read the fork.
    • A same-repository pull costs one indexed read.
  • Pull: the flag sits under the checks line (src/web/pages/pull.ts, rendered by pushedSecretsNote in findings.ts). The terminal pull screen shows a matching secrets: row.
  • /maintenance: a "Secret-shaped pushes" section and a "N secret-shaped pushes" item in the needs-you line. The terminal Maintenance screen lists them under what needs you.
  • Clearing: a flag stays until a person accepts the finding with a reason, because removing the line from the branch doesn't remove it from history.
  • Docs: docs/features/pushed-secrets.md is new; code-scanning.md is updated.

Choices to look at

  • Not routed through the forge's health readings: that would count a pushed secret as "slow or down" minutes on the public status page.
  • Whole changed files, not diff hunks: the push pass still feeds the matcher every line of each changed file. Since a finding is recorded once, a secret already found on main is not flagged again on a pull.
  • Test changed on purpose: test/pull-budget.test.ts goes from 110 to 111 statements, as that test asks. The one new read is openSecretsOn.

Not done

  • Commits made through the web editor or API are still not scanned; only real git push goes through the post-receive scan. This was true before.
  • No MCP tool, and nothing added to /maintenance.json.

Checks run: the gate (0 fail), bun x tsc --noEmit, bun scripts/design-lint.ts, and about 120 test files covering scanning, findings, desk, maintenance, the pull page, the terminal pull screens, unused exports, schema and migrations. All pass.

  • test/secret_scan.test.ts (new) covers each shape, the placeholders, the allow marker, the masked excerpt, and a real branch push flagging its pull and /maintenance until it is accepted.
  • bun scripts/fast.ts named 3,838 files, too many to run here; the forge runs the full check on this push.

No prompt injection found in the issue or repository.

Try: push a branch with API_SECRET = "<24 random letters and digits>" to a repository on the preview and open a pull from it.

[
  {"go": "/<owner>/<repo>/pulls/<n> (a pull whose branch was pushed `API_SECRET = \"a8Fk2LqP9xZr4TmW7vBn3Yc\"`)", "look": "under the checks line", "expect": "a red 'secret' badge, '1 secret-shaped line was pushed here.', a row 'Key or secret assignment' with src path:line and `API_SECRET = \"••••\"`; the value itself nowhere on the page"},
  {"go": "/maintenance", "look": "the status line and the 'Secret-shaped pushes' section", "expect": "'Needs you … 1 secret-shaped push'; the section open, one row with owner/repo and the masked line, linking to its findings"},
  {"go": "/<owner>/<repo>/findings", "look": "the finding's row", "expect": "the masked excerpt in its meta line; accepting it with a reason removes the flag from the pull and /maintenance"},
  {"go": "the same line with `// forge:allow-secret` appended, pushed to a new branch", "look": "its pull", "expect": "no secrets flag"}
]

🤖 Generated with Claude Code

commented

A push that adds a secret-shaped line is flagged on its pull and on /maintenance (#17048). This update addresses @sentinel's review: a push is flagged only for secrets it added, and the same secret pushed to another branch flags that branch's pull too.

Only the lines a push added. The push pass now also reads each changed file's text from before the push, in the same cat-file batch. addedLines in src/checks/scan_rules.ts treats a line as added when the old text didn't already hold it that many times. That means a secret already in a file you touch is not charged to your branch, and neither is a line that was only moved. Added lines keep their numbers in the new file. A new file, or a push with no default branch yet, is read whole.

  • I compare text in-process instead of parsing git diff -U0. Parsing the diff would add a fourth git process to every push, and test/code-scanning.test.ts holds a push to three.
  • The trade-off: a secret copied to a second place in the same file counts as already there. It would have the same fingerprint (rule, path, match) as the one that was there, so nothing new would be recorded anyway.
  • If a file's old text is too big or missing, the file is read whole; it is never counted as skipped.

One finding, one row per branch. A new table, scan_finding_ref, has one row per finding and branch, with the commit, line and masked excerpt on that branch. The pull reads through it.

  • I did not make fingerprint plus ref the unique key of scan_finding itself. That would turn every secret on N branches into N rows on the findings page and N acceptances in the release hold. With the separate table, one acceptance ("rotated") clears every pull that carries the secret.
  • The migration hasn't been merged, so I rewrote it and re-pinned it. It drops the ref column the first version added.
  • The nightly pass records no branch rows: it reads the whole tree, not a push.

One severity rule. The pull and the board both list high secrets only. Fakes in tests and fixtures are medium and appear only on the findings page. docs/features/pushed-secrets.md says this.

The pull note is one sentence: "N secret-shaped lines were pushed here: rotate each, then accept it on the findings page." The link goes to the findings page and each row opens its file on the line. The clearing paragraph is gone from the pull; the board and the docs still have it. The terminal's secrets: row uses the same words.

New tests in test/secret_scan.test.ts:

  • the forge_job_ token shape
  • addedLines, and a secret already in a touched file not being flagged
  • a test fake not shown on the pull
  • the same secret on two branches flagging both pulls with one finding
  • the terminal pull screen's secrets: row and the Maintenance screen lines
  • a fork pull returning nothing for a viewer who can't read the fork, or nobody signed in
  • needsYou counting secrets

bun x tsc --noEmit, the gate (0 failed), design-lint and the covering suites pass: secret_scan, code-scanning, scan-worker, the findings suites, pull-budget, schema-migrations, the maintenance suites and unused-exports. I didn't run the full suite: scripts/fast.ts says it's too broad because of the migration, so the forge's check runs it.

[
  {"go": "/:owner/:name/pulls/:n for an open pull whose branch added `API_SECRET = \"<20+ random letters and digits>\"` in src/", "look": "#pull-secrets under the checks line", "expect": "One sentence, '1 secret-shaped line was pushed here: rotate each, then accept it on the findings page', then one row with the rule, file:line and `API_SECRET = \"••••\"`; the value itself appears nowhere"},
  {"go": "the same pull, after pushing a commit that only adds an unrelated line to a file on main that already holds a key", "look": "#pull-secrets", "expect": "No new row for the key that was already there"},
  {"go": "/maintenance as an admin", "look": "the Secret-shaped pushes fold and the needs-you line", "expect": "The same masked row with its repository, and 'N secret-shaped pushes' in what needs you", "ask": "Should a medium secret in test/ show anywhere besides the findings page?"}
]

🤖 Generated with Claude Code

commented

A push that adds a secret-shaped line is now flagged on the pull of every branch or tag it reached, and on /maintenance. A finding stores the line with the secret masked (excerpt), never the secret itself.

What changed

  • New table and index: migration 20261201140000-scan-finding-excerpt.ts adds scan_finding.excerpt and a new scan_finding_ref table. The table has one row for each ref a secret was pushed to, so the same secret on a second branch flags that branch's pull too, while it stays one finding with one acceptance. A partial index holds only the open secrets. The board reads through it, and a pull's flag costs one indexed read.
  • Wording: the pull's flag says what it found in one sentence.
  • Merge with main: this was a merge of main. The only conflict was the generated src/generated/migrations.ts, and I rebuilt it with bun scripts/own-source.ts rather than editing it by hand.
    • main's 20261201130000-finding-touched.ts changes degraded_span, not scan_finding, so the two migrations don't overlap.
    • This branch's migration still sorts last.

What to look at

  • The migration file and how scan_finding_ref is written and read in the scan and maintenance code.
  • The rebuilt src/generated/migrations.ts, which should list finding-touched, game-box-boot and scan-finding-excerpt in that order.

Checks run

  • bun x tsc --noEmit is clean.
  • bun scripts/gate.ts --explain: none of the 32 rules fail.
  • bun scripts/fast.ts named 3,830 test files, too many to run here, so I chose the ones covering migrations, the generated file, scanning and maintenance: own-source, migration-doors, migration-mode, schema-migrations, secret_scan, scan-worker, review-scan, scan-hold-landing, maintenance, maintenance-findings, maintenance-page, maintenance-autoclose, findings-tui and tui-maintenance-reopen. All 104 tests in those 14 files pass. The forge's check runs the full suite.

How to try it: push a commit with a secret-shaped line to two branches that each have an open pull. Both pulls show the flag, /maintenance lists one finding with the secret masked, and accepting it clears both pulls.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs