Opened 6 years ago

Closed 6 years ago

#13980 closed (invalid)

The markdown template tag in django.contrib.markup should escape preexisting HTML, as its output is marked as safe

Reported by: Fletcher Tomalty Owned by: nobody
Component: Contrib apps Version: 1.2
Severity: Keywords: markup, markdown, safe, escape
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm not sure about the other markup options, but Markdown itself should definitely not be marked as safe. You can easily render <script type="text/javascript">alert('pwned')</script> with Markdown, and with that is_safe = True there, the HTML will not be escaped.

Attachments (1)

markup.py (3.4 KB) - added by Fletcher Tomalty 6 years ago.
Removed the is_safe = True so that markdown output will be escaped

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by Fletcher Tomalty

Attachment: markup.py added

Removed the is_safe = True so that markdown output will be escaped

comment:1 Changed 6 years ago by anonymous

Patch needs improvement: set

Please add a proper SVN diff file

comment:2 Changed 6 years ago by Fletcher Tomalty

Keywords: markup markdown safe escape added
Patch needs improvement: unset
Summary: The markdown template tag in django.contrib.markup should not be marked as safe outputThe markdown template tag in django.contrib.markup should escape preexisting HTML, as its output is marked as safe

You're right. That was stupid of me.

But I was also wrong about the bug/security issue. Markdown would be totally broken if we escaped its output (the user would just see HTML code), so we obviously can't remove the is_safe = True line.

What should really be done is to actually escape the input before Markdown processes it, and continue to mark it as safe output. We can do this using django.utils.html.escape.

comment:3 Changed 6 years ago by Fletcher Tomalty

Resolution: invalid
Status: newclosed

Wow. I just realized that's what the safe mode feature is for. DISREGARD THIS.

Note: See TracTickets for help on using tickets.
Back to Top