Repository navigation
Reject invalid EC and OKP JWK key data with DataError - #8770
Conversation
There was a problem hiding this comment.
Superseded by the review of
7fd072cf.
This review, of 270e8ee1
💬 Approved with comments — The change is a spec-aligned switch of error types on imports that already fail. The only note is an INFO asking for the compatibility decision to be recorded in the commit message.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
Correct, spec-aligned change. The commit message doesn't record a compatibility decision for the changed error names.
Recommendation: 💬 Optional Nits
- [INFO] The exception name thrown by importKey changes for deployed Workers, and the commit message doesn't record a compatibility decision. (
src/workerd/api/crypto/ec.c++:653)
View full review
The ec.c++ edits only change the DOMException type. Control flow and success paths are unchanged. The failure from EC_KEY_check_key was already a DataError, so these paths now agree with it. The narrowed WPT expectations and their comments match the code.
One note: the exception's name changes from OperationError/NotSupportedError to DataError for imports that already fail. That is observable to user code. The repository's backward-compatibility guidance asks for the compatibility decision to be recorded in the commit message.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security concerns. The change only affects which exception type is thrown on import paths that already reject.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
Only the exception types on error paths change, so there is no performance impact.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 270e8ee1
Web Crypto rejects an imported JWK whose key data is invalid with a DataError. workerd rejected an EC JWK whose x and y are not a point on the curve, such as a shortened x or P-521 coordinates imported as P-256, with an OperationError from EC_POINT_set_affine_coordinates_GFp. An Ed25519 or X25519 JWK whose crv names the other curve was rejected with a NotSupportedError. In this patch these imports reject with a DataError, as does an EC private key whose d is rejected by EC_KEY_set_private_key. Only the error type changes; no import that succeeds today starts to fail. Code that checks the error's name sees DataError instead of OperationError or NotSupportedError. We accept that risk without a compatibility flag, because these imports already fail and the new name matches the spec. The WPT expectations for the EC and OKP importKey failure tests shrink to the cases that still import: an EC JWK with a missing or mismatched crv, and an OKP private JWK whose x does not match d.
270e8ee to
7fd072c
Compare
There was a problem hiding this comment.
💬 Approved with comments — The change is a spec-aligned switch of error types on imports that already fail. The only note is an INFO asking for the compatibility decision to be recorded in the commit message.
Findings: 1 info
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
Correct, spec-aligned change. The commit message doesn't record a compatibility decision for the changed error names.
Recommendation: 💬 Optional Nits
- [INFO] The exception name thrown by importKey changes for deployed Workers, and the commit message doesn't record a compatibility decision. (
src/workerd/api/crypto/ec.c++:653)
View full review
The ec.c++ edits only change the DOMException type. Control flow and success paths are unchanged. The failure from EC_KEY_check_key was already a DataError, so these paths now agree with it. The narrowed WPT expectations and their comments match the code.
One note: the exception's name changes from OperationError/NotSupportedError to DataError for imports that already fail. That is observable to user code. The repository's backward-compatibility guidance asks for the compatibility decision to be recorded in the commit message.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security concerns. The change only affects which exception type is thrown on import paths that already reject.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
Only the exception types on error paths change, so there is no performance impact.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 7fd072cf — same changes as 270e8ee1, so this is that commit's review (no new review was run; line numbers are as of 270e8ee1)
Web Crypto rejects an imported JWK whose key data is invalid with a
DataError. workerd rejected an EC JWK whosexandyare not a point on the curve, such as a shortenedxor P-521 coordinates imported as P-256, with anOperationErrorfromEC_POINT_set_affine_coordinates_GFp. An Ed25519 or X25519 JWK whosecrvnames the other curve was rejected with aNotSupportedError.In this patch these imports reject with a
DataError, as does an EC private key whosedis rejected byEC_KEY_set_private_key. Only the error type changes, and no import that succeeds today starts to fail. Code that checks the error's name seesDataErrorinstead, and we accept that without a compatibility flag because these imports already fail and the new name matches the spec. The WPT expectations forec_importKey_failures_{ECDH,ECDSA}andokp_importKey_failures_{Ed25519,X25519}shrink to the cases that still import: an EC JWK with a missing or mismatchedcrv, and an OKP private JWK whosexdoes not matchd.//src/wpt:WebCryptoAPI@passed 100 of 100 runs with--runs_per_test=100.