reply.fromParameters() drops query params after a second "?"
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
- Ambito
- backend-api-design
Direzione di ricerca
L’issue individua extractUrlComponents() e la chiamata errata urlString.split('?', 2); trova questa funzione e leggi il codice circostante che gestisce gli URL. Riproduci il problema con la richiesta fornita che contiene un secondo ?, poi verifica che entrambi i parametri di query arrivino all’upstream. Il lavoro è completato quando la stringa di query viene preservata e i test pertinenti coprono questo caso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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"}.
- Lingua principale
- JavaScript
- Stelle
- 394
- Fork
- 105
- Merge medio
- 9h 34m
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fastify/fastify-http-proxy
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
fastify/fastify-http-proxy#493 ·
Tutte le issue di fastify/fastify-http-proxy
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
arfct/timezone.fyi#19 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
tensorflow/tfjs#8754 ·
-
Marketplace time-zone issueApertabug main ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openhab/openhab-webui#4671 ·
I maintainer di solito rispondono entro 1 giorno
-
scratch-paint's npm test does not run lint, so CI never lints paint; one lint error is currently in developForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
scratchfoundation/scratch-editor#754 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 96/100
google/site-kit-wp#14102 ·
I maintainer di solito rispondono entro 2 giorni