Skip to content

fix(rules): leaked-secrets samples, placeholders, base64 runs, prefix collisions, Paystack labelling #1283 #1227 - #1298

Closed
nc9 wants to merge 1 commit into
mainfrom
fix/1283-1227-secrets-placeholders
Closed

nc9 wants to merge 1 commit into
mainfrom
fix/1283-1227-secrets-placeholders

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1283
Fixes #1227

False-positive cluster in security/leaked-secrets from the 38k-site corpus triage. Every silenced class has a paired real-shaped control that still reports, and a megabyte-scale adversarial timing test.

What changes

  • jwt.io sample token is dropped only when the payload is EXACTLY the published one (sub 1234567890, name John Doe, iat 1516239022, optional admin: true) and its HMAC verifies under a published sample secret (your-256-bit-secret, secret, ...). Any other claim or value, or any other signature, is read like any other token.
  • Twitter bearer: not inside a base64/data: payload, not next to / + unless handed over after Bearer/Authorization/token/key (including Bearer+), not mostly A, needs a real tail, max 200 chars.
  • Hashed asset names (neon_<hash>.png, sk-<hash>.svg, key-<hash>.webp, re_<hash>.woff2) are file names, for the four low-specificity prefixes only (Neon, legacy OpenAI sk-, Mailgun key-, Resend re_). sk-ant-, AIza, SG., GitHub and Stripe tokens followed by an extension still report.
  • A valid mod-97 DO IBAN is not a Spaces key. A lowercase slug after a vendor word is not a token unless it is the value of a credential-named assignment.
  • sk_live_/sk_test_ + exactly 40 hex = Paystack .... Other hex-only tails of 32+ chars: unknown-provider key, medium inside a data-*-key/data-*-token attribute whose name has no secret/private/server/admin/master, high everywhere else.
  • PEM header needs a base64 run of 32+ chars after it with only line breaks and joins between (any written form: \n, \u000a, %0A, &#10;, &#13;&#10;, <br>/<p>/<div>, quotes, commas, +, .concat(, .join(, spaces, armor headers). Prose, code or another ----- marker between means prose. (The first version of this PR said 60+ characters; the code and docs now say 32.)
  • Connection strings: a documentation-word password (whole stems only: s3cret, password123, examplepassword) on localhost/loopback/.localhost/.test/.example/.invalid with no host=/hostaddr= override is dropped. .internal and .local are NOT unroutable and do not qualify. A password that is itself a template placeholder (${pass}, {{ pass }}, {password}, %s, %(pw)s) is dropped; a hard-coded password beside a templated host/user, or containing %s/%D0/{abc}, reports.
  • Stripe's published sample key tails are suppressed under sk/rk live/test.
  • example is a placeholder only as example + a credential noun (+ short number): example-password, example_secret. Example1234, ExampleKey report.

Deliberately not done

  • changeme and s3cret as bare generic values stay reportable: an existing corpus negative pins changeme as "as often a real default credential as a placeholder". Only the connection-string case (docs password on unroutable host) uses the leet/word list.
  • *.internal etc. with a random password stays high: that is a real prod credential shape.

Test changes

Existing fixtures used the Stripe sample tail and header-only PEM strings; they now use a different tail and a PEM with a body. The harness escapeJsBody no longer escapes the n of a \n (its own doc comment said it left those alone).

Verification

  • bun test on the 7 leaked-secrets files by path: all pass (2308 + 158 + 28). Before the change 13 of the 28 new tests fail.
  • squirrel audit on a local fixture page (8 false-positive snippets + a neon png): none reported; 5 real-shaped controls (PEM with body, strong-password pg URL, other sk_test_, admin JWT, Paystack live) plus the widget key all reported.
  • tsgo --noEmit in packages/rules, make validate in docs, detect-secrets hook on the changed files: clean.
  • Codex pass not run (codex MCP rejected every model on this account).

Rule count/catalog unchanged (no new rule; two new report type labels). Skill change: none needed.

Bypass probes and results (review-pub-secrets findings and my own)

Every row is a test in leaked-secrets-samples.test.ts.

Allowlist Probe Result
PEM body Real key as ["hdr","<64>","<64>"].join("\n") (double and single quotes, no spaces), "..\n".concat("<b64>"), <br>, <br />, <p>/<div> per line, \n, \r\n, \u000a, %0A, &#10;, &#13;&#10;, spaces, one-line blob, " + " joins, armor headers Found a HIGH hole (first version split on whitespace and dropped the array/concat/html forms). Fixed: separator-tolerant gap. All 18 forms report
PEM body Prose header followed by var id="<40 base64>", code, another header, elided MIIE..., <p>Copy it now</p><p>run</p> All stay dropped
Template markers Hard-coded password with @${DB_HOST}, @{host}, ${user} user, %s, %D0x, {abc} inside the password Hole: whole-authority marker test dropped them. Fixed: the password alone is tested and only a whole-placeholder password drops. All report
Documentation password .internal, .local, .svc.cluster.local hosts; CompassRoseAtlas, Bypassing, TesterBob, Rootsalt on localhost Holes (private hosts treated as unroutable; substring stems). Fixed: hosts list is loopback + RFC-reserved only; whole stems only. All report
Twitter bearer Authorization=Bearer+AAAA..., access_token=AAAA...=, header form Hole for + and =. Fixed. All report
Asset extension sk-ant-, AIza, SG. tokens followed by .css, .map, .png, .svg, .woff2 Hole. Fixed: only the four hash-collision prefixes qualify. All report
Widget downgrade data-secret-key, data-private-key, data-server-token, data-admin-key with a hex sk_live_ Hole. Fixed: stays high, no widget hint
Slug skip cloudflareToken:"correct-horse-battery-staple-token-value" and a slug under a credential key Hole. Fixed: slug skip only outside credential-named assignments; both report
jwt.io sample Sample + iss/exp/other iat/admin:false/missing name, signed with a published secret; sample + scope/role/permissions; minted admin token with real secret Hole (iss/exp allowed with any value). Fixed: exact published payload only. All report
example placeholder Example1234, ExampleKey, example123, Example-Corp, ExampleCorp#2024! Hole (minor). Fixed: noun required. All report
Structural tokens + extension GitHub token and Stripe key followed by .svg/.png Report
Host override localhost/db?host=prod, hostaddr=, localhost@real-host, localhost.acme-prod.net Report
Stripe sample tail Altered tail, real key next to the sample Report
Encodings Real key percent-encoded, in a base64 blob, \u0041-escaped bearer, zero-width before a PEM body Report
Case / unicode PASSWORD:'EXAMPLE-PASSWORD' is a placeholder (case-insensitive by design); exa\u200bmple-password reports As stated

Composition with #1228 (landed via #1241): in main; passes in the full run. Compose with #1277: only CHANGELOG and .secrets.baseline conflict.

Later review rounds

Allowlist Probe Result
PEM armor Prose header + Note: keep it safe + a 40-char base64 run Hole (any word: text counted as an armor header). Fixed: only Proc-Type, DEK-Info, Version, Comment, Hash, Charset, MessageID lines are skipped; the prose stays dropped, the armored key reports
Template password A random password wrapped in braces ({Xk9mQ2...}) Hole ({name} accepted any name). Fixed: {name} is lower-case snake only; the braced random password reports
Control regression Private real-site corpus (368 findings, 383 fetched pages and scripts) run on main and on this branch, diffed finding by finding 0 removed, 0 added: no finding on real sites changes except the classes this PR names, which do not occur in that corpus

Final review round

Item Result
PEM body search cost 5 MB of repeated headers, header + A x31, header + <br><br><p>: 2.1-3.1 s before. The search now reads at most 600 characters per header and stops at the first -----: 72, 79 and 36 ms. Counter-based tests assert the examined characters per header (a work counter, not wall time)
HTML wrapper tags Any tag with up to 200 attribute characters now separates lines (<td>, <b>, <i>, highlighter <span class="line" data-line=... style=...>); tests for both
Asset names Legacy OpenAI sk-, Neon, Mailgun and Resend tokens are skipped only after /, a quote, (, = or a comma, and only for image/font/media extensions. .map and .css, and a token followed by .png in running text, report
Documented trade-offs A password made only of stems (adminroot) on localhost/.test/.example/.invalid is treated as the example it almost always is; a bare /- or +-adjacent bearer with no Bearer/Authorization/token/key before it is not matched

Rebase 2026-11-01

Rebased on main (v0.0.156, 99f63d3) as part of the stack 1298 -> 1300 -> 1318 -> 1319 -> 1320; CHANGELOG bullets re-inserted under [Unreleased]; .secrets.baseline line numbers refreshed (no new entries). Draft: corpus A/B pending.

Review round

  • PEM bodies: a key wrapped narrowly (16, 20, 24, 30, 31 characters, a short first line before 64-character lines, or chunked JS string concatenation) is a key again (main reported it): chunk lengths of 16+ add up to 32, a word or ... ends them, several short chunks must mix case and digits, the gap before the body stays bounded at 400 raw characters. Elided and prose cases stay silent. A + inside a body is base64, a + between literals is a join.
  • security/leaked-secrets: placeholder and documentation examples still reported (localhost connection string, vendor sample key, bare PEM header, example-password) #1227 criterion 3 (values inside <pre>/<code> on docs-like pages downgraded to info) is DESCOPED, not implemented: a live-shaped key pasted in a docs block is a real leak. The acceptance criteria are amended by lane-review-prs.
  • isLowercaseSlug removed: with it off, every suite passes and a 24,000-shape differential (slugs under brand keywords in six embeddings) produced identical findings on and off, so main already ignored its input; the docs "Slugs" bullet is gone.
  • New tests: Paystack live key server-only vs browser-served, multi-host every, both Stripe sample tails, bounded PEM gap, percent-encoded line breaks, example-* digit cap and anchoring, hex tail minimum, docs-password length cap, query-parameter password, jwt.io name check.
  • Docs: the PEM bullet states the 32-character run and the narrow-wrap behaviour.

Skill change: none.

Delta review leftovers

  • Docs: a PEM body wrapped at fewer than 16 characters per line is NOT matched, nor one whose chunks total under 32.
  • Tests pin the narrow-wrap rule's bounds: the 16-character chunk floor (8/12/15-wide bodies silent), the 32 threshold (16+15 and a lone 31 silent; 16+16 and a lone 32 report), each part of the mix check missing in turn and each of a digit, + and / satisfying it, a word or non-base64 token ending the body, and filler between chunks (the 400 gap applies before the first chunk only; the 600-character read bounds the whole). 8 of 8 mutants fail a test.
    Skill change: none.

Twitter bearer false negative fixed

A public-format app-only bearer (21 or 22 A, then %2B, %2F, %3D segments, about 118 characters) was no longer detected in assignment, bare-string, URL-parameter and attribute contexts: the page's percent-escapes were decoded first, which cut the token at its first +, / or =, and the plausibility check read a stub. decodePercentRun now leaves a run holding that shape (19+ A not preceded by a letter, digit, + or /, a token and a percent-escape within 200 characters) as written, so the pattern and its checks read the whole token. Base64 A runs stay dropped; an encoded document with a blob inside is still decoded. Tests: the 19/21/22/24-A encoded token in six contexts, the unencoded 19-A cases, and the encoded-document control; mutants (no skip, no lookbehind, A-run length, tail bound) fail a test.
Skill change: none.

…rs, docs passwords, base64 A runs, asset names; labels Paystack keys #1283 #1227

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/1283-1227-secrets-placeholders branch from ea36d4b to 3dcfdde Compare November 1, 2026 19:54
@nc9 nc9 mentioned this pull request Nov 1, 2026
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant