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

オープン 初心者向け
#491 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@RaphaelFakhri がすでに取り組んでいます。

2026年11月5日 から。

  • #492 @RaphaelFakhri による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

Issue では extractUrlComponents() と誤った呼び出し urlString.split('?', 2) が指摘されています。この関数を見つけ、周辺の URL 処理を読んでください。2 つ目の ? を含む提示されたリクエストで再現し、両方のクエリパラメーターが upstream に届くことを確認してください。クエリー文字列が保持され、関連するテストでこのケースがカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Prerequisites
  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported
Fastify version

5.x

Plugin version

11.6.6

Node.js version

22.x

Description

reply.fromParameters() truncates the query string at the second ?. Everything after it, including later &key=value pairs, is lost.

A literal ? is valid inside a query string (RFC 3986, section 3.4), and it is common in redirect parameters such as ?next=/a?b=1.

The cause is urlString.split('?', 2) in extractUrlComponents(). String.prototype.split with a limit discards the rest of the string instead of keeping it in the last element.

The default handler is not affected, because it removes the query string from the destination and @fastify/reply-from forwards the original one. The problem appears when you use reply.fromParameters() as documented in the README and pass its url to reply.from().

Steps to reproduce
const Fastify = require('fastify')
const proxy = require('@fastify/http-proxy')

const origin = Fastify()
origin.get('/api2/echo', async (request) => request.query)

const server = Fastify()
server.register(proxy, {
  upstream: 'http://localhost:3001',
  prefix: '/api',
  rewritePrefix: '/api2',
  preHandler (request, reply, done) {
    const { url, options } = reply.fromParameters(request.url, request.params, '/api')
    reply.from(url, options)
  }
})

await origin.listen({ port: 3001 })
await server.listen({ port: 3000 })
curl 'http://localhost:3000/api/echo?next=/a?b=1&c=2'
Expected behavior

The upstream receives {"next":"/a?b=1","c":"2"}.

The actual response is {"next":"/a"}.

主要言語
JavaScript
スター
394
フォーク
105
平均マージ
9時間 34分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fastify/fastify-http-proxy のほかの issue

fastify/fastify-http-proxy の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。