Skip to content
Snippets Groups Projects
Commit e48d52d5 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Lock down the Richtext editor and bleach all user answers

parent a4549fb6
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ class RichTextFieldBlock(TextFieldBlock): ...@@ -39,6 +39,7 @@ class RichTextFieldBlock(TextFieldBlock):
widget = TinyMCE(mce_attrs={ widget = TinyMCE(mce_attrs={
'elementpath': False, 'elementpath': False,
'branding': False, 'branding': False,
'toolbar1': 'undo redo | styleselect | bold italic | bullist numlist | link'
}) })
class Meta: class Meta:
......
...@@ -477,7 +477,7 @@ class ApplicationSubmission(WorkflowHelpers, AbstractFormSubmission): ...@@ -477,7 +477,7 @@ class ApplicationSubmission(WorkflowHelpers, AbstractFormSubmission):
return super().save(*args, **kwargs) return super().save(*args, **kwargs)
def render(self): def render_answers(self):
context = {'fields': []} context = {'fields': []}
for field in self.form_fields: for field in self.form_fields:
try: try:
...@@ -494,6 +494,8 @@ class ApplicationSubmission(WorkflowHelpers, AbstractFormSubmission): ...@@ -494,6 +494,8 @@ class ApplicationSubmission(WorkflowHelpers, AbstractFormSubmission):
data = [choices[value] for value in data] data = [choices[value] for value in data]
except KeyError: except KeyError:
data = [choices[int(value)] for value in data] data = [choices[int(value)] for value in data]
else:
data = str(data)
context['fields'].append({ context['fields'].append({
'field': form_field, 'field': form_field,
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
Email {{ object.email }} Email {{ object.email }}
</div> </div>
<div> <div>
{{ object.render }} {{ object.render_answers }}
</div> </div>
</div> </div>
<div> <div>
......
{% load bleach_tags %}
{% for field in fields %} {% for field in fields %}
<div> <div>
<h5>{{ field.field.label }}</h5> <h5>{{ field.field.label }}</h5>
...@@ -10,7 +11,7 @@ ...@@ -10,7 +11,7 @@
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}
<div>{{ field.value }}</div> <div>{{ field.value|bleach }}</div>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
...@@ -60,6 +60,7 @@ INSTALLED_APPS = [ ...@@ -60,6 +60,7 @@ INSTALLED_APPS = [
'django_filters', 'django_filters',
'django_select2', 'django_select2',
'addressfield', 'addressfield',
'django_bleach',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
...@@ -318,3 +319,14 @@ SOCIAL_AUTH_PIPELINE = ( ...@@ -318,3 +319,14 @@ SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.load_extra_data', 'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details', 'social_core.pipeline.user.user_details',
) )
# Bleach Settings
BLEACH_ALLOWED_TAGS = ['h2', 'h3', 'p', 'b', 'i', 'em', 'strong', 'a', 'ul', 'ol', 'li']
BLEACH_ALLOWED_ATTRIBUTES = ['href', 'title', 'style']
BLEACH_ALLOWED_STYLES = ['font-family', 'font-weight', 'text-decoration', 'font-variant']
BLEACH_STRIP_TAGS = True
BLEACH_STRIP_COMMENTS = True
...@@ -2,6 +2,7 @@ Django==1.11.8 ...@@ -2,6 +2,7 @@ Django==1.11.8
wagtail==1.13.1 wagtail==1.13.1
psycopg2==2.7.3.1 psycopg2==2.7.3.1
Pillow==4.3.0 Pillow==4.3.0
django-bleach==0.3.0
django-extensions==1.7.4 django-extensions==1.7.4
django-countries==5.1 django-countries==5.1
Werkzeug==0.11.11 Werkzeug==0.11.11
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment