-
-
Notifications
You must be signed in to change notification settings - Fork 150
fix(crypto): match Node 26 parity #6836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fix(crypto): #6783 match Node 26 X509 `checkIP` errors and KMAC edge behavior, including non-byte-aligned lengths and empty JWK keys. |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 15088
🌐 Web query:
WebCrypto modern algorithms JWK k field decoding invalid JWK fail wicg github.io webcrypto modernalgos💡 Result:
The "k" field in a JSON Web Key (JWK) is used to carry the raw key material for symmetric algorithms (typically with the "oct" key type) [1][2][3]. Decoding issues related to this field are generally caused by improper handling of Base64URL encoding—a variant of Base64 required by the JOSE specifications (RFC 7517) which replaces '+' with '-' and '/' with '', and omits padding [1][2]. In the context of the Web Cryptography API and its extensions (such as the Modern Algorithms proposal), "invalid JWK" errors during the decoding of the "k" field typically arise from: 1. Improper Encoding/Decoding: The "k" value must be decoded from its Base64URL representation into a raw byte array (Uint8Array) before it can be processed as a key by the WebCrypto subtle.importKey operation [1][3]. If an implementation attempts to treat the string directly as a key or uses standard Base64 decoding (which fails on characters like '-' and ''), a DataError or SyntaxError is standard behavior [1][2]. 2. Validation Requirements: Specifications and browser implementations enforce strict checks on the "k" field. For example, if the key length implied by the decoded "k" parameter does not match the requirements of the algorithm specified in the JWK (or provided to importKey), the operation will fail [4][2]. 3. WebCrypto "Modern Algorithms": The WICG "Modern Algorithms" specification [2] explicitly governs the handling of JWK inputs for new algorithms (like ML-KEM). Similar to the base WebCrypto API, it mandates that the "k" (or "priv"/"pub") fields must be valid Base64URL encoded data [2]. If a JWK is malformed—such as having an incorrect key type ("kty") for the algorithm, missing required fields, or having invalid Base64URL characters—the API is required to throw a DataError [2]. If you are encountering this error, ensure that: - The Base64URL string is correctly padded if your decoder requires it (though RFC 7517 suggests padding should be omitted) or, conversely, ensure your decoder is RFC-compliant and handles unpadded Base64URL correctly [1][2]. - The "kty" (Key Type) and "alg" (Algorithm) fields in your JWK object align with the WebCrypto algorithm you are importing into [2][3]. - You are not passing the JWK object directly as a key material buffer, but rather passing the parsed JWK structure to the importKey function where the browser/runtime handles the internal decoding [3].
Citations:
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 14707
Do not allow malformed JWK
kdecoding as an empty KMAC key.jwk_import_key_bytes(...).unwrap_or_else(|| Vec::new())converts a missing or invalid decodedkvalue into the same zero-length byte vector as an explicitly present empty JWK. Since KMAC is now in the empty-key allowlist, malformed JWKs can be imported as zero-length keys instead of failing key-material validation. Preserve the decode result: allowk: ""only when explicit, and reject missing or invalidkdata.🤖 Prompt for AI Agents