Summary
MCP Appium contains a stored cross-site scripting vulnerability where attacker-controlled mobile element attributes are interpolated into an HTML UI without proper escaping.
If an attacker can influence the app-under-test UI, they can inject scripts that execute in the MCP client and trigger arbitrary MCP tools, leading to unauthorized actions such as screenshots and page source retrieval.
Affected context
This vulnerability occurs in MCP Appium's locator generator UI, specifically in environments where MCP assistants use the generate_locators tool and render the returned HTML in a browser-like client.
It is most relevant when the mobile app under test exposes text, content-desc, resource-id, or locator selector values that can be influenced by untrusted users or external input and are subsequently reflected in the MCP UI without proper escaping.
Exploit preconditions
- Attack surface: The MCP locator generator UI rendered by the MCP client.
- Required access: Ability to control or influence the UI of the mobile app under test (e.g., user-controlled labels, accessibility text, resource IDs, or selectors).
- Trigger point: Use of the
generate_locatorstool, which causes the vulnerablecreateLocatorGeneratorUIoutput to be injected into the MCP client's DOM. - Why exploitation is possible: Attacker-controlled element attributes are interpolated directly into an HTML template literal without HTML or JavaScript context escaping, allowing arbitrary script injection that runs when the MCP UI is rendered.
Why this happens
The underlying bug is a classic stored cross-site scripting issue mapped to CWE-79.
The createLocatorGeneratorUI function treats untrusted mobile element attributes as safe HTML and combines them into a template literal without escaping or encoding.
Because these values are inserted into a rendered page, any embedded script or event handler is executed in the browser context, enabling the attacker's JavaScript to call window.parent.postMessage and drive MCP tool execution.
Conceptually, this is an unsafe mixing of data and code where presentation templates accept unvalidated, unencoded user-influenced data.
Potential impact
- Attacker-controlled scripts may trigger arbitrary MCP tools (e.g., screenshots, page source retrieval, or other registered capabilities).
- Unauthorized collection of sensitive test or application information via automated tooling.
- Manipulation of testing workflows, including falsifying automation results or steering tool behavior.
- Potential lateral impact if MCP tools integrate with external systems or CI pipelines.
General mitigation guidance
Effective mitigation focuses on strict separation of untrusted data from executable content in UI templates.
Common patterns include:
- Applying robust HTML and JavaScript context-aware escaping to all element attributes before inserting them into templates.
- Using templating engines or component frameworks that encode values by default instead of manual string interpolation.
- Treating all app-under-test UI content as untrusted and validating or sanitizing it prior to rendering in MCP-facing UIs.
- Limiting what UI-derived data is rendered, and avoiding embedding it directly in script blocks or event handler attributes.
- Implementing least-privilege for MCP tools so that even if a UI script runs, its ability to perform sensitive operations is constrained.
How teams detect issues like this
Detection typically involves examining how UI templates handle untrusted data and ensuring that encoding rules are consistently applied.
High-level strategies include:
- Static analysis rules that flag direct string interpolation of untrusted values into HTML or JavaScript contexts (e.g., template literals,
innerHTMLassignments). - Code review checklists that require verification of escaping/sanitization for any data originating from app-under-test attributes before inclusion in MCP UI resources.
- Security policies that mandate use of safe templating frameworks and prohibit raw DOM injection from tool outputs.
- Optional automated scanning tools or dynamic tests that attempt to inject benign script payloads into UI attributes and observe whether they execute when rendered in the MCP client.

