
A minimal, runnable demonstration fo the Path Traversal(CWE-22) vulnerability class, usicng the recently dislosed CVE-2026-14628 as a real-world reference point.
CVE-2026-14628 affects 'NousResearch/hermes-agent' (< 2026.5.16).
The extract_media function in gateway/platforms/base.py builds a filesystem path from incoming webhook payload without validating it, allowing, a remote, unauthenticated attacker to read files outside the intented media directory.
AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:Nhermes-agent codebase. Instead, it reproduces the exact vulnerability pattern in a small, self-contained example so the flaw and its fix are easy to study and reuse as a reference when reviewing other code.| File | Purpose |
|---|---|
vulnerable_example.py | Reproduces the flawed logic: builds a path via naive string concatenation, no validation |
secure_example.py | Fixed version: validates the resolved absolute path stays within the intended root directory |
python3 vulnerable_example.py
Output shows the "attacker" successfully reading a file (secret_outside_media_root.txt) that lives outside the intended media_storage/ directory, using an input like ../secret_outside_media_root.txt.
python3 secure_example.py
The same malicious input is rejected with a clear PathTraversalError.
Two complementary defenses are applied in secure_example.py:
.. or path separators are rejected before touching the filesystem at all (fail fast, clear error for legitimate callers).candidate_path = os.path.abspath(os.path.join(MEDIA_ROOT, filename))
if not candidate_path.startswith(MEDIA_ROOT + os.sep):
raise PathTraversalError(...)
Path traversal is one of the most common and most avoidable vulnerability classes in software that handles file uploads, downloads, or any user-controlled filename — webhook handlers, media processors, log viewers, template engines, and file-serving APIs are frequent targets. The fix is cheap (a handful of lines); the cost of skipping it is arbitrary file disclosure, and in worse cases (when combined with write access) remote code execution.
This project is for educational purposes only. It is a generic reproduction of a known vulnerability class, not a working exploit against any specific live or unpatched software. Do not use these techniques against systems you do not own or have explicit authorization to test.