fix: GHSA-mvf2-f6gm-w987 JWT Algorithm Confusion via Whitespace-Prefix#586
fix: GHSA-mvf2-f6gm-w987 JWT Algorithm Confusion via Whitespace-Prefix#586antoatta85 wants to merge 3 commits intomasterfrom
Conversation
…xed RSA Public Key
There was a problem hiding this comment.
Pull request overview
This PR fixes an incomplete mitigation for GHSA-mvf2-f6gm-w987 / CVE-2023-48223 by ensuring leading whitespace on PEM inputs does not bypass ^-anchored key detection, which could otherwise misclassify an RSA/EC/Ed public key as an HMAC secret and re-enable JWT algorithm confusion.
Changes:
- Trim key strings before regex / substring checks in
performDetectPublicKeyAlgorithmsandperformDetectPrivateKeyAlgorithm. - Add regression tests covering leading whitespace (
\n, spaces, tabs) for RSA/EC/Ed public key detection and signer/verifier rejection guards.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/crypto.js |
Applies trim() prior to PEM/cert detection logic to prevent whitespace-prefixed key misclassification. |
test/crypto.spec.js |
Adds regression tests validating correct algorithm detection and guard behavior with whitespace-prefixed keys/certs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@antoatta85 , we really need this fix, because pipelines are blocked. Can you push the requested changes ? I could provide a change, but don't have the permissions 😬 |
I will be reviewing this PR during this morning, along with any others that are open on this repository. If you have any changes you think should occur with this PR please feel free to comment and we'll take them into account. |
1)
|
|
CI pipeline of one my projects is blocked by this. Hoping to get it resolved soon. Thank you! |
|
@antoatta85 Please can you review/incorporate the feedback from @FlowmasterHaggla above? |
|
Hey @SociableSteve and @antoatta85, thanks for moving on this! Since this CVE is currently blocking CI security audits for downstream projects, I went ahead and incorporated @FlowmasterHaggla's feedback (including the \n edge case) into a superseding PR here: #598 I'm more than happy to close mine if @antoatta85 gets a chance to update this branch, if more changes are required, I just wanted to provide a fix that can be merged to unblock the release. |
@SociableSteve done! |
* fix: GHSA-mvf2-f6gm-w987 JWT Algorithm Confusion via Whitespace-Prefixed RSA Public Key * fix: resolve JWT algorithm confusion with leading whitespace and gaps in EC/PKCS8 decodin * test: remove redundant whitespace test spotted in code review --------- Co-authored-by: antoatta85 <antonio.attanasio@nearform.com>
|
Resolved in #598 |
fix: trim whitespace from PEM keys before pattern matching (GHSA-mvf2-f6gm-w987)
The fix for CVE-2023-48223 introduced a
^-anchored regex (publicKeyPemMatcher) todetect RSA public keys. Any leading whitespace in the key string — common when keys are
loaded from databases, YAML configs, or environment variables — caused the anchor to
fail, misclassifying the RSA public key as an HMAC secret and re-enabling the original
algorithm confusion attack.
The private key path already called
.trim()before matching; the public key path did not.Fix
key.trim()is now applied before all regex and string matches in bothperformDetectPublicKeyAlgorithmsandperformDetectPrivateKeyAlgorithm(src/crypto.js).Tests added
Regression tests in
test/crypto.spec.jscovering keys with leading\n, spaces, and tabs for:FIXES #589