Summary
A path traversal flaw in Home Assistant Core's backup handling allows crafted backup archives to write files outside the intended backup directory during initial onboarding.
By abusing the backup name field to inject absolute paths, an unauthenticated attacker can cause arbitrary files to be written anywhere on the host filesystem, especially dangerous when Home Assistant runs as root.
Affected context
This vulnerability occurs in Home Assistant Core's backup restore logic during the initial onboarding period, when backups can be uploaded without prior authentication.
It affects environments where:
- Backup archives are accepted and processed from untrusted clients
- The backup metadata (e.g.,
backup.json) includes a user-suppliednamefield - That
nameis used to construct filesystem paths viapathlib.Pathwithout sufficient normalization or validation
Risk is amplified when the Home Assistant process has broad filesystem permissions, such as running as root or sharing host volumes.
Exploit preconditions
- Attack surface: Network-accessible Home Assistant instance exposed during the onboarding window
- Required access: No prior authentication; ability to submit a crafted backup archive to the onboarding endpoint
- Trigger point: Processing of
backup.jsonwithin the uploaded archive, where thenamefield is combined with the configured backup directory usingpathlib.Path.__truediv__ - Why exploitation is possible: The code trusts the
namevalue as a safe relative path, allowing absolute paths to override the configured backup directory and write attacker-controlled data to arbitrary locations on the host filesystem
Why this happens
The root cause is improper validation of user-controlled path components when constructing filesystem paths from backup metadata.
The backup restore logic combines a configured base backup directory with the name field from backup.json using pathlib.Path.__truediv__, assuming the result will remain within the intended directory.
However, when name is an absolute path, Path.__truediv__ discards the base directory and resolves to the attacker-specified location, leading to a classic CWE-22: Path Traversal scenario.
This pattern reflects a broader bug class where untrusted inputs are directly used in path construction without enforcing relative paths, canonicalization, or directory confinement checks.
Potential impact
- Overwriting or creating arbitrary files on the host filesystem
- Planting or modifying configuration files to alter Home Assistant behavior
- Dropping web templates, scripts, or other artifacts that may later be executed by other components
- Tampering with system or service files when running with elevated privileges, potentially leading to full host compromise
- Persisting malicious content in locations that survive application restarts or upgrades
General mitigation guidance
Effective mitigation focuses on strictly constraining filesystem paths derived from user input and tightening the onboarding attack surface.
Common defensive patterns include:
- Treating all backup metadata, including names, as untrusted and enforcing that they resolve to paths strictly under a predefined backup directory
- Normalizing and canonicalizing constructed paths, then validating that the final resolved path begins with the intended base directory before any filesystem operation
- Rejecting or sanitizing absolute paths and path elements such as
.., path separators, or device-specific prefixes in user-supplied fields - Using dedicated, least-privilege filesystem locations for backup import and restore, separated from critical system or configuration directories
- Running Home Assistant with reduced privileges and without full host filesystem access where possible, limiting the blast radius of any file-write issue
- Designing onboarding flows to minimize unauthenticated file-handling capabilities and to require explicit user confirmation for restore actions
How teams detect issues like this
Organizations can detect similar issues by focusing on how paths are built and validated in file-handling code:
- Static analysis patterns: Flag uses of
pathlib.Pathoros.pathwhere untrusted data is directly appended or joined to a base directory without subsequent canonicalization and boundary checks - Code review signals: Look for backup/restore, upload, and import paths where metadata fields like
name,filename, orpathare used as-is in filesystem operations - Runtime monitoring: Enable logging around backup imports, especially unexpected absolute paths or unusual directory targets, and alert on anomalies
- Policy enforcement: Establish secure coding guidelines requiring explicit path normalization and directory confinement checks for any feature that writes files based on client input
Automated code scanning tools and CI-integrated linters can be configured to highlight path concatenation patterns that lack validation, helping catch similar flaws early.

