-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hello,
I would like to suggest a small change to make the nonce verification in the Key Binding JWT more flexible.
Current Behavior
Currently, the verify method requires a nonce string in the options to perform an equality check. It seems that if the nonce is not provided, the entire Key Binding JWT verification may be skipped.
sd-jwt-js/packages/core/src/index.ts
Lines 223 to 225 in b8733bc
| if (!options?.keyBindingNonce) { | |
| return { payload, header }; | |
| } |
sd-jwt-js/packages/core/src/index.ts
Lines 550 to 552 in b8733bc
| if (!options?.keyBindingNonce) { | |
| return { payload, headers }; | |
| } |
Use Case for Change
The current approach works well for a simple challenge-response flow. However, some other scenarios require more flexibility.
For example, a verifier might want to validate the Key Binding JWT's signature first, but handle the nonce check separately in cases like these:
Presenter-Generated Nonce: The presenter generates a nonce, and the verifier needs to check it against a database of previously used nonces to prevent replay attacks.
Verifier-Generated Nonce with DB State: The verifier generates a nonce and stores its status (e.g., status: 'issued') in a database. When the response is received, the verifier must look up the incoming nonce to validate its status and then mark it as used.
In both scenarios, the verifier needs to inspect the nonce value from the JWT before running its own validation logic. The current API makes this difficult, as it requires providing the expected value upfront.
Proposal
I propose making the nonce parameter in the options object truly optional with the following logic:
If a nonce string is provided: The behavior remains the same (perform a strict equality check).
If nonce is NOT provided: The method should only skip the nonce check but still perform all other Key Binding JWT validations (e.g., signature verification).
Thank you.