Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 801fb7a

Browse files
committed
WIP: ie custom namespaces
1 parent cef78c2 commit 801fb7a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/ngSanitize/sanitize.js

+37
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ function htmlParser(html, handler) {
336336
throw $sanitizeMinErr('uinput', "Failed to sanitize html because the input is unstable");
337337
}
338338
mXSSAttempts--;
339+
340+
// strip custom-namespaced attributes on IE<=11
341+
if (document.documentMode <= 11) {
342+
stripCustomNsAttrs(inertBodyElement);
343+
}
339344
html = inertBodyElement.innerHTML; //trigger mXSS
340345
inertBodyElement.innerHTML = html;
341346
} while (html !== inertBodyElement.innerHTML);
@@ -467,5 +472,37 @@ function htmlSanitizeWriter(buf, uriValidator) {
467472
}
468473

469474

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+
470507
// define ngSanitize module and register $sanitize service
471508
angular.module('ngSanitize', []).provider('$sanitize', $SanitizeProvider);

0 commit comments

Comments
 (0)