GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: fix various edge cases by panva · Pull Request #66237 · nodejs/node

Conversation

@panva

@panva panva commented Sep 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fix conversion, key handling, and algorithm edge cases found during an implementation audit.

  • Separate Web IDL conversion from algorithm validation, preserving getter receivers and validating converted values. Correct algorithm and hash normalization, importKey() union conversion, and SubtleCrypto.supports() overload resolution and unbound calls.
  • Use intrinsic buffer bounds in getRandomValues(), randomFill(), and randomFillSync(). Treat detached parameters as empty and avoid constructor/species hooks when copying parameters, derived bits, key usages, and hybrid key material.
  • Correct CryptoKey prototypes, RSA key metadata and JWK alg validation, duplicate JWK key operations, and EC key import/export. Report native JWK export failures as OperationError.
  • Allow backend-supported short AES-GCM IVs, reject undersized AES-KW inputs, isolate unrelated OpenSSL cipher errors, and correct PBKDF2 iteration-limit handling. Process Argon2 lanes serially when OpenSSL cannot use its own worker threads.
  • Use OpenSSL's cSHAKE and KMAC implementations and remove the custom Keccak framing. Non-empty cSHAKE functionName or customization requires OpenSSL 4.0; when both are empty, continue using SHAKE. Customization retains the 512-byte limit and cannot contain null bytes.
  • Reject non-byte-aligned cSHAKE/KMAC outputs and KMAC keys pending clarification of their bit-string encoding. Require KMAC keys of at least 32 bits and make zero-length KMAC verification accept an empty signature.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@panva panva added the commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. label Sep 23, 2026
@nodejs-github-bot

nodejs-github-bot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/performance
  • @nodejs/security-wg
  • @nodejs/web-standards
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Sep 23, 2026
@codecov

codecov Bot commented Sep 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.48872% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.30%. Comparing base (a2c8da5) to head (4f26a35).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/crypto/webidl.js 92.40% 5 Missing and 1 partial ⚠️
src/crypto/crypto_keys.cc 64.70% 2 Missing and 4 partials ⚠️
lib/internal/crypto/hash.js 50.00% 4 Missing ⚠️
src/crypto/crypto_kmac.cc 81.81% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66237      +/-   ##
==========================================
+ Coverage   90.28%   90.30%   +0.02%     
==========================================
  Files         789      789              
  Lines      272878   272784      -94     
  Branches    52097    52086      -11     
==========================================
- Hits       246360   246336      -24     
+ Misses      16975    16952      -23     
+ Partials     9543     9496      -47     
Files with missing lines Coverage Δ
lib/internal/crypto/aes.js 94.59% <100.00%> (+0.84%) ⬆️
lib/internal/crypto/argon2.js 98.71% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/cfrg.js 95.75% <100.00%> (+0.06%) ⬆️
lib/internal/crypto/chacha20_poly1305.js 98.26% <100.00%> (+0.03%) ⬆️
lib/internal/crypto/diffiehellman.js 97.72% <100.00%> (-0.02%) ⬇️
lib/internal/crypto/ec.js 96.94% <100.00%> (+0.03%) ⬆️
lib/internal/crypto/hkdf.js 100.00% <100.00%> (ø)
lib/internal/crypto/kem_hybrids.js 98.38% <100.00%> (+<0.01%) ⬆️
lib/internal/crypto/keys.js 97.59% <100.00%> (-0.72%) ⬇️
lib/internal/crypto/mac.js 99.03% <100.00%> (+0.01%) ⬆️
... and 17 more

... and 28 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@panva
panva force-pushed the webcrypto-findings branch from 536fc0b to 54f9426 Compare September 23, 2026 12:39
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
jasnell
jasnell approved these changes Sep 23, 2026
View reviewed changes

@jasnell jasnell left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think some of the additional validations would technically qualify as semver-major but I'd prefer to not have to land it as such. I think we could probably get away with classifying them as bug fixes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 23, 2026
@panva

panva commented Sep 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I think some of the additional validations would technically qualify as semver-major but I'd prefer to not have to land it as such. I think we could probably get away with classifying them as bug fixes.

Thank you James, some of the added validations are just fail earlies that would fall into OperationError, some of them are for [experimental] algorithms or methods, some are really edge case bug fixes that, I concur, I don't feel are needed to be treated as [semver-major].

jasnell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
panva added 18 commits September 24, 2026 09:21
@panva
crypto: use internal random buffer bounds
f82a804
Read buffer lengths and element sizes from internal slots in
randomFillSync() and randomFill(). Shadowed properties can otherwise
skip filling, change the selected range, or fail a native bounds check.

Use the intrinsic byte length for the getRandomValues() quota check and
keep its delegation to randomFillSync().

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: match algorithm names as ASCII
1cbd118
Reject non-ASCII equivalents of registered Web Crypto algorithm names.
Skip the character scan when the input already uses the canonical name.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: reject short AES-KW inputs
131cc41
Enforce the minimum key-wrap input lengths before the empty-input
shortcut, including the integrity-check block when unwrapping.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: isolate cipher job errors
0e286f0
Use only errors captured by the cipher job when converting its result.
Unrelated errors on the event loop thread must not turn a successful
operation into a failure or trigger an assertion.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: convert getRandomValues views
5d64d76
Apply Web IDL view conversion before checking the integer array type,
including shared and resizable backing-buffer restrictions.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: validate normalized hash names
bd27c23
Check the normalized SHA algorithm instead of reading the caller hash
name before conversion. This prevents changing getters from bypassing
the supported hash check.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: allow short AES-GCM IVs
7129683
Allow nonempty GCM IVs shorter than the default length and let the
underlying cipher enforce its supported range.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: allow unbound SubtleCrypto.supports
3d8975b
Static Web IDL operations do not require an interface receiver.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: resolve supports overloads by type
7f417a0
Convert the third argument before checking the operation, and apply
additional-algorithm checks only for that overload.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: copy detached parameters as empty
9b6c75e
Treat detached BufferSource parameters as empty byte sequences during
algorithm normalization, including detached DataViews.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: convert importKey data as a union
a45414a
Choose the BufferSource or JsonWebKey branch from the value, then
check the requested format after algorithm normalization.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: copy parameters without array species
677404d
Allocate byte copies directly so typed-array species cannot replace
normalized parameters or bit-truncated key material.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: check RSA JWK alg with SHA-3 hashes
4f7f16f
Reject a supplied JWK alg when no matching identifier exists for the
requested RSA algorithm and hash.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: reject duplicate unknown key usages
191d52a
Check all JWK key_ops entries for duplicates before ignoring unknown
usage names.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: handle PBKDF2 iteration limits
2ae6b20
Report OperationError for unsupported iteration counts and return an
empty result before invoking the backend when no output is requested.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: separate conversion from validation
e937421
Convert algorithm dictionaries on the original receiver, with name
read once. Validate normalized parameters in their operation steps
after the method-level key checks and generation usage checks.

This also makes Argon2 validation use converted parallelism and keeps
later dictionary conversion errors ahead of semantic parameter errors.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: copy derived bits without species
36bb4f6
Use the byte-copy helper for truncated ECDH results so ArrayBuffer
species cannot replace or resize the returned key material.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
@panva
crypto: minimize RSA public exponent metadata
716fc4e
Omit leading zero octets from generated CryptoKey publicExponent
values, matching the BigInteger representation.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: copy parameters without array species
28da49e
Allocate byte copies directly so typed-array species cannot replace
normalized parameters or bit-truncated key material.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: check RSA JWK alg with SHA-3 hashes
46ee861
Reject a supplied JWK alg when no matching identifier exists for the
requested RSA algorithm and hash.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: reject duplicate unknown key usages
8c502a6
Check all JWK key_ops entries for duplicates before ignoring unknown
usage names.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: handle PBKDF2 iteration limits
5e05532
Report OperationError for unsupported iteration counts and return an
empty result before invoking the backend when no output is requested.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: copy derived bits without species
3180698
Use the byte-copy helper for truncated ECDH results so ArrayBuffer
species cannot replace or resize the returned key material.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: minimize RSA public exponent metadata
2ac8c82
Omit leading zero octets from generated CryptoKey publicExponent
values, matching the BigInteger representation.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: create key usage arrays without species
6d97ccd
Build public usages and JWK key_ops from the native usage mask so
array species cannot replace or mutate internal usage arrays.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: derive Argon2 without worker threads
abaf24b
Keep Argon2 lane count independent from backend worker availability.
When the OpenSSL thread pool is unavailable, compute lanes serially.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: report actual RSA modulus lengths
53773e5
Use the generated key's modulus size for both CryptoKey algorithm
objects. Preserve successful backend generation when it rounds the
requested size, keeping metadata consistent across export and cloning.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: split hybrid keys without species
759548e
Create byte views directly when splitting hybrid KEM keys and seeds,
so typed-array species cannot alter the component key material.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: use the public CryptoKey prototype
fb0661d
Give generated, imported, converted, and transferred keys the public
interface prototype directly, without an intermediate internal object.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: include EC public keys in PKCS8 exports
84a20cd
Export Web Crypto EC private keys from a clone with the public point
included, even when the imported encoding omitted it. Preserve the
original KeyObject encoding state.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: map JWK export failures to OperationError
9be7d39
Map inaccessible key material to the Web Crypto error type, including
seedless ML-DSA and ML-KEM keys converted from KeyObjects.

Assisted-by: Codex
Signed-off-by: Filip Skokan <[email protected]>
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: check EC coordinate conversion results
7613706
Propagate coordinate conversion failures instead of importing an
oversized JWK coordinate as zero. Keep equivalent short and zero-padded
integer encodings accepted by the native decoder.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
benchmark: cover Web Crypto conversion costs
b218f16
Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 27, 2026
@panva @aduh95
crypto: verify empty KMAC outputs
a0dd2f5
Compare empty KMAC outputs with empty signatures as equal, as required
by the verification algorithm. Skip CRYPTO_memcmp for zero-length
buffers while retaining the constant-time comparison for other MACs.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
HoonDongKang pushed a commit to HoonDongKang/node that referenced this pull request Sep 28, 2026
@panva @HoonDongKang
crypto: use internal random buffer bounds
971ab72
Read buffer lengths and element sizes from internal slots in
randomFillSync() and randomFill(). Shadowed properties can otherwise
skip filling, change the selected range, or fail a native bounds check.

Use the intrinsic byte length for the getRandomValues() quota check and
keep its delegation to randomFillSync().

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: nodejs#66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
HoonDongKang pushed a commit to HoonDongKang/node that referenced this pull request Sep 28, 2026
@panva @HoonDongKang
crypto: match algorithm names as ASCII
58ed008
Reject non-ASCII equivalents of registered Web Crypto algorithm names.
Skip the character scan when the input already uses the canonical name.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: nodejs#66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
HoonDongKang pushed a commit to HoonDongKang/node that referenced this pull request Sep 28, 2026
@panva @HoonDongKang
crypto: reject short AES-KW inputs
f96da54
Enforce the minimum key-wrap input lengths before the empty-input
shortcut, including the integrity-check block when unwrapping.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: nodejs#66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
HoonDongKang pushed a commit to HoonDongKang/node that referenced this pull request Sep 28, 2026
@panva @HoonDongKang
crypto: isolate cipher job errors
7419af7
Use only errors captured by the cipher job when converting its result.
Unrelated errors on the event loop thread must not turn a successful
operation into a failure or trigger an assertion.

Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: nodejs#66237
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Aviv Keller <[email protected]>
@panva panva mentioned this pull request Sep 29, 2026
[v26.x backport] crypto: fix various edge cases #66391
Closed
@github-actions github-actions Bot mentioned this pull request Oct 5, 2026
2026-10-07, Version 26.11.0 (Current) #66546
Merged
This was referenced Oct 22, 2026
fix: do not reuse MSW's fake TLS sessions for the mock backend project-alone/frontend-boilerplate#84
Merged
Starter 서버가 WebCrypto AES 처리 중 Node assertion으로 죽는다 project-alone/frontend-boilerplate#82
Closed
@panva panva mentioned this pull request Oct 23, 2026
[v24.x backport] crypto, test, and tooling fixes #66970
Closed
This was referenced Oct 25, 2026
webcrypto: add Argon2d, Argon2i and Argon2id oven-sh/bun#46902
Closed
Add the QuotaExceededError global oven-sh/bun#47040
Closed
@leapmux-renovate leapmux-renovate Bot mentioned this pull request Nov 1, 2026
chore(deps): Update Node.js to v26 leapmux/leapmux#578
Merged
@panva panva mentioned this pull request Nov 2, 2026
webcrypto: valid AES-GCM decrypt aborts (errors->Empty()) after tls.connect() with an undeserializable session (v24.x) #67203
Closed
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
2026-11-30, Version 24.23.0 'Krypton' (LTS) #67663
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes
@avivkeller avivkeller avivkeller approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. backported-to-v24.x PRs backported to the v24.x-staging branch. backported-to-v26.x PRs backported to the v26.x-staging branch. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@panva @nodejs-github-bot @jasnell @avivkeller @aduh95
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.