Open redirect via `//<host>/..%2f<dir>` in directory trailing-slash redirect

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

Nessuno ha ancora preso questa issue.

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, cli, security

Direzione di ricerca

Inizia in lib/core/index.js, in corrispondenza di decodePathname(parsed.pathname) e del reindirizzamento delle directory con slash finale, che crea l’intestazione Location. Aggiungi un test di regressione usando la forma della richiesta fornita e verifica che il reindirizzamento resti sull’origine del server e abbia una sola barra iniziale. L’issue non indica un file di test, quindi individua prima i test di reindirizzamento esistenti ed esegui la suite pertinente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In http-server 14.1.1 and master (0d3b7bb, Node.js v26.13.0), requesting a path starting with //<host>/..%2f<subdir> when the served root contains <subdir> returns a 302 redirect with a scheme-relative Location header (//<host>/..%2f<subdir>/) that browsers resolve to http://<host>/..%2f<subdir>/ (CWE-601; incomplete fix for ecstatic advisory GHSA-9q64-mpxx-87fg).

const httpServer = require('http-server');
const fs = require('fs');

fs.mkdirSync('./test-root/dir', { recursive: true });
const server = httpServer.createServer({ root: './test-root' });

server.listen(0, '127.0.0.1', async () => {
  const { port } = server.server.address();
  const url = `http://127.0.0.1:${port}//evil.example/..%2fdir`;
  const res = await fetch(url, { redirect: 'manual' });
  const loc = res.headers.get('location');
  console.log('Status:', res.status);
  console.log('Location:', loc);
  console.log('Resolved URL:', new URL(loc, url).href);
  server.close();
});

Expected: Location is a single-slash origin-relative path (e.g. Location: /dir/) that stays on http://127.0.0.1:<port>/.

Actual:

Status: 302
Location: //evil.example/..%2fdir/
Resolved URL: http://evil.example/..%2fdir/

Reference: RFC 9110 §10.2.2 (Location header field) and WHATWG URL Standard §4.4 (a relative-URL string beginning with // is parsed as a scheme-relative-special-url whose host is the authority following //); see also GHSA-9q64-mpxx-87fg and commit jfhbrook/node-ecstatic@be6fc25.

In lib/core/index.js, decodePathname(parsed.pathname) decodes %2f and normalizes //evil.example/../dir to pathname = '/dir' (matching the local directory without a trailing slash), but the 302 response constructs Location from the unnormalized parsed.pathname (ensureUriEncoded(${parsed.pathname}/${q})) instead of pathname or a path with leading slashes collapsed ('/' + parsed.pathname.replace(/^[\/\\]+/, '')).

Credit: https://ucsbplse.github.io/

Lingua principale
JavaScript
Stelle
14.2k
Fork
1.6k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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 http-party/http-server

Tutte le issue di http-party/http-server

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.