GHSA-XJW9-38CR-6372

Vulnerability from github – Published: 2026-09-17 20:31 – Updated: 2026-09-17 20:31
VLAI
Summary
djust: A template binding inherits a context safety grant it never earned (XSS)
Details

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 = mark_safe('<b>trusted</b>')
template     {% with p=user_input %}{{ p }}{% endwith %}

  djust   '<img src=x onerror=alert(1)>'          <- executes
  django  '&lt;img src=x onerror=alert(1)&gt;'

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 mark_safe (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 mark_safe 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 mark_safe'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.

Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 1.1.1"
      },
      "package": {
        "ecosystem": "PyPI",
        "name": "djust"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "1.1.2"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [],
  "database_specific": {
    "cwe_ids": [
      "CWE-116",
      "CWE-79"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-09-17T20:31:48Z",
    "nvd_published_at": null,
    "severity": "HIGH"
  },
  "details": "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.\n\ndjust\u0027s context safety channel is keyed by **name**, not by value. Every bind copied the value and left the grant in place:\n\n```\nview marks   p = mark_safe(\u0027\u003cb\u003etrusted\u003c/b\u003e\u0027)\ntemplate     {% with p=user_input %}{{ p }}{% endwith %}\n\n  djust   \u0027\u003cimg src=x onerror=alert(1)\u003e\u0027          \u003c- executes\n  django  \u0027\u0026lt;img src=x onerror=alert(1)\u0026gt;\u0027\n```\n\n## Affected binds\n\nEight distinct shapes were live. All are fixed in 1.1.2:\n\n| shape | example |\n|---|---|\n| `{% with %}` rebinding a marked name | `{% with p=hostile %}{{ p }}{% endwith %}` |\n| `{% with %}` **descendant** of a rebound name | `{% with p=hostile %}{{ p.a }}{% endwith %}` |\n| `{% with %}` binding over a marked name | `{% with q=hostile %}{{ q }}{% endwith %}` |\n| `{% for %}` loop variable | `{% for p in hostiles %}{{ p }}{% endfor %}` |\n| `{% for %}` descendant | `{% for p in hostiles %}{{ p.a }}{% endfor %}` |\n| `{% for %}` tuple unpacking | `{% for k, v in rows %}{{ v }}{% endfor %}` |\n| `{% include \u2026 with %}` | `{% include \"c.html\" with q=hostile %}` |\n| assign tags | `{% \u2026 as x %}` |\n\nNo 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 \u2014 an ordinary pattern, since a view commonly marks trusted markup safe and templates commonly reuse short names such as `p`, `item` or `row`.\n\n## Impact\n\nStored or reflected XSS in any djust application that combines `mark_safe` (or any framework path that grants a context key safety) with a template that rebinds that name. Exploitation requires no unusual template construct.\n\n## Patches\n\nFixed in **1.1.2**, and in 1.2.0 (`main`).\n\nThe 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 \u2014 a grant being **lost** across some binds, causing over-escaping \u2014 and fixing only the reported direction would have left this leak in place. Both directions are the same rule.\n\n**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 `mark_safe` reaching a template through `dict.values` / `dict.items`). Both escape *more* than Django rather than less, so neither is a leak.\n\n## Workarounds\n\nBefore upgrading, avoid reusing a context name for both `mark_safe`\u0027d content and untrusted input, and avoid rebinding such a name in `{% with %}`, `{% for %}`, `{% include \u2026 with %}` or an assign tag.\n\n## Credit\n\nFound 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.",
  "id": "GHSA-xjw9-38cr-6372",
  "modified": "2026-09-17T20:31:48Z",
  "published": "2026-09-17T20:31:48Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/djust-org/djust/security/advisories/GHSA-xjw9-38cr-6372"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/djust-org/djust"
    },
    {
      "type": "WEB",
      "url": "https://github.com/djust-org/djust/releases/tag/v1.1.2"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N",
      "type": "CVSS_V4"
    }
  ],
  "summary": "djust: A template binding inherits a context safety grant it never earned (XSS)"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…

Related by attack behaviour

Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.


Loading…