Skip to content

Commit

Permalink
fix(client): don't override protocol for socket connection to 127.0.0…
Browse files Browse the repository at this point in the history
….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
  • Loading branch information
nougad authored and hiroppy committed Nov 29, 2019
1 parent f501e83 commit 3a31917
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions client-src/default/utils/createSocketUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function createSocketUrl(resourceQuery) {
// because the browser doesn't accept non-secure websockets.
if (
hostname &&
hostname !== '127.0.0.1' &&
(self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0')
) {
protocol = self.location.protocol;
Expand Down
4 changes: 4 additions & 0 deletions test/client/utils/__snapshots__/createSocketUrl.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`createSocketUrl should return the url when __resourceQuery is ?test 1`]

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

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

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

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

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

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"`;

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

exports[`createSocketUrl should return the url when the current script source is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;
Expand Down
1 change: 1 addition & 0 deletions test/client/utils/createSocketUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('createSocketUrl', () => {
'http://0.0.0.0',
'https://localhost:123',
'http://user:pass@[::]:8080',
'http://127.0.0.1',
// TODO: comment out after the major release
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
// 'file://filename',
Expand Down

0 comments on commit 3a31917

Please sign in to comment.