@@ -40,16 +40,16 @@ var $sanitizeMinErr = angular.$$minErr('$sanitize');
40
40
* @kind function
41
41
*
42
42
* @description
43
- * The input is sanitized by parsing the html into tokens. All safe tokens (from a whitelist) are
43
+ * The input is sanitized by parsing the HTML into tokens. All safe tokens (from a whitelist) are
44
44
* then serialized back to properly escaped html string. This means that no unsafe input can make
45
45
* it into the returned string, however, since our parser is more strict than a typical browser
46
46
* parser, it's possible that some obscure input, which would be recognized as valid HTML by a
47
- * browser, won't make it through the sanitizer.
47
+ * browser, won't make it through the sanitizer. The input may also contain SVG markup.
48
48
* The whitelist is configured using the functions `aHrefSanitizationWhitelist` and
49
49
* `imgSrcSanitizationWhitelist` of {@link ng.$compileProvider `$compileProvider`}.
50
50
*
51
- * @param {string } html Html input.
52
- * @returns {string } Sanitized html .
51
+ * @param {string } html HTML input.
52
+ * @returns {string } Sanitized HTML .
53
53
*
54
54
* @example
55
55
<example module="sanitizeExample" deps="angular-sanitize.js">
@@ -193,6 +193,12 @@ var inlineElements = angular.extend({}, optionalEndTagInlineElements, makeMap("a
193
193
"bdi,bdo,big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s," +
194
194
"samp,small,span,strike,strong,sub,sup,time,tt,u,var" ) ) ;
195
195
196
+ // SVG Elements
197
+ // https://wiki.whatwg.org/wiki/Sanitization_rules#svg_Elements
198
+ var svgElements = makeMap ( "animate,animateColor,animateMotion,animateTransform,circle,defs," +
199
+ "desc,ellipse,font-face,font-face-name,font-face-src,g,glyph,hkern,image,linearGradient," +
200
+ "line,marker,metadata,missing-glyph,mpath,path,polygon,polyline,radialGradient,rect,set," +
201
+ "stop,svg,switch,text,title,tspan,use" ) ;
196
202
197
203
// Special Elements (can contain anything)
198
204
var specialElements = makeMap ( "script,style" ) ;
@@ -201,16 +207,41 @@ var validElements = angular.extend({},
201
207
voidElements ,
202
208
blockElements ,
203
209
inlineElements ,
204
- optionalEndTagElements ) ;
210
+ optionalEndTagElements ,
211
+ svgElements ) ;
205
212
206
213
//Attributes that have href and hence need to be sanitized
207
- var uriAttrs = makeMap ( "background,cite,href,longdesc,src,usemap" ) ;
208
- var validAttrs = angular . extend ( { } , uriAttrs , makeMap (
209
- 'abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' +
214
+ var uriAttrs = makeMap ( "background,cite,href,longdesc,src,usemap,xmlns:href " ) ;
215
+
216
+ var htmlAttrs = makeMap ( 'abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' +
210
217
'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,' +
211
218
'ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,' +
212
219
'scope,scrolling,shape,size,span,start,summary,target,title,type,' +
213
- 'valign,value,vspace,width' ) ) ;
220
+ 'valign,value,vspace,width' ) ;
221
+
222
+ // SVG attributes (without "id" and "name" attributes)
223
+ // https://wiki.whatwg.org/wiki/Sanitization_rules#svg_Attributes
224
+ var svgAttrs = makeMap ( 'accent-height,accumulate,additive,alphabetic,arabic-form,ascent,' +
225
+ 'attributeName,attributeType,baseProfile,bbox,begin,by,calcMode,cap-height,class,color,' +
226
+ 'color-rendering,content,cx,cy,d,dx,dy,descent,display,dur,end,fill,fill-rule,font-family,' +
227
+ 'font-size,font-stretch,font-style,font-variant,font-weight,from,fx,fy,g1,g2,glyph-name,' +
228
+ 'gradientUnits,hanging,height,horiz-adv-x,horiz-origin-x,ideographic,k,keyPoints,' +
229
+ 'keySplines,keyTimes,lang,marker-end,marker-mid,marker-start,markerHeight,markerUnits,' +
230
+ 'markerWidth,mathematical,max,min,offset,opacity,orient,origin,overline-position,' +
231
+ 'overline-thickness,panose-1,path,pathLength,points,preserveAspectRatio,r,refX,refY,' +
232
+ 'repeatCount,repeatDur,requiredExtensions,requiredFeatures,restart,rotate,rx,ry,slope,stemh,' +
233
+ 'stemv,stop-color,stop-opacity,strikethrough-position,strikethrough-thickness,stroke,' +
234
+ 'stroke-dasharray,stroke-dashoffset,stroke-linecap,stroke-linejoin,stroke-miterlimit,' +
235
+ 'stroke-opacity,stroke-width,systemLanguage,target,text-anchor,to,transform,type,u1,u2,' +
236
+ 'underline-position,underline-thickness,unicode,unicode-range,units-per-em,values,version,' +
237
+ 'viewBox,visibility,width,widths,x,x-height,x1,x2,xlink:actuate,xlink:arcrole,xlink:role,' +
238
+ 'xlink:show,xlink:title,xlink:type,xml:base,xml:lang,xml:space,xmlns,xmlns:xlink,y,y1,y2,' +
239
+ 'zoomAndPan' ) ;
240
+
241
+ var validAttrs = angular . extend ( { } ,
242
+ uriAttrs ,
243
+ svgAttrs ,
244
+ htmlAttrs ) ;
214
245
215
246
function makeMap ( str ) {
216
247
var obj = { } , items = str . split ( ',' ) , i ;
0 commit comments