T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/download_waste_calendar.py:337
- Finding
- Server-Controlled Filename Allows Arbitrary File Write## Vulnerability Details **File Location**: `scripts/download_waste_calendar.py`, lines 337–340 and 387–395 **Vulnerability Type**: Unsanitized server-provided filename and path traversal **Risk Level**: High ```python def extract_filename(headers) -> str | None: disposition = headers.get("Content-Disposition", "") match = re.search(r'filename="?([^";]+)"?', disposition) return match.group(1) if match else None ``` ```python def choose_output_path(requested_path: str | None, filename: str) -> Path: if requested_path: return Path(requested_path).expanduser().resolve() return Path.cwd() / filename def write_file(path: Path, data: bytes) -> None: path.parent.mkdir(parents=True, exist_ok=True) path.write_bytes(data) ``` ### Technical Analysis The filename extracted from the HTTP `Content-Disposition` response header is passed directly into `Path.cwd() / filename`. The application does not remove path separators, reject absolute paths, normalize the resulting path, or verify that the resolved destination remains inside the current working directory. A filename containing traversal components, such as `../../target`, can therefore escape the intended output directory. Under `pathlib` semantics, an absolute filename can also cause the current working directory operand to be discarded. The subsequent `mkdir(parents=True, exist_ok=True)` creates missing parent directories, while `write_bytes()` overwrites an existing destination without confirmation. HTTPS protects the connection in transit but does not establish that a filename supplied by the remote application is safe for local filesystem use. Exploitation requires control over or compromise of the download response, such as through a compromised portal, an upstream server-side flaw, or a compromised trusted TLS endpoint. ### Attack Path 1. The user runs the Skill without supplying `--output`. 2. The Skill requests an ICS o ...[truncated 1014 chars]
- Remediation
- ## Remediation Suggestions - Treat the server-provided filename only as a display name and reduce it to a basename using `Path(filename).name`. - Reject absolute paths, `..` components, path separators, control characters, and unexpected filename characters. - Resolve the final path and verify that it remains within an explicitly selected output directory, for example with `resolved_path.is_relative_to(resolved_output_directory)`. - Generate a local fixed filename such as `waste-calendar.ics` or `waste-calendar.pdf` when no explicit output path is supplied. - Require explicit confirmation or a dedicated overwrite option before replacing an existing file. - Prefer exclusive file creation where appropriate and handle symbolic links safely to reduce overwrite and link-following risks.
