reply.fromParameters() drops query params after a second "?"
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
Issue 指出了 extractUrlComponents() 和有问题的调用 urlString.split('?', 2);找到该函数并阅读周围的 URL 处理代码。使用提供的、包含第二个 ? 的请求复现问题,然后检查两个查询参数是否都传递到了 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 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
scratchfoundation/scratch-editor#754 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 96/100
google/site-kit-wp#14102 ·
维护者通常 2 天内回复