Summary
A stored cross-site scripting (XSS) vulnerability in n8n's MCP OAuth client registration allows attacker-controlled script content to be injected via the client_name field and later rendered in a toast notification.
When a victim authorizes a malicious OAuth client and another user revokes it, the resulting notification can execute arbitrary JavaScript in the victim's authenticated browser session, enabling credential theft and workflow manipulation.
Affected context
This vulnerability arises in n8n's web-based user interface where MCP OAuth clients are created, authorized, and revoked.
The issue manifests specifically when:
- An unauthenticated attacker can register an MCP OAuth client and control its
client_name. - A victim user later authorizes this malicious client through the OAuth consent dialog.
- A second user (or the same user, depending on configuration) revokes that client, triggering a toast notification.
The notification renders the attacker-controlled client_name without adequate sanitization or encoding, allowing script execution in the context of the authenticated n8n session.
Exploit preconditions
- Attack surface: n8n web UI, specifically the MCP OAuth client registration, consent, and revocation flows.
- Required access:
- The attacker needs network access to the n8n instance to register an MCP OAuth client (no authentication required).
- A victim with a valid n8n account must authorize the malicious OAuth client.
- A second user with the ability to revoke the client must perform the revocation action.
- Trigger point: The toast notification that appears when the OAuth client access is revoked, which displays the crafted
client_name. - Why exploitation is possible: The
client_namefrom the MCP OAuth client is treated as trusted content and rendered into the toast notification without appropriate HTML/JavaScript context-aware escaping or sanitization, enabling injected script to run in the victim's browser.
Why this happens
The root cause is improper neutralization of user-controlled data in a web UI context, mapped to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
The MCP OAuth client_name field, which is fully attacker-controlled, is stored and later rendered into a toast notification without being encoded according to the rules of the HTML/DOM context in which it appears.
This lack of output encoding/sanitization allows the injected script to be interpreted by the browser as executable JavaScript.
Additionally, the workflow involves multiple users (one authorizing the OAuth client and another revoking it), which can obscure trust boundaries and lead to assumptions that any data displayed in notifications is safe, even when it originated from unauthenticated input.
Potential impact
- Hijacking of authenticated n8n sessions via theft of session tokens or cookies.
- Unauthorized access to workflow credentials, API keys, and connection secrets stored in n8n.
- Manipulation, creation, or deletion of workflows and automations.
- Privilege escalation if the victim user has elevated roles or administrative permissions.
- Lateral movement by leveraging compromised workflows to access integrated third-party services.
- Persistent compromise of automation pipelines, including data exfiltration or tampering.
General mitigation guidance
Effective mitigation typically focuses on treating all user-supplied or indirectly controlled data as untrusted and applying strict output encoding rules.
Common defensive patterns include:
- Enforcing context-aware output encoding for all dynamic values rendered into HTML, attributes, or JavaScript contexts (e.g., using templating frameworks that auto-escape by default).
- Sanitizing or restricting allowed characters in display fields such as
client_name, limiting them to safe subsets where scripting cannot be expressed. - Adopting a "safe by default" UI layer where notifications, dialogs, and other components only accept pre-escaped, strongly typed data.
- Clearly separating "data from UI" by preventing arbitrary markup from being injected into component templates.
- Reducing trust zones by validating and normalizing values coming from unauthenticated or semi-trusted flows like OAuth registrations.
- Applying least privilege principles for tokens and credentials exposed through the UI, limiting what an XSS attacker can access.
How teams detect issues like this
Detection strategies for this kind of XSS issue typically combine preventative and investigative approaches:
- Static analysis: Configure rules or linters to flag direct insertion of user-controlled data into UI components, especially into HTML or JavaScript sinks, without use of approved escaping functions.
- Code review: During reviews, pay special attention to UI elements that render data from external systems (e.g., OAuth clients), toast notifications, and other cross-cutting components; verify they use centralized, safe rendering helpers.
- Security testing: Incorporate automated and manual XSS tests into CI/CD pipelines, including tests for stored XSS in notification systems and workflow logs.
- Logging and monitoring: Track unusual registration of OAuth clients and patterns of repeated client creation with suspicious names, as these may indicate probing for XSS.
- Policy enforcement: Use internal UI frameworks or component libraries with enforced escaping guarantees, and restrict direct DOM manipulation or insertion of raw HTML.

