Repository navigation
Commit a354293
authored
fix(removeScripts): filter executable data URLs (#2263)
## Summary
- centralize executable URL detection in `isExecutableUrl`
- reject `javascript:` and legacy `vbscript:` URLs
- collapse links to active `data:` documents (`text/html`,
`application/xhtml+xml`, and `image/svg+xml`)
- preserve inert `data:` media types such as `image/png`
- add coverage for default and namespaced `href` attributes, MIME
parameters, case normalization, inert data URLs, and VBScript URLs
## Why this is necessary
`removeScripts` currently recognizes `javascript:` links, but other URL
schemes can also represent executable content:
- A `data:` URL can carry an HTML, XHTML, or SVG document containing
script. Whether that content runs depends on how the URL is loaded and
browser navigation policy, but these are active document formats and
should not pass a plugin whose purpose is to remove scripts.
- `vbscript:` was only implemented by legacy Internet Explorer and is
not supported by modern browsers. We still reject it because the
compatibility cost is negligible, it provides defense in depth for old
environments, and it makes the security-oriented scheme denylist
explicit and complete. Also it silences these security advisories and
reporters.
Rejecting every `data:` URL would be unnecessarily destructive because
many SVGs legitimately link to inert embedded resources such as PNG
images. This change therefore filters only media types that browsers
parse as script-capable documents. Comments next to the implementation
explain both the legacy VBScript decision and the selective parsing of
data URLs.
This addresses the underlying concern reported by code-scanning alerts
[#18](https://github.com/svg/svgo/security/code-scanning/18) and
[#19](https://github.com/svg/svgo/security/code-scanning/19).
## Validation
- `pnpm test` — 1,554 passed, 9 skipped
- `pnpm typecheck`
- ESLint and Prettier checks for all changed source and documentation
files1 parent 4e0d2ac commit a354293
4 files changed
Lines changed: 84 additions & 8 deletions
File tree
- docs/04-plugins
- lib/svgo
- plugins
- test/plugins
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
156 | 200 | | |
157 | 201 | | |
158 | 202 | | |
| |||
166 | 210 | | |
167 | 211 | | |
168 | 212 | | |
169 | | - | |
| 213 | + | |
170 | 214 | | |
171 | 215 | | |
172 | 216 | | |
173 | | - | |
| 217 | + | |
174 | 218 | | |
175 | 219 | | |
176 | | - | |
| 220 | + | |
177 | 221 | | |
178 | 222 | | |
179 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
0 commit comments