jwt_authn accepts JWTs with non-canonical base64url signature encoding
jwt_authn accepts a JWT whose signature segment has non-zero unused bits in its final base64url character. For an RS256 (2048-bit) signature, the 256-byte value leaves 4 unused bits in the last character, so 16 different characters (e.g. Q..f) decode to identical bytes and all pass verification.
Strict JWT libraries (e.g. PyJWT) reject these with "Invalid crypto padding". RFC 4648 §3.5 permits decoders to reject non-zero pad bits, and RFC 7515 expects a single compact serialization.
Similar to #27877 (trailing characters after a valid JWT were accepted).
Repro:
- Configure jwt_authn with a remote JWKS (RS256).
- Send a valid token -> 200.
- Replace the last signature character with another in the same 16-char group -> 200 (expected 401).
- Replace it with a character outside the group -> 401.
Request: reject non-canonical base64url segments (or add a strict-decoding option).
Hi maintainers, I would like to work on this issue.
🔍 Analysis & Security Spec
RFC 7515 specifies that base64url-encoded signatures must have zero unused trailing bits in the final encoded character. Currently, jwt_authn in Envoy accepts non-canonical base64url signatures with non-zero trailing bits for RS256/ES256 signatures, allowing multiple syntactically distinct JWT representations for the same cryptographic signature.
🛠️ Proposed Implementation Plan
- Enforce Canonical Base64url Validation: In
source/extensions/filters/http/jwt_authn/, update the base64url decoding utility to enforce canonical bit padding. - Strict Verification: Reject tokens containing non-canonical signature encodings with
JwtVerificationResult::SignatureVerificationFailed.
🧪 Testing Plan
- Add test vectors in
test/extensions/filters/http/jwt_authn/jwt_authenticator_test.ccwith signatures containing non-zero trailing bits and verify rejection.
Could you please assign this issue to me? Thanks!
cc @TAOXUY @tyxia
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.