Summary
Discourse prior to specific patched versions failed to escape malicious second factor names in the delete confirmation dialog, enabling stored cross-site scripting.
When an administrator impersonates an attacker-controlled account, the crafted 2FA name can execute arbitrary JavaScript in the admin's browser, exposing sensitive actions and data.
Affected context
This vulnerability appears in Discourse instances where:
- Two-factor authentication is enabled for user accounts
- Administrators can impersonate user accounts for support or moderation
- The 2FA delete confirmation dialog renders the second factor name in the browser
Under these conditions, an attacker who can register or control an account and set a crafted 2FA name can persist script code that executes when an admin interacts with that dialog during impersonation.
Exploit preconditions
- Attack surface: Web administration interface of a Discourse instance.
- Required access: Ability for an attacker to create or control a user account and configure a malicious second factor name.
- Trigger point: An administrator impersonates the attacker-controlled account and opens the 2FA delete confirmation dialog.
- Why exploitation is possible: The second factor name is rendered without proper HTML escaping or sanitization, allowing embedded JavaScript code to run in the admin's browser context.
Why this happens
The underlying issue is improper neutralization of user-controlled data before it is included in HTML content.
The second factor name, which is a user-supplied string, is inserted into the delete confirmation dialog without robust escaping or sanitization.
This aligns with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where dynamic content is trusted and interpreted as executable script by the browser.
Potential impact
- An attacker may execute arbitrary JavaScript in the context of an administrator session.
- Attackers could hijack admin accounts by stealing session tokens or triggering privileged actions.
- Malicious scripts can manipulate forum configuration, user permissions, or content.
- The attacker could pivot to broader system compromise through social engineering or administrative actions performed via injected scripts.
General mitigation guidance
Effective mitigation centers on enforcing strict output encoding wherever user-controlled data is rendered in HTML pages, dialogs, or templates.
Recommended defensive patterns include:
- Applying context-appropriate escaping (HTML, attribute, JavaScript) to all dynamic values in templates.
- Treating 2FA labels, usernames, and other display fields as untrusted input by default.
- Centralizing rendering helpers so user-supplied strings never bypass encoding.
- Limiting powerful admin impersonation functionality to well-audited flows and ensuring all impersonation views adhere to the same sanitization rules.
- Using a secure templating system that defaults to safe encoding rather than raw HTML injection.
How teams detect issues like this
Detection can leverage both automated and manual review techniques:
- Static analysis rules searching for direct insertion of user-controlled variables into HTML templates without escaping.
- Template linting that flags use of raw interpolation helpers for potentially hostile fields such as names, labels, and descriptions.
- Code review checklists that require verification of output encoding for any new or modified admin-facing dialogs, especially those involving impersonation.
- Security testing that exercises impersonation flows with specially crafted values containing script markers to observe whether they are rendered or neutralized.
- Integrating automated security scanning tools that simulate XSS payloads in form fields, account attributes, and configuration names.

