Skip to content

fix(jjwt): isolate verification keys and parser configuration - #2

Merged
loong10k merged 2 commits into
mainfrom
test/main-jjwt-security-regressions
Nov 4, 2026
Merged

loong10k merged 2 commits into
mainfrom
test/main-jjwt-security-regressions

Conversation

@loong10k

@loong10k loong10k commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes verification with the wrong key when two different keys or SigningKeyResolvers have the same hashCode. Both repositories previously selected a static cached parser by hashCode plus expiry mode, also reusing the first repository's clock, allowed skew and compression resolver across instances and later configuration updates.

Build an independent immutable parser for each request using the supplied key/resolver and current repository settings. Removing the unbounded global caches avoids retaining key material and resolver object graphs globally; no key encoding, fingerprint, digest or substitute identity hash is introduced. Relevant mutable settings use volatile for individual-field visibility, and the compression resolver is read once per construction. Public APIs, null-argument NPE types, authentication defaults and existing expiry/exception semantics are preserved.

Replace print-only examples with offline assertions using public test-only keys. Retain both originally failing isolation assertions and cover verify/getPlayload, expiry=true/false, both key directions, resolver replacement, clock/skew/compression changes and concurrent colliding-key/resolver callers. The concurrent scenarios use eight workers, each executing sixteen rounds of own-token success and other-token rejection through both entry points.

Validation:

  • Before repair, both original collision rejection tests failed locally and in CI; added lifecycle tests also demonstrated stale parser configuration.
  • After repair, JDK 17 full reactor mvn -B --no-transfer-progress clean verify: 43 tests, zero failures/errors/skips. Independent read-only review ran the complete JDK 17 reactor successfully and found no merge blocker in the final production/test changes. This is not a formal PR approval.
  • Local JJWT line coverage from the successful full verify is 395/597 (66.16%). This remains below the unchanged 90% warning threshold. API and Nimbus have no test suite/data here; reactor success is not full security coverage of those modules.
  • git diff --check: passed.

Limits: volatile does not make multiple simultaneous setters an atomic configuration transaction, and callers remain responsible for the thread safety of supplied clock/key/resolver objects. Parser construction now occurs per operation; its throughput/allocation impact has not been benchmarked. Already-returned parsers keep their construction-time references/settings. No dependency, publishing, security-setting or coverage-rule changes.

@loong10k loong10k changed the title test(jjwt): add security assertions and expose parser cache isolation failures fix(jjwt): isolate verification keys and parser configuration Nov 4, 2026
@loong10k
loong10k marked this pull request as ready for review November 4, 2026 02:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T02:13:04.156346Z 9734c43 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@loong10k
loong10k merged commit c6edbf6 into main Nov 4, 2026
1 check passed
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