CVE-2026-115868: A Cross-Site Scripting Flaw in Django’s truncatechars_html Filter
- Home
- Blog
Advisory: CVE-2026-115868 (GHSA-2q44-jvmf-fqjp · EUVD-2026-141379)
Severity: Moderate (Django security policy) · CVSS 4.0 = 5.1
Vector (v4.0): CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N
Weakness: CWE-79 (Cross-site Scripting)
Component: truncatechars_html filter / django.utils.text.Truncator.chars() (html=True)
Affected: Django 6.1 (< 6.1.4) / 6.0 (< 6.0.11) / 5.2 (< 5.2.20)
Fixed in: Django 6.1.4 / 6.0.11 / 5.2.20
Reported by: JoeCyberTech
Published: 2 December 2026
truncatechars_html is a Django template filter that shortens a string of HTML to a maximum number of characters while keeping the markup valid — it closes any tag it cut through and appends an ellipsis. Because the result is HTML, its output is marked safe and the template engine does not escape it again.
I found that for a specific class of inputs — those whose visible text length is exactly equal to the truncation length — the filter (and the underlying Truncator.chars() with html=True) can return content that was not put through the same escaping as the normal truncation path. When that output is placed inside an HTML attribute, a crafted value can break out of the attribute and inject script — a cross-site scripting (XSS) vulnerability.
Django assigned it CVE-2026-115868 and rated it moderate; the fix shipped on 2 December 2026 in Django 6.1.4, 6.0.11 and 5.2.20. Some outlets covered the release under the nickname “Django4Shell” — though the flaw itself is a moderate XSS, not the remote code execution that the nickname might suggest.
What truncatechars_html Is For
truncatechars_html is the HTML-aware sibling of truncatechars. Given {{ value|truncatechars_html:30 }}, it keeps the first 30 characters of visible text, repairs the markup so no tag is left open, and adds “…”. Developers reach for it to show safe previews of rich text — comment snippets, article teasers, search results — without breaking the page layout or leaking raw markup. Its promise is that the result is well-formed, length-bounded, and safe to drop into a template.
The Boundary Condition
The problem lives at the edge. The filter has a fast path: if the input is already short enough, there is nothing to cut, so it returns the content as-is. The bug is that the comparison that decides “already short enough” and the escaping applied along the truncating path do not agree at one exact point — when the visible text length equals the requested limit. At that boundary the input is treated as not needing truncation and takes the shortcut, skipping a normalization/escaping step the longer path performs. A value that should have had a character neutralized passes through intact.
Why the Attribute Context Matters
On its own, HTML-context output is usually fine — a stray < would be shown as text or produce a harmless element. The danger is the attribute sink. When the filter’s result is interpolated into an attribute:
<div data-note="{{ note|truncatechars_html:N }}"></div>
<img alt="{{ caption|truncatechars_html:N }}">
<span title="{{ payload|truncatechars_html:N }}">hover me</span>
a character that survived un-neutralized — a double quote — closes the attribute early, and the attacker-controlled tail becomes new attributes: " onmouseover=alert(document.cookie) x=". Because truncatechars_html output is marked safe, Django’s auto-escaping does not step in to save you. The context the developer chose (an attribute) turns a subtle filter edge-case into executable script.
Root Cause
This is CWE-79 arising from a parser/length edge case rather than a missing-escape-everywhere bug. The filter is correct across the vast majority of inputs; XSS only lines up when the precise equality of text-length and truncation-length combines with an attribute sink. That is exactly the kind of flaw that survives review and testing: the common cases look safe, and the trigger is one character-count away from them.
Proof of Concept (the vulnerable pattern)
A template (N is the truncation length; payload is attacker-controlled rich text):
{# vulnerable sink: filter output placed inside an attribute #}
<span title="{{ payload|truncatechars_html:N }}">hover me</span>
Supply a payload whose visible text length is exactly N and that carries a quote-bearing tail. On a vulnerable Django the filter returns it without neutralizing the quote; rendered into the title attribute it breaks out and injects an event handler. On a patched Django the same input is escaped and the attribute stays intact. (The exact trigger is a length-boundary input; the lesson is the combination of this filter with an attribute context.)
Impact
Moderate. The CVSS 4.0 vector (AV:N/AC:L/AT:N/PR:N/UI:A/…/SC:L/SI:L) captures it: network-reachable, no privileges, but it needs a victim to interact (UI:A) and the impact lands on a subsequent system (the browser) with low confidentiality/integrity effect — classic reflected/stored XSS. In practice, an attacker who can route attacker-influenced rich text through a truncatechars_html-in-an-attribute sink can run script in a victim’s session: steal session cookies or CSRF tokens, act as the victim, or deface the page. It is not RCE and not the “Django4Shell” the nickname suggests — but XSS in a core, widely-used template filter is worth patching promptly because the vulnerable pattern (previewing user content in an attribute) is common.
The Fix and What to Do
Django 6.1.4, 6.0.11 and 5.2.20 correct the boundary handling so the equal-length path escapes consistently with the truncating path. Upgrade to one of those (or later). If you cannot upgrade immediately:
- Do not place
truncatechars_htmloutput inside HTML attributes — use it in element text only. - Escape it yourself for the attribute context where you must preview user content in an attribute, rather than relying on the filter’s “safe” output.
- Treat all rich-text previews as untrusted and prefer a server-side sanitizer (e.g. an allow-list cleaner) before truncation.
Final Assessment
truncatechars_html is a small, trusted helper, and that is precisely why an escaping gap in it matters: its output is marked safe and dropped verbatim into templates across thousands of projects. The flaw was a single boundary condition — text length equal to the truncation length — but boundaries are where safe-by-default code quietly stops being safe. Upgrading to 6.1.4 / 6.0.11 / 5.2.20 closes it.
References
CVE Record
CVE-2026-115868
GitHub Security Advisory
GHSA-2q44-jvmf-fqjp
ENISA EUVD
EUVD-2026-141379
CWE-79: Cross-site Scripting
https://cwe.mitre.org/data/definitions/79.html
Django security releases (2 Dec 2026)
6.1.4, 6.0.11, 5.2.20
Fix commit (main)
django/django@454f44f
In the News
This Django security release (which includes CVE-2026-115868) was covered by specialist security media, government cybersecurity institutions, and official advisories.
- New “Django4Shell” Vulnerability — Django Security Release↗
- Django4Shell Vulnerability — Django Security Release↗
- Django News — XSS and information-leakage advisories↗
- Cyber Fortnightly — news aggregator↗
- Django security advisory (AV26-1219)↗
- EUVD-2026-141379 (CVE-2026-115868)↗
- Django security releases issued: 6.1.4, 6.0.11, 5.2.20↗
- oss-security: Django CVE-2026-115868 & others↗
Discovered and reported by JoeCyberTech — credited in the Django security release of 2 December 2026 (“Django would like to thank JoeCyberTech for reporting this issue”). GitHub: HackingRepo
Leave a Comment