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

Commit 46b8065

Browse files
hugomnpkozlowski-opensource
authored andcommitted
fix(ngSanitize): Do not ignore white-listed svg camelCased attributes
Closes #10779 Closes #10990 Closes #11124
1 parent c67f88b commit 46b8065

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ngSanitize/sanitize.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,18 @@ var svgAttrs = makeMap('accent-height,accumulate,additive,alphabetic,arabic-form
236236
'underline-position,underline-thickness,unicode,unicode-range,units-per-em,values,version,' +
237237
'viewBox,visibility,width,widths,x,x-height,x1,x2,xlink:actuate,xlink:arcrole,xlink:role,' +
238238
'xlink:show,xlink:title,xlink:type,xml:base,xml:lang,xml:space,xmlns,xmlns:xlink,y,y1,y2,' +
239-
'zoomAndPan');
239+
'zoomAndPan', true);
240240

241241
var validAttrs = angular.extend({},
242242
uriAttrs,
243243
svgAttrs,
244244
htmlAttrs);
245245

246-
function makeMap(str) {
246+
function makeMap(str, lowercaseKeys) {
247247
var obj = {}, items = str.split(','), i;
248-
for (i = 0; i < items.length; i++) obj[items[i]] = true;
248+
for (i = 0; i < items.length; i++) {
249+
obj[lowercaseKeys ? angular.lowercase(items[i]) : items[i]] = true;
250+
}
249251
return obj;
250252
}
251253

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)