Skip to content

fix: honor per-request key override on jwtVerify and jwtSign#423

Open
xianjianlf2 wants to merge 1 commit into
fastify:mainfrom
xianjianlf2:fix/jwtverify-key-override-346
Open

fix: honor per-request key override on jwtVerify and jwtSign#423
xianjianlf2 wants to merge 1 commit into
fastify:mainfrom
xianjianlf2:fix/jwtverify-key-override-346

Conversation

@xianjianlf2

Copy link
Copy Markdown

Fixes #346.

A key supplied in the per-request options of request.jwtVerify (and reply.jwtSign) was silently ignored. After the secret resolver ran, mergeOptionsWithKey overwrote the caller-provided key with the resolved registration secret, so the documented behaviour — "key … if provided, it will override the value of secret" (README, sign/verify options) — did not apply on these paths.

This path is inconsistent with the standalone fastify.jwt.verify(token, { key }), which already honors the override.

Change: capture the caller-provided key before the per-request options are merged, and when present use it instead of the resolved secret. Registration-level secret resolution and global option precedence are unchanged.

Tests: added a regression test for request.jwtVerify({ verify: { key } }); the existing support extended config contract test now genuinely exercises the override on both the sign and verify paths. Full suite green, 100% coverage retained.

A `key` passed in the per-request options of `request.jwtVerify` (and
`reply.jwtSign`) was silently discarded: after the secret resolver ran,
`mergeOptionsWithKey` overwrote the caller-provided `key` with the
resolved registration secret, so the documented "key overrides secret"
behaviour did not apply on these paths.

Capture the caller-provided `key` before the options are merged and,
when present, use it instead of the resolved secret. Registration-level
secret resolution and global option precedence are unchanged.

Closes fastify#346
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.

Unable to set key override on request.jwtVerify

1 participant