Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_client: prevent domain fronting (Host mismatch) when using proxy #36805

Closed
wants to merge 5 commits into from
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
LouisSung marked this conversation as resolved.
Show resolved Hide resolved
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