Skip to content

Conversation

@weareoutman
Copy link
Member

@weareoutman weareoutman commented Nov 25, 2025

依赖检查

组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。

请勾选以下两组选项其中之一:

  • 本次 MR 没有使用上游组件(例如框架、后台组件等)的较新版本提供的特性。

或者:

  • 本次 MR 使用了上游组件(例如框架、后台组件等)的较新版本提供的特性。
  • 在对应的文件中更新了该上游组件的依赖版本(或确认了当前声明的依赖版本已包含本次 MR 使用的新特性)。

提交信息检查

Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。

破坏性变更是针对于下游使用者而言,可以通过本次改动对下游使用者的影响来识别变更类型:

  • 下游使用者不做任何改动,仍可以正常工作时,那么它属于普通变更。
  • 反之,下游使用者不做改动就无法正常工作时,那么它属于破坏性变更。

例如,构件修改了一个属性名,小产品 Storyboard 中需要使用新属性名才能工作,那么它就是破坏性变更。
又例如,构件还没有任何下游使用者,那么它的任何变更都是普通变更。

破坏性变更:

  • ⚠️ 本次 MR 包含破坏性变更的提交,请继续确认以下所有选项:
  • 没有更好的兼容方案,必须做破坏性变更。
  • 使用了 feat 作为提交类型。
  • 标注了 BREAKING CHANGE: 你的变更说明
  • 同时更新了本仓库中所有下游使用者的调用。
  • 同时更新了本仓库中所有下游使用者对该子包的依赖为即将发布的 major 版本。
  • 同时为其它仓库的 Migrating 做好了准备,例如文档或批量改动的方法。
  • 手动验证过破坏性变更在 Migrate 后可以正常工作。
  • 破坏性变更所在的提交没有意外携带其它子包的改动。

新特性:

  • 本次 MR 包含新特性的提交,且该提交不带有破坏性变更,并使用了 feat 作为提交类型。
  • 给新特性添加了单元测试。
  • 手动验证过新特性可以正常工作。

问题修复:

  • 本次 MR 包含问题修复的提交,且该提交不带有新特性或破坏性变更,并使用了 fix 作为提交类型。
  • 给问题修复添加了单元测试。
  • 手动验证过问题修复得到解决。

杂项工作:

即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:

  • 本次 MR 包含杂项工作的提交,且该提交不带有问题修复、新特性或破坏性变更,并使用了 chore, docs, test 等作为提交类型。

Summary by CodeRabbit

发布说明

  • 新功能
    • 新增应用程序图片资源服务能力,支持从多个预配置路径提供图片资源。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Walkthrough

添加图片服务中间件。在现有中间件配置中引入新的 serveAppImages 中间件工厂,并在两个特定路径上注册该中间件以处理应用图片资源的 GET 请求。

Changes

聚类 / 文件 变更摘要
中间件路由配置
packages/brick-container/serve/middlewares/getMiddlewares.js
导入新的 serveAppImages 中间件工厂;在 getMiddlewaresgetPreMiddlewares 中各添加两条路由(sa-static/${appId}/versions/0.0.0/webroot/-/imagessa-static/${appId}/versions/0.0.0/webroot/-/micro-apps/${appId}/images),均映射至 serveAppImages(env, appId)
新增中间件工厂
packages/brick-container/serve/middlewares/serveAppImages.js
新增默认导出函数 serveAppImages({ rootDir }, appId),返回异步中间件用于处理 GET 请求,通过 tryServeFilesrootDir/{mock-micro-apps|apps}/{appId}/dist/images{req.path} 候选路径服务图片资源;非 GET 请求转发至 next

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • 新增中间件工厂的逻辑直接,依赖于现有的 tryServeFiles 工具函数——验证其集成方式
  • 确认在 getMiddlewares.js 中添加的两条路由路径与预期的应用架构对齐
  • 检查 serveAppImages 的参数传递(env vs { rootDir })是否与工厂函数签名一致

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning PR 描述包含了完整的检查清单模板结构,但所有必需的确认项均未勾选,且缺少对工作内容的具体说明。 请根据提交类型勾选相应的破坏性变更/新特性/问题修复/杂项工作选项,并在简单描述部分说明实现的具体内容和验证情况。
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地反映了主要变更:添加支持为应用图片提供服务的功能。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch steve/v3-serve-app-images

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cypress
Copy link

cypress bot commented Nov 25, 2025

next-core    Run #11828

Run Properties:  status check passed Passed #11828  •  git commit f6f03b5538 ℹ️: Merge 3a5b706ed2b6fb5d019b84d991f76979bdcdfdd4 into 8b56a7ae267ef34303a936bd380c...
Project next-core
Branch Review steve/v3-serve-app-images
Run status status check passed Passed #11828
Run duration 00m 24s
Commit git commit f6f03b5538 ℹ️: Merge 3a5b706ed2b6fb5d019b84d991f76979bdcdfdd4 into 8b56a7ae267ef34303a936bd380c...
Committer Shenwei Wang
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 17
View all changes introduced in this branch ↗︎

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for serving app images in development mode by introducing a new middleware function serveAppImages that handles image requests for standalone apps.

  • Adds a new middleware serveAppImages that serves image files from local app directories
  • Registers two image serving paths for each app in the development server
  • Reorganizes imports in getMiddlewares.js to place external packages before local imports

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/brick-container/serve/middlewares/serveAppImages.js New middleware function that serves app images from mock-micro-apps and apps directories for local development
packages/brick-container/serve/middlewares/getMiddlewares.js Adds two image serving routes per app and reorganizes imports to follow convention of external packages first

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

export default function serveAppImages({ rootDir }, appId) {
/**
* @param {import("express").Request} req
* @param {import("express").Response} res
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc comment is missing the next parameter. The returned async function takes three parameters (req, res, next), but the JSDoc only documents two. This should be:

/**
 * @param {import("express").Request} req
 * @param {import("express").Response} res
 * @param {import("express").NextFunction} next
 */
Suggested change
* @param {import("express").Response} res
* @param {import("express").Response} res
* @param {import("express").NextFunction} next

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/brick-container/serve/middlewares/getMiddlewares.js (1)

111-114: 考虑添加注释说明两种路径模式的用途。

这里注册了两个不同的 URL 模式(/-/images/-/micro-apps/${appId}/images),但它们都指向相同的图片源。建议添加注释说明为什么需要支持这两种模式(例如向后兼容性或不同的部署场景)。

packages/brick-container/serve/middlewares/serveAppImages.js (2)

4-4: 建议添加参数验证。

函数没有验证 rootDirappId 参数。建议添加基本的验证以防止运行时错误,例如检查 rootDir 是否存在,以及 appId 是否包含非法字符(如路径遍历字符)。

可以考虑添加如下验证:

 export default function serveAppImages({ rootDir }, appId) {
+  if (!rootDir) {
+    throw new Error("rootDir is required for serveAppImages");
+  }
+  if (!appId || /[./\\]/.test(appId)) {
+    throw new Error("Invalid appId for serveAppImages");
+  }
+
   /**
    * @param {import("express").Request} req
    * @param {import("express").Response} res

9-13: async 关键字非必需。

中间件函数声明为 async 但内部没有使用 await。虽然不影响功能,但可以移除 async 关键字以保持代码简洁。

-  return async function (req, res, next) {
+  return function (req, res, next) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8b56a7a and 3a5b706.

📒 Files selected for processing (2)
  • packages/brick-container/serve/middlewares/getMiddlewares.js (2 hunks)
  • packages/brick-container/serve/middlewares/serveAppImages.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/brick-container/serve/middlewares/getMiddlewares.js (3)
packages/brick-container/build.config.js (1)
  • baseHref (15-15)
packages/brick-container/serve/getProxy.js (1)
  • appId (506-506)
packages/brick-container/serve/middlewares/serveAppImages.js (1)
  • serveAppImages (4-24)
packages/brick-container/serve/middlewares/serveAppImages.js (2)
packages/brick-container/serve/getProxy.js (1)
  • appId (506-506)
packages/serve-helpers/src/tryFiles.js (1)
  • tryServeFiles (22-40)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: Agent
  • GitHub Check: build (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/brick-container/serve/middlewares/getMiddlewares.js (2)

2-2: 导入语句正确。

新增的 serveAppImages 导入与现有的导入风格一致。

Also applies to: 8-8


106-109: 原评论有误 - 代码实际上是正确的。

env 对象由 getEnv() 函数返回,其中明确包含了 rootDir 属性(serve/env.js 第 135 行)。serveAppImages() 能正确解构该属性,调用处 getMiddlewares.js 第 108 和 113 行无需任何修改。

Likely an incorrect or invalid review comment.

packages/brick-container/serve/middlewares/serveAppImages.js (1)

1-2: 导入语句正确。

所需的依赖已正确导入。

Comment on lines +15 to +22
tryServeFiles(
["mock-micro-apps", "apps"].map((folder) =>
path.join(rootDir, folder, appId, "dist/images", req.path)
),
req,
res,
next
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

验证路径遍历安全性。

req.path 直接用于构建文件路径。虽然 path.join() 会规范化路径,且 Express 的 res.sendFile() 提供了一定的保护,但建议验证 tryServeFiles 和底层文件服务逻辑是否充分防止了路径遍历攻击(例如 ../../ 序列)。

运行以下脚本检查 tryServeFiles 的实现细节:


🏁 Script executed:

#!/bin/bash
# 查看 tryServeFiles 的完整实现以确认安全性
ast-grep --pattern 'export function tryServeFiles($$$) {
  $$$
}'

# 查找是否有路径验证逻辑
rg -nP '(normalize|resolve|relative|\.\./)' packages/serve-helpers/src/ --type=js

Length of output: 1492


Now I need to check the tryFiles function implementation to see if there's any path validation:

验证路径遍历安全性 - 确认存在安全漏洞

您的原始评论准确指出了一个实际存在的安全问题。经验证,代码确实存在路径遍历风险:

虽然 Express 的 res.sendFile() 函数本身并非固有脆弱,但当用户输入用于确定文件路径时,它可能成为目录遍历攻击的来源。

关键问题是 path.normalize 并非独立的安全解决方案——它可能移除某些冗余路径元素,但不能防止遍历攻击。在此代码中,req.path 直接来自 HTTP 请求,且 path.join() 虽然规范化路径,但 攻击者仍可使用 "../" 访问根目录。

建议修复方案: 将规范化路径与硬编码或配置的可信根目录进行比较,若比较失败则表示检测到路径遍历,应拒绝请求。应在 tryServeFiles 前或内部添加验证,确保最终解析路径以受信基路径开头。

@weareoutman weareoutman merged commit 75a07d4 into v3 Nov 25, 2025
15 checks passed
@weareoutman weareoutman deleted the steve/v3-serve-app-images branch November 25, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants