T09 · Insecure Skill Coding Practices
- Location
nex-decision-journal.py:582- Finding
Arbitrary User-Writable File Overwrite via Export Path Traversal
- Content
View full analysis
Vulnerability Details
File Location:
nex-decision-journal.py, lines 582–586
Vulnerability Type: Unrestricted export path / path traversal leading to arbitrary file overwrite
Risk Level: MediumVulnerable Code
python output_file = args.output or f"decisions_export.{args.format}" output_path = EXPORT_DIR / output_file with open(output_path, 'w', encoding='utf-8') as f: f.write(data)Technical Analysis
The
--outputargument is used directly to construct the export destination without validating that it is a simple filename or confirming that the resolved destination remains insideEXPORT_DIR.Python's
pathlibpath composition does not provide containment by itself:- An absolute
output_filecauses the intendedEXPORT_DIRprefix to be discarded. - A relative value containing
..components can traverse outside the export directory. - Opening the destination with mode
wcreates the file if absent and truncates it if it already exists.
Consequently, an attacker who can influence the command arguments can direct JSON or CSV export data into any file writable by the account executing the Skill.
Attack Path
-
The journal contains at least one decision, ensuring that
export_decisions()returns non-empty data. -
An attacker influences the user or Agent to run an export command with a crafted destination, such as:
bash nex-decision-journal export json --output ../../target-fileAn absolute user-writable path could also be supplied.
-
The application combines the untrusted value with
EXPORT_DIRbut does not resolve and validate the resulting path. -
open(output_path, 'w')creates or truncates the selected target. -
Serialized decision-journal data is written over the target file.
Impact Assessment
Exploitation is limited to the filesystem privileges of the user running the Skill; no privilege escalation was identified. ...[truncated 692 chars]
- An absolute
- Remediation
View remediation
Remediation Suggestions
Restrict exports to the configured export directory and prevent silent replacement of existing files:
- Reject absolute output paths.
- Prefer accepting only a filename, rejecting
/,\,./..path components, and platform-specific path separators. - Resolve both the export root and destination, then verify containment before opening the file.
- Create
EXPORT_DIRbefore validation and account for symlinks. - Use exclusive creation mode (
x) by default, or require explicit confirmation or an--overwriteoption before replacing an existing file. - Return a clear error when validation fails.
Example hardening:
python export_root = EXPORT_DIR.resolve() output_file = args.output or f"decisions_export.{args.format}" if Path(output_file).is_absolute(): raise ValueError("Output must be a filename inside the export directory") output_path = (export_root / output_file).resolve() try: output_path.relative_to(export_root) except ValueError: raise ValueError("Output path escapes the export directory") if output_path.exists(): raise FileExistsError( f"Export destination already exists: {output_path}" ) with open(output_path, "x", encoding="utf-8") as f: f.write(data)If subdirectories are not required, enforce
Path(output_file).name == output_fileand write only directly beneathEXPORT_DIR. For stronger protection against symlink races, use descriptor-relative filesystem operations and prohibit following symlinks where the operating system supports those controls.
