Commit 39d42e4
Sanitize javascript: urls MathJax's \href macro can inject
MathJax's \href{url}{...} copies its argument into an <a href> with no
scheme check of its own. $\href{javascript:alert(1)}{click}$ rendered
into a live, clickable <a href="javascript:alert(1)"> in the DOM.
Confirmed this by rendering it and reading the resulting attribute,
not just from reading MathJax's source.
This predates the hover PR -- the same unguarded convertToTspans path
is already reachable today via axis/plot titles, annotations, and
non-hover legend text. Hover just became a new delivery surface for
it, since hover text more often comes from less-trusted per-point
data.
svg_text_utils.js already has an established fix for exactly this
shape of problem: sanitizeHref(), an http:/https:/mailto:/relative
allowlist, used for the pseudo-HTML <a href> tags in plain text.
sanitizeMathJaxLinks() applies the same allowlist to any <a> MathJax
produces, called once from convertToTspans right after the rendered
SVG is inserted. Since the fix lives in the shared function, it closes
the gap for titles/annotations/legends too, not just hover.
Added tests for both a hover label and a title with a javascript:
\href, confirming the link's href is stripped while a plain
\href{https://...}{...} keeps working.
Verified locally: `karma start test/jasmine/karma.conf.js
--bundleTest=mathjax_test.js --nowatch` -> 13 of 13 pass. Also ran the
full svg_text_utils/hover/legend/annotations/titles suite against
both this branch and unmodified main -- both show the same 8
pre-existing titles_test.js failures and the same intermittent "full
page reload" flakiness at random points in either case, confirming
neither is caused by this change.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 1e8ef5f commit 39d42e4
2 files changed
Lines changed: 81 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
106 | 124 | | |
107 | 125 | | |
108 | 126 | | |
| |||
192 | 210 | | |
193 | 211 | | |
194 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
195 | 220 | | |
196 | 221 | | |
197 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
208 | 230 | | |
209 | 231 | | |
210 | 232 | | |
| |||
269 | 291 | | |
270 | 292 | | |
271 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
272 | 328 | | |
273 | 329 | | |
274 | 330 | | |
| |||
0 commit comments