@@ -73,8 +73,7 @@ def build_inlinepatterns(md_instance, **kwargs):
73
73
inlinePatterns ["autolink" ] = AutolinkPattern (AUTOLINK_RE , md_instance )
74
74
inlinePatterns ["automail" ] = AutomailPattern (AUTOMAIL_RE , md_instance )
75
75
inlinePatterns ["linebreak" ] = SubstituteTagPattern (LINE_BREAK_RE , 'br' )
76
- if md_instance .safeMode != 'escape' :
77
- inlinePatterns ["html" ] = HtmlPattern (HTML_RE , md_instance )
76
+ inlinePatterns ["html" ] = HtmlPattern (HTML_RE , md_instance )
78
77
inlinePatterns ["entity" ] = HtmlPattern (ENTITY_RE , md_instance )
79
78
inlinePatterns ["not_strong" ] = SimpleTextPattern (NOT_STRONG_RE )
80
79
inlinePatterns ["em_strong" ] = DoubleTagPattern (EM_STRONG_RE , 'strong,em' )
@@ -201,8 +200,6 @@ def __init__(self, pattern, markdown_instance=None):
201
200
self .compiled_re = re .compile ("^(.*?)%s(.*?)$" % pattern ,
202
201
re .DOTALL | re .UNICODE )
203
202
204
- # Api for Markdown to pass safe_mode into instance
205
- self .safe_mode = False
206
203
if markdown_instance :
207
204
self .markdown = markdown_instance
208
205
@@ -362,7 +359,7 @@ def handleMatch(self, m):
362
359
if href :
363
360
if href [0 ] == "<" :
364
361
href = href [1 :- 1 ]
365
- el .set ("href" , self .sanitize_url ( self . unescape (href .strip () )))
362
+ el .set ("href" , self .unescape (href .strip ()))
366
363
else :
367
364
el .set ("href" , "" )
368
365
@@ -371,52 +368,6 @@ def handleMatch(self, m):
371
368
el .set ("title" , title )
372
369
return el
373
370
374
- def sanitize_url (self , url ):
375
- """
376
- Sanitize a url against xss attacks in "safe_mode".
377
-
378
- Rather than specifically blacklisting `javascript:alert("XSS")` and all
379
- its aliases (see <http://ha.ckers.org/xss.html>), we whitelist known
380
- safe url formats. Most urls contain a network location, however some
381
- are known not to (i.e.: mailto links). Script urls do not contain a
382
- location. Additionally, for `javascript:...`, the scheme would be
383
- "javascript" but some aliases will appear to `urlparse()` to have no
384
- scheme. On top of that relative links (i.e.: "foo/bar.html") have no
385
- scheme. Therefore we must check "path", "parameters", "query" and
386
- "fragment" for any literal colons. We don't check "scheme" for colons
387
- because it *should* never have any and "netloc" must allow the form:
388
- `username:password@host:port`.
389
-
390
- """
391
- if not self .markdown .safeMode :
392
- # Return immediately bipassing parsing.
393
- return url
394
-
395
- try :
396
- scheme , netloc , path , params , query , fragment = url = urlparse (url )
397
- except ValueError : # pragma: no cover
398
- # Bad url - so bad it couldn't be parsed.
399
- return ''
400
-
401
- locless_schemes = ['' , 'mailto' , 'news' ]
402
- allowed_schemes = locless_schemes + ['http' , 'https' , 'ftp' , 'ftps' ]
403
- if scheme not in allowed_schemes :
404
- # Not a known (allowed) scheme. Not safe.
405
- return ''
406
-
407
- if netloc == '' and scheme not in locless_schemes : # pragma: no cover
408
- # This should not happen. Treat as suspect.
409
- return ''
410
-
411
- for part in url [2 :]:
412
- if ":" in part :
413
- # A colon in "path", "parameters", "query"
414
- # or "fragment" is suspect.
415
- return ''
416
-
417
- # Url passes all tests. Return url as-is.
418
- return urlunparse (url )
419
-
420
371
421
372
class ImagePattern (LinkPattern ):
422
373
""" Return a img element from the given match. """
@@ -427,7 +378,7 @@ def handleMatch(self, m):
427
378
src = src_parts [0 ]
428
379
if src [0 ] == "<" and src [- 1 ] == ">" :
429
380
src = src [1 :- 1 ]
430
- el .set ('src' , self .sanitize_url ( self . unescape (src ) ))
381
+ el .set ('src' , self .unescape (src ))
431
382
else :
432
383
el .set ('src' , "" )
433
384
if len (src_parts ) > 1 :
@@ -469,7 +420,7 @@ def handleMatch(self, m):
469
420
def makeTag (self , href , title , text ):
470
421
el = util .etree .Element ('a' )
471
422
472
- el .set ('href' , self . sanitize_url ( href ) )
423
+ el .set ('href' , href )
473
424
if title :
474
425
el .set ('title' , title )
475
426
@@ -481,7 +432,7 @@ class ImageReferencePattern(ReferencePattern):
481
432
""" Match to a stored reference and return img element. """
482
433
def makeTag (self , href , title , text ):
483
434
el = util .etree .Element ("img" )
484
- el .set ("src" , self . sanitize_url ( href ) )
435
+ el .set ("src" , href )
485
436
if title :
486
437
el .set ("title" , title )
487
438
0 commit comments