See how homeassistant-ai compares to other vendors in security performance
Summary
The ha-mcp OAuth consent form renders user-controlled parameters via Python f-strings with no HTML escaping. An attacker who can reach the OAuth endpoint and convince the server operator to follow a crafted authorization URL could execute JavaScript in the operator's browser. This affects only users running the beta OAuth mode (ha-mcp-oauth), which is not part of the standard setup and requires explicit configuration.
Details
Unescaped f-string rendering
consentform.py builds HTML using Python f-strings. No call to html.escape() exists anywhere in the file. The following values are rendered unescaped:
- clientname / clientid — in HTML element context (lines 299, 303) - clientid, redirecturi, state — in HTML attribute context (lines 310–312), where a " character breaks out of value="" - errormessage, error, errordescription — in error display paths (lines 36–40, 496–497)
An attacker can register a client with a malicious clientname via the /register (DCR) endpoint, which accepts clientname without sanitization. If the server operator then visits a crafted authorization URL for that client, the payload executes in their browser.
Open Dynamic Client Registration
DCR is enabled by default with no initial access token required. This is intentional: Claude.ai and ChatGPT must self-register on first use, which is the standard MCP OAuth flow (RFC 7591). Requiring a pre-shared token would break those integrations. Registration alone grants no access — authorization requires an explicit action by the server operator.
Impact
Affected configuration: OAuth mode only (ha-mcp-oauth, requires MCPBASEURL). This mode is in beta and is not included in the main setup documentation. The vast majority of ha-mcp users run stdio mode, which is not affected.
Attack requirements: 1. The attacker can reach the ha-mcp OAuth endpoint (it binds to 0.0.0.0 in HTTP mode) 2. The attacker registers a malicious client via /register 3. The attacker convinces the server operator — the person who set up ha-mcp — to follow a crafted authorization URL for an unrecognized application
Step 3 is a meaningful social engineering bar: the consent form displays the (unfamiliar) application name, and the operator has no legitimate reason to authorize an OAuth client they didn't initiate through Claude.ai or ChatGPT. Normal usage involves being redirected to the consent form from one of those platforms, not from an external link.
If exploited, a JavaScript payload could exfiltrate data entered into the consent form, including the Home Assistant Long-Lived Access Token.
Fix
Upgrade to 7.0.0
Summary
The ha-mcp OAuth consent form (beta feature) accepts a user-supplied haurl and makes a server-side HTTP request to {haurl}/api/config with no URL validation. An unauthenticated attacker can submit arbitrary URLs to perform internal network reconnaissance via an error oracle. Two additional code paths in OAuth tool calls (REST and WebSocket) are affected by the same primitive.
The primary deployment method (private URL with pre-configured HOMEASSISTANTTOKEN) is not affected.
Details
Code path 1 — Consent form validation (reported)
When a user submits the OAuth consent form, validatehacredentials() (provider.py) makes a server-side GET request to {haurl}/api/config with no scheme, IP, or domain validation. Different exception types produce distinct error messages, creating an error oracle:
| Outcome | Message returned | Information leaked | |---------|------------------|--------------------| | ConnectError | "Could not connect..." | Host down or port closed | | TimeoutException | "Connection timed out..." | Host up, port filtered | | HTTP 401 | "Invalid access token..." | Service alive, requires auth | | HTTP 403 | "Access forbidden..." | Service alive, forbidden | | HTTP ≥ 400 | "Failed to connect: HTTP {N}" | Service alive, exact status |
An attacker can drive the flow programmatically: register a client via open DCR (POST /register), initiate authorization, extract a txnid, and submit arbitrary haurl values. No user interaction required.
Code path 2 — REST tool calls with forged token
OAuth access tokens are stateless base64-encoded JSON payloads ({"haurl": "...", "hatoken": "..."}). Since tokens are not signed, an attacker can forge a token with an arbitrary haurl. REST tool calls then make HTTP requests to hardcoded HA API paths on that host (/config, /states, /services, etc.). JSON responses are returned to the caller.
In practice, path control is limited — most endpoints use absolute paths that ignore the haurl path component. Useful exfiltration requires the target to return JSON at HA API paths, which is unlikely for non-HA services.
Code path 3 — WebSocket tool calls with forged token
The same forged token triggers WebSocket connections to ws://{haurl}/api/websocket. The client follows the HA WebSocket handshake protocol (waits for authrequired, sends auth, expects authok). Non-HA targets fail at the protocol level and return nothing useful. Realistic exploitation is limited to pivoting to another HA instance on the internal network.
Impact
Confirmed: Internal network reconnaissance via error oracle (all 3 code paths). An attacker can map reachable hosts and open ports from the server's network position.
Scope
OAuth mode is a beta feature, documented separately in docs/OAUTH.md and not part of the main setup instructions. The standard deployment method (pre-configured HOMEASSISTANTURL and HOMEASSISTANTTOKEN) is not affected.
Fix
Upgrade to 7.0.0