Repository navigation
test(rules): leaked-secrets corpus, unit tests and benchmark baseline - #358
Merged
Merged
Conversation
A corpus-driven harness for security/leaked-secrets: one seeded generator per FAST/CONTEXT pattern (values built from parts, never a token literal), twelve embedding contexts, hand-written boundary negatives, interaction probes, exact (pattern, check, location) expectations per case, and a checked-in snapshot of the raw scanner output so any detector change is a reviewable diff. 20 known gaps are asserted as CURRENT behaviour with a todo each, so the suite is green today and every fix flips one expectation. bench:secrets scans a 200-page synthetic corpus (66.7 MB) and records ms/MB, findings and peak RSS; baseline in the README. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
7 tasks
… audited sites Negatives synthesised from what the detector fired on in the cloud audit history (no real values reproduced): ordinary-word CONTEXT keywords beside hashes and nonces, prefix patterns with no left boundary (re_ inside _Care_Dry…, a UUID tail as a Telegram id, fooghp_/xsk_live_/abcAKIA), Neon and PayPal on URL slugs, i18n sentences as secrets, Shopify storefront tokens as a scoping question, Bearer template vs literal, AIza in the public tier, and one-finding-per-distinct-value dedup on a shared theme bundle. All pinned as knownGap; 33 distinct gaps now. 1038 pass / 64 todo. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
Contributor
Author
Second commit (8dbb30b): real-world false-positive shapes
|
… secrets corpus Every key and value interpolated into script text now goes through JSON.stringify (js/bad-code-sanitization), and the mirrored `example.com` false-positive test is a substring predicate rather than a regex CodeQL reads as an unanchored URL check (js/regex/missing-regexp-anchor). Same output: the snapshot is byte-identical. Claude-Session: https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP Signed-off-by: Nik Cubrilovic <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A unit-test and benchmark harness for
security/leaked-secrets. No detector changes in this PR: the corpus comes first, fixes are separate PRs.packages/rules/tests/security/leaked-secrets/generators.ts: one seeded generator per FAST/CONTEXT pattern (88). Every value is assembled at runtime from parts; no line is a token-shaped literal and nothing is a real credential.contexts.ts: 12 embedding contexts (inline config object,window.__ENV,__NEXT_DATA__,__NUXT__, HTML comment,<meta content>,data-*, JSON-LD, external webpack bundle,fetch()Bearer header,.envdump in<pre>, sourcemap comment), each declaring the rule-level location.negatives.ts: hand-written look-alikes at pattern and filter boundaries (GTM/GA ids,pk_live/pk_test, AIza browser key, Sentry DSN, PostHogphc_, Supabase anon JWT vs first-party HS256/RS256 JWTs, base64 image, checksums beside brand prose, UUID ids, Bearer templates, identifiers under credential keys,sk-prefixed identifiers one over and one under the floor, 7- vs 8-char passwords, placeholders, aghp_token suppressed by the FP word list, CSS soup, Google OAuth client id, Mapboxpk., PayPal ids).cases.ts: every generator × every accepting context (realism-gated), the negatives, and interaction probes. Exact(pattern, check, location)per case.expected.json: snapshot of rawscanPageForSecrets+ external-script output per case (masked values only).UPDATE_SECRETS_SNAPSHOT=1rewrites it.tests/security/leaked-secrets.test.ts: 1015 pass / 45 todo / 0 fail. Asserts exact finding sets, negatives, masking, dedup across three locations, and the double scan of inline scripts.scripts/bench-leaked-secrets.ts+bun run bench:secrets: 200-page synthetic corpus (66.7 MB, minified filler withsegment/cloudflare/twiliosprinkled, three 2–5 MB bundles). Baseline on M2/16 GB: best 946 ms, 14.2 ms/MB, peak RSS 383 MB.Known gaps (asserted as current behaviour, one
test.todoeach; the suite prints the list)20 distinct. The six briefed (Clerk shadowed by Stripe, PayPal class omits B–Y, Sanity fires on
sk…identifiers, inline scripts scanned twice, no PostHog pattern, no size cap) plus 14 found while building the corpus, among them: Twitter bearer tokens are always dropped by thea{16,}filter; the FP list is unanchored substring tests (a key containingxxx/fake/dummyis dropped); Sanity fires inside base64 images; a Bearer header around a dotted value (JWT) yields a duplicate medium finding, so a Supabase anon key in a Bearer header is warned on; PayPal runs before Azure and DO Spaces before New Relic and both downgrade the later high finding;looksLikeCodeIdentifierdrops ~30% of random keyed values (camelCase,on/isprefixes,_with lowercase); the Supabase pattern is the generic HS256 header, so any session JWT is "Supabase anon" and aservice_roleJWT is reported as public. Full list in the README.Checks
bun test packages/rules/tests/security/leaked-secrets.test.tsgreen; the pre-existingtests/leaked-secrets.test.tsuntouched and green.tsgo --noEmiton the package and on the harness files (withnoUnusedLocals) clean..secrets.baselinegains one entry for thebench:secretsscript name.https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP