Skip to content

fix(jwt-auth): enforce algorithm match before signature verification#13182

Open
shreemaan-abhishek wants to merge 4 commits intoapache:masterfrom
shreemaan-abhishek:fix/jwt-auth-algo-mismatch
Open

fix(jwt-auth): enforce algorithm match before signature verification#13182
shreemaan-abhishek wants to merge 4 commits intoapache:masterfrom
shreemaan-abhishek:fix/jwt-auth-algo-mismatch

Conversation

@shreemaan-abhishek
Copy link
Copy Markdown
Contributor

@shreemaan-abhishek shreemaan-abhishek commented Apr 8, 2026

Summary

  • Enforce that the JWT header's alg claim matches the consumer's configured algorithm before performing signature verification, per RFC 8725 Section 2.1

Test plan

  • New test case (TEST 52 in t/plugin/jwt-auth.t): creates an RS256 consumer, submits a token with mismatched algorithm, asserts 401 rejection with correct error log
  • prove -I. -Itest-nginx/lib -r t/plugin/jwt-auth.t passes

Verify that the JWT header's "alg" claim matches the consumer's
configured algorithm before performing signature verification,
per RFC 8725 Section 2.1.

Signed-off-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
- Add nil guard on jwt.header before accessing alg to prevent
  potential nil index errors on malformed tokens
- Remove untrusted token alg value from log message; only log
  the expected algorithm
- Update test to match revised log message
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Apr 8, 2026
nic-6443
nic-6443 previously approved these changes Apr 9, 2026
moonming
moonming previously approved these changes Apr 9, 2026
Baoyuantop
Baoyuantop previously approved these changes Apr 9, 2026
Signed-off-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
…lgo-mismatch

Signed-off-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants