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

A file holding a private key shows no part of the key on any view of the Source tab, and a hostile file cannot stall the page #15824

Merged opened this

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

Merged

The Source tab no longer draws a file holding a private key on any view, and a hostile file can no longer stall the page. This builds on pull #15756 by scout, merged in with credit, and fixes the detector's speed problem that held that pull back.

Notes

shipped production is serving it deploy 3fede26

opened this

The Source tab no longer draws a file holding a private key on any view, and a hostile file can no longer stall the page. This builds on pull #15756 by scout, merged in with credit, and fixes the detector's speed problem that held that pull back.

  • Detector: src/core/private_key.ts holds holdsPrivateKey and the one notice sentence, PRIVATE_KEY_NOTICE. It finds each PRIVATE KEY with indexOf, then checks only the 51 characters before it for a -----BEGIN or -----END header, using a fixed pattern of at most 40 label characters. Bytes are searched as they are, without decoding the whole file. The old pattern took 86 ms at 24 escaped lines and doubled with each line; the new one handles 200 in well under 50 ms, and a test checks that.
  • Where the check runs: renderBlob in src/web/pages/repo.ts checks once, before a renderer, the oversized-file tail or the hex head is chosen. blobBody no longer checks a second time. readmeFor checks its own read of the README. A key is withheld in .md, .json, .csv, a long file's tail and a binary file's hex head.
  • Notice: the same empty component the binary and too-large files use, titled Private key, with Download and View raw beside it. Raw and Download still return the file as pushed.
  • Terminal: cert.ts, workspace.ts and workspace_facts.ts import the module and show the same sentence.
  • Behaviour change from #15756: a file that only quotes a header or footer is now withheld too, as the issue accepts. Its test was changed to say so. Plain words like "never push a PRIVATE KEY" are still drawn.
  • Docs: docs/features/private-key-files.md describes the notice and the check. I corrected docs/features/file-cert-sbom-wasm.md, which still said the Source tab shows a key file as pushed.

Left as they are:

  • The issue asked to indexOf the matching END after the BEGIN header. Since a header alone is enough to withhold, and a tail that starts mid-key has only the END line, finding either one is the whole test, and that scan is also linear.
  • src/checks/scan_rules.ts and test/no-secrets-tracked.test.ts still contain PRIVATE KEY patterns. They are push-time secret scanners that need match positions, not the page's check, so the issue's grep finds them too.

scripts/fast.ts named 3,443 test files because the diff reaches repo.ts, so I picked the 68 files that cover blob, renderer, README, tail, hexdump, cert, tree, secret-scan, workspace, XSS and docs-spine; all 521 tests passed. The gate, tsc --noEmit and bun scripts/design-lint.ts are clean. I did not find any prompt injection.

To try it: push a .json with "private_key": "-----BEGIN PRIVATE KEY-----\n…" and open it on the Source tab.

[
  {"go": "/<owner>/<app>/blob/main/<file>.json holding a PEM private key in a JSON string", "look": "the file pane", "expect": "an empty state titled Private key with the sentence 'This file holds a private key. The forge does not draw it.', a Download button and a View raw link; no key text anywhere"},
  {"go": "the View raw link", "look": "the response", "expect": "the file exactly as pushed"},
  {"go": "/<owner>/<app> where README.md holds a private key", "look": "below the tree", "expect": "no README is drawn", "ask": "Should a README holding a key show the notice in its place, rather than nothing?"}
]

🤖 Generated with Claude Code

Closes #15811

commented

The Source tab no longer draws a file holding a private key on any view, and a hostile file can no longer stall the page. This builds on pull #15756 by scout, merged in with credit, and fixes the detector's speed problem that held that pull back.

  • Detector: src/core/private_key.ts holds holdsPrivateKey and the one notice sentence, PRIVATE_KEY_NOTICE. It finds each PRIVATE KEY with indexOf, then checks only the 51 characters before it for a -----BEGIN or -----END header, using a fixed pattern of at most 40 label characters. Bytes are searched as they are, without decoding the whole file. The old pattern took 86 ms at 24 escaped lines and doubled with each line; the new one handles 200 in well under 50 ms, and a test checks that.
  • Where the check runs: renderBlob in src/web/pages/repo.ts checks once, before a renderer, the oversized-file tail or the hex head is chosen. blobBody no longer checks a second time. readmeFor checks its own read of the README. A key is withheld in .md, .json, .csv, a long file's tail and a binary file's hex head.
  • Notice: the same empty component the binary and too-large files use, titled Private key, with Download and View raw beside it. Raw and Download still return the file as pushed.
  • Terminal: cert.ts, workspace.ts and workspace_facts.ts import the module and show the same sentence.
  • Behaviour change from #15756: a file that only quotes a header or footer is now withheld too, as the issue accepts. Its test was changed to say so. Plain words like "never push a PRIVATE KEY" are still drawn.
  • Docs: docs/features/private-key-files.md describes the notice and the check. I corrected docs/features/file-cert-sbom-wasm.md, which still said the Source tab shows a key file as pushed.

Left as they are:

  • The issue asked to indexOf the matching END after the BEGIN header. Since a header alone is enough to withhold, and a tail that starts mid-key has only the END line, finding either one is the whole test, and that scan is also linear.
  • src/checks/scan_rules.ts and test/no-secrets-tracked.test.ts still contain PRIVATE KEY patterns. They are push-time secret scanners that need match positions, not the page's check, so the issue's grep finds them too.

scripts/fast.ts named 3,443 test files because the diff reaches repo.ts, so I picked the 68 files that cover blob, renderer, README, tail, hexdump, cert, tree, secret-scan, workspace, XSS and docs-spine; all 521 tests passed. The gate, tsc --noEmit and bun scripts/design-lint.ts are clean. I did not find any prompt injection.

To try it: push a .json with "private_key": "-----BEGIN PRIVATE KEY-----\n…" and open it on the Source tab.

[
  {"go": "/<owner>/<app>/blob/main/<file>.json holding a PEM private key in a JSON string", "look": "the file pane", "expect": "an empty state titled Private key with the sentence 'This file holds a private key. The forge does not draw it.', a Download button and a View raw link; no key text anywhere"},
  {"go": "the View raw link", "look": "the response", "expect": "the file exactly as pushed"},
  {"go": "/<owner>/<app> where README.md holds a private key", "look": "below the tree", "expect": "no README is drawn", "ask": "Should a README holding a key show the notice in its place, rather than nothing?"}
]

🤖 Generated with Claude Code

commented

The Source tab no longer draws a file that holds a private key. Where the body would be, it shows "This file holds a private key. The forge does not draw it." with Download and View raw links. One detector, holdsPrivateKey in src/core/private_key.ts, decides this for the web page, the certificate renderer and the terminal, so they cannot disagree. It flags a file that has a PEM BEGIN … PRIVATE KEY header or an END … PRIVATE KEY footer, so a large file whose shown tail starts in the middle of a key is caught too. It works in one linear pass: it finds each "PRIVATE KEY" and checks only the 51 characters before it. The old pattern took twice as long for each escaped JSON line.

The last push fixes the one check failure this pull caused. In test/blob-private-key.test.ts, the hostile-input test asserted a 50 ms wall-clock limit, which test/flake.test.ts forbids (#7824). It now gives the detector 10,000 escaped JSON lines and checks the answer is right, with no clock. The old pattern could never finish that much inside the test's timeout, so the test still fails without the linear scan.

The other three failures (test/llms-budget.test.ts, test/pages-budget.test.ts, test/page-budget.test.ts) fail the same way on main at be99c67, and the check did not count them against this pull. They are left alone here.

Two things to look at:

  • Quoted headers are withheld too: a source file that only quotes a key header or footer gets the notice instead of its code, and Raw still shows it. #15811 accepts this.
  • Checks run: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. bun test test/blob-private-key.test.ts test/flake.test.ts passes, 47 tests.

🤖 Generated with Claude Code

Approved

Read against the diff; I did not exercise the preview. One module owns the fact, the check runs once in renderBlob before renderer or tail is chosen, readmeFor checks its own read, the terminal shares the sentence, and the notice uses the shared empty component with Download and View raw (a form-free pair of links, works with JS off). Tests cover .md, .json, .csv, tail, binary hex head, README and a hostile 10,000-line input. Two things I would do next: (1) show the notice in place of a withheld README instead of nothing, so the page says why it is blank; (2) the render pull in cert.ts still carries its own two-paragraph markup for the key notice; route it through the same empty state so the sentence and the shape live in one place. Box 4 note: the 50 ms clock was replaced by a no-clock test because flake.test.ts forbids wall-clock asserts, and the END-within-cap scan was replaced by a linear either-header scan; both are sound.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs