Skip to content

fix(rules): leaked-secrets drops a JWT-shaped match that does not decode to a JWT #1283 - #1528

Closed
nc9 wants to merge 5 commits into
mainfrom
fix/1283-jwt-nondecoding
Closed

nc9 wants to merge 5 commits into
mainfrom
fix/1283-jwt-nondecoding

Conversation

@nc9

@nc9 nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1283 (the last open criterion: "A JSON Web Token match is reported only when its header decodes to a JSON object with an alg field and its payload decodes to a JSON object; otherwise it's dropped").

refineJwt kept a match that did not decode as a generic JWT-shaped string at medium (and secrets-confidence.test.ts pinned it). It now drops only on proof (isNotAJwt): a header or payload within the 8,192-character read bound whose JSON.parse failed with a SyntaxError or that parsed to something that is not a plain object. Scanner limits are not proof: a part past 8,192 characters, an empty part and a RangeError (JSON nested too deeply) are undecided and report.

Shapes that stop reporting (JSON Web Token and Supabase Anon Key patterns)

  • a part within the bound that is not base64 of JSON (text, random characters), truncated JSON, JSON with trailing bytes
  • a part within the bound that is a JSON array, string, number or null

Reported (medium generic JSON Web Token, or the token's own classification)

  • a header object with no string alg (missing, null, number, array, object) over a payload that classifies as specific: service_role, admin scope, Supabase anon and authenticated, Hygraph (management and content), Shopify storefront keep their classification. Tested as 7 payload classes x 6 headers.
  • a part past 8,192 characters, valid JSON or not (a service_role payload padded to 9,000 characters; a 9,000-character header)
  • JSON nested too deeply to parse (RangeError, tested with a stubbed JSON.parse; a 5,000-deep object within the bound parses and keeps its classification)
  • an empty (detached) payload

Dropped with a no-alg header

A no-alg header over a payload that would be a plain generic token (JSON Web Token, expired, Session Token (JWT)): plain claims, permissions:["*"], wallet and Netlify beacon payloads (the beacon branch needs a string alg, so they are plain tokens under such a header; the wallet-shaped {typ:"JWT"} case in leaked-secrets-public-tier.test.ts is []).

Decoy segments

One decoy eyJ<30>. right before a real token: the pattern consumes decoy.header.payload as one match; the real token is now classified from the two parts after the decoy (was a generic or dropped match). Known limit, tracked in #1530: two decoys in a row consume the real payload, and the match is dropped (documented, and pinned by a test).

Still reported

Every token with a decodable header and payload (any claims, any header fields, alg: none, expired tokens as JSON Web Token (expired) at info, admin scope at high), plus the undecided cases above.

Tests

  • secrets-confidence.test.ts: dropped-shape table (both patterns), a keep table for no-alg headers (generic and service_role), oversize and deep-nesting cases, the RangeError/SyntaxError split, undecided cases (empty, oversize header).
  • leaked-secrets-jwt-shape-1283.test.ts: the same at scan level.
  • leaked-secrets-public-tier.test.ts: the {typ:"JWT"} wallet case reports again (flipped back).
  • Mutants killed (also: plain-type set members, the no-alg branch always/never, the decoy shift): cap 8,192 to 1e9, every error as not-json, every error as inconclusive, empty-part check, not-object proof removed, not-json proof removed, null check removed.

Skill change: none.

nc9 added 4 commits November 2, 2026 10:00
…e and unparseable-deep parts report #1283

Signed-off-by: Nik Cubrilovic <[email protected]>
…ic payload; looks through one decoy segment #1283

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9 nc9 mentioned this pull request Nov 2, 2026
@nc9

nc9 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.159 as 13c7cbe9, 103d8027, 83566198, 947ec13a, 394391e6 via #1531 (the commits were re-created by the rebase-merge; matched by their cherry-pick trailers). Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.159

nik

@nc9 nc9 closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant