Skip to content
Merged
Changes from all 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: 6 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,16 @@ Server.prototype.setContentHeaders = function (req, res, next) {
next();
};

Server.prototype.checkHost = function (headers) {
Server.prototype.checkHost = function (headers, headerToCheck) {
// allow user to opt-out this security check, at own risk
if (this.disableHostCheck) {
return true;
}

if (!headerToCheck) headerToCheck = 'host';
// get the Host header and extract hostname
// we don't care about port not matching
const hostHeader = headers.host;
const hostHeader = headers[headerToCheck];

if (!hostHeader) {
return false;
Expand Down Expand Up @@ -725,8 +727,8 @@ Server.prototype.listen = function (port, hostname, fn) {
return;
}

if (!this.checkHost(connection.headers)) {
this.sockWrite([ connection ], 'error', 'Invalid Host header');
if (!this.checkHost(connection.headers) || !this.checkHost(connection.headers, 'origin')) {
this.sockWrite([ connection ], 'error', 'Invalid Host/Origin header');

connection.close();

Expand Down