GitHub Advisoryadvisory · npm
GHSA-x975-rgx4-5fh4 appium-mcp: Unescaped Locator Data XSS in MCP-UI Resource (createLocatorGeneratorUI)
HIGH
Official page ↗
- Ecosystem
- npm
- Packages
- appium-mcp
- Severity
- High
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:H/A:N
- Weaknesses
- CWE-79
- Reviewed
- 2026-06-19
Affected packages
• npm appium-mcp: < 1.85.10 → fixed in 1.85.10
Description
Unescaped Locator Data XSS in MCP-UI Resource (createLocatorGeneratorUI)
Summary
`appium-mcp`'s `createLocatorGeneratorUI` function interpolates attacker-controlled element attributes — `text`, `content-desc`, `resource-id`, and locator selector values — directly into an HTML template literal without any HTML or JavaScript context escaping. An attacker who controls the UI of the app under test can inject arbitrary HTML and JavaScript into the MCP UI resource returned by the `generate_locators` tool. When a victim's MCP client renders this resource, the injected script executes and can invoke arbitrary MCP tools via `window.parent.postMessage`, leading to unauthorized MCP tool execution such as taking screenshots, reading page source, or any other registered capability.
Details
The vulnerability is a stored/reflected cross-site scripting (XSS) issue in the MCP UI generation pipeline.
Vulnerable sink — `src/ui/mcp-ui-utils.ts:730–740`:
```ts
${element.text ? `Text: ${element.text}` : ''}
${element.contentDesc ? `Content Desc: ${element.contentDesc}` : ''}
${element.resourceId ? `Resource ID: ${element.resourceId}` : ''}
${selector}
Test
```
None of `element.text`, `element.contentDesc`, `element.resourceId`, `selector`, or `strategy` are HTML-escaped before insertion. The `onclick` attribute additionally embeds `selector` and `strategy` into an inline JavaScript string using only a backtick-escape that is insufficient to prevent breakout via HTML event attribute syntax or single-quote injection.
By contrast, `createPageSourceInspectorUI` at `src/ui/mcp-ui-utils.ts:911–916` does apply escaping to the page source, confirming that the protection gap in `createLocatorGeneratorUI` is an oversight, not a design choice.
Complete data flow (source → sink):
1. `src/tools/test-generation/locators.ts:57` — `getPageSource(driver)` reads the page source XML from an active Appium session; the connected app is fully attacker-controlled.
2. `src/tools/test-generation/locators.ts:72` — the raw page source is passed to `generateAllElementLocators`.
3. `src/locators/source-parsing.ts:108` — XML attribute values undergo only newline replacement (`attr.value.replace(/(\n)/gm, '\n')`); HTML entities such as `<` are decoded into raw ``, `"`, `'`) applied to all element properties in the HTML context, and `JSON.stringify` for values embedded inside JavaScript string literals in `onclick` handlers.
PoC
Prerequisites:
• `appium-mcp` v1.85.8 or v1.85.9 installed from npm
• Node.js 20+ with the package built (`npm install && npm run build`)
• An MCP client that renders HTML resources returned by `generate_locators` (e.g., VS Code with the Appium MCP extension, or any WebView-based MCP host)
Static confirmation (no Appium session required):
```bash
node --input-type=module
`;
const locators = generateAllElementLocators(xml, true, 'uiautomator2', { fetchableOnly: true });
const html = createLocatorGeneratorUI(locators);
console.log('UNESCAPED in contentDesc present: ', html.includes('xss-in-contentDesc'));
console.log('UNESCAPED in resourceId present: ', html.includes('xss-resource-id'));
EOF
```
Expected output:
```
UNESCAPED in contentDesc present: true
UNESCAPED in resourceId present: true
```
Dynamic confirmation (Docker, network-isolated):
```bash
Build context is the parent directory (contains repo/ and vuln-001/)
docker build -t appium-mcp-vuln-001 \
-f vuln-001/Dockerfile \
reports/npmAI_303_appium__appium-mcp
docker run --rm --network none appium-mcp-vuln-001
```
The container output confirms:
```
HTML has unescaped Text:
│ [PASS] XSS CONFIRMED │
│ createLocatorGeneratorUI inserted the raw XSS tag │
│ execute the onerror handler, enabling arbitrary MCP tool │
```
End-to-end exploitation against a real MCP client:
1. Attacker publishes or sideloads an Android/iOS app whose UI element `text`, `content-desc`, or `resource-id` attributes contain an XSS payload (e.g., ``).
2. Victim developer connects their Appium MCP server to the attacker's app and calls the `generate_locators` MCP tool.
3. The MCP client renders the returned HTML resource in a WebView / iframe.
4. The injected `onerror` handler fires and posts a crafted `tool` message to the parent frame, causing the MCP host to invoke arbitrary registered tools (e.g., `appium_screenshot`, `execute_script`, `get_page_source`) without user confirmation.
Impact
This is a Cross-Site Scripting (XSS) vulnerability. Any developer using `appium-mcp` with an MCP client that renders HTML resources (the intended workflow for the UI feature) is impacted when they inspect elements from an attacker-controlled application.
Impact scenarios:
• Arbitrary MCP tool invocation: Injected JavaScript calls `window.parent.postMessage` with any tool name and parameters, executing MCP tools silently (e.g., taking screenshots, reading page source, executing scripts on the device).
• Credential and data exfiltration: Via `execute_script` or screenshot tools, an attacker can extract sensitive data visible on the device screen or in the page source.
• Lateral movement / persistence: If the MCP host exposes file-system or shell tools, the attacker can escalate to arbitrary code execution on the developer's machine.
• Supply-chain / CI abuse: Automated test pipelines that call `generate_locators` against third-party app builds are equally vulnerable; no human interaction beyond running the pipeline is required.
The attack requires no authentication (`PR:N`), the tool is enabled by default (`default-on: Y`), and the scope is changed (`S:C`) because JavaScript executes in the MCP host frame rather than the sandboxed resource.
Reproduction artifacts
`Dockerfile`
```dockerfile
VULN-001 PoC: Unescaped Locator Data XSS in appium-mcp createLocatorGeneratorUI
Build context…
Related
Weakness · CWE (1)
- CWE-79 Improper Neutralization of Input During Web Page Generation weakness