# Integrations

A custom integration runs inside Home Assistant's own Python process and can reach every device, token and file in the config folder. Home Assistant has helpers for logins, storage and web requests, and using them is safer than writing your own.

Source: https://ha-barkley.github.io/security/controls/integrations/

From HASC, the Home Assistant Security Controls for integrations, cards and apps. A community catalog, not an official Home Assistant or Open Home Foundation project.

Each control has an ID, cited as HASC-CI-4, and a level from 1 to 3. "Level marker" means anyone can check the control from outside the project, and levels are graded on those controls only.

> **From the 2026 sweep.** 235 integrations add at least one page that opens without logging in to Home Assistant. 69 install a Python package version with a known vulnerability. The [Marketplace report](https://ha-barkley.github.io/marketplace/2026/malware-and-ways-in/) has more on this.

These steps apply only if you publish an integration.

## Controls

### INT-1: Never fetch code at run time

*Level 1 · Applies to integrations*

Don't run `pip install` from inside the integration, and don't download a script and run it. List packages in `manifest.json` with exact versions, and Home Assistant installs them.

`manifest.json (part)`

```
"requirements": ["examplelib==2.4.1"]
```

### INT-2: Keep the login on every page you add

*Level 1 · Applies to integrations*

`HomeAssistantView` requires a login unless you turn it off. Only turn it off when the situation calls for it and none of these safer options fits:

- For calls from a device or a cloud service, use a webhook. It uses an id nobody can guess and can be limited to the local network.
- For a link to something that can't log in, like a speaker playing a sound or an image in a notification, use a signed path from `async_sign_path`. The page keeps its login check, and the link expires.
- For signing in to a cloud account, use Home Assistant's OAuth2 config flow helper (`config_entry_oauth2_flow`), which provides the redirect page for you.
- For your card's or panel's JavaScript, use `hass.http.async_register_static_paths`. These files load without a login by design, so put code in them and keep data out.

`Do webhook for inbound calls`

```
from homeassistant.components import webhook

webhook.async_register(
    hass, DOMAIN, "Example device",
    entry.data[CONF_WEBHOOK_ID], handle_webhook,
    local_only=True,
)
```

`Don't a page with the login turned off for no reason`

```
class StatusView(HomeAssistantView):
    url = "/api/example/status"
    name = "api:example:status"
    requires_auth = False   # anyone on the network
```

If you do turn the login off, return nothing sensitive from that page, and check any token or signature yourself in the handler. Create a webhook id in the config flow with `webhook.async_generate_id()`.

### INT-3: Save settings and state with the storage helper, and never with pickle

*Level 1 · Applies to integrations*

The helper writes JSON safely, versions it, and keeps it where backups find it. Loading a pickle file runs any code inside it, so anything that can write that file can run code in Home Assistant.

For other kinds of data: large or binary files (images, firmware, models) go in plain files in your own folder, many records you query go in SQLite, and history belongs in entities, which the recorder already keeps.

`__init__.py`

```
from homeassistant.helpers.storage import Store

store = Store(hass, 1, f"{DOMAIN}.cache")
data = await store.async_load() or {}
await store.async_save(data)
```

### INT-4: Use Home Assistant's shared web session

*Level 1 · Applies to integrations*

**Use Home Assistant's shared web session** with certificate checks on. Only offer "don't verify SSL" for local devices with self-signed certificates, and default it to off.

`coordinator.py`

```
from homeassistant.helpers.aiohttp_client import async_get_clientsession

session = async_get_clientsession(hass)
```

### INT-5: Avoid the calls that turn data into code

*Level 1 · Applies to integrations*

`pickle.load`, `eval`, `exec`, `yaml.load` without a safe loader, and `subprocess` with `shell=True`.

### INT-6: Send each credential only to its own service

*Level 1 · Applies to integrations*

A Supervisor token goes to the Supervisor, a user's cloud token goes to that cloud, and nothing goes to your own server unless the README says so.

### Check it worked

With Home Assistant running, open each page your integration adds in a private browser window. Every one should ask you to log in, or answer 401, except the ones you opened on purpose for a reason above.

Barkley flags pages that skip the login, credentials sent somewhere other than their owner, code downloaded and run, pickle of stored data, and libraries with known vulnerabilities.
