Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Server.prototype.checkHost = function(headers) {
// also allow public hostname if provided
if(typeof this.publicHost === "string") {
const idxPublic = this.publicHost.indexOf(":");
const publicHostname = idxPublic >= 0 ? this.publicHost.substr(0, idx) : this.publicHost;
const publicHostname = idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
if(hostname === publicHostname) return true;
}

Expand Down
55 changes: 55 additions & 0 deletions test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,59 @@ describe("Validation", function() {
throw new Error("Validation didn't fail");
})
});

describe("checkHost", function() {
it("should always allow any host if options.disableHostCheck is set", function() {
const options = {
public: "test.host:80",
disableHostCheck: true
};
const headers = {
host: "bad.host"
};
const server = new Server(compiler, options);
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});

it("should allow any valid options.public when host is localhost", function() {
const options = {
public: "test.host:80"
};
const headers = {
host: "localhost"
};
const server = new Server(compiler, options);
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});

it("should allow any valid options.public when host is 127.0.0.1", function() {
const options = {
public: "test.host:80"
};
const headers = {
host: "127.0.0.1"
};
const server = new Server(compiler, options);
if(!server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});

it("should not allow hostnames that don't match options.public", function() {
const options = {
public: "test.host:80",
};
const headers = {
host: "test.hostname:80"
};
const server = new Server(compiler, options);
if(server.checkHost(headers)) {
throw new Error("Validation didn't fail");
}
});
})
});