Skip to content

Check export support before extractable in exportKey and wrapKey - #8772

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

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

Conversation

@littledivy

Copy link
Copy Markdown
Member

exportKey() and wrapKey() check that the key is extractable first, and the NotSupportedError for an algorithm with no export only comes later, from the default CryptoKey::Impl::exportKey(). HKDF and PBKDF2 keys can only be imported as non-extractable, so they always got InvalidAccessError. The spec checks export support first (exportKey step 6, wrapKey step 11), and WebCryptoAPI/export-key-error-order.https.any.js expects NotSupportedError.

In this patch CryptoKey::Impl gets a supportsExport() virtual, false for HKDF and PBKDF2, and a requireExportable() helper that runs both checks in spec order for exportKey() and wrapKey(). Only calls that already fail change, and only in the error type, so there is no compat flag. The four expected failures for that WPT are removed.

//src/wpt:WebCryptoAPI@ passed 100 of 100 runs with --runs_per_test=100, and //src/wpt:WebCryptoAPI@all-autogates and the crypto and node:crypto key tests pass.

exportKey() and wrapKey() check that the key is extractable before
anything else, and the NotSupportedError for an algorithm with no export
only comes from the default CryptoKey::Impl::exportKey() after that.
HKDF and PBKDF2 keys can only be imported as non-extractable, so they
always got InvalidAccessError. The spec checks export support first
(exportKey step 6, wrapKey step 11), and the WPT
export-key-error-order.https.any.js expects NotSupportedError.

In this patch CryptoKey::Impl gets a supportsExport() virtual, false for
HKDF and PBKDF2, and a requireExportable() helper that runs both checks
in spec order for exportKey() and wrapKey(). Only calls that already
fail change, and only in the error type, so there is no compat flag.
@littledivy
littledivy requested review from a team as code owners November 21, 2026 04:06

@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 — A small change that puts the two error checks in spec order without changing which calls succeed. No issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

The change only reorders two checks, and both still run before any key material is exported.


📖 AGENTS.md: ✅ LGTM

This change doesn't need an AGENTS.md update.


📋 Code Quality: ✅ LGTM

requireExportable() tests the same extractable condition as before and adds the export-support check ahead of it. Only HKDF and PBKDF2 lack an exportKey() override, and both now override supportsExport() to return false. The error message is unchanged. The WPT expectations are updated.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The new comments in impl.h and pbkdf2.c++ describe the current behaviour accurately.


Reviewed commit: 3e1baad7

@littledivy
littledivy merged commit b89b434 into main Nov 21, 2026
23 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-21-crypto-arg-checks branch November 21, 2026 04:44
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