Skip to content

fix(rules): leaked-secrets drops a header-only JWT after Bearer #1227 - #1527

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/1227-bearer-jwt-header
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/1227-bearer-jwt-header

Conversation

@nc9

@nc9 nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1227 (the last open criterion: "A JWT that is only a header segment (no payload or signature) is not reported").

Bearer eyJhbGciOiJIUzI1NiIs (the header segment of a JWT, no dot) was reported at medium as a Bearer Token: isJwtHead only suppresses a Bearer value when a second segment follows. isHeaderOnlyJwt now drops it, on positive proof only:

  • the WHOLE body decodes (base64url, JSON.parse) to a plain object that has an alg and only JOSE header keys (alg, typ, kid, cty, enc, zip, x5t, x5t#S256, x5u, x5c, jku, jwk, crit); bodies over 2,048 characters are not read as one; or
  • the body is 64 characters or fewer, cut mid-JSON, and its decoded prefix opens with {"alg", {"typ", {"kid" or {"cty";
  • and the text after it does not continue a token. Continuation: a . followed by a token character (so .-<payload> continues, a sentence period does not), %, \, or whitespace or , followed by . or eyJ. End of text, a quote, a bracket and other punctuation do not.

Shapes that stop reporting

A complete JOSE header (any JOSE key set with an alg), and a truncated one of 64 characters or fewer, after Bearer in a script, an Authorization header, a curl example and a <code> block.

Shapes that report (were wrongly dropped by the first version)

  • an opaque base64url JSON value that merely opens with alg/typ/kid/cty and carries other keys ({"typ":"access","sub":...}, {"alg":"x","sub":...,"token":...}), at 120 and 1,000 characters of padding
  • a JOSE-only object with no alg; a truncated value past 64 characters; a short truncated value that does not open with a header key
  • a real JWT after Bearer with %2E, a space, a comma, a newline or escaped newline, or .- between its parts

Acceptance criterion

  • a header-only JWT after Bearer is not reported (fixture); a full Bearer <JWT> and an opaque bearer still report
  • Tests (leaked-secrets-bearer-header-1227.test.ts, 8 cases). Mutants killed: key-name check, alg requirement, 64-character bound, 2,048 bound, whole-body decode (vs first 24 characters), prefix regex relaxed, and each continuation clause (., %, \, ,/eyJ).

Skill change: none.

nc9 added 2 commits November 2, 2026 09:22
…whole JOSE header or short truncation, not a continued token #1227

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 482d1054, 77a006d5 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