Repository navigation
Commit 7c634ec
fix(core): block dangerous data: and vbscript: URLs in URL sanitizer
The URL sanitizer previously only blocked `javascript:` URLs via a
negative lookahead. This left other potentially dangerous URL schemes
unblocked, including `data:text/html` (which can execute scripts in
some environments), `vbscript:` (script execution in legacy IE), and
bare `data:` URIs with no explicit media type.
This change extends the URL sanitizer to also block:
- `vbscript:` URLs
- `data:` URLs except for safe media subtypes (image/*, video/*, audio/*)
Safe media data: URIs (e.g. `data:image/png;base64,...`) continue to be
allowed as they are commonly used for inline images and do not execute
scripts when loaded via `<img src>`.
This resolves a longstanding TODO in html_sanitizer.ts to special-case
`data:image/` URIs, which has been open since the sanitizer was first
written.
Applications that rely on non-media `data:` URLs (e.g. `data:text/plain`
or `data:application/pdf`) in sanitized contexts should use
`bypassSecurityTrustUrl()` to explicitly mark them as trusted.
(cherry picked from commit e96936a)1 parent 39ef1dc commit 7c634ec
3 files changed
Lines changed: 44 additions & 6 deletions
File tree
- packages/core
- src/sanitization
- test/sanitization
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | | - | |
| 47 | + | |
| 48 | + | |
39 | 49 | | |
40 | 50 | | |
41 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
72 | 98 | | |
73 | 99 | | |
74 | 100 | | |
0 commit comments