Skip to content

Commit c400741

Browse files
committed
templatetags: Do not mark output of msgid tag as safe
The msgid template tag exists to remove angle brackets from either side of the Message-ID header. It also marks its output as safe, meaning it does not get autoescaped by Django templating. Its output is not safe. A maliciously crafted email can include HTML tags inside the Message-ID header, and as long as the angle brackets are not at the start and end of the header, we will quite happily render them. Rather than using mark_safe(), use escape() to explicitly escape the Message-ID. Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com> (backported from 133a6c9) Signed-off-by: Daniel Axtens <dja@axtens.net>
1 parent 3e66958 commit c400741

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

patchwork/templatetags/patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from __future__ import absolute_import
2222

2323
from django import template
24+
from django.utils.html import escape
2425
from django.utils.safestring import mark_safe
2526
from django.template.defaultfilters import stringfilter
2627

@@ -65,4 +66,4 @@ def state_class(state):
6566
@register.filter
6667
@stringfilter
6768
def msgid(value):
68-
return mark_safe(value.strip('<>'))
69+
return escape(value.strip('<>'))

0 commit comments

Comments
 (0)