envoy icon indicating copy to clipboard operation
envoy copied to clipboard

jwt_authn accepts JWTs with non-canonical base64url signature encoding

Open akashbhalke-dev opened this issue 1 month ago • 4 comments

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:

  1. Configure jwt_authn with a remote JWKS (RS256).
  2. Send a valid token -> 200.
  3. Replace the last signature character with another in the same 16-char group -> 200 (expected 401).
  4. Replace it with a character outside the group -> 401.

Request: reject non-canonical base64url segments (or add a strict-decoding option).

akashbhalke-dev avatar Oct 07 '26 07:10 akashbhalke-dev

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

  1. Enforce Canonical Base64url Validation: In source/extensions/filters/http/jwt_authn/, update the base64url decoding utility to enforce canonical bit padding.
  2. 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.cc with signatures containing non-zero trailing bits and verify rejection.

Could you please assign this issue to me? Thanks!

adityamukesh avatar Oct 07 '26 09:10 adityamukesh

cc @TAOXUY @tyxia

nezdolik avatar Oct 07 '26 09:10 nezdolik

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.

github-actions[bot] avatar Nov 06 '26 12:11 github-actions[bot]

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.

github-actions[bot] avatar Nov 13 '26 16:11 github-actions[bot]