Repository navigation
Check export support before extractable in exportKey and wrapKey - #8772
Conversation
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.
There was a problem hiding this comment.
✅ 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
exportKey()andwrapKey()check that the key is extractable first, and the NotSupportedError for an algorithm with no export only comes later, from the defaultCryptoKey::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), andWebCryptoAPI/export-key-error-order.https.any.jsexpects NotSupportedError.In this patch
CryptoKey::Implgets asupportsExport()virtual, false for HKDF and PBKDF2, and arequireExportable()helper that runs both checks in spec order forexportKey()andwrapKey(). 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-autogatesand the crypto and node:crypto key tests pass.