T09 · Insecure Skill Coding Practices
- Location
scripts/ha_control.py:23- Finding
Unrestricted Authenticated Home Assistant Service Invocation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ha_control.py, lines 23-34 and 67-70
Vulnerability Type: Missing allowlist and insufficient input validation
Risk Level: HighVulnerable Code
python def call_service(entity_id, service, data=None): """Call Home Assistant service""" url = f"{HA_URL}/api/services/{service}" headers = { "Authorization": f"Bearer {HA_TOKEN}", "Content-Type": "application/json" } payload = {"entity_id": entity_id} if data: payload.update(data)python entity_id = sys.argv[1] service = sys.argv[2] data = json.loads(sys.argv[3]) if len(sys.argv) > 3 else None success = call_service(entity_id, service, data)Technical Analysis
The script accepts the Home Assistant service path, entity identifier, and arbitrary JSON fields directly from command-line arguments. It performs no allowlist validation for permitted services or entities and does not validate the schema, type, range, or names of additional payload fields.
Although the Skill is documented as a controller for specific Xiaomi speakers and air conditioners, the implementation can invoke any Home Assistant service accessible to the configured bearer token. The supplied
servicevalue is interpolated directly into the API endpoint, while caller-controlled JSON is merged into the authenticated request body.This is not operating-system command injection, because the values are not passed to a shell. The security issue is excessive API authority: the generic authenticated service-call primitive exposes substantially more functionality than the Skill's declared purpose.
Attack Path
- An attacker or untrusted caller gains the ability to invoke
ha_control.py. - The caller supplies an entity outside the documented Xiaomi device list.
- The caller supplies a Home Assistant service associated with that entity or another privileged integration.
- The caller optionally prov ...[truncated 1144 chars]
- An attacker or untrusted caller gains the ability to invoke
- Remediation
View remediation
Remediation Suggestions
- Define an explicit allowlist of permitted entity and service combinations. For example, only allow the documented Xiaomi entity IDs with their required services.
- Reject any entity or service that is not present in the allowlist.
- Define a strict payload schema for each operation:
- Require text values to be strings with a reasonable maximum length.
- Restrict air-conditioner temperatures to the documented range of 16–30°C.
- Restrict mode options to
Auto,Cool,Heat,Dry, orFan. - Reject unknown payload fields.
- Do not expose a generic service path to callers. Map high-level actions such as
turn_ac_offto fixed internal service and entity values. - Use a dedicated, least-privileged Home Assistant account or token whose permissions are limited to the required entities.
- Log security-relevant validation failures without logging the bearer token or sensitive command content.
- Require explicit user confirmation for safety-sensitive physical actions where appropriate.
