mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-19 14:32:16 +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:
|
||||
return text
|
||||
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':
|
||||
return mark_safe('<div class="markdown">' + html + '</div>')
|
||||
return mark_safe('<div class="markdown">' + str(soup) + '</div>')
|
||||
elif input_format == 'rml':
|
||||
# Convert format to RML
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
|
||||
# Image aren't supported so remove them
|
||||
for img in soup('img'):
|
||||
|
||||
Reference in New Issue
Block a user