You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "nic-6443 (via GitHub)" <gi...@apache.org> on 2026/09/02 14:05:19 UTC
[PR] fix(jwe-decrypt): honor the protected header AAD on every supported OpenResty [apisix]
nic-6443 opened a new pull request, #13913:
URL: https://github.com/apache/apisix/pull/13913
### Description
`jwe-decrypt` rejects every token a standard JWE library produces on the older OpenResty releases APISIX supports.
RFC 7516 authenticates the encoded protected header as the AES-GCM additional authenticated data, and the plugin passes it as the third argument of `aes_default:decrypt(ciphertext, tag, o.header)`. `resty.aes` only grew that parameter in lua-resty-string 0.16; on OpenResty 1.21.4, the oldest release `apisix/cli/ops.lua` accepts, the signature is `decrypt(self, s, tag)` and the argument is dropped without a word. The AAD attempt and the backward compatible attempt then run the exact same decryption without AAD, so a token whose tag covers the header always fails and the request gets `400 failed to decrypt JWE token`. A token built without AAD decrypts fine, which is what makes this look like a key problem rather than an AAD one.
The AEAD now runs through `resty.openssl`, which takes the AAD on every version and is already used by `apisix/upstream.lua`, `jwt-auth`, `cas-auth` and `openid-connect`.
`resty.openssl` also hands the tag to OpenSSL as it is. OpenSSL accepts a GCM tag shorter than the 128 bits RFC 7518 fixes for `A256GCM` and then verifies only the bits it was given, so the IV and tag lengths are checked before the token reaches it. The same check rejects a tag carrying trailing bytes, which `resty.aes` silently truncated to its first 16 — a token had many valid encodings until now.
Behavior change: a token whose IV is not 96 bits, or whose tag is not 128 bits, is now rejected. Both are fixed by RFC 7518 for `A256GCM` and every JWE library emits them, but a token minted through the `/apisix/plugin/jwe/encrypt` endpoint removed in #13464 with an explicit `iv` of another length no longer decrypts.
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(jwe-decrypt): honor the protected header AAD on every supported OpenResty [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on PR #13913:
URL: https://github.com/apache/apisix/pull/13913#issuecomment-5511224783
Closing this for now — the change is being withdrawn. Happy to reopen if there is interest in it later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(jwe-decrypt): honor the protected header AAD on every supported OpenResty [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #13913:
URL: https://github.com/apache/apisix/pull/13913#discussion_r3915032261
##########
docs/en/latest/plugins/jwe-decrypt.md:
##########
@@ -178,7 +178,7 @@ To generate a JWE token for the Consumer, use any JWE library that supports dire
base64url(header).<empty>.base64url(iv).base64url(ciphertext).base64url(tag)
```
-where the header is `{"alg":"dir","enc":"A256GCM","kid":"<consumer-key>"}`; `alg` and `enc` are rejected if they are set to anything else. The IV must be unique and randomly generated for every token; never reuse an IV with the same key.
+where the header is `{"alg":"dir","enc":"A256GCM","kid":"<consumer-key>"}`; `alg` and `enc` are rejected if they are set to anything else. `A256GCM` is defined with a 96-bit IV and a 128-bit authentication tag, and a token carrying either at another length is rejected. The IV must be unique and randomly generated for every token; never reuse an IV with the same key.
Review Comment:
Rephrased to name the parts: "a token whose IV or authentication tag has another length is rejected". Same wording in the Chinese doc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(jwe-decrypt): honor the protected header AAD on every supported OpenResty [apisix]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13913:
URL: https://github.com/apache/apisix/pull/13913#discussion_r3915010337
##########
docs/en/latest/plugins/jwe-decrypt.md:
##########
@@ -178,7 +178,7 @@ To generate a JWE token for the Consumer, use any JWE library that supports dire
base64url(header).<empty>.base64url(iv).base64url(ciphertext).base64url(tag)
```
-where the header is `{"alg":"dir","enc":"A256GCM","kid":"<consumer-key>"}`; `alg` and `enc` are rejected if they are set to anything else. The IV must be unique and randomly generated for every token; never reuse an IV with the same key.
+where the header is `{"alg":"dir","enc":"A256GCM","kid":"<consumer-key>"}`; `alg` and `enc` are rejected if they are set to anything else. `A256GCM` is defined with a 96-bit IV and a 128-bit authentication tag, and a token carrying either at another length is rejected. The IV must be unique and randomly generated for every token; never reuse an IV with the same key.
Review Comment:
The sentence “a token carrying either at another length is rejected” is grammatically awkward and a bit hard to parse in the English docs; rephrase to clearly state that tokens with a non-96-bit IV or non-128-bit tag are rejected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(jwe-decrypt): honor the protected header AAD on every supported OpenResty [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 closed pull request #13913: fix(jwe-decrypt): honor the protected header AAD on every supported OpenResty
URL: https://github.com/apache/apisix/pull/13913
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org