Skip to content

Commit

Permalink
Filtering errors by safe is NOT safe!
Browse files Browse the repository at this point in the history
This corrects the assumption that django errors are safe.

eg: If you have a GET form with a field call foo and insert:

    ?foo=bar

into the url, where bar is not a valid choice, the error for a
ChoiceField will be:

    Select a valid choice. bar is not one of the available choices.

Obviously this is a VERY bad thing to mark as safe. Imagine we have:

    ?foo=<script>alert('This is bad')</script>

We are now manipulating the page into executing code... This is bad.

https://docs.djangoproject.com/en/dev/topics/templates/#automatic-html-escaping
  • Loading branch information
Charlie Denton authored and maraujop committed Sep 17, 2011
1 parent 381d781 commit afb7fd9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion uni_form/templates/uni_form/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div id="div_{{ field.auto_id }}" class="ctrlHolder{% if field.errors %} error{% endif %}{% if field|is_checkbox %} checkbox{% endif %}{% if field.field.widget.attrs.class %} {{ field.field.widget.attrs.class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% for error in field.errors %}
<p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="errorField">
{{ error|safe }}
{{ error }}
</p>
{% endfor %}

Expand Down
2 changes: 1 addition & 1 deletion uni_form/templates/uni_form/field.strict.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div id="div_{{ field.auto_id }}" class="ctrlHolder{% if field.errors %} error{% endif %}{% if field|is_checkbox %} checkbox{% endif %}{% if field.field.widget.attrs.class %} {{ field.field.widget.attrs.class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% for error in field.errors %}
<p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="errorField">
{{ error|safe }}
{{ error }}
</p>
{% endfor %}

Expand Down

0 comments on commit afb7fd9

Please sign in to comment.