fix: honor per-request key override on jwtVerify and jwtSign#423
Open
xianjianlf2 wants to merge 1 commit into
Open
fix: honor per-request key override on jwtVerify and jwtSign#423xianjianlf2 wants to merge 1 commit into
xianjianlf2 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #346.
A
keysupplied in the per-request options ofrequest.jwtVerify(andreply.jwtSign) was silently ignored. After the secret resolver ran,mergeOptionsWithKeyoverwrote the caller-providedkeywith the resolved registration secret, so the documented behaviour — "key … if provided, it will override the value of secret" (README,sign/verifyoptions) — 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
keybefore 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 existingsupport extended config contracttest now genuinely exercises the override on both the sign and verify paths. Full suite green, 100% coverage retained.