mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 00:42:17 +00:00
FIX: Prevent js injection through markdown fields
This commit is contained in:
@@ -14,11 +14,14 @@ def markdown_filter(text, input_format='html'):
|
|||||||
if text is None:
|
if text is None:
|
||||||
return text
|
return text
|
||||||
html = markdown.markdown(text, extensions=['markdown.extensions.nl2br'])
|
html = markdown.markdown(text, extensions=['markdown.extensions.nl2br'])
|
||||||
|
# Convert format to RML
|
||||||
|
soup = BeautifulSoup(html, "html.parser")
|
||||||
|
# Prevent code injection
|
||||||
|
for script in soup('script'):
|
||||||
|
script.string = "Your script shall not pass!"
|
||||||
if input_format == 'html':
|
if input_format == 'html':
|
||||||
return mark_safe('<div class="markdown">' + html + '</div>')
|
return mark_safe('<div class="markdown">' + str(soup) + '</div>')
|
||||||
elif input_format == 'rml':
|
elif input_format == 'rml':
|
||||||
# Convert format to RML
|
|
||||||
soup = BeautifulSoup(html, "html.parser")
|
|
||||||
|
|
||||||
# Image aren't supported so remove them
|
# Image aren't supported so remove them
|
||||||
for img in soup('img'):
|
for img in soup('img'):
|
||||||
|
|||||||
Reference in New Issue
Block a user