Skip to content

fix: keep query params after a '?' in fromParameters - #492

Merged
Tony133 merged 2 commits into
fastify:mainfrom
RaphaelFakhri:fix/fromparameters-query-question-mark
Nov 14, 2026
Merged

Tony133 merged 2 commits into
fastify:mainfrom
RaphaelFakhri:fix/fromparameters-query-question-mark

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

reply.fromParameters() splits the URL with split('?', 2). With a limit, split drops everything after the second ?, so a request such as /api/echo?next=/a?b=1&c=2 reaches the upstream as ?next=%2Fa. Both b=1 and c=2 are lost.

A literal ? is valid inside a query string (RFC 3986, section 3.4), and it is common in redirect parameters.

This change splits the URL on the first ? only. The new test proxies through reply.fromParameters() and reply.from(), as shown in the README, and checks the query that the upstream receives.

The default handler is not affected, because @fastify/reply-from forwards the original query string.

Checklist

Fixes #491

@RaphaelFakhri

Copy link
Copy Markdown
Contributor Author

The failing Test (20, ubuntu-latest) job is not caused by this change. main (ce4d419) fails the same three tests with @fastify/reply-from@12.8.1, which was released after the last green main run: HTTP paths cannot escape rewritePrefix, reply.fromParameters cannot escape rewritePrefix, and percent-encoded backslashes remain path data. With @fastify/reply-from@12.8.0, the full suite passes on Node 20 both on main and on this branch.

@SameRainbows

This comment was marked as spam.

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@Tony133
Tony133 merged commit edb5f2c into fastify:main Nov 14, 2026
17 checks passed
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.

reply.fromParameters() drops query params after a second "?"

3 participants