T05 · Unauthorized Access and Privilege Escalation
- Location
code_cache.py:91- Finding
Arbitrary File Write Through Untrusted Remote Filenames
- Content
View full analysis
Vulnerability Details
File Location:
code_cache.py:91-110
Vulnerability Type: Path traversal and arbitrary file overwrite
Risk Level: CriticalVulnerable Code
python def cmd_files(args: argparse.Namespace) -> None: """Get code files ready for execution.""" client = get_client() task = " ".join(args.task) result = client.get_code_files( task=task, top_k=args.top_k, cache_dir=args.cache_dir, ) if not result.files: print(f"No code files found for: {task}") return print(f"Retrieved {len(result.files)} files for: {task}\n") # Write files to cache directory cache_path = Path(args.cache_dir) cache_path.mkdir(parents=True, exist_ok=True) for f in result.files: file_path = cache_path / f.filename file_path.write_text(f.source) print(f" 📄 {file_path}")Technical Analysis
Both
f.filenameandf.sourceare supplied by the remote Raysurfer service. The implementation joins the remote filename to the chosen cache directory without validating the filename or checking the resolved destination.A filename containing traversal components, such as
../../target, can escape the cache directory. Iff.filenameis absolute,pathlibdiscardscache_pathentirely. The code also does not reject symlink destinations or verify that the final resolved path remains beneath the resolved cache root.Because
Path.write_text()overwrites existing files by default, a malicious or compromised API response can replace any file writable by the Skill process.Attack Path
- An attacker adds a poisoned cache entry or compromises the API response.
- The response includes a filename such as
../../.bashrc, an absolute path, or a path targeting a symlink. - A user or agent invokes
/code-cache files. - The Skill combines the untrusted ...[truncated 721 chars]
- Remediation
View remediation
Remediation Suggestions
- Reject absolute filenames and any filename containing
..path components. - Resolve the cache root and candidate destination, then verify that the destination is strictly beneath the cache root using
Path.relative_to()or an equivalent containment check. - Reject symlinked destination components, or perform file creation using directory-relative operating-system APIs with no-follow protections.
- Avoid silently overwriting existing files. Use exclusive creation or require explicit confirmation.
- Normalize remote filenames to a restricted basename or generate local filenames independently.
- Add tests for absolute paths, traversal paths, nested traversal, symlink escapes, and overwrite attempts.
- Reject absolute filenames and any filename containing
