Skip to content

crypto: align WebCrypto error behavior with specs - #65550

Open
panva wants to merge 3 commits into
nodejs:mainfrom
panva:fix-webcrypto-spec-errors
Open

crypto: align WebCrypto error behavior with specs#65550
panva wants to merge 3 commits into
nodejs:mainfrom
panva:fix-webcrypto-spec-errors

Conversation

@panva

@panva panva commented Aug 25, 2026

Copy link
Copy Markdown
Member

This aligns three WebCrypto behaviors with their specifications:

  • RSA-PSS verification with an impossible saltLength now resolves false while signing continues to reject with OperationError (WebCrypto, RFC 8017).
  • Exporting a private key as SPKI now rejects with InvalidAccessError, including through wrapKey(), as required by the export steps.
  • JWK imports now validate requested usages before key_ops, so SyntaxError takes precedence when both are invalid (RSA-PSS, ECDSA, ML-KEM).

panva added 3 commits August 25, 2026 22:51
Let OpenSSL handle representable salt lengths so verification of an
impossible length resolves false. Guard values outside the native int32
parameter range to prevent SignJob from silently ignoring them.

Move the digest-size helper next to HKDF, its remaining consumer.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Reject SPKI export of a private asymmetric key with InvalidAccessError
as required by the algorithm export steps. Let wrapKey propagate the
same export failure.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Check requested usages against the JWK public or private key type
before validating key_ops. This preserves the SyntaxError precedence
specified for RSA, EC, CFRG, ML-DSA, and ML-KEM imports.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
@panva panva added the commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. label Aug 25, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (7aaf9b4) to head (be76256).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #65550   +/-   ##
=======================================
  Coverage   90.13%   90.13%           
=======================================
  Files         751      751           
  Lines      253639   253641    +2     
  Branches    47790    47794    +4     
=======================================
+ Hits       228618   228622    +4     
+ Misses      16264    16258    -6     
- Partials     8757     8761    +4     
Files with missing lines Coverage Δ
lib/internal/crypto/cfrg.js 95.90% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/ec.js 96.91% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/hkdf.js 100.00% <100.00%> (ø)
lib/internal/crypto/ml_dsa.js 97.39% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/ml_kem.js 95.35% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/rsa.js 94.62% <100.00%> (-0.08%) ⬇️
lib/internal/crypto/util.js 97.42% <ø> (+0.31%) ⬆️
lib/internal/crypto/webcrypto.js 97.77% <100.00%> (+<0.01%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@panva panva added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Aug 26, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 26, 2026
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. webcrypto

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants