JWS verify accepts a payload segment with non-zero unused base64url bits

Open Beginner friendly
#407 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
Half a day
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start from jws.JWS.deserialize and jws.JWS.verify, following how the signing input is assembled for the HMAC check; the issue suspects it is rebuilt from the decoded payload rather than the received segment. Reproduce with the provided script against Wycheproof tcId 374, then add a regression test and run the JWS test suite. Done means the AB payload token is rejected while valid tokens still verify.

Written by the indexing model from the issue text.

Description

Low/informational finding, no forgery involved.

jwcrypto 1.6.1 verifies a compact JWS whose payload segment was changed only in its unused base64url bits. In Wycheproof json_web_signature_test.json tcId 374 the payload segment is AB, but the HMAC was computed over AA (both decode to 0x00). RFC 7515 §5.2 step 8 validates the signature against the received signing input, BASE64URL(header) || '.' || BASE64URL(payload), so this one should fail. It looks like the signing input gets rebuilt from the decoded payload instead of using the segment as received.

Impact is just malleability: a second spelling of the same token verifies, and the payload itself doesn't change.

from importlib.metadata import version
from jwcrypto import jwk, jws

# Wycheproof testvectors_v1/json_web_signature_test.json, tcId 374 (expected invalid).
compact = "eyJraWQiOiJoczI1Ni1rZXkiLCJhbGciOiJIUzI1NiJ9.AB.8sL_ycV8G_D-K_2A3I0EW3NoPMeQzv13cAzuHlQ5TAE"
key = jwk.JWK.from_json('{"kty":"oct","kid":"hs256-key","use":"sig","alg":"HS256","k":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}')
obj = jws.JWS()
obj.deserialize(compact)
print("jwcrypto=" + version("jwcrypto"))
try:
    obj.verify(key)
except Exception as exc:
    print("actual=reject " + type(exc).__name__)
else:
    print("actual=accept payload_hex=" + obj.payload.hex())
jwcrypto=1.6.1
actual=accept payload_hex=00

Found while running the Wycheproof JOSE vectors against a set of JWT libraries

Dominant language
Python
Stars
478
Forks
132
Avg merge
7h 38m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from latchset/jwcrypto

All issues in latchset/jwcrypto

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.