]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: jwe: fix NULL deref crash with empty CEK and non-dir alg
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 7 Apr 2026 07:48:09 +0000 (09:48 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Tue, 7 Apr 2026 08:57:47 +0000 (10:57 +0200)
In sample_conv_jwt_decrypt_secret(), when a JWE token has an empty
encrypted-key section but the algorithm is not "dir" (e.g. A128KW),
neither branch initializes decrypted_cek. The NULL pointer is then
passed to decrypt_ciphertext() which dereferences it:

  - For GCM encodings: aes_process() calls b_orig(NULL) -> SIGSEGV
  - For CBC encodings: b_data(NULL) at jwe.c:463 -> SIGSEGV

A single HTTP request with a crafted Authorization header crashes the
worker process. Trigger token (JOSE header {"alg":"A128KW","enc":"A128GCM"},
empty CEK section between the two dots):

  eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4R0NNIn0..AAAAAAAAAAAAAAAA.AA.AA

Reachable in any configuration using the jwt_decrypt_secret converter.
The other two decrypt converters (jwt_decrypt_jwk, jwt_decrypt_cert)
already have the check.

This must be backported as far as JWE support exists.

src/jwe.c

index 2cf4a7adcdfc35ee7460f2d98fafcfb47bfff31c..d7497888e7b04f36ed478a216bb2b5f6e30f0bf2 100644 (file)
--- a/src/jwe.c
+++ b/src/jwe.c
@@ -718,6 +718,10 @@ static int sample_conv_jwt_decrypt_secret(const struct arg *args, struct sample
                        goto end;
 
                chunk_memcpy(decrypted_cek, secret_smp.data.u.str.area, secret_smp.data.u.str.data);
+       } else {
+               /* Empty CEK with a non-"dir" algorithm: nothing we can use to
+                * derive a key. Bail out instead of passing NULL down. */
+               goto end;
        }
 
        /* Decode the encrypted content thanks to decrypted_cek secret */