reply.fromParameters() drops query params after a second "?"
評価
- 難易度
- 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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fastify/fastify-http-proxy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
fastify/fastify-http-proxy#493 ·
fastify/fastify-http-proxy の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
arfct/timezone.fyi#19 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
tensorflow/tfjs#8754 ·
-
bug main ui
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
openhab/openhab-webui#4671 ·
メンテナーはふだん 1 日以内に返信
-
scratch-paint's npm test does not run lint, so CI never lints paint; one lint error is currently in develop対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
scratchfoundation/scratch-editor#754 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 96/100
google/site-kit-wp#14102 ·
メンテナーはふだん 2 日以内に返信