vite 6.0.8 → 6.0.9

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.
@@ -748,10 +748,14 @@ const socketHost = `${__HMR_HOSTNAME__ || importMetaUrl.hostname}:${hmrPort || i
748
748
  const directSocketHost = __HMR_DIRECT_TARGET__;
749
749
  const base = __BASE__ || "/";
750
750
  const hmrTimeout = __HMR_TIMEOUT__;
751
+ const wsToken = __WS_TOKEN__;
751
752
  const transport = normalizeModuleRunnerTransport(
752
753
  (() => {
753
754
  let wsTransport = createWebSocketModuleRunnerTransport({
754
- createConnection: () => new WebSocket(`${socketProtocol}://${socketHost}`, "vite-hmr"),
755
+ createConnection: () => new WebSocket(
756
+ `${socketProtocol}://${socketHost}?token=${wsToken}`,
757
+ "vite-hmr"
758
+ ),
755
759
  pingInterval: hmrTimeout
756
760
  });
757
761
  return {
@@ -762,7 +766,7 @@ const transport = normalizeModuleRunnerTransport(
762
766
  if (!hmrPort) {
763
767
  wsTransport = createWebSocketModuleRunnerTransport({
764
768
  createConnection: () => new WebSocket(
765
- `${socketProtocol}://${directSocketHost}`,
769
+ `${socketProtocol}://${directSocketHost}?token=${wsToken}`,
766
770
  "vite-hmr"
767
771
  ),
768
772
  pingInterval: hmrTimeout
@@ -912,7 +916,9 @@ async function handleMessage(payload) {
912
916
  if (hasDocument && !willUnload) {
913
917
  console.log(`[vite] server connection lost. Polling for restart...`);
914
918
  const socket = payload.data.webSocket;
915
- await waitForSuccessfulPing(socket.url);
919
+ const url = new URL(socket.url);
920
+ url.search = "";
921
+ await waitForSuccessfulPing(url.href);
916
922
  location.reload();
917
923
  }
918
924
  }
@@ -6,6 +6,7 @@ import require$$1$1, { fileURLToPath as fileURLToPath$1, URL as URL$3, pathToFil
6
6
  import { promisify as promisify$4, format as format$2, inspect, stripVTControlCharacters } from 'node:util';
7
7
  import { performance } from 'node:perf_hooks';
8
8
  import require$$0$6, { createRequire as createRequire$1, builtinModules } from 'node:module';
9
+ import crypto$2 from 'node:crypto';
9
10
  import esbuild, { transform as transform$1, formatMessages, build as build$b } from 'esbuild';
10
11
  import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, ENV_ENTRY, DEP_VERSION_RE, SPECIAL_QUERY_RE, DEV_PROD_CONDITION, JS_TYPES_RE, KNOWN_ASSET_TYPES, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_SERVER_MAIN_FIELDS, DEFAULT_CLIENT_CONDITIONS, DEFAULT_SERVER_CONDITIONS } from '../constants.js';
11
12
  import require$$0$2, { posix, win32, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join, sep } from 'path';
@@ -23,7 +24,6 @@ import require$$0$8 from 'stream';
23
24
  import require$$2 from 'os';
24
25
  import require$$2$1 from 'child_process';
25
26
  import os$3 from 'node:os';
26
- import crypto$2 from 'node:crypto';
27
27
  import { promises } from 'node:dns';
28
28
  import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
29
29
  import { parseAstAsync, parseAst } from 'rollup/parseAst';
@@ -40,6 +40,7 @@ import zlib$1 from 'zlib';
40
40
  import require$$0$9 from 'buffer';
41
41
  import require$$1$3 from 'https';
42
42
  import require$$4$2 from 'tls';
43
+ import net$1 from 'node:net';
43
44
  import require$$4$3 from 'assert';
44
45
  import * as qs from 'node:querystring';
45
46
  import { gzip } from 'node:zlib';
@@ -37669,6 +37670,100 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
37669
37670
 
37670
37671
  var WebSocketServerRaw_ = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
37671
37672
 
37673
+ const allowedHostsCache = /* @__PURE__ */ new WeakMap();
37674
+ const isFileOrExtensionProtocolRE = /^(?:file|.+-extension):/i;
37675
+ function getAdditionalAllowedHosts(resolvedServerOptions, resolvedPreviewOptions) {
37676
+ const list = [];
37677
+ if (typeof resolvedServerOptions.host === "string" && resolvedServerOptions.host) {
37678
+ list.push(resolvedServerOptions.host);
37679
+ }
37680
+ if (typeof resolvedServerOptions.hmr === "object" && resolvedServerOptions.hmr.host) {
37681
+ list.push(resolvedServerOptions.hmr.host);
37682
+ }
37683
+ if (typeof resolvedPreviewOptions.host === "string" && resolvedPreviewOptions.host) {
37684
+ list.push(resolvedPreviewOptions.host);
37685
+ }
37686
+ if (resolvedServerOptions.origin) {
37687
+ const serverOriginUrl = new URL(resolvedServerOptions.origin);
37688
+ list.push(serverOriginUrl.hostname);
37689
+ }
37690
+ return list;
37691
+ }
37692
+ function isHostAllowedWithoutCache(allowedHosts, additionalAllowedHosts, host) {
37693
+ if (isFileOrExtensionProtocolRE.test(host)) {
37694
+ return true;
37695
+ }
37696
+ const trimmedHost = host.trim();
37697
+ if (trimmedHost[0] === "[") {
37698
+ const endIpv6 = trimmedHost.indexOf("]");
37699
+ if (endIpv6 < 0) {
37700
+ return false;
37701
+ }
37702
+ return net$1.isIP(trimmedHost.slice(1, endIpv6)) === 6;
37703
+ }
37704
+ const colonPos = trimmedHost.indexOf(":");
37705
+ const hostname = colonPos === -1 ? trimmedHost : trimmedHost.slice(0, colonPos);
37706
+ if (net$1.isIP(hostname) === 4) {
37707
+ return true;
37708
+ }
37709
+ if (hostname === "localhost" || hostname.endsWith(".localhost")) {
37710
+ return true;
37711
+ }
37712
+ for (const additionalAllowedHost of additionalAllowedHosts) {
37713
+ if (additionalAllowedHost === hostname) {
37714
+ return true;
37715
+ }
37716
+ }
37717
+ for (const allowedHost of allowedHosts) {
37718
+ if (allowedHost === hostname) {
37719
+ return true;
37720
+ }
37721
+ if (allowedHost[0] === "." && (allowedHost.slice(1) === hostname || hostname.endsWith(allowedHost))) {
37722
+ return true;
37723
+ }
37724
+ }
37725
+ return false;
37726
+ }
37727
+ function isHostAllowed(config, host) {
37728
+ if (config.server.allowedHosts === true) {
37729
+ return true;
37730
+ }
37731
+ if (!allowedHostsCache.has(config)) {
37732
+ allowedHostsCache.set(config, /* @__PURE__ */ new Set());
37733
+ }
37734
+ const allowedHosts = allowedHostsCache.get(config);
37735
+ if (allowedHosts.has(host)) {
37736
+ return true;
37737
+ }
37738
+ const result = isHostAllowedWithoutCache(
37739
+ config.server.allowedHosts,
37740
+ config.additionalAllowedHosts,
37741
+ host
37742
+ );
37743
+ if (result) {
37744
+ allowedHosts.add(host);
37745
+ }
37746
+ return result;
37747
+ }
37748
+ function hostCheckMiddleware(config) {
37749
+ return function viteHostCheckMiddleware(req, res, next) {
37750
+ const hostHeader = req.headers.host;
37751
+ if (!hostHeader || !isHostAllowed(config, hostHeader)) {
37752
+ const hostname = hostHeader?.replace(/:\d+$/, "");
37753
+ const hostnameWithQuotes = JSON.stringify(hostname);
37754
+ res.writeHead(403, {
37755
+ "Content-Type": "text/plain"
37756
+ });
37757
+ res.end(
37758
+ `Blocked request. This host (${hostnameWithQuotes}) is not allowed.
37759
+ To allow this host, add ${hostnameWithQuotes} to \`server.allowedHosts\` in vite.config.js.`
37760
+ );
37761
+ return;
37762
+ }
37763
+ return next();
37764
+ };
37765
+ }
37766
+
37672
37767
  const WebSocketServerRaw = process.versions.bun ? (
37673
37768
  // @ts-expect-error: Bun defines `import.meta.require`
37674
37769
  import.meta.require("ws").WebSocketServer
@@ -37684,6 +37779,19 @@ const wsServerEvents = [
37684
37779
  ];
37685
37780
  function noop$3() {
37686
37781
  }
37782
+ function hasValidToken(config, url) {
37783
+ const token = url.searchParams.get("token");
37784
+ if (!token) return false;
37785
+ try {
37786
+ const isValidToken = crypto$2.timingSafeEqual(
37787
+ Buffer.from(token),
37788
+ Buffer.from(config.webSocketToken)
37789
+ );
37790
+ return isValidToken;
37791
+ } catch {
37792
+ }
37793
+ return false;
37794
+ }
37687
37795
  function createWebSocketServer(server, config, httpsOptions) {
37688
37796
  if (config.server.ws === false) {
37689
37797
  return {
@@ -37707,7 +37815,6 @@ function createWebSocketServer(server, config, httpsOptions) {
37707
37815
  send: noop$3
37708
37816
  };
37709
37817
  }
37710
- let wss;
37711
37818
  let wsHttpServer = undefined;
37712
37819
  const hmr = isObject$2(config.server.hmr) && config.server.hmr;
37713
37820
  const hmrServer = hmr && hmr.server;
@@ -37719,20 +37826,47 @@ function createWebSocketServer(server, config, httpsOptions) {
37719
37826
  const clientsMap = /* @__PURE__ */ new WeakMap();
37720
37827
  const port = hmrPort || 24678;
37721
37828
  const host = hmr && hmr.host || undefined;
37829
+ const shouldHandle = (req) => {
37830
+ const protocol = req.headers["sec-websocket-protocol"];
37831
+ if (protocol === "vite-ping") return true;
37832
+ const hostHeader = req.headers.host;
37833
+ if (!hostHeader || !isHostAllowed(config, hostHeader)) {
37834
+ return false;
37835
+ }
37836
+ if (config.legacy?.skipWebSocketTokenCheck) {
37837
+ return true;
37838
+ }
37839
+ if (req.headers.origin) {
37840
+ const parsedUrl = new URL(`http://example.com${req.url}`);
37841
+ return hasValidToken(config, parsedUrl);
37842
+ }
37843
+ return true;
37844
+ };
37845
+ const handleUpgrade = (req, socket, head, isPing) => {
37846
+ wss.handleUpgrade(req, socket, head, (ws) => {
37847
+ if (isPing) {
37848
+ ws.close(
37849
+ /* Normal Closure */
37850
+ 1e3
37851
+ );
37852
+ return;
37853
+ }
37854
+ wss.emit("connection", ws, req);
37855
+ });
37856
+ };
37857
+ const wss = new WebSocketServerRaw({ noServer: true });
37858
+ wss.shouldHandle = shouldHandle;
37722
37859
  if (wsServer) {
37723
37860
  let hmrBase = config.base;
37724
37861
  const hmrPath = hmr ? hmr.path : undefined;
37725
37862
  if (hmrPath) {
37726
37863
  hmrBase = path$d.posix.join(hmrBase, hmrPath);
37727
37864
  }
37728
- wss = new WebSocketServerRaw({ noServer: true });
37729
37865
  hmrServerWsListener = (req, socket, head) => {
37730
- if ([HMR_HEADER, "vite-ping"].includes(
37731
- req.headers["sec-websocket-protocol"]
37732
- ) && req.url === hmrBase) {
37733
- wss.handleUpgrade(req, socket, head, (ws) => {
37734
- wss.emit("connection", ws, req);
37735
- });
37866
+ const protocol = req.headers["sec-websocket-protocol"];
37867
+ const parsedUrl = new URL(`http://example.com${req.url}`);
37868
+ if ([HMR_HEADER, "vite-ping"].includes(protocol) && parsedUrl.pathname === hmrBase) {
37869
+ handleUpgrade(req, socket, head, protocol === "vite-ping");
37736
37870
  }
37737
37871
  };
37738
37872
  wsServer.on("upgrade", hmrServerWsListener);
@@ -37753,16 +37887,13 @@ function createWebSocketServer(server, config, httpsOptions) {
37753
37887
  } else {
37754
37888
  wsHttpServer = createServer$3(route);
37755
37889
  }
37756
- wss = new WebSocketServerRaw({ noServer: true });
37757
37890
  wsHttpServer.on("upgrade", (req, socket, head) => {
37758
37891
  const protocol = req.headers["sec-websocket-protocol"];
37759
37892
  if (protocol === "vite-ping" && server && !server.listening) {
37760
37893
  req.destroy();
37761
37894
  return;
37762
37895
  }
37763
- wss.handleUpgrade(req, socket, head, (ws) => {
37764
- wss.emit("connection", ws, req);
37765
- });
37896
+ handleUpgrade(req, socket, head, protocol === "vite-ping");
37766
37897
  });
37767
37898
  wsHttpServer.on("error", (e) => {
37768
37899
  if (e.code === "EADDRINUSE") {
@@ -37780,9 +37911,6 @@ ${e.stack || e.message}`),
37780
37911
  });
37781
37912
  }
37782
37913
  wss.on("connection", (socket) => {
37783
- if (socket.protocol === "vite-ping") {
37784
- return;
37785
- }
37786
37914
  socket.on("message", (raw) => {
37787
37915
  if (!customListeners.size) return;
37788
37916
  let parsed;
@@ -43900,6 +44028,10 @@ async function _createServer(inlineConfig = {}, options) {
43900
44028
  if (cors !== false) {
43901
44029
  middlewares.use(corsMiddleware(typeof cors === "boolean" ? {} : cors));
43902
44030
  }
44031
+ const { allowedHosts } = serverConfig;
44032
+ if (allowedHosts !== true && !serverConfig.https) {
44033
+ middlewares.use(hostCheckMiddleware(config));
44034
+ }
43903
44035
  middlewares.use(cachedTransformMiddleware(server));
43904
44036
  const { proxy } = serverConfig;
43905
44037
  if (proxy) {
@@ -44020,10 +44152,11 @@ const serverConfigDefaults = Object.freeze({
44020
44152
  port: DEFAULT_DEV_PORT,
44021
44153
  strictPort: false,
44022
44154
  host: "localhost",
44155
+ allowedHosts: [],
44023
44156
  https: undefined,
44024
44157
  open: false,
44025
44158
  proxy: undefined,
44026
- cors: true,
44159
+ cors: false,
44027
44160
  headers: {},
44028
44161
  // hmr
44029
44162
  // ws
@@ -46190,8 +46323,9 @@ function clientInjectionsPlugin(config) {
46190
46323
  const hmrTimeoutReplacement = escapeReplacement(timeout);
46191
46324
  const hmrEnableOverlayReplacement = escapeReplacement(overlay);
46192
46325
  const hmrConfigNameReplacement = escapeReplacement(hmrConfigName);
46326
+ const wsTokenReplacement = escapeReplacement(config.webSocketToken);
46193
46327
  injectConfigValues = (code) => {
46194
- return code.replace(`__MODE__`, modeReplacement).replace(/__BASE__/g, baseReplacement).replace(`__SERVER_HOST__`, serverHostReplacement).replace(`__HMR_PROTOCOL__`, hmrProtocolReplacement).replace(`__HMR_HOSTNAME__`, hmrHostnameReplacement).replace(`__HMR_PORT__`, hmrPortReplacement).replace(`__HMR_DIRECT_TARGET__`, hmrDirectTargetReplacement).replace(`__HMR_BASE__`, hmrBaseReplacement).replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement).replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement).replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement);
46328
+ return code.replace(`__MODE__`, modeReplacement).replace(/__BASE__/g, baseReplacement).replace(`__SERVER_HOST__`, serverHostReplacement).replace(`__HMR_PROTOCOL__`, hmrProtocolReplacement).replace(`__HMR_HOSTNAME__`, hmrHostnameReplacement).replace(`__HMR_PORT__`, hmrPortReplacement).replace(`__HMR_DIRECT_TARGET__`, hmrDirectTargetReplacement).replace(`__HMR_BASE__`, hmrBaseReplacement).replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement).replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement).replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement).replace(`__WS_TOKEN__`, wsTokenReplacement);
46195
46329
  };
46196
46330
  },
46197
46331
  async transform(code, id, options) {
@@ -48738,8 +48872,8 @@ function createCachedImport(imp) {
48738
48872
  return cached;
48739
48873
  };
48740
48874
  }
48741
- const importPostcssImport = createCachedImport(() => import('./dep-BthWCIj2.js').then(function (n) { return n.i; }));
48742
- const importPostcssModules = createCachedImport(() => import('./dep-C-SVMOic.js').then(function (n) { return n.i; }));
48875
+ const importPostcssImport = createCachedImport(() => import('./dep-CgjxNdwk.js').then(function (n) { return n.i; }));
48876
+ const importPostcssModules = createCachedImport(() => import('./dep-BurZv_3i.js').then(function (n) { return n.i; }));
48743
48877
  const importPostcss = createCachedImport(() => import('postcss'));
48744
48878
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
48745
48879
  let alwaysFakeWorkerWorkerControllerCache;
@@ -52882,6 +53016,7 @@ function resolvePreviewOptions(preview2, server) {
52882
53016
  port: preview2?.port ?? DEFAULT_PREVIEW_PORT,
52883
53017
  strictPort: preview2?.strictPort ?? server.strictPort,
52884
53018
  host: preview2?.host ?? server.host,
53019
+ allowedHosts: preview2?.allowedHosts ?? server.allowedHosts,
52885
53020
  https: preview2?.https ?? server.https,
52886
53021
  open: preview2?.open ?? server.open,
52887
53022
  proxy: preview2?.proxy ?? server.proxy,
@@ -52962,6 +53097,10 @@ async function preview(inlineConfig = {}) {
52962
53097
  if (cors !== false) {
52963
53098
  app.use(corsMiddleware(typeof cors === "boolean" ? {} : cors));
52964
53099
  }
53100
+ const { allowedHosts } = config.preview;
53101
+ if (allowedHosts !== true && !config.preview.https) {
53102
+ app.use(hostCheckMiddleware(config));
53103
+ }
52965
53104
  const { proxy } = config.preview;
52966
53105
  if (proxy) {
52967
53106
  app.use(proxyMiddleware(httpServer, proxy, config));
@@ -53122,7 +53261,8 @@ const configDefaults = Object.freeze({
53122
53261
  removeSsrLoadModule: undefined
53123
53262
  },
53124
53263
  legacy: {
53125
- proxySsrExternalModules: false
53264
+ proxySsrExternalModules: false,
53265
+ skipWebSocketTokenCheck: false
53126
53266
  },
53127
53267
  logLevel: "info",
53128
53268
  customLogger: undefined,
@@ -53567,6 +53707,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
53567
53707
  rollupOptions: config.worker?.rollupOptions || {}
53568
53708
  };
53569
53709
  const base = withTrailingSlash(resolvedBase);
53710
+ const preview = resolvePreviewOptions(config.preview, server);
53570
53711
  resolved = {
53571
53712
  configFile: configFile ? normalizePath$3(configFile) : undefined,
53572
53713
  configFileDependencies: configFileDependencies.map(
@@ -53595,7 +53736,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
53595
53736
  },
53596
53737
  server,
53597
53738
  builder,
53598
- preview: resolvePreviewOptions(config.preview, server),
53739
+ preview,
53599
53740
  envDir,
53600
53741
  env: {
53601
53742
  ...userEnv,
@@ -53623,6 +53764,12 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
53623
53764
  dev: resolvedDevEnvironmentOptions,
53624
53765
  build: resolvedBuildOptions,
53625
53766
  environments: resolvedEnvironments,
53767
+ // random 72 bits (12 base64 chars)
53768
+ // at least 64bits is recommended
53769
+ // https://owasp.org/www-community/vulnerabilities/Insufficient_Session-ID_Length
53770
+ webSocketToken: Buffer.from(
53771
+ crypto$2.getRandomValues(new Uint8Array(9))
53772
+ ).toString("base64url"),
53626
53773
  getSortedPlugins: undefined,
53627
53774
  getSortedPluginHooks: undefined,
53628
53775
  /**
@@ -53661,7 +53808,8 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
53661
53808
  dot: true
53662
53809
  }
53663
53810
  ),
53664
- safeModulePaths: /* @__PURE__ */ new Set()
53811
+ safeModulePaths: /* @__PURE__ */ new Set(),
53812
+ additionalAllowedHosts: getAdditionalAllowedHosts(server, preview)
53665
53813
  };
53666
53814
  resolved = {
53667
53815
  ...config,
@@ -1,4 +1,4 @@
1
- import { O as commonjsGlobal, N as getDefaultExportFromCjs } from './dep-Beq30MX9.js';
1
+ import { O as commonjsGlobal, N as getDefaultExportFromCjs } from './dep-BdTvomPN.js';
2
2
  import require$$0$2 from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -1,4 +1,4 @@
1
- import { N as getDefaultExportFromCjs } from './dep-Beq30MX9.js';
1
+ import { N as getDefaultExportFromCjs } from './dep-BdTvomPN.js';
2
2
  import require$$0 from 'path';
3
3
  import { l as lib } from './dep-3RmXg9uo.js';
4
4
 
package/dist/node/cli.js CHANGED
@@ -2,12 +2,13 @@ import path from 'node:path';
2
2
  import fs__default from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { M as colors, G as createLogger, r as resolveConfig } from './chunks/dep-Beq30MX9.js';
5
+ import { M as colors, G as createLogger, r as resolveConfig } from './chunks/dep-BdTvomPN.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
9
9
  import 'node:util';
10
10
  import 'node:module';
11
+ import 'node:crypto';
11
12
  import 'esbuild';
12
13
  import 'path';
13
14
  import 'fs';
@@ -23,7 +24,6 @@ import 'stream';
23
24
  import 'os';
24
25
  import 'child_process';
25
26
  import 'node:os';
26
- import 'node:crypto';
27
27
  import 'node:dns';
28
28
  import 'vite/module-runner';
29
29
  import 'rollup/parseAst';
@@ -40,6 +40,7 @@ import 'zlib';
40
40
  import 'buffer';
41
41
  import 'https';
42
42
  import 'tls';
43
+ import 'node:net';
43
44
  import 'assert';
44
45
  import 'node:querystring';
45
46
  import 'node:zlib';
@@ -740,7 +741,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
740
741
  `[boolean] force the optimizer to ignore the cache and re-bundle`
741
742
  ).action(async (root, options) => {
742
743
  filterDuplicateOptions(options);
743
- const { createServer } = await import('./chunks/dep-Beq30MX9.js').then(function (n) { return n.Q; });
744
+ const { createServer } = await import('./chunks/dep-BdTvomPN.js').then(function (n) { return n.Q; });
744
745
  try {
745
746
  const server = await createServer({
746
747
  root,
@@ -833,7 +834,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
833
834
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(
834
835
  async (root, options) => {
835
836
  filterDuplicateOptions(options);
836
- const { createBuilder } = await import('./chunks/dep-Beq30MX9.js').then(function (n) { return n.R; });
837
+ const { createBuilder } = await import('./chunks/dep-BdTvomPN.js').then(function (n) { return n.R; });
837
838
  const buildOptions = cleanGlobalCLIOptions(
838
839
  cleanBuilderCLIOptions(options)
839
840
  );
@@ -868,7 +869,7 @@ cli.command("optimize [root]", "pre-bundle dependencies").option(
868
869
  ).action(
869
870
  async (root, options) => {
870
871
  filterDuplicateOptions(options);
871
- const { optimizeDeps } = await import('./chunks/dep-Beq30MX9.js').then(function (n) { return n.P; });
872
+ const { optimizeDeps } = await import('./chunks/dep-BdTvomPN.js').then(function (n) { return n.P; });
872
873
  try {
873
874
  const config = await resolveConfig(
874
875
  {
@@ -894,7 +895,7 @@ ${e.stack}`),
894
895
  cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(
895
896
  async (root, options) => {
896
897
  filterDuplicateOptions(options);
897
- const { preview } = await import('./chunks/dep-Beq30MX9.js').then(function (n) { return n.S; });
898
+ const { preview } = await import('./chunks/dep-BdTvomPN.js').then(function (n) { return n.S; });
898
899
  try {
899
900
  const server = await preview({
900
901
  root,
@@ -674,6 +674,18 @@ interface CommonServerOptions {
674
674
  * Set to 0.0.0.0 to listen on all addresses, including LAN and public addresses.
675
675
  */
676
676
  host?: string | boolean;
677
+ /**
678
+ * The hostnames that Vite is allowed to respond to.
679
+ * `localhost` and subdomains under `.localhost` and all IP addresses are allowed by default.
680
+ * When using HTTPS, this check is skipped.
681
+ *
682
+ * If a string starts with `.`, it will allow that hostname without the `.` and all subdomains under the hostname.
683
+ * For example, `.example.com` will allow `example.com`, `foo.example.com`, and `foo.bar.example.com`.
684
+ *
685
+ * If set to `true`, the server is allowed to respond to requests for any hosts.
686
+ * This is not recommended as it will be vulnerable to DNS rebinding attacks.
687
+ */
688
+ allowedHosts?: string[] | true;
677
689
  /**
678
690
  * Enable TLS + HTTP/2.
679
691
  * Note: this downgrades to TLS only when the proxy option is also used.
@@ -709,8 +721,14 @@ interface CommonServerOptions {
709
721
  /**
710
722
  * Configure CORS for the dev server.
711
723
  * Uses https://github.com/expressjs/cors.
724
+ *
725
+ * When enabling this option, **we recommend setting a specific value
726
+ * rather than `true`** to avoid exposing the source code to untrusted origins.
727
+ *
712
728
  * Set to `true` to allow all methods from any origin, or configure separately
713
729
  * using an object.
730
+ *
731
+ * @default false
714
732
  */
715
733
  cors?: CorsOptions | boolean;
716
734
  /**
@@ -722,6 +740,12 @@ interface CommonServerOptions {
722
740
  * https://github.com/expressjs/cors#configuration-options
723
741
  */
724
742
  interface CorsOptions {
743
+ /**
744
+ * Configures the Access-Control-Allow-Origin CORS header.
745
+ *
746
+ * **We recommend setting a specific value rather than
747
+ * `true`** to avoid exposing the source code to untrusted origins.
748
+ */
725
749
  origin?: CorsOrigin | ((origin: string | undefined, cb: (err: Error, origins: CorsOrigin) => void) => void);
726
750
  methods?: string | string[];
727
751
  allowedHeaders?: string | string[];
@@ -3900,6 +3924,18 @@ interface LegacyOptions {
3900
3924
  * https://github.com/vitejs/vite/discussions/14697.
3901
3925
  */
3902
3926
  proxySsrExternalModules?: boolean;
3927
+ /**
3928
+ * In Vite 6.0.8 and below, WebSocket server was able to connect from any web pages. However,
3929
+ * that could be exploited by a malicious web page.
3930
+ *
3931
+ * In Vite 6.0.9+, the WebSocket server now requires a token to connect from a web page.
3932
+ * But this may break some plugins and frameworks that connects to the WebSocket server
3933
+ * on their own. Enabling this option will make Vite skip the token check.
3934
+ *
3935
+ * **We do not recommend enabling this option unless you are sure that you are fine with
3936
+ * that security weakness.**
3937
+ */
3938
+ skipWebSocketTokenCheck?: boolean;
3903
3939
  }
3904
3940
  interface ResolvedWorkerOptions {
3905
3941
  format: 'es' | 'iife';
@@ -3946,6 +3982,17 @@ type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'json' | 'as
3946
3982
  appType: AppType;
3947
3983
  experimental: ExperimentalOptions;
3948
3984
  environments: Record<string, ResolvedEnvironmentOptions>;
3985
+ /**
3986
+ * The token to connect to the WebSocket server from browsers.
3987
+ *
3988
+ * We recommend using `import.meta.hot` rather than connecting
3989
+ * to the WebSocket server directly.
3990
+ * If you have a usecase that requires connecting to the WebSocket
3991
+ * server, please create an issue so that we can discuss.
3992
+ *
3993
+ * @deprecated
3994
+ */
3995
+ webSocketToken: string;
3949
3996
  } & PluginHookUtils>;
3950
3997
  interface PluginHookUtils {
3951
3998
  getSortedPlugins: <K extends keyof Plugin>(hookName: K) => PluginWithRequiredHook<K>[];
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-Beq30MX9.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, C as createFilter, h as createIdResolver, G as createLogger, n as createRunnableDevEnvironment, c as createServer, w as createServerHotChannel, v as createServerModuleRunner, d as defineConfig, u as fetchModule, j as formatPostcssSourceMap, J as isFileLoadingAllowed, I as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, K as loadEnv, A as mergeAlias, z as mergeConfig, x as moduleRunnerTransform, y as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, L as resolveEnvPrefix, E as rollupVersion, H as searchForWorkspaceRoot, F as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Beq30MX9.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-BdTvomPN.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, C as createFilter, h as createIdResolver, G as createLogger, n as createRunnableDevEnvironment, c as createServer, w as createServerHotChannel, v as createServerModuleRunner, d as defineConfig, u as fetchModule, j as formatPostcssSourceMap, J as isFileLoadingAllowed, I as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, K as loadEnv, A as mergeAlias, z as mergeConfig, x as moduleRunnerTransform, y as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, L as resolveEnvPrefix, E as rollupVersion, H as searchForWorkspaceRoot, F as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-BdTvomPN.js';
4
4
  export { DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import 'node:fs';
@@ -10,6 +10,7 @@ import 'node:url';
10
10
  import 'node:util';
11
11
  import 'node:perf_hooks';
12
12
  import 'node:module';
13
+ import 'node:crypto';
13
14
  import 'path';
14
15
  import 'fs';
15
16
  import 'node:child_process';
@@ -25,7 +26,6 @@ import 'stream';
25
26
  import 'os';
26
27
  import 'child_process';
27
28
  import 'node:os';
28
- import 'node:crypto';
29
29
  import 'node:dns';
30
30
  import 'vite/module-runner';
31
31
  import 'module';
@@ -41,6 +41,7 @@ import 'zlib';
41
41
  import 'buffer';
42
42
  import 'https';
43
43
  import 'tls';
44
+ import 'node:net';
44
45
  import 'assert';
45
46
  import 'node:querystring';
46
47
  import 'node:zlib';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.0.8",
3
+ "version": "6.0.9",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",