Skip to content
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

@fastify/jwt integration example unsafe? #320

Closed
Ricki-BumbleDev opened this issue Nov 9, 2024 · 1 comment · Fixed by #332
Closed

@fastify/jwt integration example unsafe? #320

Ricki-BumbleDev opened this issue Nov 9, 2024 · 1 comment · Fixed by #332
Assignees

Comments

@Ricki-BumbleDev
Copy link

Ricki-BumbleDev commented Nov 9, 2024

In the README there is this @fastify/jwt integration example:

const fastify = Fastify()
const getJwks = buildGetJwks()

fastify.register(fjwt, {
  decode: { complete: true },
  secret: (request, token, callback) => {
    const {
      header: { kid, alg },
      payload: { iss },
    } = token
    getJwks
      .getPublicKey({ kid, domain: iss, alg })
      .then(publicKey => callback(null, publicKey), callback)
  },
})

I could see someone blindly copy-pasting this without checking the issuer.

(AFAICT fetching the JWKS from the domain supplied by the client in the iss field of the JWT payload without validating is unsafe. An attacker could craft a JWT with a fake iss pointing to a domain they control? They could set up a JWKS endpoint that provides a public key of their choosing. This would allow the attacker to generate and sign a token that the server would then consider valid.)

I think the issuersWhitelist property should explicitly be added in the example to emphasise its importance and avoid this pitfall.

const getJwks = buildGetJwks({ issuersWhitelist: ['...'] })
@simoneb
Copy link
Member

simoneb commented Nov 10, 2024

@ilteoood in case you want to take a look at this one too

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 a pull request may close this issue.

3 participants