Fix RsaPrivateKey dropping CRT params; add security regression tests - #3
Merged
Conversation
Port the remaining fix from Effect-TS/effect#6566: the RsaPrivateKey union tried the d-only member before the full CRT member, and since Struct decoding drops unlisted fields, a complete RSA private key lost its CRT parameters (p, q, dp, dq, qi) on decode. The full CRT form now comes first. Also port the PR's applicable security regression tests: algorithm/key family binding and use:enc rejection, JWKS verification surviving a malformed key, fail-closed handling of algorithm-mismatched keys in Jws.verify, the maxSignatures cap, and RsaPrivateKey round-trips.
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.
Ports the security/bug fixes from Effect-TS/effect#6566 that were not yet present in this codebase.
Gap analysis
The codebase already matched the PR's state as of its
7a82a65acommit — the security-audit hardening (Jwk.isCompatibleWith/isSymmetric/isPrivate, theJws.verifyalgorithmsallowlist /maxSignaturescap / fail-closed key import and verify / trustable gate onjku/embedded-jwkkeys,Jwt.verify'salgorithms/types/BadType) and the skip-malformed-keys behavior inJwt.verifywere all present. The JWE-only fixes do not apply (no Jwe module here). One fix remained:Changes
src/Jwk.ts— reorder theRsaPrivateKeyunion so the full CRT member is tried before the d-only member (from upstream commit0d0afbb6). Previously a complete RSA private key matched the d-only struct first, and since Struct decoding drops unlisted fields, its CRT parameters (p,q,dp,dq,qi) were silently discarded — corrupting the key on round-trip.test/Security.test.ts— port the PR's applicable security regression tests: algorithm-family/key-type binding anduse: "enc"rejection, JWKS verification surviving a malformed key alongside a good one, fail-closed handling of an algorithm-mismatched key inJws.verify, themaxSignaturescap, and CRT-preservation plus d-onlyRsaPrivateKeyround-trips.Verification
pnpm check,pnpm lint, andpnpm testall pass (15/15).