Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const {
StringPrototypeCharCodeAt,
StringPrototypeIncludes,
StringPrototypeIndexOf,
StringPrototypeReplace,
StringPrototypeStartsWith,
StringPrototypeToUpperCase,
Symbol,
TypedArrayPrototypeSlice,
Expand Down Expand Up @@ -284,6 +286,14 @@ function ClientRequest(input, options, cb) {
if (port && +port !== defaultPort) {
hostHeader += ':' + port;
}

// Prevent potential domain fronting misjudgement when using proxy
// Overwrite the "default Host requst header" with the host of path
Comment thread
LouisSung marked this conversation as resolved.
Outdated
if (!StringPrototypeStartsWith(this.path, '/')) {
hostHeader = new URL(
`http://${StringPrototypeReplace(this.path, /^.*:\/\//, '')}`).host;
}

this.setHeader('Host', hostHeader);
}

Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-tls-over-http-tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const proxy = net.createServer((clientSocket) => {
`CONNECT localhost:${server.address().port} ` +
'HTTP/1.1\r\n' +
'Proxy-Connections: keep-alive\r\n' +
`Host: localhost:${proxy.address().port}\r\n` +
// Match header Host with destination Host
`Host: localhost:${server.address().port}\r\n` +
'Connection: close\r\n\r\n');

console.log('PROXY: got CONNECT request');
Expand Down