Repository navigation
Report invalid options from the general serializations #920
Closed
Omair-Asdaq
started this conversation in
Ideas
Replies: 1 comment
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
generalVerifyandgeneralDecryptfold faults raised while preparing the parts shared by all signatures or recipients intoJWSSignatureVerificationFailed/JWEDecryptionFailed. That collapsing is deliberate for token faults, but the caller's option validation (prepareVerify/prepareDecrypt) runs inside the sametry, so an invalid option is reported as a verification or decryption failure.Reproduction
With a valid general JWS and key:
The same mismatch exists for
keyManagementAlgorithmsandcontentEncryptionAlgorithmsingeneralDecryptversuscompactDecryptandflattenedDecrypt.test/jwt/verify.test.tsandtest/jwt/decrypt.test.tsalready pin theTypeErrorand its message for the compact path, so the general serializations are the inconsistent ones.Expected
An invalid option should raise the same
TypeErrorwith the same message in the general serializations as in the compact and flattened ones. Token faults (missing payload, bad key, tampered tag) should keep producingJWSSignatureVerificationFailed/JWEDecryptionFailed.Proposed change
Move the
prepareVerify/prepareDecryptcalls out of the fault-collapsingtryso option validation runs first, leaving token-fault behavior unchanged. Add one regression test per serialization to the existing general test files.Evidence
On Node 24.15.0 with the current main, the two new tests fail with exactly the mismatch above and pass after moving the calls; the full suite is 535 pass / 1 pre-existing Windows-only
declaration_commentsfailure,tap/run-node.tsis 224/224, and tsc/prettier/check:subpaths/check:bundlesare clean. I can share the patch and the exact commands once the approach is agreed.Question
Would you like me to prepare a fix for this, or would you prefer a different approach?
All reactions