vite 6.1.4 → 6.1.6

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,4 +1,4 @@
1
- import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-B--GINb9.js';
1
+ import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-DAc1iKf4.js';
2
2
  import require$$0$2 from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -41823,8 +41823,11 @@ function sirv (dir, opts={}) {
41823
41823
  }
41824
41824
 
41825
41825
  const knownJavascriptExtensionRE = /\.(?:[tj]sx?|[cm][tj]s)$/;
41826
+ const ERR_DENIED_FILE = "ERR_DENIED_FILE";
41826
41827
  const sirvOptions = ({
41827
- getHeaders
41828
+ config,
41829
+ getHeaders,
41830
+ disableFsServeCheck
41828
41831
  }) => {
41829
41832
  return {
41830
41833
  dev: true,
@@ -41840,6 +41843,19 @@ const sirvOptions = ({
41840
41843
  res.setHeader(name, headers[name]);
41841
41844
  }
41842
41845
  }
41846
+ },
41847
+ shouldServe: disableFsServeCheck ? undefined : (filePath) => {
41848
+ const servingAccessResult = checkLoadingAccess(config, filePath);
41849
+ if (servingAccessResult === "denied") {
41850
+ const error = new Error("denied access");
41851
+ error.code = ERR_DENIED_FILE;
41852
+ error.path = filePath;
41853
+ throw error;
41854
+ }
41855
+ if (servingAccessResult === "fallback") {
41856
+ return false;
41857
+ }
41858
+ return true;
41843
41859
  }
41844
41860
  };
41845
41861
  };
@@ -41848,7 +41864,9 @@ function servePublicMiddleware(server, publicFiles) {
41848
41864
  const serve = sirv(
41849
41865
  dir,
41850
41866
  sirvOptions({
41851
- getHeaders: () => server.config.server.headers
41867
+ config: server.config,
41868
+ getHeaders: () => server.config.server.headers,
41869
+ disableFsServeCheck: true
41852
41870
  })
41853
41871
  );
41854
41872
  const toFilePath = (url) => {
@@ -41874,6 +41892,7 @@ function serveStaticMiddleware(server) {
41874
41892
  const serve = sirv(
41875
41893
  dir,
41876
41894
  sirvOptions({
41895
+ config: server.config,
41877
41896
  getHeaders: () => server.config.server.headers
41878
41897
  })
41879
41898
  );
@@ -41900,42 +41919,47 @@ function serveStaticMiddleware(server) {
41900
41919
  }
41901
41920
  }
41902
41921
  const resolvedPathname = redirectedPathname || pathname;
41903
- let fileUrl = path$d.resolve(dir, removeLeadingSlash(resolvedPathname));
41904
- if (resolvedPathname[resolvedPathname.length - 1] === "/" && fileUrl[fileUrl.length - 1] !== "/") {
41905
- fileUrl = withTrailingSlash(fileUrl);
41906
- }
41907
- if (!ensureServingAccess(fileUrl, server, res, next)) {
41908
- return;
41909
- }
41922
+ path$d.resolve(dir, removeLeadingSlash(resolvedPathname));
41910
41923
  if (redirectedPathname) {
41911
41924
  url.pathname = encodeURI(redirectedPathname);
41912
41925
  req.url = url.href.slice(url.origin.length);
41913
41926
  }
41914
- serve(req, res, next);
41927
+ try {
41928
+ serve(req, res, next);
41929
+ } catch (e) {
41930
+ if (e && "code" in e && e.code === ERR_DENIED_FILE) {
41931
+ respondWithAccessDenied(e.path, server, res);
41932
+ return;
41933
+ }
41934
+ throw e;
41935
+ }
41915
41936
  };
41916
41937
  }
41917
41938
  function serveRawFsMiddleware(server) {
41918
41939
  const serveFromRoot = sirv(
41919
41940
  "/",
41920
- sirvOptions({ getHeaders: () => server.config.server.headers })
41941
+ sirvOptions({
41942
+ config: server.config,
41943
+ getHeaders: () => server.config.server.headers
41944
+ })
41921
41945
  );
41922
41946
  return function viteServeRawFsMiddleware(req, res, next) {
41923
41947
  if (req.url.startsWith(FS_PREFIX)) {
41924
41948
  const url = new URL(req.url, "http://example.com");
41925
41949
  const pathname = decodeURI(url.pathname);
41926
- if (!ensureServingAccess(
41927
- slash$1(path$d.resolve(fsPathFromId(pathname))),
41928
- server,
41929
- res,
41930
- next
41931
- )) {
41932
- return;
41933
- }
41934
41950
  let newPathname = pathname.slice(FS_PREFIX.length);
41935
41951
  if (isWindows$3) newPathname = newPathname.replace(/^[A-Z]:/i, "");
41936
41952
  url.pathname = encodeURI(newPathname);
41937
41953
  req.url = url.href.slice(url.origin.length);
41938
- serveFromRoot(req, res, next);
41954
+ try {
41955
+ serveFromRoot(req, res, next);
41956
+ } catch (e) {
41957
+ if (e && "code" in e && e.code === ERR_DENIED_FILE) {
41958
+ respondWithAccessDenied(e.path, server, res);
41959
+ return;
41960
+ }
41961
+ throw e;
41962
+ }
41939
41963
  } else {
41940
41964
  next();
41941
41965
  }
@@ -41959,25 +41983,35 @@ function isFileLoadingAllowed(config, filePath) {
41959
41983
  if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true;
41960
41984
  return false;
41961
41985
  }
41962
- function ensureServingAccess(url, server, res, next) {
41986
+ function checkLoadingAccess(config, path2) {
41987
+ if (isFileLoadingAllowed(config, slash$1(path2))) {
41988
+ return "allowed";
41989
+ }
41990
+ if (isFileReadable(path2)) {
41991
+ return "denied";
41992
+ }
41993
+ return "fallback";
41994
+ }
41995
+ function checkServingAccess(url, server) {
41963
41996
  if (isFileServingAllowed(url, server)) {
41964
- return true;
41997
+ return "allowed";
41965
41998
  }
41966
41999
  if (isFileReadable(cleanUrl(url))) {
41967
- const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
41968
- const hintMessage = `
42000
+ return "denied";
42001
+ }
42002
+ return "fallback";
42003
+ }
42004
+ function respondWithAccessDenied(url, server, res) {
42005
+ const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
42006
+ const hintMessage = `
41969
42007
  ${server.config.server.fs.allow.map((i) => `- ${i}`).join("\n")}
41970
42008
 
41971
42009
  Refer to docs https://vite.dev/config/server-options.html#server-fs-allow for configurations and more details.`;
41972
- server.config.logger.error(urlMessage);
41973
- server.config.logger.warnOnce(hintMessage + "\n");
41974
- res.statusCode = 403;
41975
- res.write(renderRestrictedErrorHTML(urlMessage + "\n" + hintMessage));
41976
- res.end();
41977
- } else {
41978
- next();
41979
- }
41980
- return false;
42010
+ server.config.logger.error(urlMessage);
42011
+ server.config.logger.warnOnce(hintMessage + "\n");
42012
+ res.statusCode = 403;
42013
+ res.write(renderRestrictedErrorHTML(urlMessage + "\n" + hintMessage));
42014
+ res.end();
41981
42015
  }
41982
42016
  function renderRestrictedErrorHTML(msg) {
41983
42017
  const html = String.raw;
@@ -43537,7 +43571,18 @@ const rawRE = /[?&]raw\b/;
43537
43571
  const inlineRE$2 = /[?&]inline\b/;
43538
43572
  const svgRE = /\.svg\b/;
43539
43573
  function deniedServingAccessForTransform(url, server, res, next) {
43540
- return (rawRE.test(url) || urlRE.test(url) || inlineRE$2.test(url) || svgRE.test(url)) && !ensureServingAccess(url, server, res, next);
43574
+ if (rawRE.test(url) || urlRE.test(url) || inlineRE$2.test(url) || svgRE.test(url)) {
43575
+ const servingAccessResult = checkServingAccess(url, server);
43576
+ if (servingAccessResult === "denied") {
43577
+ respondWithAccessDenied(url, server, res);
43578
+ return true;
43579
+ }
43580
+ if (servingAccessResult === "fallback") {
43581
+ next();
43582
+ return true;
43583
+ }
43584
+ }
43585
+ return false;
43541
43586
  }
43542
43587
  function cachedTransformMiddleware(server) {
43543
43588
  return function viteCachedTransformMiddleware(req, res, next) {
@@ -44712,6 +44757,17 @@ function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
44712
44757
  return searchForWorkspaceRoot(dir, root);
44713
44758
  }
44714
44759
 
44760
+ function rejectInvalidRequestMiddleware() {
44761
+ return function viteRejectInvalidRequestMiddleware(req, res, next) {
44762
+ if (req.url?.includes("#")) {
44763
+ res.writeHead(400);
44764
+ res.end();
44765
+ return;
44766
+ }
44767
+ return next();
44768
+ };
44769
+ }
44770
+
44715
44771
  function createServer(inlineConfig = {}) {
44716
44772
  return _createServer(inlineConfig, { listen: true });
44717
44773
  }
@@ -45049,6 +45105,7 @@ async function _createServer(inlineConfig = {}, options) {
45049
45105
  if (process.env.DEBUG) {
45050
45106
  middlewares.use(timeMiddleware(root));
45051
45107
  }
45108
+ middlewares.use(rejectInvalidRequestMiddleware());
45052
45109
  const { cors } = serverConfig;
45053
45110
  if (cors !== false) {
45054
45111
  middlewares.use(corsMiddleware(typeof cors === "boolean" ? {} : cors));
@@ -50019,8 +50076,8 @@ function createCachedImport(imp) {
50019
50076
  return cached;
50020
50077
  };
50021
50078
  }
50022
- const importPostcssImport = createCachedImport(() => import('./dep-stc9c31V.js').then(function (n) { return n.i; }));
50023
- const importPostcssModules = createCachedImport(() => import('./dep-7B7unqQx.js').then(function (n) { return n.i; }));
50079
+ const importPostcssImport = createCachedImport(() => import('./dep-UkrSh7Qt.js').then(function (n) { return n.i; }));
50080
+ const importPostcssModules = createCachedImport(() => import('./dep-BsiYfecU.js').then(function (n) { return n.i; }));
50024
50081
  const importPostcss = createCachedImport(() => import('postcss'));
50025
50082
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
50026
50083
  let alwaysFakeWorkerWorkerControllerCache;
@@ -1,4 +1,4 @@
1
- import { P as getDefaultExportFromCjs } from './dep-B--GINb9.js';
1
+ import { P as getDefaultExportFromCjs } from './dep-DAc1iKf4.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,7 +2,7 @@ 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 { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-B--GINb9.js';
5
+ import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-DAc1iKf4.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -745,7 +745,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
745
745
  `[boolean] force the optimizer to ignore the cache and re-bundle`
746
746
  ).action(async (root, options) => {
747
747
  filterDuplicateOptions(options);
748
- const { createServer } = await import('./chunks/dep-B--GINb9.js').then(function (n) { return n.S; });
748
+ const { createServer } = await import('./chunks/dep-DAc1iKf4.js').then(function (n) { return n.S; });
749
749
  try {
750
750
  const server = await createServer({
751
751
  root,
@@ -839,7 +839,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
839
839
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(
840
840
  async (root, options) => {
841
841
  filterDuplicateOptions(options);
842
- const { createBuilder } = await import('./chunks/dep-B--GINb9.js').then(function (n) { return n.T; });
842
+ const { createBuilder } = await import('./chunks/dep-DAc1iKf4.js').then(function (n) { return n.T; });
843
843
  const buildOptions = cleanGlobalCLIOptions(
844
844
  cleanBuilderCLIOptions(options)
845
845
  );
@@ -878,7 +878,7 @@ cli.command(
878
878
  ).action(
879
879
  async (root, options) => {
880
880
  filterDuplicateOptions(options);
881
- const { optimizeDeps } = await import('./chunks/dep-B--GINb9.js').then(function (n) { return n.R; });
881
+ const { optimizeDeps } = await import('./chunks/dep-DAc1iKf4.js').then(function (n) { return n.R; });
882
882
  try {
883
883
  const config = await resolveConfig(
884
884
  {
@@ -905,7 +905,7 @@ ${e.stack}`),
905
905
  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(
906
906
  async (root, options) => {
907
907
  filterDuplicateOptions(options);
908
- const { preview } = await import('./chunks/dep-B--GINb9.js').then(function (n) { return n.U; });
908
+ const { preview } = await import('./chunks/dep-DAc1iKf4.js').then(function (n) { return n.U; });
909
909
  try {
910
910
  const server = await preview({
911
911
  root,
@@ -4167,11 +4167,9 @@ declare function searchForWorkspaceRoot(current: string, root?: string): string;
4167
4167
 
4168
4168
  /**
4169
4169
  * Check if the url is allowed to be served, via the `server.fs` config.
4170
+ * @deprecated Use the `isFileLoadingAllowed` function instead.
4170
4171
  */
4171
4172
  declare function isFileServingAllowed(config: ResolvedConfig, url: string): boolean;
4172
- /**
4173
- * @deprecated Use the `isFileServingAllowed(config, url)` signature instead.
4174
- */
4175
4173
  declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
4176
4174
  declare function isFileLoadingAllowed(config: ResolvedConfig, filePath: string): boolean;
4177
4175
 
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-B--GINb9.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-B--GINb9.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-DAc1iKf4.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-DAc1iKf4.js';
4
4
  export { defaultAllowedOrigins, 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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.1.4",
3
+ "version": "6.1.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",