Skip to content

Reject invalid EC and OKP JWK key data with DataError - #8770

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-crypto-import-checks
Nov 21, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-crypto-import-checks

Conversation

@littledivy

@littledivy littledivy commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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, and no import that succeeds today starts to fail. Code that checks the error's name sees DataError instead, and we accept that without a compatibility flag because these imports already fail and the new name matches the spec. The WPT expectations for ec_importKey_failures_{ECDH,ECDSA} and okp_importKey_failures_{Ed25519,X25519} 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.

//src/wpt:WebCryptoAPI@ passed 100 of 100 runs with --runs_per_test=100.

@littledivy
littledivy requested review from a team as code owners November 21, 2026 03:41

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/workerd/api/crypto/ec.c++ Resolved
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.
@littledivy
littledivy force-pushed the littledivy/2026-11-21-crypto-import-checks branch from 270e8ee to 7fd072c Compare November 21, 2026 03:46

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 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)

@littledivy
littledivy enabled auto-merge November 21, 2026 03:48
@littledivy
littledivy merged commit ea0cd74 into main Nov 21, 2026
24 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-21-crypto-import-checks branch November 21, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants