Skip to content

Commit 3a31917

Browse files
nougadhiroppy
authored andcommittedNov 29, 2019
fix(client): don't override protocol for socket connection to 127.0.0.1 (#2303)
Chrome and Firefox accept `http://`/`ws://` mixed-content connection to `127.0.0.1` even when the actual website is loaded via `https://`. Fixes #2302
1 parent f501e83 commit 3a31917

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed
 

‎client-src/default/utils/createSocketUrl.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function createSocketUrl(resourceQuery) {
4646
// because the browser doesn't accept non-secure websockets.
4747
if (
4848
hostname &&
49+
hostname !== '127.0.0.1' &&
4950
(self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0')
5051
) {
5152
protocol = self.location.protocol;

‎test/client/utils/__snapshots__/createSocketUrl.test.js.snap

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ exports[`createSocketUrl should return the url when __resourceQuery is ?test 1`]
44

55
exports[`createSocketUrl should return the url when __resourceQuery is http://0.0.0.0 1`] = `"http://localhost/sockjs-node"`;
66

7+
exports[`createSocketUrl should return the url when __resourceQuery is http://127.0.0.1 1`] = `"http://127.0.0.1/sockjs-node"`;
8+
79
exports[`createSocketUrl should return the url when __resourceQuery is http://user:pass@[::]:8080 1`] = `"http://user:pass@localhost:8080/sockjs-node"`;
810

911
exports[`createSocketUrl should return the url when __resourceQuery is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;
@@ -22,6 +24,8 @@ exports[`createSocketUrl should return the url when the current script source is
2224

2325
exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http://localhost/sockjs-node"`;
2426

27+
exports[`createSocketUrl should return the url when the current script source is http://127.0.0.1 1`] = `"http://127.0.0.1/sockjs-node"`;
28+
2529
exports[`createSocketUrl should return the url when the current script source is http://user:pass@[::]:8080 1`] = `"http://user:pass@localhost:8080/sockjs-node"`;
2630

2731
exports[`createSocketUrl should return the url when the current script source is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;

‎test/client/utils/createSocketUrl.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('createSocketUrl', () => {
1010
'http://0.0.0.0',
1111
'https://localhost:123',
1212
'http://user:pass@[::]:8080',
13+
'http://127.0.0.1',
1314
// TODO: comment out after the major release
1415
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
1516
// 'file://filename',

0 commit comments

Comments
 (0)
Please sign in to comment.