fix: validate JWK alg/crv/kty per algorithm in subtle.importKey#1021
Merged
Conversation
Node validates JWK alg and crv fields against the algorithm name and hash at import time. RNQC silently accepted mismatched values, which allowed malformed keys to flow into crypto operations and broke interop with Node-produced JWKs. - RSA: validate jwk.alg against the per-context expected name derived from algorithm.hash (RS256, PS256, RSA-OAEP-256, ...) - Ed25519/Ed448: require crv === algorithm.name; if alg is present, accept only algorithm.name or 'EdDSA' - X25519/X448: require crv === algorithm.name (no alg check, per Node) Closes #1001
Add `kty === 'OKP'` check to edImportKey to reject non-OKP keyData inline, matching the pattern already used by rsaImportKey/ecImportKey and Node's `Invalid JWK "kty" Parameter` message. Refactor the nested ternary in rsaImportKey's alg check into a switch for readability. Add X25519/X448 `crv` mismatch tests to cover the now-ungated crv check, and replace the Ed `use="enc"` test (which only exercised pre-existing validateJwkStructure behavior) with a `kty: 'EC'` test that actually exercises the new check.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
🤖 End-to-End Test Results - AndroidStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
Contributor
🤖 End-to-End Test Results - iOSStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
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.


Summary
Tightens JWK validation in
subtle.importKeyfor RSA and CFRG algorithms so that mismatchedalg,crv, orktyparameters are rejected at the JS layer with aDataErrorDOMException, matching Node.js's WebCrypto behavior.Previously, mismatched JWK parameters either passed through to the C++ layer (yielding opaque errors) or were silently accepted.
Changes
RSASSA-PKCS1-v1_5,RSA-PSS,RSA-OAEP): whenjwk.algis set, verify it matches the algorithm + hash combination (e.g. RSA-PSS + SHA-256 →PS256).Ed25519,Ed448,X25519,X448): verifyjwk.kty === 'OKP'andjwk.crv === algorithm.name. For Ed curves, ifjwk.algis set it must equal the algorithm name or'EdDSA'.'JWK "alg" does not match the requested algorithm','JWK "crv" Parameter and algorithm name mismatch','Invalid JWK "kty" Parameter') for downstream parity.'EdDSA'-accepted/wrong-kty, and X25519/X448 wrong-crv.Test plan
algfor each of RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEPcrv, mismatchedalg, and wrongktyalg: 'EdDSA'crvFixes #1001