crypto: avoid throwing key brand checks - #65503
Open
panva wants to merge 2 commits into
Open
Conversation
Use the native KeyObject FunctionTemplate brand check instead of probing slot access and catching ERR_INVALID_THIS. Keep a private-field fast path for ordinary same-realm KeyObjects. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Use the native CryptoKey FunctionTemplate brand check instead of probing slot access and catching ERR_INVALID_THIS. Keep a private-field fast path for ordinary same-realm CryptoKeys. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Collaborator
|
Review requested:
|
avivkeller
approved these changes
Aug 23, 2026
Collaborator
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65503 +/- ##
==========================================
- Coverage 90.14% 90.13% -0.02%
==========================================
Files 751 751
Lines 252521 252701 +180
Branches 47511 47552 +41
==========================================
+ Hits 227635 227771 +136
- Misses 16192 16210 +18
- Partials 8694 8720 +26
🚀 New features to boost your workflow:
|
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.
Use the native KeyObject and CryptoKey FunctionTemplate brand check instead of probing slot access and catching ERR_INVALID_THIS. Keep a private-field fast path for ordinary same-realm keys.
Before this change
isKeyObject()andisCryptoKey()detected invalid objects by calling their slot getters, catchingERR_INVALID_THIS, and returningfalse. Becausenode:cryptoAPIs check key inputs for being key objects first this change has a positive downstream effect on every use of those APIs that isn't with a key object (e.g. PEM, DER, JWK, etc) as well as on use with key object embedded in an regular object as{ key: KeyObject, ...options }createHmac()with a Buffer keycreateCipheriv()with a Buffer keyhkdfSync()with a Buffer keycreatePublicKey()with DER optionscreatePrivateKey()with DER optionssign()with DER optionsverify()with DER optionspublicEncrypt()with options and a BufferdiffieHellman()with two Buffer keysencapsulate()/decapsulate()with a Buffer keyObject-form key inputs benefit more because both the options object and its key payload previously caused failed brand checks.
SubtleCryptooperations are unaffected because they use WebIDL interface conversion instead ofisCryptoKey().