T09 · Insecure Skill Coding Practices
- Location
scripts/download_waste_calendar.py:337- Finding
Server-Controlled Filename Allows Arbitrary File Write
- Content
View full analysis
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: Highpython def extract_filename(headers) -> str | None: disposition = headers.get("Content-Disposition", "") match = re.search(r'filename="?([^";]+)"?', disposition) return match.group(1) if match else Nonepython 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-Dispositionresponse header is passed directly intoPath.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. Underpathlibsemantics, an absolute filename can also cause the current working directory operand to be discarded. The subsequentmkdir(parents=True, exist_ok=True)creates missing parent directories, whilewrite_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
- The user runs the Skill without supplying
--output. - The Skill requests an ICS o ...[truncated 1014 chars]
- The user runs the Skill without supplying
- Remediation
View 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.icsorwaste-calendar.pdfwhen 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.
- Treat the server-provided filename only as a display name and reduce it to a basename using
