BarkleyGitHub
Controls · SEC
Markdown file

Secrets

A secret is anything that lets someone act as you or as your users, such as a token, a password or a private key. Keep it in the user’s config entry or in GitHub’s encrypted secrets, and out of the code, the logs and diagnostics downloads.

From the 2026 sweepGitleaks found something that looks like a key in 907 apps, mostly in tests and docs. 58 have something that looks like a key in the code they ship, and most of them (41 of 58) are a vendor's own client key or certificate, the same for every user. The Marketplace report has more on this.

Controls

  1. SEC-1Level 1Ask users for credentials in the config flow, with a password field, and read them from the config entry. Don't hard-code your own account's keys into the app.

    config_flow.py
    from homeassistant.helpers.selector import (
        TextSelector, TextSelectorConfig, TextSelectorType,
    )
    
    STEP_USER = vol.Schema({
        vol.Required(CONF_USERNAME): str,
        vol.Required(CONF_PASSWORD): TextSelector(
            TextSelectorConfig(type=TextSelectorType.PASSWORD)
        ),
    })
  2. SEC-2Level 1Redact diagnostics and keep secrets out of logs. Users paste diagnostics into public issues.

    diagnostics.py
    from homeassistant.components.diagnostics import async_redact_data
    
    TO_REDACT = {CONF_PASSWORD, CONF_API_KEY, CONF_TOKEN, "serial_number"}
    
    async def async_get_config_entry_diagnostics(hass, entry):
        return {"entry": async_redact_data(entry.as_dict(), TO_REDACT)}
  3. SEC-3WithdrawnIgnore local secret files. Withdrawn on November 27, 2026, because two other controls cover it: REPO-3 ignores secret files in .gitignore, and CI-3 turns on push protection.

  4. SEC-4Level 2In CI, prefer no secret at all. Use the built-in GITHUB_TOKEN with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

  5. SEC-5Level 1If a secret leaks, revoke it first. Removing it from the history doesn't help, because clones, forks and caches already have a copy. Issue a new key, then clean up the history.

Check it worked

Download your integration's diagnostics with a real config entry and search the file for your password and token. Neither should appear.

Open the full page