Skip to content

Commit 8bb3ca8

Browse files
3846masaevilebottnawi
authored andcommitted
fix: regression in checkHost for checking Origin header (#1606)
1 parent ff2874f commit 8bb3ca8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Server.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@ Server.prototype.checkHost = function (headers, headerToCheck) {
646646
}
647647

648648
// use the node url-parser to retrieve the hostname from the host-header.
649-
const hostname = url.parse(`//${hostHeader}`, false, true).hostname;
649+
const hostname = url.parse(
650+
// if hostHeader doesn't have scheme, add // for parsing.
651+
/^(.+:)?\/\//.test(hostHeader) ? hostHeader : `//${hostHeader}`,
652+
false,
653+
true,
654+
).hostname;
650655
// always allow requests with explicit IPv4 or IPv6-address.
651656
// A note on IPv6 addresses:
652657
// hostHeader will always contain the brackets denoting

test/Validation.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ describe('Validation', () => {
171171
}
172172
});
173173

174+
it('should allow urls with scheme for checking origin', () => {
175+
const options = {
176+
public: 'test.host:80'
177+
};
178+
const headers = {
179+
origin: 'https://test.host'
180+
};
181+
const server = new Server(compiler, options);
182+
if (!server.checkHost(headers, 'origin')) {
183+
throw new Error("Validation didn't fail");
184+
}
185+
});
186+
174187
describe('allowedHosts', () => {
175188
it('should allow hosts in allowedHosts', () => {
176189
const tests = [

0 commit comments

Comments
 (0)