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

Commit b86876c

Browse files
petebacondarwinNarretz
authored andcommitted
fix($sanitize): sanitize xml:base attributes
On Firefox there is a XSS vulnerability if a malicious attacker can write into the `xml:base` attribute on an SVG anchor. Thanks to Masato Kinugawa at Cure23
1 parent c7bea44 commit b86876c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/ngSanitize/sanitize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function $SanitizeProvider() {
269269
optionalEndTagElements);
270270

271271
//Attributes that have href and hence need to be sanitized
272-
var uriAttrs = toMap('background,cite,href,longdesc,src,xlink:href');
272+
var uriAttrs = toMap('background,cite,href,longdesc,src,xlink:href,xml:base');
273273

274274
var htmlAttrs = toMap('abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' +
275275
'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,' +

test/ngSanitize/sanitizeSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ describe('HTML', function() {
327327
'<svg xmlns="http://www.w3.org/2000/svg"><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://example.com"></a></svg>');
328328
});
329329

330+
it('should sanitize SVG xml:base attribute values', function() {
331+
expectHTML('<svg xmlns="http://www.w3.org/2000/svg"><a xml:base="javascript:alert(1)//" href="#"></a></svg>')
332+
.toEqual('<svg xmlns="http://www.w3.org/2000/svg"><a href="#"></a></svg>');
333+
334+
expectHTML('<svg xmlns="http://www.w3.org/2000/svg"><a xml:base="https://example.com" href="#"></a></svg>')
335+
.toEqual('<svg xmlns="http://www.w3.org/2000/svg"><a xml:base="https://example.com" href="#"></a></svg>');
336+
337+
});
338+
330339
it('should sanitize unknown namespaced SVG attributes', function() {
331340
expectHTML('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>')
332341
.toBeOneOf('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>',

0 commit comments

Comments
 (0)