CWE-22
Allowed-with-ReviewImproper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Abstraction: Base · Status: Stable
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.
13235 vulnerabilities reference this CWE, most recent first.
GHSA-6GXG-HJ4J-68Q6
Vulnerability from github – Published: 2023-07-20 21:30 – Updated: 2024-04-04 06:18Office Suite Premium v10.9.1.42602 was discovered to contain a local file inclusion (LFI) vulnerability via the component /etc/hosts.
{
"affected": [],
"aliases": [
"CVE-2023-37601"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2023-07-20T19:15:10Z",
"severity": "HIGH"
},
"details": "Office Suite Premium v10.9.1.42602 was discovered to contain a local file inclusion (LFI) vulnerability via the component /etc/hosts.",
"id": "GHSA-6gxg-hj4j-68q6",
"modified": "2024-04-04T06:18:00Z",
"published": "2023-07-20T21:30:58Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2023-37601"
},
{
"type": "WEB",
"url": "https://packetstormsecurity.com/files/173146/Office-Suite-Premium-10.9.1.42602-Local-File-Inclusion.html"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N",
"type": "CVSS_V3"
}
]
}
GHSA-6H2C-G688-Q9QR
Vulnerability from github – Published: 2022-03-30 00:00 – Updated: 2022-04-07 21:54Jenkins Pipeline: Phoenix AutoTest Plugin 1.3 and earlier allows attackers with Item/Configure permission to copy arbitrary files and directories from the Jenkins controller to the agent workspace.
{
"affected": [
{
"package": {
"ecosystem": "Maven",
"name": "com.surenpi.jenkins:phoenix-autotest"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"last_affected": "1.3"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2022-28156"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": true,
"github_reviewed_at": "2022-04-07T21:54:34Z",
"nvd_published_at": "2022-03-29T13:15:00Z",
"severity": "MODERATE"
},
"details": "Jenkins Pipeline: Phoenix AutoTest Plugin 1.3 and earlier allows attackers with Item/Configure permission to copy arbitrary files and directories from the Jenkins controller to the agent workspace.",
"id": "GHSA-6h2c-g688-q9qr",
"modified": "2022-04-07T21:54:34Z",
"published": "2022-03-30T00:00:24Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-28156"
},
{
"type": "WEB",
"url": "https://www.jenkins.io/security/advisory/2022-03-29/#SECURITY-2683"
},
{
"type": "WEB",
"url": "http://www.openwall.com/lists/oss-security/2022/03/29/1"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N",
"type": "CVSS_V3"
}
],
"summary": "Path traversal in Jenkins Phoenix AutoTest Plugin"
}
GHSA-6H2F-WJHF-4WJX
Vulnerability from github – Published: 2025-12-10 20:21 – Updated: 2025-12-11 15:51Summary
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):
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):
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:
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:
#!/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:
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
- The PoC uses the exact same logic as the vulnerable code in
download_media.pyandclient.py - The malicious filename
../../../tmp/malicious_filecauses the path to escape from/tmp/tmpXXX/downloads/to/tmp/malicious_file - Python's
os.path.join()andos.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
- Attacker must be able to send messages to the victim's bot/account
- Victim must download the media without specifying a custom filename
- 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:
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.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 2.3.68"
},
"package": {
"ecosystem": "PyPI",
"name": "pyrofork"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "2.3.69"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2025-67720"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": true,
"github_reviewed_at": "2025-12-10T20:21:54Z",
"nvd_published_at": "2025-12-11T02:16:19Z",
"severity": "MODERATE"
},
"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\u0027s `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\u0027s 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\u0027t 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\u0027s `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\u0027s 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(\u0027\\x00\u0027, \u0027\u0027)\n # Handle edge cases\n if not file_name or file_name in (\u0027.\u0027, \u0027..\u0027):\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.",
"id": "GHSA-6h2f-wjhf-4wjx",
"modified": "2025-12-11T15:51:44Z",
"published": "2025-12-10T20:21:54Z",
"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"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N",
"type": "CVSS_V3"
}
],
"summary": "Pyrofork has a Path Traversal in download_media Method"
}
GHSA-6H2P-2F7R-XQ55
Vulnerability from github – Published: 2022-05-17 05:23 – Updated: 2025-04-11 04:00Directory traversal vulnerability in Caucho Quercus, as distributed in Resin before 4.0.29, allows remote attackers to create files in arbitrary directories via a .. (dot dot) in a pathname within an HTTP request.
{
"affected": [],
"aliases": [
"CVE-2012-2968"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2012-08-12T16:55:00Z",
"severity": "MODERATE"
},
"details": "Directory traversal vulnerability in Caucho Quercus, as distributed in Resin before 4.0.29, allows remote attackers to create files in arbitrary directories via a .. (dot dot) in a pathname within an HTTP request.",
"id": "GHSA-6h2p-2f7r-xq55",
"modified": "2025-04-11T04:00:25Z",
"published": "2022-05-17T05:23:56Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2012-2968"
},
{
"type": "WEB",
"url": "http://caucho.com/resin-4.0/changes/changes.xtp"
},
{
"type": "WEB",
"url": "http://en.securitylab.ru/lab"
},
{
"type": "WEB",
"url": "http://en.securitylab.ru/lab/PT-2012-05"
},
{
"type": "WEB",
"url": "http://www.kb.cert.org/vuls/id/309979"
}
],
"schema_version": "1.4.0",
"severity": []
}
GHSA-6H3G-375J-8GV3
Vulnerability from github – Published: 2022-05-24 16:59 – Updated: 2024-04-04 02:33An issue was discovered on Xiaomi Mi WiFi R3G devices before 2.28.23-stable. There is a directory traversal vulnerability to read arbitrary files via a misconfigured NGINX alias, as demonstrated by api-third-party/download/extdisks../etc/config/account. With this vulnerability, the attacker can bypass authentication.
{
"affected": [],
"aliases": [
"CVE-2019-18371"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2019-10-23T21:15:00Z",
"severity": "HIGH"
},
"details": "An issue was discovered on Xiaomi Mi WiFi R3G devices before 2.28.23-stable. There is a directory traversal vulnerability to read arbitrary files via a misconfigured NGINX alias, as demonstrated by api-third-party/download/extdisks../etc/config/account. With this vulnerability, the attacker can bypass authentication.",
"id": "GHSA-6h3g-375j-8gv3",
"modified": "2024-04-04T02:33:45Z",
"published": "2022-05-24T16:59:47Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2019-18371"
},
{
"type": "WEB",
"url": "https://github.com/UltramanGaia/Xiaomi_Mi_WiFi_R3G_Vulnerability_POC/blob/master/arbitrary_file_read_vulnerability.py"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N",
"type": "CVSS_V3"
}
]
}
GHSA-6H3M-36W8-HV68
Vulnerability from github – Published: 2022-03-10 22:07 – Updated: 2022-03-24 00:21(This document is canonically: https://advisories.nats.io/CVE/CVE-2022-26652.txt)
Background
NATS.io is a high performance open source pub-sub distributed communication technology, built for the cloud, on-premise, IoT, and edge computing.
JetStream is the optional RAFT-based resilient persistent feature of NATS.
Problem Description
The JetStream streams can be backed up and restored via NATS. The backup format is a tar archive file. Inadequate checks on the filenames within the archive file permit a so-called "Zip Slip" attack in the stream restore.
NATS nats-server through 2022-03-09 (fixed in release 2.7.4) did not correctly sanitize elements of the archive file, thus a user of NATS could cause the NATS server to write arbitrary content to an attacker-controlled filename.
Affected versions
NATS Server: * 2.2.0 up to and including 2.7.3. + Introduced with JetStream Restore functionality * Fixed with nats-io/nats-server: 2.7.4 * Docker image: nats https://hub.docker.com/_/nats * NB users of OS package files from our releases: a change in goreleaser defaults, discovered late in the release process, moved the install directory from /usr/local/bin to /usr/bin; we are evaluating the correct solution for subsequent releases, but not recutting this release.
NATS Streaming Server * 0.15.0 up to and including 0.24.2 * Fixed with nats-io/nats-streaming-server: 0.24.3 * Embeds a nats-server, but this server is the old approach which JetStream replaces, so unlikely (but not impossible) to be configured with JS support
Workarounds
- Disable JetStream for untrusted users.
- If only one NATS account uses JetStream, such that cross-user attacks are not an issue, and any user in that account with access to the JetStream API is fully trusted anyway, then appropriate sandboxing techniques will prevent exploit.
- Eg, with systemd, the supplied util/nats-server-hardened.service example configuration demonstrates that NATS runs fine as an unprivileged user under ProtectSystem=strict and PrivateTmp=true restrictions; by only opening a ReadWritePaths hole for the JetStream storage area, the impact of this vulnerability is limited.
Solution
Upgrade the NATS server to at least 2.7.4.
We fully support the util/nats-server-hardened.service configuration for running a NATS server and encourage this approach.
Credits
This issue was reported (on 2022-03-07) to the NATS Maintainers by
Yiming Xiang, TIANJI LAB of NSFOCUS.
Thank you / 谢谢你!
{
"affected": [
{
"package": {
"ecosystem": "Go",
"name": "github.com/nats-io/nats-server/v2"
},
"ranges": [
{
"events": [
{
"introduced": "2.2.0"
},
{
"fixed": "2.7.4"
}
],
"type": "ECOSYSTEM"
}
]
},
{
"package": {
"ecosystem": "Go",
"name": "github.com/nats-io/nats-streaming-server"
},
"ranges": [
{
"events": [
{
"introduced": "0.15.0"
},
{
"fixed": "0.24.3"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2022-26652"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": true,
"github_reviewed_at": "2022-03-10T22:07:30Z",
"nvd_published_at": "2022-03-10T17:47:00Z",
"severity": "HIGH"
},
"details": "(This document is canonically: \u003chttps://advisories.nats.io/CVE/CVE-2022-26652.txt\u003e)\n\n## Background\n\nNATS.io is a high performance open source pub-sub distributed communication technology, built for the cloud, on-premise, IoT, and edge computing.\n\nJetStream is the optional RAFT-based resilient persistent feature of NATS.\n\n\n## Problem Description\n\nThe JetStream streams can be backed up and restored via NATS. The backup format is a tar archive file. Inadequate checks on the filenames within the archive file permit a so-called \"Zip Slip\" attack in the stream restore.\n\nNATS nats-server through 2022-03-09 (fixed in release 2.7.4) did not correctly sanitize elements of the archive file, thus a user of NATS\ncould cause the NATS server to write arbitrary content to an attacker-controlled filename.\n\n\n## Affected versions\n\nNATS Server:\n * 2.2.0 up to and including 2.7.3.\n + Introduced with JetStream Restore functionality\n * Fixed with nats-io/nats-server: 2.7.4\n * Docker image: nats \u003chttps://hub.docker.com/_/nats\u003e\n * NB users of OS package files from our releases: a change in goreleaser defaults, discovered late in the release process, moved the install directory from /usr/local/bin to /usr/bin; we are evaluating the correct solution for subsequent releases, but not recutting this release.\n\nNATS Streaming Server\n * 0.15.0 up to and including 0.24.2\n * Fixed with nats-io/nats-streaming-server: 0.24.3\n * Embeds a nats-server, but this server is the old approach which JetStream replaces, so unlikely (but not impossible) to be\n configured with JS support\n\n\n## Workarounds\n\n * Disable JetStream for untrusted users.\n * If only one NATS account uses JetStream, such that cross-user attacks are not an issue, and any user in that account with access to the JetStream API is fully trusted anyway, then appropriate sandboxing techniques will prevent exploit.\n + Eg, with systemd, the supplied util/nats-server-hardened.service example configuration demonstrates that NATS runs fine as an unprivileged user under ProtectSystem=strict and PrivateTmp=true restrictions; by only opening a ReadWritePaths hole for the JetStream storage area, the impact of this vulnerability is limited.\n\n\n## Solution\n\nUpgrade the NATS server to at least 2.7.4.\n\nWe fully support the util/nats-server-hardened.service configuration for running a NATS server and encourage this approach.\n\n\n## Credits\n\nThis issue was reported (on 2022-03-07) to the NATS Maintainers by\nYiming Xiang, TIANJI LAB of NSFOCUS. \nThank you / \u8c22\u8c22\u4f60\uff01\n",
"id": "GHSA-6h3m-36w8-hv68",
"modified": "2022-03-24T00:21:10Z",
"published": "2022-03-10T22:07:30Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/nats-io/nats-server/security/advisories/GHSA-6h3m-36w8-hv68"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-26652"
},
{
"type": "WEB",
"url": "https://github.com/nats-io/nats-server/pull/2917"
},
{
"type": "WEB",
"url": "https://advisories.nats.io/CVE/CVE-2022-26652.txt"
},
{
"type": "PACKAGE",
"url": "https://github.com/nats-io/nats-server"
},
{
"type": "WEB",
"url": "https://github.com/nats-io/nats-server/releases"
},
{
"type": "WEB",
"url": "https://github.com/nats-io/nats-server/releases/tag/v2.7.4"
},
{
"type": "WEB",
"url": "https://github.com/nats-io/nats-streaming-server/releases/tag/v0.24.3"
},
{
"type": "WEB",
"url": "http://www.openwall.com/lists/oss-security/2022/03/10/1"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N",
"type": "CVSS_V3"
}
],
"summary": "Arbitrary file write in nats-server"
}
GHSA-6H3X-V824-M53P
Vulnerability from github – Published: 2022-02-25 00:00 – Updated: 2022-03-05 00:00A Directory Traversal vulnerability exists in the Xerte Project Xerte through 3.10.3 when downloading a project file via download.php.
{
"affected": [],
"aliases": [
"CVE-2021-44665"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2022-02-24T21:15:00Z",
"severity": "MODERATE"
},
"details": "A Directory Traversal vulnerability exists in the Xerte Project Xerte through 3.10.3 when downloading a project file via download.php.",
"id": "GHSA-6h3x-v824-m53p",
"modified": "2022-03-05T00:00:57Z",
"published": "2022-02-25T00:00:56Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-44665"
},
{
"type": "WEB",
"url": "https://github.com/thexerteproject/xerteonlinetoolkits/commit/48a9880c6ac38f4d215f9143baf3d6e6062a1871"
},
{
"type": "WEB",
"url": "http://packetstormsecurity.com/files/166181/Xerte-3.10.3-Directory-Traversal.html"
}
],
"schema_version": "1.4.0",
"severity": []
}
GHSA-6H4Q-63C5-QFQF
Vulnerability from github – Published: 2024-01-13 06:30 – Updated: 2024-01-24 21:53An issue was discovered in the flaskcode package through 0.0.8 for Python. An unauthenticated directory traversal, exploitable with a GET request to a /resource-data/.txt URI (from views.py), allows attackers to read arbitrary files.
{
"affected": [
{
"package": {
"ecosystem": "PyPI",
"name": "flaskcode"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"last_affected": "0.0.8"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2023-52288"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": true,
"github_reviewed_at": "2024-01-24T21:53:25Z",
"nvd_published_at": "2024-01-13T04:15:08Z",
"severity": "HIGH"
},
"details": "An issue was discovered in the flaskcode package through 0.0.8 for Python. An unauthenticated directory traversal, exploitable with a GET request to a /resource-data/\u003cfile_path\u003e.txt URI (from views.py), allows attackers to read arbitrary files.",
"id": "GHSA-6h4q-63c5-qfqf",
"modified": "2024-01-24T21:53:25Z",
"published": "2024-01-13T06:30:26Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2023-52288"
},
{
"type": "WEB",
"url": "https://gitlab.com/daniele_m/cve-list/-/blob/main/README.md"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N",
"type": "CVSS_V3"
}
],
"summary": "Path traversal in flaskcode"
}
GHSA-6H58-C7R7-G2HW
Vulnerability from github – Published: 2022-05-14 01:10 – Updated: 2023-08-16 22:23The UberFire Framework 0.3.x does not properly restrict paths, which allows remote attackers to (1) execute arbitrary code by uploading crafted content to FileUploadServlet or (2) read arbitrary files via vectors involving FileDownloadServlet.
{
"affected": [
{
"package": {
"ecosystem": "Maven",
"name": "org.uberfire:uberfire-parent"
},
"ranges": [
{
"events": [
{
"introduced": "0.3.0.Beta5"
},
{
"last_affected": "0.3.1.Final"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2014-8114"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": true,
"github_reviewed_at": "2023-08-16T22:23:43Z",
"nvd_published_at": "2015-02-20T16:59:00Z",
"severity": "MODERATE"
},
"details": "The UberFire Framework 0.3.x does not properly restrict paths, which allows remote attackers to (1) execute arbitrary code by uploading crafted content to FileUploadServlet or (2) read arbitrary files via vectors involving FileDownloadServlet.",
"id": "GHSA-6h58-c7r7-g2hw",
"modified": "2023-08-16T22:23:43Z",
"published": "2022-05-14T01:10:41Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2014-8114"
},
{
"type": "WEB",
"url": "https://github.com/uberfire/uberfire/commit/21ec50eb15"
},
{
"type": "WEB",
"url": "https://web.archive.org/web/20200227080813/http://www.securityfocus.com/bid/88199"
},
{
"type": "WEB",
"url": "http://rhn.redhat.com/errata/RHSA-2015-0234.html"
},
{
"type": "WEB",
"url": "http://rhn.redhat.com/errata/RHSA-2015-0235.html"
}
],
"schema_version": "1.4.0",
"severity": [],
"summary": "UberFire Framework Improperly Restricts Paths"
}
GHSA-6H5G-5JJX-PMV8
Vulnerability from github – Published: 2024-06-04 15:30 – Updated: 2024-06-04 15:30Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') vulnerability in Wow-Company Woocommerce – Recent Purchases allows PHP Local File Inclusion.This issue affects Woocommerce – Recent Purchases: from n/a through 1.0.1.
{
"affected": [],
"aliases": [
"CVE-2024-35634"
],
"database_specific": {
"cwe_ids": [
"CWE-22"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2024-06-04T14:15:12Z",
"severity": "MODERATE"
},
"details": "Improper Limitation of a Pathname to a Restricted Directory (\u0027Path Traversal\u0027) vulnerability in Wow-Company Woocommerce \u2013 Recent Purchases allows PHP Local File Inclusion.This issue affects Woocommerce \u2013 Recent Purchases: from n/a through 1.0.1.",
"id": "GHSA-6h5g-5jjx-pmv8",
"modified": "2024-06-04T15:30:58Z",
"published": "2024-06-04T15:30:58Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-35634"
},
{
"type": "WEB",
"url": "https://patchstack.com/database/vulnerability/woo-recent-purchases/woocommerce-recent-purchases-plugin-1-0-1-file-inclusion-vulnerability?_s_id=cve"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:N/A:N",
"type": "CVSS_V3"
}
]
}
Mitigation MIT-5.1
Strategy: Input Validation
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does.
- When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue."
- Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
- When validating filenames, use stringent allowlists that limit the character set to be used. If feasible, only allow a single "." character in the filename to avoid weaknesses such as CWE-23, and exclude directory separators such as "/" to avoid CWE-36. Use a list of allowable file extensions, which will help to avoid CWE-434.
- Do not rely exclusively on a filtering mechanism that removes potentially dangerous characters. This is equivalent to a denylist, which may be incomplete (CWE-184). For example, filtering "/" is insufficient protection if the filesystem also supports the use of "\" as a directory separator. Another possible error could occur when the filtering is applied in a way that still produces dangerous data (CWE-182). For example, if "../" sequences are removed from the ".../...//" string in a sequential fashion, two instances of "../" would be removed from the original string, but the remaining characters would still form the "../" string.
Mitigation MIT-15
For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
Mitigation MIT-20.1
Strategy: Input Validation
- Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked.
- Use a built-in path canonicalization function (such as realpath() in C) that produces the canonical version of the pathname, which effectively removes ".." sequences and symbolic links (CWE-23, CWE-59). This includes:
- realpath() in C
- getCanonicalPath() in Java
- GetFullPath() in ASP.NET
- realpath() or abs_path() in Perl
- realpath() in PHP
Mitigation MIT-4
Strategy: Libraries or Frameworks
Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482].
Mitigation MIT-29
Strategy: Firewall
Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth [REF-1481].
Mitigation MIT-17
Strategy: Environment Hardening
Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
Mitigation MIT-21.1
Strategy: Enforcement by Conversion
- When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
- For example, ID 1 could map to "inbox.txt" and ID 2 could map to "profile.txt". Features such as the ESAPI AccessReferenceMap [REF-185] provide this capability.
Mitigation MIT-22
Strategy: Sandbox or Jail
- Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software.
- OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations.
- This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise.
- Be careful to avoid CWE-243 and other weaknesses related to jails.
Mitigation MIT-34
Strategy: Attack Surface Reduction
- Store library, include, and utility files outside of the web document root, if possible. Otherwise, store them in a separate directory and use the web server's access control capabilities to prevent attackers from directly requesting them. One common practice is to define a fixed constant in each calling program, then check for the existence of the constant in the library/include file; if the constant does not exist, then the file was directly requested, and it can exit immediately.
- This significantly reduces the chance of an attacker being able to bypass any protection mechanisms that are in the base program but not in the include files. It will also reduce the attack surface.
Mitigation MIT-39
- Ensure that error messages only contain minimal details that are useful to the intended audience and no one else. The messages need to strike the balance between being too cryptic (which can confuse users) or being too detailed (which may reveal more than intended). The messages should not reveal the methods that were used to determine the error. Attackers can use detailed information to refine or optimize their original attack, thereby increasing their chances of success.
- If errors must be captured in some detail, record them in log messages, but consider what could occur if the log messages can be viewed by attackers. Highly sensitive information such as passwords should never be saved to log files.
- Avoid inconsistent messaging that might accidentally tip off an attacker about internal state, such as whether a user account exists or not.
- In the context of path traversal, error messages which disclose path information can help attackers craft the appropriate attack strings to move through the file system hierarchy.
Mitigation MIT-16
Strategy: Environment Hardening
When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.
CAPEC-126: Path Traversal
An adversary uses path manipulation methods to exploit insufficient input validation of a target to obtain access to data that should be not be retrievable by ordinary well-formed requests. A typical variety of this attack involves specifying a path to a desired file together with dot-dot-slash characters, resulting in the file access API or function traversing out of the intended directory structure and into the root file system. By replacing or modifying the expected path information the access function or API retrieves the file desired by the attacker. These attacks either involve the attacker providing a complete path to a targeted file or using control characters (e.g. path separators (/ or \) and/or dots (.)) to reach desired directories or files.
CAPEC-64: Using Slashes and URL Encoding Combined to Bypass Validation Logic
This attack targets the encoding of the URL combined with the encoding of the slash characters. An attacker can take advantage of the multiple ways of encoding a URL and abuse the interpretation of the URL. A URL may contain special character that need special syntax handling in order to be interpreted. Special characters are represented using a percentage character followed by two digits representing the octet code of the original character (%HEX-CODE). For instance US-ASCII space character would be represented with %20. This is often referred as escaped ending or percent-encoding. Since the server decodes the URL from the requests, it may restrict the access to some URL paths by validating and filtering out the URL requests it received. An attacker will try to craft an URL with a sequence of special characters which once interpreted by the server will be equivalent to a forbidden URL. It can be difficult to protect against this attack since the URL can contain other format of encoding such as UTF-8 encoding, Unicode-encoding, etc.
CAPEC-76: Manipulating Web Input to File System Calls
An attacker manipulates inputs to the target software which the target software passes to file system calls in the OS. The goal is to gain access to, and perhaps modify, areas of the file system that the target software did not intend to be accessible.
CAPEC-78: Using Escaped Slashes in Alternate Encoding
This attack targets the use of the backslash in alternate encoding. An adversary can provide a backslash as a leading character and causes a parser to believe that the next character is special. This is called an escape. By using that trick, the adversary tries to exploit alternate ways to encode the same character which leads to filter problems and opens avenues to attack.
CAPEC-79: Using Slashes in Alternate Encoding
This attack targets the encoding of the Slash characters. An adversary would try to exploit common filtering problems related to the use of the slashes characters to gain access to resources on the target host. Directory-driven systems, such as file systems and databases, typically use the slash character to indicate traversal between directories or other container components. For murky historical reasons, PCs (and, as a result, Microsoft OSs) choose to use a backslash, whereas the UNIX world typically makes use of the forward slash. The schizophrenic result is that many MS-based systems are required to understand both forms of the slash. This gives the adversary many opportunities to discover and abuse a number of common filtering problems. The goal of this pattern is to discover server software that only applies filters to one version, but not the other.