Skip to content

fix(desktop): allow localhost browser previews - #2445

Open
yuaiccc wants to merge 2 commits into
makecindy:mainfrom
yuaiccc:fix/allow-localhost-browser-preview
Open

fix(desktop): allow localhost browser previews#2445
yuaiccc wants to merge 2 commits into
makecindy:mainfrom
yuaiccc:fix/allow-localhost-browser-preview

Conversation

@yuaiccc

@yuaiccc yuaiccc commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

这次改了什么

摘要

在 browser managed config 的 SSRF policy 中新增 allowedHostnames: ['localhost'],使受管浏览器预览能打开开发者的本地 web 应用。这是 hostname 级例外(非原始 loopback IP、非 RFC1918/LAN),沿用既有 SSRF guard;fake-IP 代理范围、metadata、link-local 等仍被拦截。同步更新 managed config 与 vendored config 解析的相关测试。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

  • 关联 Issue / 需求:无
  • 本 PR 包含:buildManagedConfig()ssrfPolicy 增加 allowedHostnames: ['localhost'];更新 SSRF 策略注释说明;browserManagedConfig.test.tsruntime-config-application.test.ts 断言 localhost 例外与既有 fake-IP 例外并存。
  • 明确不包含:不放宽 127.0.0.1 / ::1 原始 IP、RFC1918/LAN、metadata、link-local;不改变 page-context evaluate 的既有残余风险边界。
  • 用户可见变化:agent 经受管浏览器可打开 http://localhost:* 的本地预览。
  • 是否存在 breaking change:无

UI 变化

不涉及:仅改主进程 SSRF 策略配置,无 renderer / 视觉 / 交互 / 文案变化。

怎么验证的

自动验证

pnpm --filter desktop exec vitest run src/main/mcp-integrations/__tests__/browserManagedConfig.test.ts
pnpm --filter browser-control-runtime exec vitest run src/__tests__/runtime-config-application.test.ts
结果:PR 作者本地已通过;本次触发重审后以 CI 为准。

手工验证

不涉及:策略由单测覆盖,无 UI 手工路径。

未执行的验证

本次未本地复跑单测,依赖 CI 重跑确认。CI 此前在 Windows unit tests 上失败,需以重跑结果为准。

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 存量插件兼容
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:

影响与回滚

  • 影响范围:仅放行 hostname localhost,不放行 127.0.0.1 / ::1 原始 IP 或 RFC1918/LAN,故不会让 agent 经由浏览器触达内网。page-context evaluate 的残余风险(Chromium 网络栈不经 Node SSRF guard)为既有约束,已在注释中说明,本 PR 不改变该边界。
  • 回滚 / 降级方式:移除 allowedHostnames: ['localhost'] 即恢复完全拦截 localhost。

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名
  • UI 改动已在「UI 变化」注明(不涉及 UI)
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档
  • 已确认测试结果或说明未执行原因

Signed-off-by: yuaiccc <yuaiccc@aliyun.com>
@yuaiccc
yuaiccc requested a review from a team as a code owner August 11, 2026 10:13
@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 为桌面端受管浏览器的 SSRF 策略增加 localhost 例外,并补充配置生成及 vendored 配置解析测试。

  • 在 managed config 中加入 allowedHostnames: ['localhost']
  • 更新 SSRF 策略说明注释
  • 验证 localhost 与既有 fake-IP 例外能被保留

Confidence Score: 3/5

当前不宜合并,因为仍存在的 localhost 主机名级例外允许 agent 访问开发者机器上任意 loopback 服务。

现有实现继续将整个 localhost 主机名加入 SSRF 白名单,且没有端口、服务范围或用户确认限制,因此此前报告的本地服务访问边界问题仍然存在。

Files Needing Attention: apps/desktop/src/main/mcp-integrations/browser-managed-config.ts

Important Files Changed

Filename Overview
apps/desktop/src/main/mcp-integrations/browser-managed-config.ts 为受管浏览器新增 localhost 主机名例外;已有线程指出的无限制本地服务访问仍未解决。
apps/desktop/src/main/mcp-integrations/tests/browserManagedConfig.test.ts 更新配置生成测试,断言 localhost 与 fake-IP 例外同时存在。
packages/browser-control-runtime/src/tests/runtime-config-application.test.ts 更新 vendored 配置解析测试,确认新增 SSRF 字段不会在解析过程中丢失。

Reviews (2): Last reviewed commit: "chore: complete PR description per forma..." | Re-trigger Greptile

ssrfPolicy: {
allowRfc2544BenchmarkRange: true,
allowIpv6UniqueLocalRange: true,
allowedHostnames: ['localhost'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 security Unrestricted localhost service access

When an agent navigates to http://localhost:<arbitrary-port>/, this hostname-wide exemption skips the normal loopback rejection, causing every HTTP service bound to localhost—not only the intended preview server—to become reachable. How this was verified: The browser navigation path applies allowedHostnames, which bypasses loopback rejection, and the checked guards contain no port or service restriction.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/mcp-integrations/browser-managed-config.ts
Line: 80

Comment:
**Unrestricted localhost service access**

When an agent navigates to `http://localhost:<arbitrary-port>/`, this hostname-wide exemption skips the normal loopback rejection, causing every HTTP service bound to localhost—not only the intended preview server—to become reachable. **How this was verified:** The browser navigation path applies `allowedHostnames`, which bypasses loopback rejection, and the checked guards contain no port or service restriction.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

格式检查未通过

请补充 PR Description 的必要段落:

  • 这次改了什么:说明允许 localhost browser previews 的具体改动和范围
  • 怎么验证的:说明测试覆盖和验证方式
  • 风险:评估放宽 localhost 访问的安全影响

另外 CI 当前失败(Windows unit tests / client-ci / Greptile Review),请一并修复。

修完描述和 CI 后 push 即可触发重新审查。

@MagicLizi MagicLizi added the status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) label Aug 11, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

@yuaiccc 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/main/mcp-integrations/browser-managed-config.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

…t flake

Signed-off-by: yuaiccc <yuaiccc@aliyun.com>
@MagicLizi MagicLizi added status:ci-failed CI 失败(review-pr 自动维护,仅展示) status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) status:ci-failed CI 失败(review-pr 自动维护,仅展示) labels Aug 12, 2026
@MagicLizi MagicLizi added status:ci-failed CI 失败(review-pr 自动维护,仅展示) status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) status:ci-failed CI 失败(review-pr 自动维护,仅展示) labels Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:awaiting-author 等作者修改(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants