GHSA-xjw9-38cr-6372: XSS
A context safety grant was inherited by a template binding that never earned it, so rebinding a name the view had marked safe left the mark attached to the new, attacker-controlled value.
djust's context safety channel is keyed by name, not by value. Every bind copied the value and left the grant in place:
view marks p = marksafe('<b>trusted</b>') template {% with p=userinput %}{{ p }}{% endwith %}
djust '<img src=x onerror=alert(1)>' <- executes django '<img src=x onerror=alert(1)>'
Affected binds
Eight distinct shapes were live. All are fixed in 1.1.2:
| shape | example | |---|---| | {% with %} rebinding a marked name | {% with p=hostile %}{{ p }}{% endwith %} | | {% with %} descendant of a rebound name | {% with p=hostile %}{{ p.a }}{% endwith %} | | {% with %} binding over a marked name | {% with q=hostile %}{{ q }}{% endwith %} | | {% for %} loop variable | {% for p in hostiles %}{{ p }}{% endfor %} | | {% for %} descendant | {% for p in hostiles %}{{ p.a }}{% endfor %} | | {% for %} tuple unpacking | {% for k, v in rows %}{{ v }}{% endfor %} | | {% include … with %} | {% include "c.html" with q=hostile %} | | assign tags | {% … as x %} |
No filter chain and no |safe anywhere in the template is required. The precondition is that the application marked some value safe under a name that a template later rebinds — an ordinary pattern, since a view commonly marks trusted markup safe and templates commonly reuse short names such as p, item or row.
Impact
Stored or reflected XSS in any djust application that combines marksafe (or any framework path that grants a context key safety) with a template that rebinds that name. Exploitation requires no unusual template construct.
Patches
Fixed in 1.1.2, and in 1.2.0 (main).
The rule is that a bind replaces the grant rather than inheriting one. It is stated that way deliberately: the originally reported defects pointed the opposite direction — a grant being lost across some binds, causing over-escaping — and fixing only the reported direction would have left this leak in place. Both directions are the same rule.
Not fixed in 1.1.2, and tracked for 1.2.0: two over-escaping cases where a grant fails to travel with a value that legitimately carries one ({% with body=post.text|linebreaks %}, and marksafe reaching a template through dict.values / dict.items). Both escape more than Django rather than less, so neither is a leak.
Workarounds
Before upgrading, avoid reusing a context name for both marksafe'd content and untrusted input, and avoid rebinding such a name in {% with %}, {% for %}, {% include … with %} or an assign tag.
Credit
Found while preparing the 1.1.1 security release: the reproducer published in GHSA-9395-2g46-rj3f was run against the built 1.1.1 artifact before that advisory was published, and proved the class was still live. Publishing the original text would have reported this class as patched when it was not.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/djustto a version that resolves this vulnerability.Fixed in 1.1.2 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 1.1.2 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 1.2.0 - Configuration
Before upgrading, avoid reusing a context name for both mark_safe'd content and untrusted input, and avoid rebinding such a name in `{% with %}`, `{% for %}`, `{% include … with %}` or an assign tag. Both directions are the same rule.
Django template usage (context safety via mark_safe and context keys) Avoid reusing/rebinding context names between mark_safe content and untrusted input in template binds = Do not use the same context name for both mark_safe'd content and untrusted input; do not rebind such names in {% with %}, {% for %}, {% include … with %}, or assign tags - Compensating control
If upgrading is not possible yet, prevent the vulnerable pattern by ensuring that template binds do not replace/inherit context safety grants for attacker-controlled values—specifically, do not reuse/rebind the same context key name that was previously marked safe.
Event History
Frequently Asked Questions
Who is exposed to this issue?
Applications are exposed where attacker-controlled data can reach djust templates that rebind a name previously marked safe. The affected patterns include {% with %}, {% for %}, tuple-unpacking loops, and {% include … with %}, including accesses to descendants such as p.a.
What conditions are required for exploitation?
A view must have marked a template name safe, and a template must later bind attacker-controlled content to that name or another affected binding target. Because safety is tracked by name rather than by value, the newly bound content can retain the prior safety grant and be rendered without escaping.
What should I do to remediate this?
Update djust to version 1.1.2, which fixes all eight affected binding shapes. Until updating, review templates for affected binding constructs that receive untrusted data after safe-marking has been applied to template names.