Skip to content

Commit 667f2a8

Browse files
committed
fix(dev): strip the request attribution header from incoming requests
1 parent 40ab1f6 commit 667f2a8

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/nuxt-cli/src/dev/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
420420
this.#cwd = options.cwd
421421

422422
this.handler = async (req, res) => {
423+
// Only the CLI's own dispatch may set the request-attribution header;
424+
// anything arriving on the wire is stripped so an external client cannot
425+
// forge or steal another request's identity in the logs.
426+
stripRequestHeader(req)
423427
// Internal endpoints answer before Nuxt exists, so they are matched ahead
424428
// of anything that waits on the first successful load, and they stay out
425429
// of the request feed.
@@ -1236,6 +1240,23 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
12361240
}
12371241
}
12381242

1243+
/**
1244+
* Remove any wire-supplied copy of the request-attribution header, from both
1245+
* the parsed headers and `rawHeaders` (which some frameworks reconstruct
1246+
* requests from), before the CLI sets its own value.
1247+
*/
1248+
function stripRequestHeader(req: IncomingMessage): void {
1249+
if (req.headers[REQUEST_HEADER] === undefined) {
1250+
return
1251+
}
1252+
delete req.headers[REQUEST_HEADER]
1253+
for (let i = req.rawHeaders.length - 2; i >= 0; i -= 2) {
1254+
if (req.rawHeaders[i]?.toLowerCase() === REQUEST_HEADER) {
1255+
req.rawHeaders.splice(i, 2)
1256+
}
1257+
}
1258+
}
1259+
12391260
function getAddressURL(addr: { address: string, port: number }, https: boolean) {
12401261
const proto = https ? 'https' : 'http'
12411262
let host = addr.address.includes(':') ? `[${addr.address}]` : addr.address

0 commit comments

Comments
 (0)