web: sanitizer strips MathML <annotation>/<semantics> from rendered KaTeX — LaTeX source missing from DOM (copy-to-LaTeX tools broken)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 77/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- frontend
Línea de trabajo
Lee packages/session-ui/src/components/markdown-cache.tsx e inspecciona la lista ADD_TAGS de la configuración del sanitizador. Confirma que la salida MathML se sanea ahí y luego comprueba que annotation y su fuente TeX permanezcan en el DOM después del cambio; se considera terminado cuando las herramientas de copia basadas en annotation puedan leer la fuente y las fórmulas renderizadas sigan mostrándose correctamente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 213k
- Forks
- 28.4k
- Merge medio
- 8 h 51 min
- PR fusionados (30 d)
- 289
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de anomalyco/opencode
-
reproduced
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
anomalyco/opencode#55369 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
reproduced
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
anomalyco/opencode#55351 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
anomalyco/opencode#55285 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
opencode on clean macos zsh .export path not working because it append and it fails because no ~/.zshrc filePosiblemente ocupada @fihaaade la tomó hace 1 día. Abiertoreproduced
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
anomalyco/opencode#55068 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
mcp: allowing an MCP tool by its documented name hides it; the bare name must be allowed tooAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
anomalyco/opencode#54919 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de anomalyco/opencode
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
vercel/streamdown#673 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
docs(stream-protocol): document messageMetatadata on start/finish and the message-metadata chunkPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertofactory-active task-identify-harness-labels-done task-identify-issue-type-done
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vercel/ai#23375 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
agilepathway/label-checker#721 ·
Los mantenedores suelen responder en 1 día
-
CLI Empathy needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
chromaui/chromatic-cli#1524 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día