reply.fromParameters() drops query params after a second "?"
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, node.js
- Área
- backend-api-design
Línea de trabajo
El issue señala extractUrlComponents() y la llamada defectuosa urlString.split('?', 2); localiza esa función y lee el código circundante que gestiona las URL. Reproduce el problema con la solicitud proporcionada que contiene un segundo ? y comprueba después que ambos parámetros de consulta llegan al upstream. El trabajo estará terminado cuando se conserve la cadena de consulta y las pruebas pertinentes cubran este caso.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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"}.
- Lenguaje dominante
- JavaScript
- Estrellas
- 394
- Forks
- 105
- Merge medio
- 9 h 34 min
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de fastify/fastify-http-proxy
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
fastify/fastify-http-proxy#493 ·
Todos los issues de fastify/fastify-http-proxy
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
arfct/timezone.fyi#19 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
tensorflow/tfjs#8754 ·
-
Marketplace time-zone issueAbiertobug main ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openhab/openhab-webui#4671 ·
Los mantenedores suelen responder en 1 día
-
scratch-paint's npm test does not run lint, so CI never lints paint; one lint error is currently in developPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
scratchfoundation/scratch-editor#754 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 96/100
google/site-kit-wp#14102 ·
Los mantenedores suelen responder en 2 días