Commit cb1683e
authored
🤖 fix: add rehype-sanitize to prevent XSS in markdown rendering (#1050)
## Problem
The error `The tag <noun> is unrecognized in this browser` indicated
that arbitrary HTML tags were being parsed and rendered. This exposed
the app to XSS attacks.
### Root Cause
The markdown rendering pipeline used:
1. `rehype-raw` - Parses raw HTML embedded in markdown
2. `rehype-harden` - Only sanitizes URLs in `<a>` and `<img>` tags
The gap: `rehype-harden` does NOT strip unknown/dangerous HTML elements
(`<script>`, `<style>`, `<form>`, `<noun>`, etc.) or remove event
handlers (`onclick`, `onerror`, etc.).
## Solution
Add `rehype-sanitize` to the plugin chain with a schema that:
- Allows safe HTML elements commonly used in markdown
- Allows KaTeX MathML elements for math rendering
- Allows `<details>`/`<summary>` for collapsible sections
- Blocks dangerous elements and strips event handlers
## Testing
- [x] `make static-check` passes
- [x] `make typecheck` passes
- [x] Mermaid tests pass
---
_Generated with `mux`_1 parent 5cc0ba8 commit cb1683e
File tree
3 files changed
+55
-2
lines changed- src/browser/components/Messages
3 files changed
+55
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
2285 | 2285 | | |
2286 | 2286 | | |
2287 | 2287 | | |
| 2288 | + | |
| 2289 | + | |
2288 | 2290 | | |
2289 | 2291 | | |
2290 | 2292 | | |
| |||
3145 | 3147 | | |
3146 | 3148 | | |
3147 | 3149 | | |
| 3150 | + | |
| 3151 | + | |
3148 | 3152 | | |
3149 | 3153 | | |
3150 | 3154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
33 | 80 | | |
34 | 81 | | |
| 82 | + | |
35 | 83 | | |
36 | | - | |
| 84 | + | |
37 | 85 | | |
38 | 86 | | |
39 | 87 | | |
| |||
0 commit comments