]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: jwt: enforce the ECDSA signature length in jwt_verify
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Tue, 20 Oct 2026 08:04:50 +0000 (10:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Oct 2026 15:43:19 +0000 (17:43 +0200)
commit36d85198a3a114c41786b12c35df9575235dd67c
treee70aa7936f5d030699da47a84ce946ce06ebf4d1
parent59366ef447aa73ed883d5b4aa66bfc4419412ad0
BUG/MINOR: jwt: enforce the ECDSA signature length in jwt_verify

RFC 7518 section 3.4 states that an ES256 signature MUST be a 64-octet
sequence made of R and S each on 32 bytes, and that validation fails
otherwise (96 bytes for ES384 and 132 for ES512). jwt_verify() and
jwt_verify_cert() accept any even length and split it in two halves, so
that R and S may be prefixed with any number of zero bytes.
This can be reproduced by taking a valid ES256 token, decoding its
signature, inserting a zero byte before each 32-byte half, and encoding it
again: the converter still returns 1.

Let's check that the signature has exactly the length mandated by the
algorithm in convert_ecdsa_sig(), and return JWT_VRFY_INVALID_TOKEN (-3)
otherwise, as was already done for odd lengths. A reg-test is provided.

This fix should be backported to all supported versions.
reg-tests/jwt/jwt_verify_ecdsa_sig_len.vtc [new file with mode: 0644]
src/jwt.c