{{ message }}
Repository navigation
Conversation
createCipheriv() and createDecipheriv() rejected a null IV, even
though Node.js documents null as the IV for ciphers that don't use
one, such as AES-ECB. A null IV is now treated as an empty IV, so it
behaves exactly like Buffer.alloc(0). Ciphers that require an IV
still reject it, and undefined is still rejected, as in Node.js.
publicEncrypt(), publicDecrypt(), privateEncrypt() and
privateDecrypt() rejected a KeyObject or CryptoKey passed as the
`key` property of an options object, e.g.
publicEncrypt({ key: createPublicKey(pem), padding }, data). Node.js
accepts this so callers can specify `padding` and similar options
alongside a KeyObject. The four functions each had a copy of the key
resolution logic; they now share prepareAsymmetricKey(), which also
unwraps such an options object.
Compatibility: both inputs previously threw ERR_INVALID_ARG_TYPE, so
accepting them cannot change the behavior of a working Worker, and
no compatibility flag is needed.
Tests were not run locally because of an outage affecting the
cfdata.org domains that edgeworker's bazel build depends on; CI is
the verification for this change.
Fixes #7772
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
npaun
marked this pull request as ready for review
October 20, 2026 04:54
Contributor
|
Review: 2 findings (1 blocking, 1 warning). Adds Node-compatible null-IV and wrapped asymmetric-key handling with targeted tests. Reviewed commit: db3a6efb · github run |
| }; | ||
|
|
||
| export const keyObjectInOptions = { | ||
| test(_, env) { |
Contributor
There was a problem hiding this comment.
[WARNING] This covers wrapped KeyObject values only, although prepareAsymmetricKey() has a separate inner instanceof CryptoKey branch. A regression that stops unwrapping a WebCrypto CryptoKey would still pass this test.
Suggested change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #7772.
createCipheriv(alg, key, null): anullIV is now treated as an empty IV, matching Node.js, which documentsnullfor ciphers without an IV (e.g. AES-ECB). Ciphers that need an IV still throwInvalid initialization vector, andundefinedstill throwsERR_INVALID_ARG_TYPE, as in Node.js.publicEncrypt({ key: keyObject, padding }, data)(andpublicDecrypt/privateEncrypt/privateDecrypt): aKeyObjectorCryptoKeypassed as thekeyproperty of an options object is now accepted. The four functions each had a copy of the key-resolution logic, and now shareprepareAsymmetricKey().Compatibility: both inputs previously threw
ERR_INVALID_ARG_TYPE, so accepting them can't break a working Worker. No compat flag is needed.Out of scope: Node.js also accepts a private key for
publicEncrypt/publicDecrypt, deriving the public key from it. workerd still rejects that withERR_CRYPTO_INVALID_KEY_OBJECT_TYPE.Test plan
New tests in
crypto_cipher-test.js:cipherivNullIv: AES-128-ECB with anullIV gives the same ciphertext as Node.js and round-trips. CBC withnulland ECB withundefinedstill throw.keyObjectInOptions:{ key: KeyObject, padding: RSA_NO_PADDING }works with all four functions. The output matches Node.js and the PEM-string path, and a wrong-type key still throws.