Skip to content

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

Merged
Baoyuantop merged 4 commits into
apache:masterfrom
shreemaan-abhishek:fix/jwt-auth-algo-mismatch
Apr 21, 2026
Merged

fix(jwt-auth): enforce algorithm match before signature verification#13182
Baoyuantop merged 4 commits into
apache:masterfrom
shreemaan-abhishek:fix/jwt-auth-algo-mismatch

Conversation

@shreemaan-abhishek

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

Copy link
Copy Markdown
Contributor

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 <[email protected]>
- 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 <[email protected]>
@Baoyuantop
Baoyuantop merged commit e4de423 into apache:master Apr 21, 2026
21 of 31 checks passed
@shreemaan-abhishek shreemaan-abhishek mentioned this pull request Jun 11, 2026
5 tasks
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.

5 participants