Skip to content

fix(auth-oauth2): use crypto.randomBytes for implicit grant OIDC nonce - #855

Open
samuel-conner wants to merge 1 commit into
mountain-loop:mainfrom
samuel-conner:fix/oauth2-implicit-csprng-nonce
Open

samuel-conner wants to merge 1 commit into
mountain-loop:mainfrom
samuel-conner:fix/oauth2-implicit-csprng-nonce

Conversation

@samuel-conner

Copy link
Copy Markdown

Summary

plugins/auth-oauth2/src/grants/implicit.ts generated the OIDC id_token replay-protection nonce query parameter using Math.random() (non-cryptographic PRNG, CWE-338), whereas sibling grants in @yaak/auth-oauth2 (authorizationCode.ts PKCE verifier and clientCredentials.ts jti) already use node:crypto.

This replaces String(Math.floor(Math.random() * 9999999999999) + 1) with randomBytes(16).toString("hex") from node:crypto (128-bit CSPRNG hex string) and adds unit tests in plugins/auth-oauth2/tests/implicit.test.ts.

Verified locally:

  • vp test --run plugins/auth-oauth2/tests: 7/7 test files, 56/56 tests passed (including 2 new tests in implicit.test.ts).
  • vp lint & vp fmt --check: 0 warnings, 0 errors.

Submission

  • This PR is a bug fix.
  • If this PR is not a bug fix, I linked the feedback item where @gschier explicitly gave me permission to work on it.
  • I have read and followed CONTRIBUTING.md.
  • I tested this change locally.
  • I added or updated tests, or tests are not reasonable for this change.
  • I added screenshots or recordings, or this change does not affect the UI.

Explicit permission feedback item (required if not a bug fix):

N/A (bug fix)

Related

Found & verified offline with CipherMap (zero-telemetry static scanner) — happy to adjust or add tests if preferred. Contact: Samuel Conner (sam@ciphermap.io · https://www.ciphermap.io/verify).

plugins/auth-oauth2/src/grants/implicit.ts generated the OIDC id_token replay-protection nonce using Math.random() (CWE-338), while sibling grants in the same plugin (authorizationCode.ts, clientCredentials.ts) already use node:crypto.

Switch to randomBytes(16).toString('hex') from node:crypto and add unit tests in plugins/auth-oauth2/tests/implicit.test.ts.

Signed-off-by: Samuel Conner <49850235+samuel-conner@users.noreply.github.com>
@github-actions github-actions Bot added the contribution: in scope Community PR appears to be in scope for maintainer review. label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the PR. This appears to match Yaak's contribution policy and is awaiting review by @gschier.

This only means the PR is in scope for review. It does not mean the change has been reviewed or accepted for merge.

@github-actions
github-actions Bot requested a review from gschier November 25, 2026 18:35
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Replaces Math.random() with randomBytes(16).toString("hex") for the implicit grant's OIDC nonce.

  • Implicit ID-token requests now get a cryptographically random nonce.

Reviews (1) · Last reviewed commit: "fix(auth-oauth2): use crypto.randomBytes..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution: in scope Community PR appears to be in scope for maintainer review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant