web: sanitizer strips MathML <annotation>/<semantics> from rendered KaTeX — LaTeX source missing from DOM (copy-to-LaTeX tools broken)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 77/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Đọc packages/session-ui/src/components/markdown-cache.tsx và kiểm tra danh sách ADD_TAGS trong cấu hình của bộ lọc làm sạch. Xác nhận đầu ra MathML được làm sạch tại đó, sau đó kiểm tra annotation và mã nguồn TeX của nó vẫn còn trong DOM sau khi thay đổi; hoàn thành khi các công cụ sao chép dựa trên annotation có thể đọc mã nguồn trong khi công thức toán đã kết xuất vẫn hiển thị chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
In the web UI, rendered math looks correct, but the LaTeX source is absent from the DOM. KaTeX produces its default output (htmlAndMathml, i.e. HTML + MathML with <semantics><annotation encoding="application/x-tex">), but the HTML is passed through sanitizeMarkdown() before insertion, and the sanitizer's mathMl profile strips <semantics> / <annotation>. Consequences:
- Browser extensions / userscripts that copy the original TeX (the KaTeX
contrib/copy-texecosystem: "Copy LaTeX", "Formula Copy", etc.) cannot work on the web UI, while they work on katex.org / other chat UIs. - MathML semantics are lost for assistive technology and other DOM consumers.
Tested on OpenCode v2.0.25 (web UI, Chrome; served bundle _assets/markdown.worker-*.js contains marked + KaTeX 0.16.47). The same config is still present in dev.
Steps to reproduce
-
Open the web UI, ask the model for a display formula, e.g.:
$$ \begin{aligned} (a+b)^3 &= (a+b)(a+b)^2 \\ &= a^3 + 3a^2 b + 3ab^2 + b^3 . \end{aligned} $$ -
With the formulas rendered, run in DevTools console:
document.querySelectorAll(".katex").length // > 0 — math is rendered document.querySelectorAll('annotation[encoding="application/x-tex"]').length // 0 — but the LaTeX source is not in the DOM -
Or install any annotation-based copy extension (e.g. "Copy LaTeX (KaTeX & MathJax)"): it does nothing on OpenCode, while working on katex.org.
Expected
The DOM should retain KaTeX's MathML output, including <annotation encoding="application/x-tex"> with the original TeX (KaTeX's default behavior; what other AI chat UIs expose).
Actual
<semantics> and <annotation> are removed by sanitization. Visual rendering is unaffected (the HTML part is kept), so the loss is invisible until you try to copy a formula's source.
Root cause
-
packages/session-ui/src/components/markdown-cache.tsx:const config = { USE_PROFILES: { html: true, mathMl: true }, SANITIZE_NAMED_PROPS: true, FORBID_TAGS: ["style"], FORBID_CONTENTS: ["style", "script"], ADD_TAGS: ["svg", "path"], ADD_ATTR: ["d", "viewBox", "preserveAspectRatio", "xmlns", "target"], } -
DOMPurify's built-in
mathMlprofile allowlist does not includesemantics/annotation/annotation-xml, so the MathML annotation (and itsencodingattribute) is dropped.
Suggested fix
Extend the allowlist (verified locally with the exact config above on doMPurify 3.4.16 — the annotation then survives sanitization and is queryable in the DOM):
- ADD_TAGS: ["svg", "path"],
+ ADD_TAGS: ["svg", "path", "semantics", "annotation", "annotation-xml"],
No ADD_ATTR change is needed (encoding is already in DOMPurify's MathML attribute allowlist). The elements are plain text containers; allowing them carries no scripting risk.
Local verification (before/after)
- Worker output: contains
application/x-tex✓ - After
sanitizeMarkdownconfig:annotationcount = 0 - After adding the three tags:
annotationcount = 1,<annotation encoding="application/x-tex">…</annotation>intact
- Ngôn ngữ chính
- TypeScript
- Star
- 213k
- Fork
- 28.4k
- Merge trung bình
- 8 giờ 51 phút
- Pull request đã merge (30 ngày)
- 289
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của anomalyco/opencode
-
reproduced
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anomalyco/opencode#55369 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
reproduced
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
anomalyco/opencode#55351 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
anomalyco/opencode#55285 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
opencode on clean macos zsh .export path not working because it append and it fails because no ~/.zshrc fileCó thể đã có người làm @fihaaade đã nhận 1 ngày trước. Đang mởreproduced
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anomalyco/opencode#55068 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: allowing an MCP tool by its documented name hides it; the bare name must be allowed tooĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
anomalyco/opencode#54919 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của anomalyco/opencode
Issue tương tự
-
Create/import wallet form shows raw "password must be at least 1 characters" instead of the translated messageCó thể đã có người làm @CapThunder19 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
joinmarket-webui/jam#1538 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t0ggles
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
nolimits4web/swiper#8240 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/inspector#2723 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status:approved type:bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
egdev6/quorb#109 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày