Skip to content

Commit 860b5e9

Browse files
Merge branch 'master' into patch-2
2 parents 185ab5d + 11c9896 commit 860b5e9

File tree

12 files changed

+262
-44
lines changed

12 files changed

+262
-44
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
stage: Test (MacOS)
1919
os: 'osx'
2020
env: SCRIPT=test
21-
node_js: 'stable'
21+
# Node 10 instead of 'stable' since Node 11 segfaults
22+
# https://github.com/webpack/webpack-dev-server/pull/1588
23+
node_js: 10
2224
- <<: *osx
2325
node_js: 'lts/*'
2426
- <<: *osx

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,51 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
<a name="3.1.14"></a>
6+
## [3.1.14](https://github.com/webpack/webpack-dev-server/compare/v3.1.13...v3.1.14) (2018-12-24)
7+
8+
9+
### Bug Fixes
10+
11+
* add workaround for Origin header in sockjs ([#1608](https://github.com/webpack/webpack-dev-server/issues/1608)) ([1dfd4fb](https://github.com/webpack/webpack-dev-server/commit/1dfd4fb))
12+
13+
14+
15+
<a name="3.1.13"></a>
16+
## [3.1.13](https://github.com/webpack/webpack-dev-server/compare/v3.1.12...v3.1.13) (2018-12-22)
17+
18+
19+
### Bug Fixes
20+
21+
* delete a comma for Node.js <= v7.x ([#1609](https://github.com/webpack/webpack-dev-server/issues/1609)) ([0bab1c0](https://github.com/webpack/webpack-dev-server/commit/0bab1c0))
22+
23+
24+
25+
<a name="3.1.12"></a>
26+
## [3.1.12](https://github.com/webpack/webpack-dev-server/compare/v3.1.11...v3.1.12) (2018-12-22)
27+
28+
29+
### Bug Fixes
30+
31+
* regression in `checkHost` for checking Origin header ([#1606](https://github.com/webpack/webpack-dev-server/issues/1606)) ([8bb3ca8](https://github.com/webpack/webpack-dev-server/commit/8bb3ca8))
32+
33+
34+
35+
<a name="3.1.11"></a>
36+
## [3.1.11](https://github.com/webpack/webpack-dev-server/compare/v3.1.10...v3.1.11) (2018-12-21)
37+
38+
39+
### Bug Fixes
40+
41+
* **bin/options:** correct check for color support (`options.color`) ([#1555](https://github.com/webpack/webpack-dev-server/issues/1555)) ([55398b5](https://github.com/webpack/webpack-dev-server/commit/55398b5))
42+
* **package:** update `spdy` v3.4.1...4.0.0 (assertion error) ([#1491](https://github.com/webpack/webpack-dev-server/issues/1491)) ([#1563](https://github.com/webpack/webpack-dev-server/issues/1563)) ([7a3a257](https://github.com/webpack/webpack-dev-server/commit/7a3a257))
43+
* **Server:** correct `node` version checks ([#1543](https://github.com/webpack/webpack-dev-server/issues/1543)) ([927a2b3](https://github.com/webpack/webpack-dev-server/commit/927a2b3))
44+
* **Server:** mime type for wasm in contentBase directory ([#1575](https://github.com/webpack/webpack-dev-server/issues/1575)) ([#1580](https://github.com/webpack/webpack-dev-server/issues/1580)) ([fadae5d](https://github.com/webpack/webpack-dev-server/commit/fadae5d))
45+
* add url for compatibility with webpack@5 ([#1598](https://github.com/webpack/webpack-dev-server/issues/1598)) ([#1599](https://github.com/webpack/webpack-dev-server/issues/1599)) ([68dd49a](https://github.com/webpack/webpack-dev-server/commit/68dd49a))
46+
* check origin header for websocket connection ([#1603](https://github.com/webpack/webpack-dev-server/issues/1603)) ([b3217ca](https://github.com/webpack/webpack-dev-server/commit/b3217ca))
47+
48+
49+
550
<a name="3.1.10"></a>
651
## [3.1.10](https://github.com/webpack/webpack-dev-server/compare/v3.1.9...v3.1.10) (2018-10-23)
752

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ live reloading. This should be used for **development only**.
1919
It uses [webpack-dev-middleware][middleware-url] under the hood, which provides
2020
fast in-memory access to the webpack assets.
2121

22+
## Table of Contents
23+
24+
1. [Getting Started](#getting-started)
25+
2. [Usage](#usage)
26+
3. [Browser Support](#browser-support)
27+
4. [Support](#support)
28+
5. [Contributing](#contributing)
29+
6. [Maintainers](#maintainers)
30+
7. [Attribution](#attribution)
31+
8. [License](#license)
32+
2233
## Getting Started
2334

2435
First things first, install the module:
@@ -43,6 +54,7 @@ The easiest way to use it is with the CLI. In the directory where your
4354
```console
4455
node_modules/.bin/webpack-dev-server
4556
```
57+
_**Note**: Many CLI options are available with `webpack-dev-server`. Explore this [link](https://webpack.js.org/configuration/dev-server/)._
4658

4759
### With NPM Scripts
4860

examples/cli/compression/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ npm run webpack-dev-server -- --open --compress
1111

1212
## What should happen
1313

14-
1. The script should open `https://localhost:8080/`.
14+
1. The script should open `http://localhost:8080/`.
1515
2. Files being sent to the browser from the `webpack` bundle should be gzipped.
1616
3. Open the console in your browser's devtools and select the _Network_ tab.
1717
4. Find `bundle.js`. The response headers should contain `Content-Encoding: gzip`.

lib/Server.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ const createCertificate = require('./utils/createCertificate');
4343
const validateOptions = require('schema-utils');
4444
const schema = require('./options.json');
4545

46+
// Workaround for sockjs@~0.3.19
47+
// sockjs will remove Origin header, however Origin header is required for checking host.
48+
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
49+
{
50+
// eslint-disable-next-line global-require
51+
const SockjsSession = require('sockjs/lib/transport').Session;
52+
const decorateConnection = SockjsSession.prototype.decorateConnection;
53+
SockjsSession.prototype.decorateConnection = function(req) {
54+
decorateConnection.call(this, req);
55+
const connection = this.connection;
56+
if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) {
57+
connection.headers.origin = req.headers.origin;
58+
}
59+
};
60+
}
61+
4662
// Workaround for node ^8.6.0, ^9.0.0
4763
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
4864
// breaking connection when certificate is not signed with prime256v1
@@ -134,6 +150,10 @@ function Server (compiler, options = {}, _log) {
134150
// eslint-disable-next-line
135151
const app = this.app = new express();
136152

153+
// ref: https://github.com/webpack/webpack-dev-server/issues/1575
154+
// remove this when send@^0.16.3
155+
express.static.mime.types.wasm = 'application/wasm';
156+
137157
app.all('*', (req, res, next) => {
138158
if (this.checkHost(req.headers)) {
139159
return next();
@@ -629,20 +649,35 @@ Server.prototype.setContentHeaders = function (req, res, next) {
629649
};
630650

631651
Server.prototype.checkHost = function (headers) {
652+
return this.checkHeaders(headers, 'host');
653+
};
654+
655+
Server.prototype.checkOrigin = function (headers) {
656+
return this.checkHeaders(headers, 'origin');
657+
};
658+
659+
Server.prototype.checkHeaders = function (headers, headerToCheck) {
632660
// allow user to opt-out this security check, at own risk
633661
if (this.disableHostCheck) {
634662
return true;
635663
}
664+
665+
if (!headerToCheck) headerToCheck = 'host';
636666
// get the Host header and extract hostname
637667
// we don't care about port not matching
638-
const hostHeader = headers.host;
668+
const hostHeader = headers[headerToCheck];
639669

640670
if (!hostHeader) {
641671
return false;
642672
}
643673

644674
// use the node url-parser to retrieve the hostname from the host-header.
645-
const hostname = url.parse(`//${hostHeader}`, false, true).hostname;
675+
const hostname = url.parse(
676+
// if hostHeader doesn't have scheme, add // for parsing.
677+
/^(.+:)?\/\//.test(hostHeader) ? hostHeader : `//${hostHeader}`,
678+
false,
679+
true
680+
).hostname;
646681
// always allow requests with explicit IPv4 or IPv6-address.
647682
// A note on IPv6 addresses:
648683
// hostHeader will always contain the brackets denoting
@@ -723,8 +758,8 @@ Server.prototype.listen = function (port, hostname, fn) {
723758
return;
724759
}
725760

726-
if (!this.checkHost(connection.headers)) {
727-
this.sockWrite([ connection ], 'error', 'Invalid Host header');
761+
if (!this.checkHost(connection.headers) || !this.checkOrigin(connection.headers)) {
762+
this.sockWrite([ connection ], 'error', 'Invalid Host/Origin header');
728763

729764
connection.close();
730765

lib/utils/addEntries.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
array-bracket-spacing,
77
space-before-function-paren
88
*/
9+
const webpack = require('webpack');
910
const createDomain = require('./createDomain');
1011

1112
function addEntries (config, options, server) {
@@ -48,6 +49,13 @@ function addEntries (config, options, server) {
4849

4950
[].concat(config).forEach((config) => {
5051
config.entry = prependEntry(config.entry || './src');
52+
53+
if (options.hot || options.hotOnly) {
54+
config.plugins = config.plugins || [];
55+
if (!config.plugins.find(plugin => plugin.constructor === webpack.HotModuleReplacementPlugin)) {
56+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
57+
}
58+
}
5159
});
5260
}
5361
}

package-lock.json

Lines changed: 51 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-dev-server",
3-
"version": "3.1.10",
3+
"version": "3.1.14",
44
"description": "Serves a webpack app. Updates the browser on changes.",
55
"bin": "bin/webpack-dev-server.js",
66
"main": "lib/Server.js",
@@ -48,9 +48,10 @@
4848
"serve-index": "^1.7.2",
4949
"sockjs": "0.3.19",
5050
"sockjs-client": "1.3.0",
51-
"spdy": "^3.4.1",
51+
"spdy": "^4.0.0",
5252
"strip-ansi": "^3.0.0",
5353
"supports-color": "^5.1.0",
54+
"url": "^0.11.0",
5455
"webpack-dev-middleware": "3.4.0",
5556
"webpack-log": "^2.0.0",
5657
"yargs": "12.0.2"

test/ContentBase.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,18 @@ describe('ContentBase', () => {
121121
.expect(404, done);
122122
});
123123
});
124+
125+
describe('Content type', () => {
126+
before((done) => {
127+
server = helper.start(config, {
128+
contentBase: [contentBasePublic]
129+
}, done);
130+
req = request(server.app);
131+
});
132+
133+
it('Request foo.wasm', (done) => {
134+
req.get('/foo.wasm')
135+
.expect('Content-Type', 'application/wasm', done);
136+
});
137+
});
124138
});

0 commit comments

Comments
 (0)