Sfoglia il codice sorgente

[fix] linkify should use tokenizer as BleachSanitizer

version-14
Anand Doshi 9 anni fa
parent
commit
2c5c76f65d
1 ha cambiato i file con 16 aggiunte e 7 eliminazioni
  1. +16
    -7
      frappe/utils/__init__.py

+ 16
- 7
frappe/utils/__init__.py Vedi File

@@ -436,18 +436,27 @@ def sanitize_html(html, linkify=False):
elif is_json(html):
return html

whitelisted_tags = (HTMLSanitizer.acceptable_elements + HTMLSanitizer.svg_elements
tags = (HTMLSanitizer.acceptable_elements + HTMLSanitizer.svg_elements
+ ["html", "head", "meta", "link", "body", "iframe", "style", "o:p"])
attributes = {"*": HTMLSanitizer.acceptable_attributes, "svg": HTMLSanitizer.svg_attributes}
styles = bleach_whitelist.all_styles
protocols = ['http', 'https', 'mailto']
strip_comments = False

# retuns html with escaped tags, escaped orphan >, <, etc.
escaped_html = bleach.clean(html,
tags=whitelisted_tags,
attributes={"*": HTMLSanitizer.acceptable_attributes, "svg": HTMLSanitizer.svg_attributes},
styles=bleach_whitelist.all_styles,
strip_comments=False)
escaped_html = bleach.clean(html, tags=tags, attributes=attributes, styles=styles, strip_comments=strip_comments)

if linkify:
escaped_html = bleach.linkify(escaped_html)
# based on bleach.clean
class s(bleach.BleachSanitizer):
allowed_elements = tags
allowed_attributes = attributes
allowed_css_properties = styles
allowed_protocols = protocols
strip_disallowed_elements = False
strip_html_comments = strip_comments

escaped_html = bleach.linkify(escaped_html, tokenizer=s)

return escaped_html



Caricamento…
Annulla
Salva