XSS attribute filtering is inconsistent and strips valid attributes
6 unresolved threads
Closes #2544110
Merge request reports
Activity
added 33 commits
-
acfc0cfe...c271adbb - 32 commits from branch
project:11.x
- 4d7442b3 - rebase
-
acfc0cfe...c271adbb - 32 commits from branch
added 231 commits
-
4d7442b3...a201c700 - 230 commits from branch
project:11.x
- 2c65cbf7 - Merge remote-tracking branch 'origin/11.x' into HEAD
-
4d7442b3...a201c700 - 230 commits from branch
added 35 commits
-
2c65cbf7...4c6cd6e3 - 34 commits from branch
project:11.x
- 3cf003db - rebase
-
2c65cbf7...4c6cd6e3 - 34 commits from branch
added 1307 commits
-
3cf003db...9e91e06c - 1305 commits from branch
project:11.x
- 754b1b9e - rebase
- 335f0623 - add to cspell:ignore and sorting
-
3cf003db...9e91e06c - 1305 commits from branch
41 'class', 42 'datetime', 43 'mailto', 44 'media', 45 'name', 46 'property', 47 'rel', 48 'rev', 49 'sizes', 50 'title', 51 'typeof', 52 'value', 53 ]; 54 55 /** 56 * The default list of Unsafe attributes that must be sanitized by filter(). 229 270 // starting with "javascript:"). However, for some non-URI 230 271 // attributes performing this filtering causes valid and safe data 231 272 // to be mangled. We prevent this by skipping protocol filtering on 232 // such attributes. 273 // such attributes. Adding check to skip angular attributes (ng). 230 271 // attributes performing this filtering causes valid and safe data 231 272 // to be mangled. We prevent this by skipping protocol filtering on 232 // such attributes. 273 // such attributes. Adding check to skip angular attributes (ng). 233 274 // @see \Drupal\Component\Utility\UrlHelper::filterBadProtocol() 234 275 // @see http://www.w3.org/TR/html4/index/attributes.html 235 $skip_protocol_filtering = str_starts_with($attribute_name, 'data-') || in_array($attribute_name, [ 236 'title', 237 'alt', 238 'rel', 239 'property', 240 'class', 241 'datetime', 242 ]); 276 $skip_protocol_filtering = str_starts_with($attribute_name, 'data-') || 277 str_starts_with($attribute_name, 'ng-') || 341 395 return !isset($html_tags[strtolower($elem)]); 342 396 } 343 397 398 /** 399 * Strips bad protocols from attribute values. 400 * 401 * @param string $name 402 * The attribute name. 403 * @param string $value 404 * The attribute value. 405 * 406 * @return string 407 * The attribute value, stripped of any bad protocols. 508 511 'Link tag with rel attribute', 509 512 ['a'], 510 513 ], 514 [ 515 '<a href="mailto:me@example.com">Drupal</a>', 516 '<a href="mailto:me@example.com">Drupal</a>', 517 'Link tag with rev attribute', 518 ['a'], 519 ], - Comment on lines +514 to +519
I also think that while we are here, and this is adding over 50% more test cases that the dataprovider is re-worked a bit. I think the message should become and array key and then the message does not need to be passed to the test method. Like this,
'Link tag with rev attribute' => [ '<a href="mailto:me@example.com">Drupal</a>', '<a href="mailto:me@example.com">Drupal</a>', ['a'], ],
Please register or sign in to reply