Repository navigation
feat(rules): decode encoded content and token structure in leaked-secrets (#360, #361) - #364
Merged
Merged
Conversation
nc9
marked this pull request as draft
September 16, 2026 01:06
nc9
force-pushed
the
feat/360-361-secrets-decoders
branch
from
September 16, 2026 02:40
cd9c585 to
33201a6
Compare
nc9
force-pushed
the
feat/360-361-secrets-decoders
branch
from
September 16, 2026 02:51
33201a6 to
1a1f5c0
Compare
nc9
force-pushed
the
feat/360-361-secrets-decoders
branch
from
September 16, 2026 03:03
1a1f5c0 to
3096c5a
Compare
nc9
marked this pull request as ready for review
September 16, 2026 03:09
…rets (#360, #361) Content decoders (#360), packages/rules/src/security/secrets/decode.ts: - HTML character references in the serialized page are decoded before the html scan, so a JSON object stored entity-encoded in an attribute is read as JSON and reports at `html`. - `\uXXXX`, `\u{X}` and `\xXX` escapes in script text are decoded (an escaped backslash is left alone), so an escaped string literal reports at the script's location. - Percent-encoded runs (3+ `%XX` escapes that decode to text) are decoded in place, so a URL-encoded settings blob reports at its plain location. - Standalone base64 runs of 64+ chars that decode to text are scanned as content of their own, two levels deep, reported with a ` (base64)` location suffix. data: URI payloads and SRI hashes are never decoded. The run finder samples every 32nd character rather than scanning them all; a 200 KB image data URI adds under 1 ms. Token decoders (#361), packages/rules/src/security/secrets/confidence.ts, all offline, never a provider call: - AWS access key id: base32 account id decode; a suffix that does not decode to a 12-digit id is medium, not high. `extra.accountId`. - GitHub classic tokens: CRC32/base62 checksum of the 30-char body, verified against a published expired token; a wrong checksum drops the finding. - JWTs: the Supabase HS256 header literal becomes a general `JSON Web Token` FAST pattern (any alg, three base64url segments); which token it is comes from the decoded claims. Supabase `service_role` high, `anon` public, expired `exp` and standalone first-party session tokens (a subject, an `exp` within 30 days, no admin scope, no third-party issuer, not inside an `Authorization: Bearer` literal or under a credential key) into a new `leaked-secrets-info` check, other issuers medium at most and never labelled Supabase, admin scopes high. Claims ride along as `extra`. - Algolia secured keys (new CONTEXT pattern): restriction params decoded; restricted keys public, unrestricted medium, non-keys dropped. - Stripe mode/kind, Slack structure, Sentry org/project as `extra`. `extra` is attached to the finding and emitted as the check item's `meta`, which the JSON, LLM and XML renderers and the API report already carry. Corpus: six new contexts (entity attribute, escaped script string, base64 data attribute, base64 global, URL-encoded data attribute and inline settings), 29 new probes, generators for GitHub and AWS produce structurally valid values, known gap 18 fixed. Two new unit suites with independent CRC32/base32 oracles and a fetch-throws guard. Bench on the precision base f445a7d: 13.96 -> 14.62 ms/MB (+4.7%), recorded in the README. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
feat/360-361-secrets-decoders
branch
from
September 16, 2026 03:11
3096c5a to
ae73289
Compare
Merged
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.
Closes #360, closes #361.
What
Two new modules under
packages/rules/src/security/secrets/, hooked intoleaked-secrets.tsat two points (content enteringscanContent, and thebuildof each finding), plus a base64 pass after the existing two passes. The FAST/CONTEXT tables are untouched except for one appended CONTEXT entry (Algolia secured key).#360 content decoders (
decode.ts)htmlscan (the serializer writes attribute quotes back as", sodata-state="{"apiKey":…}"was invisible). Reports athtml.\uXXXX/\u{X}/\xXXdecoded in script text; an escaped backslash is left alone. Reports at the script's location.(base64)location suffix.data:URI payloads and SRI hashes are never decoded; binary blobs are skipped; 256 blobs / 8 MB decoded per text.{64,}regex both blew the budget). A 200 KB image data URI adds under 1 ms (pinned in a test).#361 token decoders (
confidence.ts), offline onlyextra.accountId.ghp_/gho_/ghu_/ghr_: CRC32 of the 30-char body, base62, 6 chars; verified against a published expired token. Wrong checksum drops the finding.service_role(Supabase) high,anonpublic, expiredexp→ newleaked-secrets-expiredinfo check, other issuers medium at most asJSON Web Token(never Supabase),adminscopes high. Claims inextra.algoliastays medium withkeyType.extra.extrabecomes the check item'smeta, whichpackages/reportJSON/LLM/XML and the API'srun-reportitem shape already carry through.Tests
tests/security/leaked-secrets.test.ts(corpus)tests/leaked-secrets.test.tstests/security/secrets-decode.test.ts(new)tests/security/secrets-confidence.test.ts(new, independent CRC32/base32 oracles,fetchthrows during the scan)packages/audit-engine/tests/streaming-collector-rules-golden.test.tsSnapshot regenerated; the only changed pre-existing rows gained
extrafields, masked values are unchanged. Four new corpus contexts, 20 new probes, known gap 18 flipped to fixed.Bench
Back to back on the same machine, 5 iterations: before
cd9f746931 ms / 13.97 ms/MB, after 990 ms / 14.85 ms/MB (+6.3%). Recorded in the README.Found, not fixed here
The pre-existing
Discord Bot Tokenpattern is quadratic on long base64 runs (2.7 s per scan of a 200 KB data URI page today). The decoders do not add to it, but the corpus probe for the data-URI criterion carries a 20 KB URI for that reason. Filed separately.Codex focused review (throw/loop/memory) folded in: decoded findings appended by iteration instead of spread, decode budget charged before allocation,
expoutsideDaterange read as absent.https://claude.ai/code/session_01T8w822GqnrviVMytnAsKFP