@rsbuild/core 2.2.2 → 2.2.3

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.
package/dist/626.js CHANGED
@@ -3425,7 +3425,7 @@ function createPublicContext(context) {
3425
3425
  async function createContext(options, userConfig, logger, loadConfigResult) {
3426
3426
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, hooks = initHooks();
3427
3427
  return {
3428
- version: "2.2.2",
3428
+ version: "2.2.3",
3429
3429
  rootPath,
3430
3430
  configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
3431
3431
  configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
@@ -6593,13 +6593,23 @@ async function getFileFromUrl(url, outputFileSystem, context) {
6593
6593
  if (pathname.includes('\0')) return {
6594
6594
  errorCode: 400
6595
6595
  };
6596
- if (UP_PATH_REGEXP.test(node_path.normalize(`./${pathname}`))) return {
6596
+ let hasUpPath = UP_PATH_REGEXP.test(pathname);
6597
+ if (hasUpPath && UP_PATH_REGEXP.test(node_path.normalize(`./${pathname}`))) return {
6597
6598
  errorCode: 403
6598
6599
  };
6599
6600
  let { environmentList, publicPathnames } = context, distPaths = environmentList.map((env)=>env.distPath), possibleFilenames = new Set();
6600
6601
  for (let [index, distPath] of distPaths.entries()){
6601
6602
  let prefix = publicPathnames[index];
6602
- prefix && '/' !== prefix && isUrlPathUnderBase(pathname, prefix) && possibleFilenames.add(node_path.join(distPath, pathname.slice(prefix.length)));
6603
+ if (prefix && '/' !== prefix && isUrlPathUnderBase(pathname, prefix)) {
6604
+ let candidatePath = node_path.join(distPath, pathname.slice(prefix.length));
6605
+ if (hasUpPath) {
6606
+ let relativePath = node_path.relative(distPath, candidatePath);
6607
+ if (UP_PATH_REGEXP.test(relativePath)) return {
6608
+ errorCode: 403
6609
+ };
6610
+ }
6611
+ possibleFilenames.add(candidatePath);
6612
+ }
6603
6613
  }
6604
6614
  for (let distPath of distPaths)possibleFilenames.add(node_path.join(distPath, pathname));
6605
6615
  for (let filename of possibleFilenames){
@@ -6783,8 +6793,13 @@ function sendError(res, code) {
6783
6793
  let byteLength = Buffer.byteLength(document);
6784
6794
  res.setHeader('Content-Length', byteLength), res.end(document);
6785
6795
  }
6796
+ let filterWebEnvironments = (environmentList)=>environmentList.filter((environment)=>isWebTarget(environment.config.output.target));
6786
6797
  function createAssetsMiddleware(context, ready, outputFileSystem) {
6787
- let { logger } = context;
6798
+ let { logger } = context, webEnvironments = filterWebEnvironments(context.environmentList), assetContext = {
6799
+ ...context,
6800
+ environmentList: webEnvironments,
6801
+ publicPathnames: webEnvironments.map((environment)=>context.publicPathnames[environment.index])
6802
+ };
6788
6803
  return async function assetsMiddleware(req, res, next) {
6789
6804
  async function goNext() {
6790
6805
  return new Promise((resolve)=>{
@@ -6796,7 +6811,7 @@ function createAssetsMiddleware(context, ready, outputFileSystem) {
6796
6811
  req.method && 'GET' !== req.method && 'HEAD' !== req.method ? await goNext() : ready(async function processRequest() {
6797
6812
  let readStream;
6798
6813
  if (!req.url) return void await goNext();
6799
- let resolved = await getFileFromUrl(req.url, outputFileSystem, context);
6814
+ let resolved = await getFileFromUrl(req.url, outputFileSystem, assetContext);
6800
6815
  if (!resolved) return void await goNext();
6801
6816
  if ('errorCode' in resolved) {
6802
6817
  403 === resolved.errorCode ? logger.error(`[rsbuild:middleware] Malicious path "${req.url}".`) : 400 === resolved.errorCode && logger.error(`[rsbuild:middleware] Invalid pathname "${req.url}".`), sendError(res, resolved.errorCode);
@@ -8423,7 +8438,7 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
8423
8438
  }), logger.debug('create dev server done'), devServer;
8424
8439
  }
8425
8440
  async function startPreviewServer(context, config, { getPortSilently } = {}) {
8426
- let environmentList, { logger } = context, { connect } = await import("./connect-next.js"), middlewares = connect(), { port, portTip } = await resolvePort(config), serverConfig = config.server, { host, headers, proxy, historyApiFallback, compress, base, cors } = serverConfig, assetPrefixes = context.environmentList.map((environment)=>environment.config.output.assetPrefix);
8441
+ let { logger } = context, { connect } = await import("./connect-next.js"), middlewares = connect(), { port, portTip } = await resolvePort(config), serverConfig = config.server, { host, headers, proxy, historyApiFallback, compress, base, cors } = serverConfig, assetPrefixes = context.environmentList.map((environment)=>environment.config.output.assetPrefix);
8427
8442
  context.publicPathnames = getPublicPathnames(assetPrefixes, base);
8428
8443
  let protocol = serverConfig.https ? 'https' : 'http', routes = getRoutes(context), urls = await getAddressUrls({
8429
8444
  protocol,
@@ -8467,13 +8482,9 @@ async function startPreviewServer(context, config, { getPortSilently } = {}) {
8467
8482
  server: previewServer,
8468
8483
  environments: context.environments
8469
8484
  });
8470
- let assetContext = (environmentList = context.environmentList.filter((environment)=>isWebTarget(environment.config.output.target)), {
8471
- ...context,
8472
- environmentList,
8473
- publicPathnames: environmentList.map((environment)=>context.publicPathnames[environment.index])
8474
- }), assetsMiddleware = createAssetsMiddleware(assetContext, (callback)=>callback(), node_fs), htmlMiddlewareOptions = {
8485
+ let webEnvironments = filterWebEnvironments(context.environmentList), assetsMiddleware = createAssetsMiddleware(context, (callback)=>callback(), node_fs), htmlMiddlewareOptions = {
8475
8486
  assetsMiddleware,
8476
- distPaths: assetContext.environmentList.map((environment)=>environment.distPath),
8487
+ distPaths: webEnvironments.map((environment)=>environment.distPath),
8477
8488
  outputFileSystem: node_fs
8478
8489
  };
8479
8490
  if (isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger)), cors) {
@@ -10209,7 +10220,7 @@ let applyServerOptions = (command)=>{
10209
10220
  };
10210
10221
  function setupCommands(argv) {
10211
10222
  let cli = ((name = "")=>new CAC(name))('rsbuild');
10212
- cli.version("2.2.2"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
10223
+ cli.version("2.2.3"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
10213
10224
  default: 'auto'
10214
10225
  }).option('--dist-path <dir>', 'Set the root directory of output files').option('--source-map', 'Enable source map').option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
10215
10226
  type: [
@@ -10274,7 +10285,7 @@ function setupCommands(argv) {
10274
10285
  }
10275
10286
  function showGreeting() {
10276
10287
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
10277
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.2.2\n`);
10288
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.2.3\n`);
10278
10289
  }
10279
10290
  function setupLogLevel(argv) {
10280
10291
  if (argv.length <= 3) return;
@@ -10296,5 +10307,5 @@ function runCLI({ argv = process.argv } = {}) {
10296
10307
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
10297
10308
  }
10298
10309
  }
10299
- let src_version = "2.2.2";
10310
+ let src_version = "2.2.3";
10300
10311
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger_createLogger as createLogger, mergeRsbuildConfig, mrmime_lookup, runCLI, src_logger as logger, src_version as version };
@@ -1,2 +1,7 @@
1
1
  import type { InternalContext, RequestHandler, Rspack } from '../../types/index.js';
2
+ /**
3
+ * Filters environments to those whose outputs may be exposed by the HTTP assets
4
+ * middleware. Node-targeted outputs are intended for server-side execution,
5
+ * such as through `loadBundle`, and must not participate in URL resolution.
6
+ */ export declare const filterWebEnvironments: (environmentList: InternalContext['environmentList']) => InternalContext['environmentList'];
2
7
  export declare function createAssetsMiddleware(context: InternalContext, ready: (callback: () => void) => void, outputFileSystem: Rspack.OutputFileSystem): RequestHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {