webpack-dev-server 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2
3
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
4
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
7
  import SockJS from "../modules/sockjs-client/index.js";
7
8
  import { log } from "../utils/log.js";
8
9
  var SockJSClient = /*#__PURE__*/function () {
@@ -1,8 +1,9 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2
3
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
4
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
7
  import { log } from "../utils/log.js";
7
8
  var WebSocketClient = /*#__PURE__*/function () {
8
9
  /**
package/client/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
2
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
3
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
5
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
6
7
  /* global __resourceQuery, __webpack_hash__ */
7
8
  /// <reference types="webpack/module" />
8
9
  import webpackHotLog from "webpack/hot/log.js";
@@ -42,7 +43,7 @@ import { isProgressSupported, defineProgressElement } from "./progress.js";
42
43
  * @param {boolean | { warnings?: boolean | string; errors?: boolean | string; runtimeErrors?: boolean | string; }} overlayOptions
43
44
  */
44
45
  var decodeOverlayOptions = function decodeOverlayOptions(overlayOptions) {
45
- if (typeof overlayOptions === "object") {
46
+ if (_typeof(overlayOptions) === "object") {
46
47
  ["warnings", "errors", "runtimeErrors"].forEach(function (property) {
47
48
  if (typeof overlayOptions[property] === "string") {
48
49
  var overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
@@ -155,7 +156,7 @@ if (parsedResourceQuery.overlay) {
155
156
  }
156
157
 
157
158
  // Fill in default "true" params for partially-specified objects.
158
- if (typeof options.overlay === "object") {
159
+ if (_typeof(options.overlay) === "object") {
159
160
  options.overlay = _objectSpread({
160
161
  errors: true,
161
162
  warnings: true,
@@ -203,7 +204,7 @@ logEnabledFeatures(enabledFeatures);
203
204
  self.addEventListener("beforeunload", function () {
204
205
  status.isUnloading = true;
205
206
  });
206
- var overlay = typeof window !== "undefined" ? createOverlay(typeof options.overlay === "object" ? {
207
+ var overlay = typeof window !== "undefined" ? createOverlay(_typeof(options.overlay) === "object" ? {
207
208
  trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
208
209
  catchRuntimeError: options.overlay.runtimeErrors
209
210
  } : {
@@ -282,7 +283,7 @@ var ansiRegex = new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\
282
283
  */
283
284
  var stripAnsi = function stripAnsi(string) {
284
285
  if (typeof string !== "string") {
285
- throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
286
+ throw new TypeError("Expected a `string`, got `".concat(_typeof(string), "`"));
286
287
  }
287
288
  return string.replace(ansiRegex, "");
288
289
  };
@@ -39,6 +39,15 @@ function SyncBailHook() {
39
39
 
40
40
 
41
41
 
42
+ function _typeof(o) {
43
+ "@babel/helpers - typeof";
44
+
45
+ return _typeof = "function" == typeof (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }) && "symbol" == typeof (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }).iterator ? function (o) {
46
+ return typeof o;
47
+ } : function (o) {
48
+ return o && "function" == typeof (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }) && o.constructor === (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }) && o !== (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }).prototype ? "symbol" : typeof o;
49
+ }, _typeof(o);
50
+ }
42
51
  function _toConsumableArray(r) {
43
52
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
44
53
  }
@@ -79,14 +88,14 @@ function _createClass(e, r, t) {
79
88
  }
80
89
  function _toPropertyKey(t) {
81
90
  var i = _toPrimitive(t, "string");
82
- return "symbol" == typeof i ? i : i + "";
91
+ return "symbol" == _typeof(i) ? i : i + "";
83
92
  }
84
93
  function _toPrimitive(t, r) {
85
- if ("object" != typeof t || !t) return t;
94
+ if ("object" != _typeof(t) || !t) return t;
86
95
  var e = t[(typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }).toPrimitive];
87
96
  if (void 0 !== e) {
88
97
  var i = e.call(t, r || "default");
89
- if ("object" != typeof i) return i;
98
+ if ("object" != _typeof(i)) return i;
90
99
  throw new TypeError("@@toPrimitive must return a primitive value.");
91
100
  }
92
101
  return ("string" === r ? String : Number)(t);
@@ -447,6 +456,15 @@ function _arrayLikeToArray(r, a) {
447
456
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
448
457
  return n;
449
458
  }
459
+ function _typeof(o) {
460
+ "@babel/helpers - typeof";
461
+
462
+ return _typeof = "function" == typeof (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }) && "symbol" == typeof (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }).iterator ? function (o) {
463
+ return typeof o;
464
+ } : function (o) {
465
+ return o && "function" == typeof (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }) && o.constructor === (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }) && o !== (typeof Symbol !== "undefined" ? Symbol : function (i) { return i; }).prototype ? "symbol" : typeof o;
466
+ }, _typeof(o);
467
+ }
450
468
  var _require = __webpack_require__(/*! ./Logger */ "./node_modules/webpack/lib/logging/Logger.js"),
451
469
  LogType = _require.LogType;
452
470
 
@@ -493,7 +511,7 @@ var filterToFunction = function filterToFunction(item) {
493
511
  return regExp.test(ident);
494
512
  };
495
513
  }
496
- if (item && typeof item === "object" && typeof item.test === "function") {
514
+ if (item && _typeof(item) === "object" && typeof item.test === "function") {
497
515
  return function (ident) {
498
516
  return item.test(ident);
499
517
  };
@@ -53,6 +53,7 @@ if (typeof Object.create === 'function') {
53
53
  \**********************************/
54
54
  /***/ (function(module) {
55
55
 
56
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
56
57
  /**
57
58
  * Helpers.
58
59
  */
@@ -80,7 +81,7 @@ var y = d * 365.25;
80
81
 
81
82
  module.exports = function (val, options) {
82
83
  options = options || {};
83
- var type = typeof val;
84
+ var type = _typeof(val);
84
85
  if (type === 'string' && val.length > 0) {
85
86
  return parse(val);
86
87
  } else if (type === 'number' && isFinite(val)) {
@@ -1347,6 +1348,7 @@ module.exports = function (availableTransports) {
1347
1348
 
1348
1349
 
1349
1350
  // pulled specific shims from https://github.com/es-shims/es5-shim
1351
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1350
1352
  var ArrayPrototype = Array.prototype;
1351
1353
  var ObjectPrototype = Object.prototype;
1352
1354
  var FunctionPrototype = Function.prototype;
@@ -1584,7 +1586,7 @@ var properlyBoxesContext = function properlyBoxed(method) {
1584
1586
  var properlyBoxesStrict = true;
1585
1587
  if (method) {
1586
1588
  method.call('foo', function (_, __, context) {
1587
- if (typeof context !== 'object') {
1589
+ if (_typeof(context) !== 'object') {
1588
1590
  properlyBoxesNonStrict = false;
1589
1591
  }
1590
1592
  });
@@ -3618,6 +3620,7 @@ if (!isChromePackagedApp) {
3618
3620
  "use strict";
3619
3621
 
3620
3622
 
3623
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3621
3624
  var eventUtils = __webpack_require__(/*! ./event */ "./node_modules/sockjs-client/lib/utils/event.js"),
3622
3625
  browser = __webpack_require__(/*! ./browser */ "./node_modules/sockjs-client/lib/utils/browser.js");
3623
3626
  var debug = function debug() {};
@@ -3787,7 +3790,7 @@ module.exports.iframeEnabled = false;
3787
3790
  if (__webpack_require__.g.document) {
3788
3791
  // postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
3789
3792
  // huge delay, or not at all.
3790
- module.exports.iframeEnabled = (typeof __webpack_require__.g.postMessage === 'function' || typeof __webpack_require__.g.postMessage === 'object') && !browser.isKonqueror();
3793
+ module.exports.iframeEnabled = (typeof __webpack_require__.g.postMessage === 'function' || _typeof(__webpack_require__.g.postMessage) === 'object') && !browser.isKonqueror();
3791
3794
  }
3792
3795
 
3793
3796
  /***/ }),
@@ -3826,9 +3829,10 @@ module.exports = logObject;
3826
3829
  "use strict";
3827
3830
 
3828
3831
 
3832
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3829
3833
  module.exports = {
3830
3834
  isObject: function isObject(obj) {
3831
- var type = typeof obj;
3835
+ var type = _typeof(obj);
3832
3836
  return type === 'function' || type === 'object' && !!obj;
3833
3837
  },
3834
3838
  extend: function extend(obj) {
@@ -4010,14 +4014,15 @@ module.exports = '1.6.1';
4010
4014
  "use strict";
4011
4015
 
4012
4016
 
4017
+ function _typeof2(o) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof2(o); }
4013
4018
  function _typeof(obj) {
4014
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
4019
+ if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
4015
4020
  _typeof = function _typeof(obj) {
4016
- return typeof obj;
4021
+ return _typeof2(obj);
4017
4022
  };
4018
4023
  } else {
4019
4024
  _typeof = function _typeof(obj) {
4020
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
4025
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
4021
4026
  };
4022
4027
  }
4023
4028
  return _typeof(obj);
@@ -4424,6 +4429,7 @@ module.exports = setup;
4424
4429
  "use strict";
4425
4430
 
4426
4431
 
4432
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4427
4433
  var required = __webpack_require__(/*! requires-port */ "./node_modules/requires-port/index.js"),
4428
4434
  qs = __webpack_require__(/*! querystringify */ "./node_modules/querystringify/index.js"),
4429
4435
  controlOrWhitespace = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,
@@ -4506,7 +4512,7 @@ function lolcation(loc) {
4506
4512
  var location = globalVar.location || {};
4507
4513
  loc = loc || location;
4508
4514
  var finaldestination = {},
4509
- type = typeof loc,
4515
+ type = _typeof(loc),
4510
4516
  key;
4511
4517
  if ('blob:' === loc.protocol) {
4512
4518
  finaldestination = new Url(unescape(loc.pathname), {});
@@ -4658,7 +4664,7 @@ function Url(address, location, parser) {
4658
4664
  index,
4659
4665
  key,
4660
4666
  instructions = rules.slice(),
4661
- type = typeof location,
4667
+ type = _typeof(location),
4662
4668
  url = this,
4663
4669
  i = 0;
4664
4670
 
@@ -4910,7 +4916,7 @@ function toString(stringify) {
4910
4916
  host += ':';
4911
4917
  }
4912
4918
  result += host + url.pathname;
4913
- query = 'object' === typeof url.query ? stringify(url.query) : url.query;
4919
+ query = 'object' === _typeof(url.query) ? stringify(url.query) : url.query;
4914
4920
  if (query) result += '?' !== query.charAt(0) ? '?' + query : query;
4915
4921
  if (url.hash) result += url.hash;
4916
4922
  return result;
package/client/overlay.js CHANGED
@@ -1,8 +1,9 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
4
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
7
  // The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app)
7
8
  // They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware).
8
9
 
@@ -597,6 +598,10 @@ var createOverlay = function createOverlay(options) {
597
598
  if (!error && !message) {
598
599
  return;
599
600
  }
601
+ // if error stack indicates a React error boundary caught the error, do not show overlay.
602
+ if (error.stack && error.stack.includes("invokeGuardedCallbackDev")) {
603
+ return;
604
+ }
600
605
  handleError(error, message);
601
606
  });
602
607
  listenToUnhandledRejection(function (promiseRejectionEvent) {
@@ -1,10 +1,11 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2
3
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
4
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
7
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
- function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
8
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
8
9
  function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
9
10
  function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
10
11
  function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
package/client/socket.js CHANGED
@@ -17,6 +17,7 @@ var maxRetries = 10;
17
17
  // It is mutable to enforce singleton
18
18
  // eslint-disable-next-line import/no-mutable-exports
19
19
  export var client = null;
20
+ var timeout;
20
21
 
21
22
  /**
22
23
  * @param {string} url
@@ -27,6 +28,9 @@ var socket = function initSocket(url, handlers, reconnect) {
27
28
  client = new Client(url);
28
29
  client.onOpen(function () {
29
30
  retries = 0;
31
+ if (timeout) {
32
+ clearTimeout(timeout);
33
+ }
30
34
  if (typeof reconnect !== "undefined") {
31
35
  maxRetries = reconnect;
32
36
  }
@@ -47,7 +51,7 @@ var socket = function initSocket(url, handlers, reconnect) {
47
51
  var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
48
52
  retries += 1;
49
53
  log.info("Trying to reconnect...");
50
- setTimeout(function () {
54
+ timeout = setTimeout(function () {
51
55
  socket(url, handlers, reconnect);
52
56
  }, retryInMs);
53
57
  }
package/lib/Server.js CHANGED
@@ -307,6 +307,8 @@ function useFn(route, fn) {
307
307
  return /** @type {BasicApplication} */ ({});
308
308
  }
309
309
 
310
+ const DEFAULT_ALLOWED_PROTOCOLS = /^(file|.+-extension):/i;
311
+
310
312
  /**
311
313
  * @typedef {Object} BasicApplication
312
314
  * @property {typeof useFn} use
@@ -437,8 +439,9 @@ class Server {
437
439
  return network.address;
438
440
  });
439
441
 
440
- for (const network of networks) {
441
- host = network.address;
442
+ if (networks.length > 0) {
443
+ // Take the first network found
444
+ host = networks[0].address;
442
445
 
443
446
  if (host.includes(":")) {
444
447
  host = `[${host}]`;
@@ -1960,7 +1963,7 @@ class Server {
1960
1963
  (req.headers);
1961
1964
  const headerName = headers[":authority"] ? ":authority" : "host";
1962
1965
 
1963
- if (this.checkHeader(headers, headerName)) {
1966
+ if (this.isValidHost(headers, headerName)) {
1964
1967
  next();
1965
1968
  return;
1966
1969
  }
@@ -1970,6 +1973,32 @@ class Server {
1970
1973
  },
1971
1974
  });
1972
1975
 
1976
+ // Register setup cross origin request check for security
1977
+ middlewares.push({
1978
+ name: "cross-origin-header-check",
1979
+ /**
1980
+ * @param {Request} req
1981
+ * @param {Response} res
1982
+ * @param {NextFunction} next
1983
+ * @returns {void}
1984
+ */
1985
+ middleware: (req, res, next) => {
1986
+ const headers =
1987
+ /** @type {{ [key: string]: string | undefined }} */
1988
+ (req.headers);
1989
+ if (
1990
+ headers["sec-fetch-mode"] === "no-cors" &&
1991
+ headers["sec-fetch-site"] === "cross-site"
1992
+ ) {
1993
+ res.statusCode = 403;
1994
+ res.end("Cross-Origin request blocked");
1995
+ return;
1996
+ }
1997
+
1998
+ next();
1999
+ },
2000
+ });
2001
+
1973
2002
  const isHTTP2 =
1974
2003
  /** @type {ServerConfiguration<A, S>} */ (this.options.server).type ===
1975
2004
  "http2";
@@ -2641,8 +2670,9 @@ class Server {
2641
2670
 
2642
2671
  if (
2643
2672
  !headers ||
2644
- !this.checkHeader(headers, "host") ||
2645
- !this.checkHeader(headers, "origin")
2673
+ !this.isValidHost(headers, "host") ||
2674
+ !this.isValidHost(headers, "origin") ||
2675
+ !this.isSameOrigin(headers)
2646
2676
  ) {
2647
2677
  this.sendMessage([client], "error", "Invalid Host/Origin header");
2648
2678
 
@@ -2676,7 +2706,8 @@ class Server {
2676
2706
 
2677
2707
  if (
2678
2708
  this.options.client &&
2679
- /** @type {ClientConfiguration} */ (this.options.client).reconnect
2709
+ /** @type {ClientConfiguration} */
2710
+ (this.options.client).reconnect
2680
2711
  ) {
2681
2712
  this.sendMessage(
2682
2713
  [client],
@@ -2691,9 +2722,9 @@ class Server {
2691
2722
  /** @type {ClientConfiguration} */
2692
2723
  (this.options.client).overlay
2693
2724
  ) {
2694
- const overlayConfig = /** @type {ClientConfiguration} */ (
2695
- this.options.client
2696
- ).overlay;
2725
+ const overlayConfig =
2726
+ /** @type {ClientConfiguration} */
2727
+ (this.options.client).overlay;
2697
2728
 
2698
2729
  this.sendMessage(
2699
2730
  [client],
@@ -3079,40 +3110,105 @@ class Server {
3079
3110
 
3080
3111
  /**
3081
3112
  * @private
3082
- * @param {{ [key: string]: string | undefined }} headers
3083
- * @param {string} headerToCheck
3113
+ * @param {string} value
3084
3114
  * @returns {boolean}
3085
3115
  */
3086
- checkHeader(headers, headerToCheck) {
3116
+ isHostAllowed(value) {
3117
+ const { allowedHosts } = this.options;
3118
+
3087
3119
  // allow user to opt out of this security check, at their own risk
3088
3120
  // by explicitly enabling allowedHosts
3121
+ if (allowedHosts === "all") {
3122
+ return true;
3123
+ }
3124
+
3125
+ // always allow localhost host, for convenience
3126
+ // allow if value is in allowedHosts
3127
+ if (Array.isArray(allowedHosts) && allowedHosts.length > 0) {
3128
+ for (let hostIdx = 0; hostIdx < allowedHosts.length; hostIdx++) {
3129
+ /** @type {string} */
3130
+ const allowedHost = allowedHosts[hostIdx];
3131
+
3132
+ if (allowedHost === value) {
3133
+ return true;
3134
+ }
3135
+
3136
+ // support "." as a subdomain wildcard
3137
+ // e.g. ".example.com" will allow "example.com", "www.example.com", "subdomain.example.com", etc
3138
+ if (allowedHost[0] === ".") {
3139
+ // "example.com" (value === allowedHost.substring(1))
3140
+ // "*.example.com" (value.endsWith(allowedHost))
3141
+ if (
3142
+ value === allowedHost.substring(1) ||
3143
+ /** @type {string} */
3144
+ (value).endsWith(allowedHost)
3145
+ ) {
3146
+ return true;
3147
+ }
3148
+ }
3149
+ }
3150
+ }
3151
+
3152
+ // Also allow if `client.webSocketURL.hostname` provided
3153
+ if (
3154
+ this.options.client &&
3155
+ typeof (
3156
+ /** @type {ClientConfiguration} */
3157
+ (this.options.client).webSocketURL
3158
+ ) !== "undefined"
3159
+ ) {
3160
+ return (
3161
+ /** @type {WebSocketURL} */
3162
+ (/** @type {ClientConfiguration} */ (this.options.client).webSocketURL)
3163
+ .hostname === value
3164
+ );
3165
+ }
3166
+
3167
+ return false;
3168
+ }
3169
+
3170
+ /**
3171
+ * @private
3172
+ * @param {{ [key: string]: string | undefined }} headers
3173
+ * @param {string} headerToCheck
3174
+ * @returns {boolean}
3175
+ */
3176
+ isValidHost(headers, headerToCheck) {
3089
3177
  if (this.options.allowedHosts === "all") {
3090
3178
  return true;
3091
3179
  }
3092
3180
 
3093
3181
  // get the Host header and extract hostname
3094
3182
  // we don't care about port not matching
3095
- const hostHeader = headers[headerToCheck];
3183
+ const header = headers[headerToCheck];
3096
3184
 
3097
- if (!hostHeader) {
3185
+ if (!header) {
3098
3186
  return false;
3099
3187
  }
3100
3188
 
3101
- if (/^(file|.+-extension):/i.test(hostHeader)) {
3189
+ if (DEFAULT_ALLOWED_PROTOCOLS.test(header)) {
3102
3190
  return true;
3103
3191
  }
3104
3192
 
3105
3193
  // use the node url-parser to retrieve the hostname from the host-header.
3106
3194
  const hostname = url.parse(
3107
- // if hostHeader doesn't have scheme, add // for parsing.
3108
- /^(.+:)?\/\//.test(hostHeader) ? hostHeader : `//${hostHeader}`,
3195
+ // if header doesn't have scheme, add // for parsing.
3196
+ /^(.+:)?\/\//.test(header) ? header : `//${header}`,
3109
3197
  false,
3110
3198
  true,
3111
3199
  ).hostname;
3112
3200
 
3201
+ if (hostname === null) {
3202
+ return false;
3203
+ }
3204
+
3205
+ if (this.isHostAllowed(hostname)) {
3206
+ return true;
3207
+ }
3208
+
3113
3209
  // always allow requests with explicit IPv4 or IPv6-address.
3114
3210
  // A note on IPv6 addresses:
3115
- // hostHeader will always contain the brackets denoting
3211
+ // header will always contain the brackets denoting
3116
3212
  // an IPv6-address in URLs,
3117
3213
  // these are removed from the hostname in url.parse(),
3118
3214
  // so we have the pure IPv6-address in hostname.
@@ -3120,60 +3216,76 @@ class Server {
3120
3216
  // and its subdomains (hostname.endsWith(".localhost")).
3121
3217
  // allow hostname of listening address (hostname === this.options.host)
3122
3218
  const isValidHostname =
3123
- (hostname !== null && ipaddr.IPv4.isValid(hostname)) ||
3124
- (hostname !== null && ipaddr.IPv6.isValid(hostname)) ||
3219
+ ipaddr.IPv4.isValid(hostname) ||
3220
+ ipaddr.IPv6.isValid(hostname) ||
3125
3221
  hostname === "localhost" ||
3126
- (hostname !== null && hostname.endsWith(".localhost")) ||
3222
+ hostname.endsWith(".localhost") ||
3127
3223
  hostname === this.options.host;
3128
3224
 
3129
3225
  if (isValidHostname) {
3130
3226
  return true;
3131
3227
  }
3132
3228
 
3133
- const { allowedHosts } = this.options;
3229
+ // disallow
3230
+ return false;
3231
+ }
3134
3232
 
3135
- // always allow localhost host, for convenience
3136
- // allow if hostname is in allowedHosts
3137
- if (Array.isArray(allowedHosts) && allowedHosts.length > 0) {
3138
- for (let hostIdx = 0; hostIdx < allowedHosts.length; hostIdx++) {
3139
- /** @type {string} */
3140
- const allowedHost = allowedHosts[hostIdx];
3233
+ /**
3234
+ * @private
3235
+ * @param {{ [key: string]: string | undefined }} headers
3236
+ * @returns {boolean}
3237
+ */
3238
+ isSameOrigin(headers) {
3239
+ if (this.options.allowedHosts === "all") {
3240
+ return true;
3241
+ }
3141
3242
 
3142
- if (allowedHost === hostname) {
3143
- return true;
3144
- }
3243
+ const originHeader = headers.origin;
3145
3244
 
3146
- // support "." as a subdomain wildcard
3147
- // e.g. ".example.com" will allow "example.com", "www.example.com", "subdomain.example.com", etc
3148
- if (allowedHost[0] === ".") {
3149
- // "example.com" (hostname === allowedHost.substring(1))
3150
- // "*.example.com" (hostname.endsWith(allowedHost))
3151
- if (
3152
- hostname === allowedHost.substring(1) ||
3153
- /** @type {string} */ (hostname).endsWith(allowedHost)
3154
- ) {
3155
- return true;
3156
- }
3157
- }
3158
- }
3245
+ if (!originHeader) {
3246
+ return this.options.allowedHosts === "all";
3159
3247
  }
3160
3248
 
3161
- // Also allow if `client.webSocketURL.hostname` provided
3162
- if (
3163
- this.options.client &&
3164
- typeof (
3165
- /** @type {ClientConfiguration} */ (this.options.client).webSocketURL
3166
- ) !== "undefined"
3167
- ) {
3168
- return (
3169
- /** @type {WebSocketURL} */
3170
- (/** @type {ClientConfiguration} */ (this.options.client).webSocketURL)
3171
- .hostname === hostname
3172
- );
3249
+ if (DEFAULT_ALLOWED_PROTOCOLS.test(originHeader)) {
3250
+ return true;
3173
3251
  }
3174
3252
 
3175
- // disallow
3176
- return false;
3253
+ const origin = url.parse(originHeader, false, true).hostname;
3254
+
3255
+ if (origin === null) {
3256
+ return false;
3257
+ }
3258
+
3259
+ if (this.isHostAllowed(origin)) {
3260
+ return true;
3261
+ }
3262
+
3263
+ const hostHeader = headers.host;
3264
+
3265
+ if (!hostHeader) {
3266
+ return this.options.allowedHosts === "all";
3267
+ }
3268
+
3269
+ if (DEFAULT_ALLOWED_PROTOCOLS.test(hostHeader)) {
3270
+ return true;
3271
+ }
3272
+
3273
+ const host = url.parse(
3274
+ // if hostHeader doesn't have scheme, add // for parsing.
3275
+ /^(.+:)?\/\//.test(hostHeader) ? hostHeader : `//${hostHeader}`,
3276
+ false,
3277
+ true,
3278
+ ).hostname;
3279
+
3280
+ if (host === null) {
3281
+ return false;
3282
+ }
3283
+
3284
+ if (this.isHostAllowed(host)) {
3285
+ return true;
3286
+ }
3287
+
3288
+ return origin === host;
3177
3289
  }
3178
3290
 
3179
3291
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-server",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Serves a webpack app. Updates the browser on changes.",
5
5
  "bin": "bin/webpack-dev-server.js",
6
6
  "main": "lib/Server.js",
@@ -49,6 +49,7 @@
49
49
  "@types/bonjour": "^3.5.13",
50
50
  "@types/connect-history-api-fallback": "^1.5.4",
51
51
  "@types/express": "^4.17.21",
52
+ "@types/express-serve-static-core": "^4.17.21",
52
53
  "@types/serve-index": "^1.9.4",
53
54
  "@types/serve-static": "^1.15.5",
54
55
  "@types/sockjs": "^0.3.36",
@@ -1347,13 +1347,25 @@ declare class Server<
1347
1347
  * @param {NextFunction} next
1348
1348
  */
1349
1349
  private setHeaders;
1350
+ /**
1351
+ * @private
1352
+ * @param {string} value
1353
+ * @returns {boolean}
1354
+ */
1355
+ private isHostAllowed;
1350
1356
  /**
1351
1357
  * @private
1352
1358
  * @param {{ [key: string]: string | undefined }} headers
1353
1359
  * @param {string} headerToCheck
1354
1360
  * @returns {boolean}
1355
1361
  */
1356
- private checkHeader;
1362
+ private isValidHost;
1363
+ /**
1364
+ * @private
1365
+ * @param {{ [key: string]: string | undefined }} headers
1366
+ * @returns {boolean}
1367
+ */
1368
+ private isSameOrigin;
1357
1369
  /**
1358
1370
  * @param {ClientConnection[]} clients
1359
1371
  * @param {string} type