T09 · Insecure Skill Coding Practices
- Location
scripts/export_analysis.py:20- Finding
Predictable Output File Allows Symlink-Based File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/export_analysis.py, lines 20–30
Vulnerability Type: Predictable file creation, symlink following, and non-exclusive overwrite
Risk Level: MediumVulnerable Code
python # Create filename with timestamp timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") # Sanitize problem_summary for filename safe_summary = "".join(c for c in problem_summary if c.isalnum() or c in (' ', '-', '_')).strip() safe_summary = safe_summary.replace(' ', '_')[:50] # Limit length filename = f"adversarial_analysis_{safe_summary}_{timestamp}.md" filepath = Path.home() / filename # Write content to file with open(filepath, 'w', encoding='utf-8') as f:Technical Analysis
The output path is generated from a caller-influenced summary and a timestamp with only one-second precision. This makes the destination filename predictable when the summary and approximate execution time are known.
The file is opened with mode
'w', which follows symbolic links and truncates an existing destination. The implementation does not use exclusive creation, verify that the destination is a regular file, reject symbolic links, or place exports in a dedicated directory with restrictive permissions.A local attacker who can create entries in the exporting user's home directory could pre-create the predicted output path as a symbolic link to another file writable by that user. When the export runs, Python follows the link and truncates or replaces the target's contents with the generated Markdown. Even without a symbolic link, a filename collision silently overwrites an existing export.
Attack Path
- The attacker obtains local access that permits creating a file or symbolic link in the victim's home directory.
- The attacker determines or influences
problem_summaryand predicts the export execution second. - The summary is sanitized using the documented character filtering and ...[truncated 1339 chars]
- Remediation
View remediation
Remediation Suggestions
- Create exports inside a dedicated directory owned by the invoking user and configured with restrictive permissions such as
0700. - Use unpredictable filenames generated with
tempfile, a cryptographically random identifier, or UUID rather than a timestamp alone. - Open new files with exclusive creation mode (
'x') and retry with a newly generated name if a collision occurs. - Refuse symbolic-link destinations and, where supported, use low-level file opening with
O_CREAT | O_EXCL | O_NOFOLLOW. - If users may select an output path, resolve and validate it against an approved export directory before writing.
- Avoid silently truncating an existing file; require explicit user confirmation for replacement.
- Perform automatic exports only after informing the user of the destination and obtaining approval when the surrounding execution policy requires it.
A hardened implementation should atomically create a new, unpredictable file within a private export directory and never follow a pre-existing filesystem entry.
- Create exports inside a dedicated directory owned by the invoking user and configured with restrictive permissions such as
