T09 · Insecure Skill Coding Practices
- Location
scripts/analyze_levels.py:467- Finding
Predictable Shared Temporary Files Permit Symlink-Based File Overwrite
- Content
View full analysis
Vulnerability Details
File Locations:
scripts/analyze_levels.py:467-472scripts/analyze_manual.py:220scripts/analyze_quick.py:196scripts/mock_analyzer.py:225
Vulnerability Type: Predictable temporary file usage and symlink-following file write
Risk Level: MediumVulnerable Code
python # Also save as JSON for debugging try: with open("/tmp/crypto_analysis.json", "w") as f: json.dump(analysis, f, indent=2, ensure_ascii=False) except: passThe auxiliary analyzers perform equivalent writes to fixed shared paths:
text /tmp/crypto_analysis_manual.json /tmp/crypto_analysis_quick.json /tmp/crypto_analysis_mock.jsonTechnical Analysis
The analyzers write debugging results to predictable names in the globally shared
/tmpdirectory. Python's normalopen(..., "w")operation follows symbolic links and truncates the destination if it already exists.On a multi-user system, another local user can create one of these predictable paths as a symbolic link before the analyzer runs. When a victim subsequently invokes the affected script, the write follows that link and replaces the linked file with JSON output, provided that the victim account has permission to write to the target.
This behavior is unnecessary for the Skill's primary function because the analysis is already printed to standard output. The broad
exceptclause also suppresses evidence of failed or redirected debug writes, making the issue harder to detect.Attack Path
- A local attacker predicts which analyzer the victim will execute.
- The attacker creates the corresponding path in
/tmpas a symbolic link to a file writable by the victim account. - The victim runs the affected analyzer.
- The script opens the predictable path in write mode.
- The operating system follows the symbolic link and truncates or replaces the linked target with the generated JSON.
...[truncated 789 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the debug-file write from normal execution unless it is explicitly requested by the user.
- If temporary output is required, use
tempfile.NamedTemporaryFileortempfile.mkstempso the file is created atomically with an unpredictable name. - Store persistent output in a user-private application directory rather than globally shared
/tmp. - Create output with restrictive permissions, such as mode
0600. - If a stable filename is unavoidable, use safe exclusive creation and reject symbolic links, including platform-appropriate
O_NOFOLLOWandO_EXCLprotections. - Apply the same correction to all four affected analyzers.
- Replace the bare
exceptclause with specific exception handling and report write failures to the caller.
