# GHSA-xjw9-38cr-6372: djust: A template binding inherits a context safety grant it never earned (XSS)

> Attackers can execute arbitrary JavaScript via XSS by rebinding template variables that were previously marked as safe, affecting djust applications.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 17 Sep 2026

## What is GHSA-xjw9-38cr-6372?

GHSA-xjw9-38cr-6372 is a cross-site scripting vulnerability in djust, published on 17 Sep 2026. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

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.

## Which versions are affected by GHSA-xjw9-38cr-6372?

2 open source packages ship an affected version, including djust.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `djust` | PyPI | All versions | 1.1.2 |
| `djust` | PyPI | All versions | 1.1.2 |

## How do I fix GHSA-xjw9-38cr-6372?

Upgrade djust to 1.1.2 or later.

## Is GHSA-xjw9-38cr-6372 being exploited?

There is no known exploitation of GHSA-xjw9-38cr-6372 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-xjw9-38cr-6372 and fix it if it is affected.

What it is: GHSA-xjw9-38cr-6372 is a cross-site scripting vulnerability in djust, published on 17 Sep 2026. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-xjw9-38cr-6372 in the wild and no public exploit code.

Affected packages and fixed versions:
- djust (PyPI): affected all versions; fixed in 1.1.2
- djust (PyPI): affected all versions; fixed in 1.1.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-xjw9-38cr-6372/ (Markdown: https://insights.sbomify.com/GHSA-xjw9-38cr-6372/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-xjw9-38cr-6372

---
From sbomify Insights: https://insights.sbomify.com/GHSA-xjw9-38cr-6372/
Summaries are generated and may contain mistakes; the official description above is the record.
