Skip to content

Commit 6a46da4

Browse files
committed
fix(ngSanitize): Do not ignore white-listed svg camelCased attributes
Closes angular#10779
1 parent 966f6d8 commit 6a46da4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ngSanitize/sanitize.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ var htmlAttrs = makeMap('abbr,align,alt,axis,bgcolor,border,cellpadding,cellspac
221221

222222
// SVG attributes (without "id" and "name" attributes)
223223
// https://wiki.whatwg.org/wiki/Sanitization_rules#svg_Attributes
224-
var svgAttrs = makeMap('accent-height,accumulate,additive,alphabetic,arabic-form,ascent,' +
224+
var svgAttrs = makeLowercaseMap('accent-height,accumulate,additive,alphabetic,arabic-form,ascent,' +
225225
'attributeName,attributeType,baseProfile,bbox,begin,by,calcMode,cap-height,class,color,' +
226226
'color-rendering,content,cx,cy,d,dx,dy,descent,display,dur,end,fill,fill-rule,font-family,' +
227227
'font-size,font-stretch,font-style,font-variant,font-weight,from,fx,fy,g1,g2,glyph-name,' +
@@ -249,6 +249,12 @@ function makeMap(str) {
249249
return obj;
250250
}
251251

252+
function makeLowercaseMap(str) {
253+
var obj = {}, items = str.split(','), i;
254+
for (i = 0; i < items.length; i++) obj[angular.lowercase(items[i])] = true;
255+
return obj;
256+
}
257+
252258

253259
/**
254260
* @example

test/ngSanitize/sanitizeSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ describe('HTML', function() {
251251
.toEqual('<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"/></svg>');
252252
});
253253

254+
it('should not ignore white-listed svg camelCased attributes', function() {
255+
expectHTML('<svg preserveAspectRatio="true"></svg>')
256+
.toEqual('<svg preserveAspectRatio="true"></svg>');
257+
258+
});
259+
254260
it('should sanitize SVG xlink:href attribute values', function() {
255261
expectHTML('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>')
256262
.toEqual('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>');

0 commit comments

Comments
 (0)