Sep 18, 2026·6 min read·10 visits
A name-based context safety grant in djust is inherited by shadowed variables, causing raw rendering of untrusted values and allowing unauthenticated remote execution of arbitrary JavaScript.
An escaping defect in the djust templating engine allows Cross-Site Scripting (XSS) when a template binding construct shadows a variable that was previously marked safe. The Rust-based context safety tracking incorrectly preserves name-based safety grants even after the variable name has been bound to a new, untrusted value.
The djust templating engine is a high-performance, reactive server-side rendering library designed for Django applications. It uses a Rust-powered backend implementation (comprising the djust_core and djust_templates crates) to compile and render templates quickly. To maintain compatibility with Django's safety markings, djust passes information about which variables have been marked as safe across the PyO3 foreign function interface boundary.
However, the mechanism used to track context safety properties was designed to key safety settings by variable name rather than using individual object instances. When standard Django templates wrap strings in SafeData subclasses, the djust engine registers the corresponding variable paths inside a flat security lookup collection. If an outer variable is marked safe, any inner shadow scope that rebinds that same variable name will inherit the safe designation.
This architectural design flaw exposes a cross-site scripting attack surface. When templates employ common shadowing structures such as nested loop scopes or with blocks, the safety metadata remains pinned to the key. This allows untrusted user inputs bound to the shadowed variable name to bypass escaping and render raw HTML directly to the client browser.
This vulnerability affects all releases of djust from version 1.0.0 up to and including version 1.1.1. The issue has been addressed in version 1.1.2 by introducing active safety-key revocation during scope binding operations.
To understand the root cause of the vulnerability, we must examine the context management architecture in crates/djust_core/src/context.rs. The Context struct tracks safe variables using a HashSet containing String keys named safe_keys. When a Python string is marked safe via Django's mark_safe, its dictionary path is added to this set.
When rendering template nodes, the engine determines whether to escape a value by calling Context::is_safe with the variable's key path. If the path exists in safe_keys, the engine skips HTML sanitization. The vulnerability occurs because the engine handles variable rebinding by overwriting the context value map while leaving the safe_keys set unchanged.
This security bypass occurs across eight template binding structures. These include with assignments, for loops, tuple unpacking in loop iterations, template inclusions using with blocks, and custom assign tags. In each case, the safety grant associated with the key survives the shadowing operation, causing the new, untrusted value to render without escaping.
Before the patch, the template renderer in crates/djust_templates/src/renderer.rs updated variable values in shadow scopes using Context::set, which did not affect the safe_keys HashSet:
// Vulnerable update path in crates/djust_templates/src/renderer.rs
new_context.set(var_name.clone(), value);To resolve this issue, the maintainers implemented Context::bind in crates/djust_core/src/context.rs. This method revokes the safety grant of the shadowed variable and any of its dotted-path descendants before binding the new value:
impl Context {
// Safe binding method introduced in v1.1.2
pub fn bind(&mut self, name: String, value: Value) {
self.revoke_safe_subtree(&name);
self.set(name, value);
}
// Revokes safety designations for the key and all nested paths
pub fn revoke_safe_subtree(&mut self, key: &str) {
if self.safe_keys.is_empty() {
return;
}
self.safe_keys.remove(key);
let prefix = format!("{}.", key);
self.safe_keys.retain(|k| !k.starts_with(&prefix));
}
}For loop constructs ({% for %}), calling revoke_safe_subtree inside the loop body would degrade performance to O(N * M) complexity, where N is the loop count and M is the size of safe_keys. To avoid this, the fix hoists the revocation step out of the loop body:
// Optimized loop initialization in crates/djust_templates/src/renderer.rs
let mut ctx = context.clone();
for var_name in var_names {
ctx.revoke_safe_subtree(var_name);
}This optimization strips safe keys from the context once before starting the loop iterations, maintaining template rendering speed while preventing safe-key inheritance.
An attacker can exploit this vulnerability by targeting template components that shadow variables that are marked safe in the parent view context. This requires the application to expose an endpoint where input can be passed into a shadowed template variable.
Consider an application where a Django view marks a variable named 'p' as safe to output trusted HTML. If the associated template subsequently binds user input to 'p' within an inner block, the input inherits the safe marking of the outer variable:
{% with p=request.GET.q %}
<div class="user-container">
{{ p }}
</div>
{% endwith %}If an attacker targets this endpoint with a payload containing malicious HTML or JavaScript, the template engine skips escaping and renders the payload directly into the HTTP response. When the response is loaded, the victim's browser processes and executes the injected script:
<div class="user-container">
<img src=x onerror=alert(document.domain)>
</div>This allows the attacker to execute arbitrary scripts in the victim's browser, enabling session hijacking, CSRF bypass, and unauthorized actions within the application.
This vulnerability poses a significant risk to applications using the djust template library. Based on CVSS v3.1 metrics, the security impact is assessed at a High severity level with a score of 8.2 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N).
The attack vector is network-based (AV:N) and requires low complexity (AC:L) to execute. It requires no authentication privileges (PR:N) but does require interaction from a victim (UI:R), such as clicking a link containing the exploit payload. The impact scope is changed (S:C) because the vulnerability allows code execution to migrate from the server's templating context to the victim's browser session.
Successful exploitation can result in a high loss of confidentiality (C:H) as attackers can steal session tokens and sensitive data. It also causes a low loss of integrity (I:L) because attackers can modify the structure of the rendered web page. The vulnerability is classified under CWE-79 (Improper Neutralization of Input During Web Page Generation).
The recommended remediation is upgrading the djust library to version 1.1.2 or higher. This release integrates safe context bindings across all template rendering pathways, ensuring safety grants do not persist past shadow scopes.
If you cannot update the library immediately, you can mitigate the vulnerability by reviewing your templates. Ensure that no variable names marked safe in your Django views are shadowed inside with, for, or include blocks. Using unique, non-overlapping names for safe-marked variables and user-controlled variables will prevent safe-key inheritance.
Additionally, you can deploy Web Application Firewall rules to block common XSS payloads at the network boundary. Rules should target script tags, execution hooks like onerror=, and JavaScript protocols in URL parameters. However, these signatures should be used as a defense-in-depth measure and not as a replacement for the library update.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N| Product | Affected Versions | Fixed Version |
|---|---|---|
djust djust-org | >= 1.0.0, <= 1.1.1 | 1.1.2 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-79 |
| Attack Vector | Network (AV:N) |
| CVSS v3.1 | 8.2 (High) |
| Exploit Status | PoC |
| KEV Status | Not Listed |
| Impact | Cross-Site Scripting (XSS) |
The software does not neutralize or incorrectly neutralizes user-controlled input before it is placed in output that is used as a web page.
CVE-2026-9639 (GHSA-j93m-3j9p-m5m8) is a null pointer dereference vulnerability in Canonical LXD affecting versions 5.0.0 through 5.21.4 and 6.0 through 6.8. The flaw resides in the (*lxdBackend).CreateCustomVolumeFromBackup method within lxd/storage/backend_lxd.go. An authenticated attacker with the can_create_storage_volumes permission can upload a crafted custom volume backup tarball that omits the expires_at field on a snapshot entry, triggering an unhandled SIGSEGV panic and terminating the LXD daemon.
An operating system command injection vulnerability (CWE-78) exists in GeoNode versions prior to 5.1.0. The vulnerability occurs in the vector upload processing pipeline when handling user-supplied geospatial files. By supplying a crafted layer name containing shell metacharacters, an authenticated attacker with basic data upload privileges can execute arbitrary commands on the underlying server or container hosting the GeoNode application and Celery worker processes.
GeoNode versions prior to 5.0.3 contain an unrestricted file upload vulnerability (CWE-434) within the document and dataset ingestion architecture. Authenticated low-privileged users can bypass upload validation via direct REST API interactions, file extension masquerading, metadata mutation via PATCH requests, or malicious archive submissions. This allows attackers to store and serve dangerous file types, alter on-disk file references, or trigger path traversal and resource exhaustion during archive extraction.
CVE-2026-55649 is a stored Cross-Site Scripting (XSS) vulnerability in GeoNode versions prior to 5.0.3. The flaw exists because document abstract metadata fields are ingested via the metadata management pipeline and stored in the backend database without HTML sanitization or input neutralization. An authenticated attacker with privileges to create or edit document metadata can inject arbitrary HTML and JavaScript payloads into these fields. When another user, such as an administrator, views the affected document page or catalog listing, the unencoded payload is rendered into the Document Object Model (DOM) and executes within the victim's browser session.
CVE-2026-55622 (GHSA-qx75-2p3r-pwm5) is an improper access control vulnerability (CWE-284) in Canonical LXD and LXC Incus (tracked as GHSA-c9f5-j9c3-mhrg). In multi-tenant deployments utilizing project-based isolation, the REST API handler for instance creation via POST /1.0/instances verifies that the authenticated user has authorization in the destination project specified by the query parameter, but fails to verify whether the user holds read or view permissions for the source instance when executing a copy operation across projects. Consequently, an authenticated client restricted to a single project can clone instances or snapshots from unauthorized projects into their own project, resulting in complete disclosure of the target instance filesystem and embedded credentials.
An authorization bypass vulnerability in Canonical LXD (tracked as GHSA-7mr3-28h5-m5vx and CVE-2026-55621, and as GHSA-64f3-v33m-w89f in Linux Containers Incus) allows an authenticated user with restricted project access to copy custom storage volumes and volume snapshots from unauthorized projects. The flaw resides in the storagePoolVolumesPost REST API handler, which verifies permissions on the destination project but fails to check whether the caller holds view entitlements on the source project or volume specified in the request body.