Summary
A stored cross-site scripting (XSS) vulnerability in Decidim allows attacker-controlled code to be stored in the user name field and later executed in other users' browsers.
When a victim passively visits an affected comment page, the injected script runs with their session context, enabling actions and data access as if performed by the victim.
Affected context
This issue arises in Decidim deployments where user-supplied profile attributes, specifically the user name field, are later rendered into comment-related views without robust output encoding.
The vulnerability is present when:
- User names can contain HTML/JavaScript-like content
- The same user name is displayed in comments or related pages
- Templates render the name directly into the page DOM without appropriate escaping or content sanitization
It typically affects multi-user environments where low-privileged participants can interact and comment.
Exploit preconditions
- Attack surface: Web interface (browser-based interaction with Decidim).
- Required access: Ability to create or modify a user account/profile, specifically the user name field; no elevated privileges are required beyond standard user access.
- Trigger point: Any page that displays the malicious user name, such as a comment page or thread where the attacker's profile is visible.
- Why exploitation is possible: The application stores user-controlled data and later embeds it into HTML responses without sufficient context-aware output encoding, allowing the browser to interpret it as active script rather than inert text.
Why this happens
The underlying bug is a classic stored XSS pattern where untrusted data is persisted and then rendered without proper escaping.
In this case, the user name field is treated as benign text but is not consistently encoded when injected into HTML templates.
This maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), where dynamic content is interpolated directly into the page without context-aware output encoding (e.g., HTML-escaping, attribute-escaping) or sanitization sufficient to neutralize script execution.
The abstract insecure pattern is: "persist attacker-controlled input and render it into web pages without enforcing strict encoding rules for the specific output context."
Potential impact
- Attackers may execute arbitrary JavaScript in the context of other users' sessions.
- Attackers could read or exfiltrate sensitive information accessible to the victim's browser, such as CSRF tokens or page content.
- Attackers can perform actions on behalf of victims (e.g., posting content, changing settings) using their authenticated session.
- Attackers may escalate impact across security boundaries, such as impersonating privileged users or administrators who view affected pages.
- Attackers can inject further malicious content for phishing, redirection, or malware distribution.
General mitigation guidance
Effective mitigation focuses on context-aware output encoding and strict handling of user-generated content:
- Treat all user-supplied fields, including profile attributes like user names, as untrusted input regardless of perceived harmlessness.
- Apply appropriate output encoding at every rendering point based on context (HTML body, attribute values, JavaScript, URLs) rather than relying solely on input filters.
- Restrict allowed characters or formats for user names and similar fields to a conservative, well-defined set (e.g., alphanumeric plus limited punctuation) to reduce risk surface.
- Use a central templating system that automatically escapes variables by default, requiring explicit opt-out only for carefully reviewed safe content.
- Separate storage of "raw" user input from "display" representations where necessary, ensuring any display representation is derived via a safe transformation or encoding step.
- Apply least-privilege principles in session handling and API design so that compromised browser contexts have minimal reach and cannot trivially perform highly privileged actions.
How teams detect issues like this
Organizations can identify and monitor for this class of issue using several complementary approaches:
- Static analysis: Use rules that flag direct insertion of user-supplied variables into HTML templates without encoding, especially in views that render profile fields, comments, or other user content.
- Template reviews: During code review, verify that templating engines have auto-escaping enabled and that any use of "raw" or "safe" rendering helpers is justified and documented.
- Security testing: Perform manual and automated XSS testing on all user profile fields and comment-related UIs, including attempts to store HTML/JavaScript-like payloads and then view them from a separate account.
- Content inspection: Monitor logs and application telemetry for anomalous patterns such as profile fields containing script-like tokens, which may indicate attempted or successful exploitation.
- Policy enforcement: Integrate secure coding guidelines and pre-commit/CI checks that prevent merging templates which bypass escaping or introduce new raw HTML injection points.

