Fix for sanitize(''') returning ''' instead of '''
This commit is contained in:
+3
-5
@@ -10,8 +10,7 @@ Cross-site scripting (XSS) defense
|
|||||||
-----------------------------------
|
-----------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from HTMLParser import HTMLParser
|
||||||
from htmllib import HTMLParser
|
|
||||||
from cgi import escape
|
from cgi import escape
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from formatter import AbstractFormatter
|
from formatter import AbstractFormatter
|
||||||
@@ -48,11 +47,10 @@ class XssCleaner(HTMLParser):
|
|||||||
],
|
],
|
||||||
allowed_attributes={'a': ['href', 'title'], 'img': ['src', 'alt'
|
allowed_attributes={'a': ['href', 'title'], 'img': ['src', 'alt'
|
||||||
], 'blockquote': ['type']},
|
], 'blockquote': ['type']},
|
||||||
fmt=AbstractFormatter,
|
|
||||||
strip_disallowed=False
|
strip_disallowed=False
|
||||||
):
|
):
|
||||||
|
|
||||||
HTMLParser.__init__(self, fmt)
|
HTMLParser.__init__(self)
|
||||||
self.result = ''
|
self.result = ''
|
||||||
self.open_tags = []
|
self.open_tags = []
|
||||||
self.permitted_tags = [i for i in permitted_tags if i[-1] != '/']
|
self.permitted_tags = [i for i in permitted_tags if i[-1] != '/']
|
||||||
@@ -77,7 +75,7 @@ class XssCleaner(HTMLParser):
|
|||||||
def handle_charref(self, ref):
|
def handle_charref(self, ref):
|
||||||
if self.in_disallowed:
|
if self.in_disallowed:
|
||||||
return
|
return
|
||||||
elif len(ref) < 7 and ref.isdigit():
|
elif len(ref) < 7 and (ref.isdigit() or ref == 'x27'): # x27 is a special case for apostrophe
|
||||||
self.result += '&#%s;' % ref
|
self.result += '&#%s;' % ref
|
||||||
else:
|
else:
|
||||||
self.result += xssescape('&#%s' % ref)
|
self.result += xssescape('&#%s' % ref)
|
||||||
|
|||||||
Reference in New Issue
Block a user