Skip to content

Improve error message for ERR_JWKS_NO_MATCHING_KEY #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sclassen
Copy link

@sclassen sclassen commented Apr 7, 2025

A config error cost me an afternoon.

This enhanced error message would have helped me find the root of my problem much faster.

Copy link
Owner

@panva panva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @sclassen

I'm sorry about the lost afternoon, can you elaborate though? What was the problem and how would this particular change help you?

This is unfortunately a breaking change as it changes the exposed error classes constuctor signature that's being used by downstream modules and user implementations of their own JWKS key resolver functions.

I believe the correct way to provide cause for the failure is not the message, which already describes exactly what the error is, but to use the, aptly named, cause option to provide more context. This could take the form of an object with the alg, kid, kty variables and a structuredClone of the current jwks

@sclassen
Copy link
Author

sclassen commented Apr 11, 2025

the cause was that an ingress nginx in our test environment replaced the JWT token.

When looking at the request in the browser the correct token was there.
Only when we started to log all tokens on the server we found that the token was replaced.
Having the kid in the message would have helped to find the nginx as the cause much faster.

@wparad
Copy link

wparad commented Apr 11, 2025

@sclassen I think you misunderstood was panva was saying. He's says to specify the cause property of the error. Rather than asking "what caused it"

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.

3 participants