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

Aperta Adatta ai principianti
#491 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@RaphaelFakhri ci sta già lavorando.

Dal 5/11/2026.

  • #492 di @RaphaelFakhri — aperta

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

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fastify/fastify-http-proxy

Tutte le issue di fastify/fastify-http-proxy

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.