Skip to content

Fix RsaPrivateKey dropping CRT params; add security regression tests - #3

Merged
leonitousconforti merged 1 commit into
mainfrom
fix/jwk-rsa-crt-params
Jul 28, 2026
Merged

Fix RsaPrivateKey dropping CRT params; add security regression tests#3
leonitousconforti merged 1 commit into
mainfrom
fix/jwk-rsa-crt-params

Conversation

@leonitousconforti

Copy link
Copy Markdown
Owner

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 7a82a65a commit — the security-audit hardening (Jwk.isCompatibleWith/isSymmetric/isPrivate, the Jws.verify algorithms allowlist / maxSignatures cap / fail-closed key import and verify / trustable gate on jku/embedded-jwk keys, Jwt.verify's algorithms/types/BadType) and the skip-malformed-keys behavior in Jwt.verify were all present. The JWE-only fixes do not apply (no Jwe module here). One fix remained:

Changes

  • src/Jwk.ts — reorder the RsaPrivateKey union so the full CRT member is tried before the d-only member (from upstream commit 0d0afbb6). 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 and use: "enc" rejection, JWKS verification surviving a malformed key alongside a good one, fail-closed handling of an algorithm-mismatched key in Jws.verify, the maxSignatures cap, and CRT-preservation plus d-only RsaPrivateKey round-trips.
  • Changeset (patch).

Verification

  • pnpm check, pnpm lint, and pnpm test all pass (15/15).
  • The CRT regression test was confirmed non-vacuous: it fails with the fix reverted and passes with it applied.

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.
@leonitousconforti
leonitousconforti merged commit 017f243 into main Jul 28, 2026
1 check passed
@leonitousconforti
leonitousconforti deleted the fix/jwk-rsa-crt-params branch July 28, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant