Skip to content

fix(ui): reject protocol-relative URLs in safeUrl - #84

Merged
helsome merged 1 commit into
helsome:mainfrom
wcy12378:fix/harden-safeurl-protocol-relative
Sep 12, 2026
Merged

fix(ui): reject protocol-relative URLs in safeUrl#84
helsome merged 1 commit into
helsome:mainfrom
wcy12378:fix/harden-safeurl-protocol-relative

Conversation

@wcy12378

Copy link
Copy Markdown
Contributor

Summary

Closes a link-injection gap in MarkdownContent's safeUrl() (introduced by #44 / issue #28).

A protocol-relative URL like //evil.com/steal starts with /, so the existing early-return branch treated it as a safe relative link and skipped the scheme allowlist. The browser then resolves it to https://evil.com/steal — an attacker-controlled host. That is exactly the link-injection vector tracked in #16 (prompt injection → malicious link).

This PR hard-blocks // protocol-relative URLs at the top of safeUrl() so every external link is forced through the allowlist, without touching the streaming renderer or the rest of #44.

Changes

  • packages/ui/src/components/chat/MarkdownContent.tsx: reject //-prefixed URLs before the relative-path check.
  • packages/ui/src/components/chat/MarkdownContent.test.tsx: add regression tests — //evil.com and //github.com/x are NOT rendered as clickable hrefs (label still shown), while https://… and real relative paths keep working.

Why a separate small PR (not reopening #57)

#57 was closed as superseded because #44 already landed the streaming-hardening for #28. This fix is a narrow, independent security hardening on top of #44's safeUrl() — no reimplementation, no dual-maintenance. Per the maintainer's note on #57, independent security gaps should be split into small PRs.

Test

bun test packages/ui/src/components/chat/MarkdownContent.test.tsx

Refs

#28 (security acceptance), #16

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

这条安全修复 scope 很小,方向也合理,不要求扩大实现。正式通过前请补齐当前统一测试报告最低字段:

  1. Bun 版本 + OS/平台;
  2. 实际执行 bun test packages/ui/src/components/chat/MarkdownContent.test.tsx 的 pass/fail 数量;
  3. rebase 最新 main 后跑基础 CI。

这是 UI 交互安全变化但没有可见样式变化,可以明确写“无可见 UI 变化”,无需为了这条专门做截图。

@wcy12378
wcy12378 force-pushed the fix/harden-safeurl-protocol-relative branch from fd58eea to dfa2bdd Compare September 12, 2026 01:49
@wcy12378

Copy link
Copy Markdown
Contributor Author

PR #84 测试报告(已 rebase 最新 main)

环境

  • Bun version: 1.4.2
  • OS/Platform: Windows 11 (Win32) — MINGW64_NT-10.0-26200 / Microsoft Windows [版本 10.0.26200.9445]
  • Base commit: 3ce3848(最新 helsome:main,已 rebase 到此版本)
  • PR commit: dfa2bdd

变更范围

packages/ui/src/components/chat/MarkdownContent.test.tsx | 19 +++++++++++++++++++
packages/ui/src/components/chat/MarkdownContent.tsx      |  7 +++++++
2 files changed, 26 insertions(+)

基础 CI

检查项 命令 结果
Typecheck (packages/ui) bun run typecheck ✅ 通过($ tsc --noEmit,exit 0)
Focused test bun test --isolate src/components/chat/MarkdownContent.test.tsx ✅ 通过

MarkdownContent.test.tsx 实测结果

bun test v1.4.2 (744846f84)

src\components\chat\MarkdownContent.test.tsx:
(pass) MarkdownContent > renders common research Markdown as semantic elements [49.40ms]
(pass) MarkdownContent > renders GFM tables and removes unsafe links [15.51ms]
(pass) MarkdownContent > blocks protocol-relative URLs that bypass the scheme allowlist [4.30ms]
(pass) MarkdownContent > does not render raw HTML from agent output [2.91ms]
(pass) MarkdownContent > keeps partial blocks stable and matches static rendering when complete [7.76ms]

 5 pass
 0 fail
 18 expect() calls
Ran 5 tests across 1 file. [2.38s]
  • Pass: 5
  • Fail: 0
  • Expect calls: 18

说明

  • 本 PR 为 UI 交互安全修复,无可见 UI 样式变化(符合评论中“无需专门截图”的说明)。
  • 分支已 force-push 到 wcy12378:fix/harden-safeurl-protocol-relative,GitHub 上 PR fix(ui): reject protocol-relative URLs in safeUrl #84 应已自动更新为基于最新 maindfa2bdd

@helsome
helsome dismissed their stale review September 12, 2026 02:40

作者已补齐 Bun/OS、实际 5 pass / 0 fail、最新 main rebase,并明确无可见 UI 变化;原测试报告 blocker 已解决。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

已补齐统一测试报告最低字段并 rebase 最新 main:Bun 1.4.2 / Windows 11,MarkdownContent focused test 5 pass / 0 fail,typecheck 通过。该变更是窄范围 URL 安全修复,无可见 UI 样式变化,不要求额外截图。

@helsome
helsome merged commit 4cdb6bd into helsome:main Sep 12, 2026
lhy-dcf pushed a commit to lhy-dcf/folio that referenced this pull request Sep 12, 2026
Co-authored-by: wcy12378 <kris@folio.local>
lhy-dcf pushed a commit to lhy-dcf/folio that referenced this pull request Sep 12, 2026
Co-authored-by: wcy12378 <kris@folio.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants