CVE-2026-40602: Homeassistant cli Handling Of User-supplied Jinja2 Templates Vulnerability

MODERATE
Advisory Identifier: GHSA-33qf-q99x-wpm8
CVSS 5.6
CWE-94 CWE-1336
Published
Advisory Summary

CVE-2026-40602 is a MODERATE (CVSS 5.6) handling of user-supplied jinja2 templates vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Homeassistant cli libraries in the PyPI ecosystem. The issue involves handling of user-supplied jinja2 templates. Remediation is available by upgrading affected packages to version 1.0.0.

CVE-2026-40602 at a Glance

CVE Identifier CVE-2026-40602
GHSA Identifier GHSA-33qf-q99x-wpm8
Severity MODERATE
CVSS v3.1 Base Score 5.6
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Homeassistant cli
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.6

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:N).

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required High (PR:H)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2026-40602

To remediate this vulnerability, upgrade all affected Homeassistant cli dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

homeassistant-cli fixed: 1.0.0
pip install homeassistant-cli>=1.0.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show homeassistant-cli

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-40602, inspect your installed packages using pip:

pip show homeassistant-cli

Analyze the terminal output to locate any version of Homeassistant cli in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.0), your application is affected.

Note: The pip show homeassistant-cli command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Homeassistant cli, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact Up to 1.0.0 of `home-assitant-cli` (or `hass-cli` for short) an unrestricted environment was used to handle Jninja2 templates instead of a sandboxed one. The user-supplied input within Jinja2 templates was rendered locally with no restrictions. This gave users access to Python's internals and extended the scope of templating beyond the intended usage. E. g., it was possible to render a template with `hass-cli template bad-template.j2 --local` that contained entries like ````j2 {%- set b = environ.__globals__['__builtins__'] -%} {%- set os = b['__import__']('os') -%} {%- set bio = b['__import__']('builtins') -%} ... ```` or other malicious Jinja2 expressions. This can lead to arbitrary code execution on the local machine. In a two step process an adversary could trick/convince an user to download third-party templates which contain harmful code (e. g., perform data manipulation or establish a remote shell) then to render those templates unchecked/reviewed/verified with `--local`. The issue only affect the local machine and not a remote Home Assistant instance. It also requires user interventions. ### Patches 1.0.0 uses `ImmutableSandboxedEnvironment` and restricts the usage of environment variables. ### Workarounds Evaluate the Jninja2 templates manually or tool-based before rendering with `hass-cli`.

CVE-2026-40602 Affected Homeassistant cli Versions

1 component(s)
Fixed Versions:
1.0.0
Product / Package Ecosystem Affected Versions Fixed Version
homeassistant-cli
PyPI
< 1.0.0
1.0.0

References

Frequently Asked Questions

What is CVE-2026-40602?
CVE-2026-40602 is a security vulnerability in Homeassistant cli involving Handling of user-supplied Jinja2 templates under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Homeassistant cli versions are affected?
Affected versions include releases prior to 1.0.0 across affected packages: homeassistant-cli.
What version fixes CVE-2026-40602?
Upgrading to 1.0.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is homeassistant-cli affected?
Yes, homeassistant-cli is affected in releases prior to 1.0.0. Upgrade your dependency to 1.0.0 or later.
What is the CVSS score of CVE-2026-40602?
CVE-2026-40602 has a CVSS v3.1 base score of 5.6 (MODERATE) with vector string CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2026-40602?
CVE-2026-40602 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check PyPI dependencies for CVE-2026-40602?
Run the dependency tree command: 'pip show homeassistant-cli'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-33qf-q99x-wpm8",
  "modified" : "2026-04-27T16:15:58Z",
  "published" : "2026-04-16T21:28:39Z",
  "aliases" : [ "CVE-2026-40602" ],
  "summary" : "Home Assistant Command-line Interface: Handling of user-supplied Jinja2 templates",
  "details" : "### Impact\n\nUp to 1.0.0 of `home-assitant-cli` (or `hass-cli` for short) an unrestricted environment was used to handle Jninja2 templates instead of a sandboxed one. The user-supplied input within Jinja2 templates was rendered locally with no restrictions. This gave users access to Python's internals and extended the scope of templating beyond the intended usage.\n\nE. g., it was possible to render a template with `hass-cli template bad-template.j2 --local` that contained entries like\n\n````j2\n{%- set b   = environ.__globals__['__builtins__'] -%}\n{%- set os  = b['__import__']('os') -%}\n{%- set bio = b['__import__']('builtins') -%}\n...\n````\n\nor other malicious Jinja2 expressions. This can lead to arbitrary code execution on the local machine.\n\nIn a two step process an adversary could trick/convince an user to download third-party templates which contain harmful code (e. g., perform data manipulation or establish a remote shell)  then to render those templates unchecked/reviewed/verified with `--local`. \n\nThe issue only affect the local machine and not a remote Home Assistant instance. It also requires user interventions.\n\n### Patches\n\n1.0.0 uses `ImmutableSandboxedEnvironment` and restricts the usage of environment variables.\n\n### Workarounds\n\nEvaluate the Jninja2 templates manually or  tool-based before rendering with `hass-cli`.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "homeassistant-cli"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/home-assistant-ecosystem/home-assistant-cli/security/advisories/GHSA-33qf-q99x-wpm8"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-40602"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/home-assistant-ecosystem/home-assistant-cli/pull/453"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/home-assistant-ecosystem/home-assistant-cli"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1336", "CWE-94" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-16T21:28:39Z",
    "nvd_published_at" : "2026-04-21T18:16:51Z"
  }
}