T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/skill-scan.py:240
- Finding
- Predictable Temporary Report Path Allows Symlink-Based File Overwrite## Vulnerability Details **File Location**: `scripts/skill-scan.py`, lines 240-243 **Vulnerability Type**: Predictable temporary file and unsafe file creation **Risk Level**: Medium ### Vulnerable Code ```python # 保存报告 report_file = f"/tmp/skill-scan-{os.path.basename(skill_path)}.json" with open(report_file, 'w') as f: json.dump(report, f, indent=2, ensure_ascii=False) ``` ### Technical Analysis The report filename is derived predictably from the basename of the scanned directory and is written directly into the shared `/tmp` directory. The call to `open(..., 'w')` follows symbolic links and does not use exclusive creation, symlink protection, or secure file permissions. A local attacker who can write to `/tmp` can pre-create the expected report path as a symbolic link to another file. If the scanner is subsequently run by a more privileged account, opening the report truncates and writes to the symbolic-link target. The generated report also contains scanned file paths and matched source-code excerpts. Its permissions depend on the process umask, potentially exposing source fragments containing credentials or other sensitive values to local users. ### Attack Path 1. The attacker identifies or predicts the basename of a directory that a privileged user will scan. 2. The attacker calculates the report path, such as `/tmp/skill-scan-target.json`. 3. The attacker creates that path as a symbolic link to a file writable by the scanner's account. 4. A privileged user invokes the scanner against the target directory. 5. The scanner follows the symbolic link when opening the report with write mode. 6. The target file is truncated and replaced with scanner-generated JSON. ### Impact Assessment Successful exploitation can overwrite or corrupt files accessible to the account running the scanner. The maximum privilege obtained is bounded by that account's existing filesystem permiss ...[truncated 386 chars]
- Remediation
- ## Remediation Suggestions - Use `tempfile.NamedTemporaryFile` or `tempfile.mkstemp` to create an unpredictable report file atomically. - Create reports with permissions limited to the owner, such as mode `0600`. - If a stable output filename is required, place it in a user-controlled output directory and use exclusive creation with `O_CREAT | O_EXCL`. - Explicitly reject symbolic links and verify that the opened file is a regular file. - Consider requiring an explicit output path instead of automatically writing to shared temporary storage. - Redact likely credentials, tokens, and secret values from captured source excerpts. - Avoid running the scanner with elevated privileges unless strictly necessary.
