vite 2.6.11 → 2.6.12

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -4143,6 +4143,21 @@ function writeFile(filename, content) {
4143
4143
  }
4144
4144
  fs__default.writeFileSync(filename, content);
4145
4145
  }
4146
+ /**
4147
+ * Use instead of fs.existsSync(filename)
4148
+ * #2051 if we don't have read permission on a directory, existsSync() still
4149
+ * works and will result in massively slow subsequent checks (which are
4150
+ * unnecessary in the first place)
4151
+ */
4152
+ function isFileReadable(filename) {
4153
+ try {
4154
+ fs__default.accessSync(filename, fs__default.constants.R_OK);
4155
+ return true;
4156
+ }
4157
+ catch {
4158
+ return false;
4159
+ }
4160
+ }
4146
4161
  /**
4147
4162
  * Delete every file and subdirectory. **The given directory must exist.**
4148
4163
  * Pass an optional `skip` array to preserve files in the root directory.
@@ -20242,7 +20257,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20242
20257
  replacer: urlReplacer
20243
20258
  }));
20244
20259
  if (isModule) {
20245
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-536fbbdc.js'); }).then(function (n) { return n.index; })).default({
20260
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-822b9d02.js'); }).then(function (n) { return n.index; })).default({
20246
20261
  ...modulesOptions,
20247
20262
  getJSON(cssFileName, _modules, outputFileName) {
20248
20263
  modules = _modules;
@@ -21207,7 +21222,7 @@ const assetAttrsConfig = {
21207
21222
  const isAsyncScriptMap = new WeakMap();
21208
21223
  async function traverseHtml(html, filePath, visitor) {
21209
21224
  // lazy load compiler
21210
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-c5e7917e.js'); }).then(function (n) { return n.compilerDom_cjs; });
21225
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-b0d06b66.js'); }).then(function (n) { return n.compilerDom_cjs; });
21211
21226
  // @vue/compiler-core doesn't like lowercase doctypes
21212
21227
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21213
21228
  try {
@@ -29963,16 +29978,10 @@ function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, target
29963
29978
  }
29964
29979
  }
29965
29980
  function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, tryPrefix, skipPackageJson) {
29966
- let isReadable = false;
29967
- try {
29968
- // #2051 if we don't have read permission on a directory, existsSync() still
29969
- // works and will result in massively slow subsequent checks (which are
29970
- // unnecessary in the first place)
29971
- fs__default.accessSync(file, fs__default.constants.R_OK);
29972
- isReadable = true;
29973
- }
29974
- catch (e) { }
29975
- if (isReadable) {
29981
+ // #2051 if we don't have read permission on a directory, existsSync() still
29982
+ // works and will result in massively slow subsequent checks (which are
29983
+ // unnecessary in the first place)
29984
+ if (isFileReadable(file)) {
29976
29985
  if (!fs__default.statSync(file).isDirectory()) {
29977
29986
  return getRealPath(file, preserveSymlinks) + postfix;
29978
29987
  }
@@ -42059,36 +42068,11 @@ function errorMiddleware(server, allowNext = false) {
42059
42068
  next();
42060
42069
  }
42061
42070
  else {
42062
- if (err instanceof AccessRestrictedError) {
42063
- res.statusCode = 403;
42064
- res.write(renderErrorHTML(err.message));
42065
- res.end();
42066
- }
42067
42071
  res.statusCode = 500;
42068
42072
  res.end();
42069
42073
  }
42070
42074
  };
42071
42075
  }
42072
- class AccessRestrictedError extends Error {
42073
- constructor(msg) {
42074
- super(msg);
42075
- }
42076
- }
42077
- function renderErrorHTML(msg) {
42078
- // to have syntax highlighting and autocompletion in IDE
42079
- const html = String.raw;
42080
- return html `
42081
- <body>
42082
- <h1>403 Restricted</h1>
42083
- <p>${msg.replace(/\n/g, '<br/>')}</p>
42084
- <style>
42085
- body {
42086
- padding: 1em 2em;
42087
- }
42088
- </style>
42089
- </body>
42090
- `;
42091
- }
42092
42076
 
42093
42077
  /**
42094
42078
  * This file is refactored into TypeScript based on
@@ -49054,7 +49038,7 @@ function readFileIfExists(value) {
49054
49038
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49055
49039
  */
49056
49040
  async function createCertificate() {
49057
- const { generate } = await Promise.resolve().then(function () { return require('./dep-5031a88d.js'); }).then(function (n) { return n.index; });
49041
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-14140c42.js'); }).then(function (n) { return n.index; });
49058
49042
  const pems = generate(null, {
49059
49043
  algorithm: 'sha256',
49060
49044
  days: 30,
@@ -56580,11 +56564,13 @@ function serveStaticMiddleware(dir, server) {
56580
56564
  const serve = sirv(dir, sirvOptions);
56581
56565
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
56582
56566
  return function viteServeStaticMiddleware(req, res, next) {
56583
- // only serve the file if it's not an html request
56567
+ // only serve the file if it's not an html request or ends with `/`
56584
56568
  // so that html requests can fallthrough to our html middleware for
56585
56569
  // special processing
56586
56570
  // also skip internal requests `/@fs/ /@vite-client` etc...
56587
- if (path__default.extname(cleanUrl(req.url)) === '.html' ||
56571
+ const cleanedUrl = cleanUrl(req.url);
56572
+ if (cleanedUrl.endsWith('/') ||
56573
+ path__default.extname(cleanedUrl) === '.html' ||
56588
56574
  isInternalRequest(req.url)) {
56589
56575
  return next();
56590
56576
  }
@@ -56609,7 +56595,9 @@ function serveStaticMiddleware(dir, server) {
56609
56595
  if (resolvedUrl.endsWith('/') && !fileUrl.endsWith('/')) {
56610
56596
  fileUrl = fileUrl + '/';
56611
56597
  }
56612
- ensureServingAccess(fileUrl, server);
56598
+ if (!ensureServingAccess(fileUrl, server, res, next)) {
56599
+ return;
56600
+ }
56613
56601
  if (redirected) {
56614
56602
  req.url = redirected;
56615
56603
  }
@@ -56627,7 +56615,9 @@ function serveRawFsMiddleware(server) {
56627
56615
  // searching based from fs root.
56628
56616
  if (url.startsWith(FS_PREFIX)) {
56629
56617
  // restrict files outside of `fs.allow`
56630
- ensureServingAccess(slash$3(path__default.resolve(fsPathFromId(url))), server);
56618
+ if (!ensureServingAccess(slash$3(path__default.resolve(fsPathFromId(url))), server, res, next)) {
56619
+ return;
56620
+ }
56631
56621
  url = url.slice(FS_PREFIX.length);
56632
56622
  if (isWindows$4)
56633
56623
  url = url.replace(/^[A-Z]:/i, '');
@@ -56643,29 +56633,60 @@ function isFileServingAllowed(url, server) {
56643
56633
  // explicitly disabled
56644
56634
  if (server.config.server.fs.strict === false)
56645
56635
  return true;
56646
- const file = ensureLeadingSlash(normalizePath$4(cleanUrl(url)));
56636
+ const cleanedUrl = cleanUrl(url);
56637
+ const file = ensureLeadingSlash(normalizePath$4(cleanedUrl));
56647
56638
  if (server.moduleGraph.safeModulesPath.has(file))
56648
56639
  return true;
56649
56640
  if (server.config.server.fs.allow.some((i) => file.startsWith(i + '/')))
56650
56641
  return true;
56651
56642
  if (!server.config.server.fs.strict) {
56652
- server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`);
56653
- server.config.logger.warnOnce(`For security concerns, accessing files outside of serving allow list will ` +
56654
- `be restricted by default in the future version of Vite. ` +
56655
- `Refer to https://vitejs.dev/config/#server-fs-allow for more details.`);
56643
+ if (isFileReadable(cleanedUrl)) {
56644
+ server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`);
56645
+ server.config.logger.warnOnce(`For security concerns, accessing files outside of serving allow list will ` +
56646
+ `be restricted by default in the future version of Vite. ` +
56647
+ `Refer to https://vitejs.dev/config/#server-fs-allow for more details.`);
56648
+ }
56656
56649
  return true;
56657
56650
  }
56658
56651
  return false;
56659
56652
  }
56660
- function ensureServingAccess(url, server) {
56661
- if (!isFileServingAllowed(url, server)) {
56662
- const allow = server.config.server.fs.allow;
56663
- throw new AccessRestrictedError(`The request url "${url}" is outside of Vite serving allow list:
56664
-
56665
- ${allow.map((i) => `- ${i}`).join('\n')}
56653
+ function ensureServingAccess(url, server, res, next) {
56654
+ if (isFileServingAllowed(url, server)) {
56655
+ return true;
56656
+ }
56657
+ if (isFileReadable(cleanUrl(url))) {
56658
+ const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
56659
+ const hintMessage = `
56660
+ ${server.config.server.fs.allow.map((i) => `- ${i}`).join('\n')}
56666
56661
 
56667
- Refer to docs https://vitejs.dev/config/#server-fs-allow for configurations and more details.`);
56662
+ Refer to docs https://vitejs.dev/config/#server-fs-allow for configurations and more details.`;
56663
+ server.config.logger.error(urlMessage);
56664
+ server.config.logger.warnOnce(hintMessage + '\n');
56665
+ res.statusCode = 403;
56666
+ res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
56667
+ res.end();
56668
56668
  }
56669
+ else {
56670
+ // if the file doesn't exist, we shouldn't restrict this path as it can
56671
+ // be an API call. Middlewares would issue a 404 if the file isn't handled
56672
+ next();
56673
+ }
56674
+ return false;
56675
+ }
56676
+ function renderRestrictedErrorHTML(msg) {
56677
+ // to have syntax highlighting and autocompletion in IDE
56678
+ const html = String.raw;
56679
+ return html `
56680
+ <body>
56681
+ <h1>403 Restricted</h1>
56682
+ <p>${msg.replace(/\n/g, '<br/>')}</p>
56683
+ <style>
56684
+ body {
56685
+ padding: 1em 2em;
56686
+ }
56687
+ </style>
56688
+ </body>
56689
+ `;
56669
56690
  }
56670
56691
 
56671
56692
  const debugLoad = createDebugger('vite:load');
@@ -66634,10 +66655,7 @@ const ROOT_FILES = [
66634
66655
  // yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
66635
66656
  function hasWorkspacePackageJSON(root) {
66636
66657
  const path = path$t.join(root, 'package.json');
66637
- try {
66638
- fs__default.accessSync(path, fs__default.constants.R_OK);
66639
- }
66640
- catch {
66658
+ if (!isFileReadable(path)) {
66641
66659
  return false;
66642
66660
  }
66643
66661
  const content = JSON.parse(fs__default.readFileSync(path, 'utf-8')) || {};
@@ -92068,4 +92086,4 @@ exports.send = send$1;
92068
92086
  exports.sortUserPlugins = sortUserPlugins;
92069
92087
  exports.source = source;
92070
92088
  exports.transformWithEsbuild = transformWithEsbuild;
92071
- //# sourceMappingURL=dep-92cbd8f1.js.map
92089
+ //# sourceMappingURL=dep-81ddae5a.js.map