Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit96e66bc

Browse files
committed
Sanitizer strip links in SVG elements
--HG--extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401138
1 parent77ee77d commit96e66bc

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎src/html5lib/sanitizer.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ class HTMLSanitizerMixin(object):
8282

8383
attr_val_is_uri= ['href','src','cite','action','longdesc',
8484
'xlink:href','xml:base']
85+
86+
svg_attr_val_allows_ref= ['clip-path','color-profile','cursor','fill',
87+
'filter','marker','marker-start','marker-mid','marker-end','mask','stroke']
88+
89+
svg_allow_local_href= ['altGlyph','animate','animateColor','animateMotion',
90+
'animateTransform','cursor','feImage','filter','linearGradient','pattern',
91+
'radialGradient','textpath','tref','set','use']
8592

8693
acceptable_css_properties= ['azimuth','background-color',
8794
'border-bottom-color','border-collapse','border-color',
@@ -136,10 +143,18 @@ def sanitize_token(self, token):
136143
iftoken.has_key("data"):
137144
attrs=dict([(name,val)forname,valintoken["data"][::-1]ifnameinself.allowed_attributes])
138145
forattrinself.attr_val_is_uri:
139-
ifnotattrs.has_key(attr):continue
146+
ifnotattrs.has_key(attr):
147+
continue
140148
val_unescaped=re.sub("[`\000-\040\177-\240\s]+",'',unescape(attrs[attr])).lower()
141149
ifre.match("^[a-z0-9][-+.a-z0-9]*:",val_unescaped)and (val_unescaped.split(':')[0]notinself.allowed_protocols):
142150
delattrs[attr]
151+
forattrinself.svg_attr_val_allows_ref:
152+
ifattrinattrs:
153+
attrs[attr]=re.sub(r'url\s*\(\s*[^#\s][^)]+?\)',' ',
154+
unescape(attrs[attr]))
155+
if (token["name"]inself.svg_allow_local_hrefand
156+
'xlink:href'inattrsandre.find('^\s*[^#\s].*',attrs['xlink:href'])):
157+
delattrs['xlink:href']
143158
ifattrs.has_key('style'):
144159
attrs['style']=self.sanitize_css(attrs['style'])
145160
token["data"]= [[name,val]forname,valinattrs.items()]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp