Commit cfcc94d
fix mixed-case DATA: bypass in img transform; broaden MIME test
CodeRabbit pointed out that sanitize-html lowercases the URL scheme
before its allowedSchemes check, so `DATA:`/`dAtA:` URLs reach
transformTags.img — and the previous case-sensitive
`attribs.src.startsWith('data:')` guard would skip MIME validation
entirely on those. A payload like `<img src="DATA:text/html,<script>…">`
would have slipped past the image-MIME allowlist.
Make the data: detection case-insensitive (only the scheme prefix, not
the full URL — the SAFE_DATA_IMAGE_URL regex already uses /i for the
MIME match). Add regression tests covering DATA:, dAtA:, Data: with
non-image payloads (must be stripped) and DATA:image/PNG (must be
preserved).
Also extend the existing image-MIME preservation test to cover bmp and
x-icon, which were already in SAFE_DATA_IMAGE_URL but not exercised.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 53d7d8e commit cfcc94d
2 files changed
Lines changed: 48 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
| |||
204 | 206 | | |
205 | 207 | | |
206 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
207 | 245 | | |
208 | 246 | | |
209 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
136 | 142 | | |
| 143 | + | |
137 | 144 | | |
138 | | - | |
139 | | - | |
140 | | - | |
| 145 | + | |
| 146 | + | |
141 | 147 | | |
142 | 148 | | |
143 | 149 | | |
| |||
0 commit comments