@@ -336,6 +336,11 @@ function htmlParser(html, handler) {
336
336
throw $sanitizeMinErr ( 'uinput' , "Failed to sanitize html because the input is unstable" ) ;
337
337
}
338
338
mXSSAttempts -- ;
339
+
340
+ // strip custom-namespaced attributes on IE<=11
341
+ if ( document . documentMode <= 11 ) {
342
+ stripCustomNsAttrs ( inertBodyElement ) ;
343
+ }
339
344
html = inertBodyElement . innerHTML ; //trigger mXSS
340
345
inertBodyElement . innerHTML = html ;
341
346
} while ( html !== inertBodyElement . innerHTML ) ;
@@ -467,5 +472,37 @@ function htmlSanitizeWriter(buf, uriValidator) {
467
472
}
468
473
469
474
475
+ /**
476
+ * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1' attribute to declare
477
+ * ns1 namespace and prefixes the attribute with 'ns1' (e.g. 'ns1:xlink:foo'). This is undesirable since we don't want
478
+ * to allow any of these custom attributes. This method strips them all.
479
+ *
480
+ * @param element Root element to process
481
+ */
482
+ function stripCustomNsAttrs ( node ) {
483
+ if ( node . nodeType === Node . ELEMENT_NODE ) {
484
+ var attrs = node . attributes ;
485
+ for ( var i = 0 , l = attrs . length ; i < l ; i ++ ) {
486
+ var attrNode = attrs [ i ] ;
487
+ var attrName = angular . toLowerCase ( attrNode . name ) ;
488
+ if ( attrName === 'xmlns:ns1' || attrName . indexOf ( 'ns1:' ) === 0 ) {
489
+ element . removeAttributeNode ( attrNode ) ;
490
+ }
491
+ }
492
+ }
493
+
494
+ var nextNode = node . firstChild ;
495
+ if ( nextNode ) {
496
+ stripCustomNsAttrs ( nextNode ) ;
497
+ }
498
+
499
+ nextNode = node . nextSibling ;
500
+ if ( nextNode ) {
501
+ stripCustomNsAttrs ( nextNode ) ;
502
+ }
503
+ }
504
+
505
+
506
+
470
507
// define ngSanitize module and register $sanitize service
471
508
angular . module ( 'ngSanitize' , [ ] ) . provider ( '$sanitize' , $SanitizeProvider ) ;
0 commit comments