Summary
The Home Assistant Companion apps for Android and iOS expose a powerful JavaScript bridge to all frames inside an in‑app WebView, including cross‑origin iframes.
Due to flawed frame scoping and unsanitized interpolation of callback identifiers, a malicious iframe can execute arbitrary JavaScript in the Home Assistant frontend's origin and exfiltrate the signed‑in user's access token.
Affected context
This issue affects Home Assistant Companion mobile applications that embed the Home Assistant frontend in a WebView and expose native functionality through JavaScript bridges:
- Android:
window.externalApp - iOS:
webkit.messageHandlers.getExternalAuth,revokeExternalAuth, andexternalBus
The vulnerability appears when:
- The bridge is accessible from all frames rather than being restricted to the top‑level origin, and
- The JavaScript callback identifier is interpolated into script without proper validation or escaping.
Under these conditions, any cross‑origin iframe rendered in the Companion app's WebView can interact with the bridge and influence code execution in the main‑frame origin context.
Exploit preconditions
- Attack surface: In‑app WebView in the Home Assistant Companion mobile apps.
- Required access:
- Ability to cause the app to load or embed attacker‑controlled web content (e.g., by visiting a malicious URL, injecting an iframe via a linked page, or exploiting another web content injection vector).
- The victim must be logged into Home Assistant via the Companion app.
- Trigger point:
- A cross‑origin iframe is rendered inside the WebView.
- The iframe invokes the exposed JavaScript bridge and leverages unsanitized callback identifier interpolation.
- Why exploitation is possible:
- The JavaScript bridge is not restricted to the trusted top‑level origin and is instead exposed to all frames, including cross‑origin iframes (CWE-749, CWE-940).
- The callback identifier from untrusted content is directly embedded into JavaScript context without sanitization or strict validation, enabling script injection (CWE-94).
- Origin and frame checks are insufficient to prevent untrusted frames from invoking privileged bridge methods (CWE-346).
Why this happens
The core problem lies in how the Companion apps expose native capabilities to web content via JavaScript bridges inside a WebView.
On both Android and iOS, bridge methods meant for trusted first‑party pages are:
- Bound too broadly, allowing all frames to access them rather than limiting access to the top‑level, same‑origin frame (CWE-749: Exposed Dangerous Method or Function; CWE-940: Improper Verification of Source of a Communication Channel).
- Implemented with a design that interpolates a JavaScript callback identifier from web content into executable script without strict validation or escaping, effectively treating untrusted input as code (CWE-94: Improper Control of Generation of Code).
Additionally, origin or trust checks are either missing or insufficiently enforced within the bridge, so the code does not reliably confirm that calls originate from the expected Home Assistant frontend origin (CWE-346: Origin Validation Error). Together, these patterns allow cross‑origin iframes to execute logic in the privileged main‑frame context and access sensitive data like the user's access token.
Potential impact
- Theft of the Home Assistant user's access token from the frontend running in the WebView.
- Account takeover by using the stolen token to impersonate the user against the Home Assistant instance.
- Unauthorized control of connected smart home devices via the compromised account.
- Modification of automation rules, device states, or configurations under the victim's identity.
- Potential pivot into the broader home network if additional services trust the Home Assistant instance or its tokens.
General mitigation guidance
Effective mitigation focuses on reducing the trust placed in embedded web content and strictly scoping JavaScript bridges:
- Restrict bridge exposure to trusted contexts:
- Bind JavaScript interfaces only to the top‑level, same‑origin document rather than all frames.
- Enforce strict origin and frame checks in every bridge handler before performing sensitive actions.
- Treat all callback identifiers and parameters as untrusted input:
- Avoid constructing JavaScript strings from untrusted values.
- Use structured messaging (e.g., JSON messages) instead of code generation patterns, and validate identifiers against a whitelist or well‑defined schema.
- Adopt a least‑privilege API surface:
- Expose only the minimal set of native methods required for the app to function.
- Separate sensitive capabilities (such as token access) from general messaging pathways.
- Harden WebView usage:
- Disable or limit JavaScript execution where not strictly necessary.
- Avoid rendering arbitrary external content inside the same WebView that has access to privileged bridges.
- Design for secure authentication handling:
- Avoid long‑lived or overly powerful tokens where possible.
- Isolate token handling in native code and avoid exposing it directly to web content.
How teams detect issues like this
Detection strategies generally aim to surface risky bridging patterns and origin validation weaknesses:
- Static analysis and linting:
- Search for WebView bindings that expose JavaScript interfaces broadly (e.g.,
addJavascriptInterfaceon Android,WKScriptMessageHandleron iOS) without origin checks. - Flag dynamic construction of JavaScript strings using untrusted data, especially in callbacks or bridge handlers.
- Code review practices:
- Review all WebView and JavaScript bridge usage with a security lens, focusing on origin enforcement and frame scoping.
- Confirm that any method granting access to tokens, authentication state, or sensitive device operations is guarded by origin validation and explicit authorization checks.
- Policy enforcement:
- Establish internal guidelines stating that WebViews must not load arbitrary external content when a privileged bridge is present.
- Require security sign‑off for any feature that exposes native functionality to web content.
- Dynamic testing:
- Use manual or automated tests to inject cross‑origin iframes into pages rendered by the Companion app and attempt to call bridge methods.
- Instrument the app to log and monitor WebView script messages, looking for unexpected origins or frame contexts invoking the bridge.

