T09 · Insecure Skill Coding Practices
- Location
scripts/coreldraw_export.py:154- Finding
Unrestricted Export Filename Allows Output Directory Traversal
- Content
View full analysis
Vulnerability Details
File Location:
scripts/coreldraw_export.py, lines 154–161 and 217–220
Vulnerability Type: Path traversal and arbitrary export-file placement
Risk Level: MediumVulnerable Code
python def parse_item(item: str) -> tuple[str, list[int]]: if ":" not in item: raise ValueError("Item must be filename:indexes, e.g. tree.png:4 or cluster.png:7-20") filename, spec = item.split(":", 1) filename = filename.strip() if not filename: raise ValueError(f"Missing filename in --item {item!r}") return filename, parse_index_spec(spec)python for filename, indexes in items: out_path = out_dir / filename if out_path.exists() and not args.overwrite: raise FileExistsError(f"Refusing to overwrite existing file: {out_path}") create_selection(layer, indexes)Technical Analysis
The filename supplied through
--itemis accepted without validating whether it is an absolute path or contains parent-directory components such as... The value is subsequently joined directly to the requested output directory:python out_path = out_dir / filenameThis operation does not guarantee that the resulting path remains inside
out_dir. A relative filename containing traversal components can escape the directory. Depending on Windows path semantics and the supplied value, an absolute path may also supersede the intended base directory.The resulting path is passed to CorelDRAW's export APIs. Consequently, this is a file-write path traversal rather than merely a misleading manifest entry. The existing-file safeguard does not prevent directory escape, and the
--overwriteoption permits replacement of an existing accessible file.Attack Path
- An attacker controls or influences an
--itemargument used by the operator or another automation layer. - The attacker supplies a filename containing traversal components, for example:
text --item "..\outside\asset.
...[truncated 1109 chars]
- An attacker controls or influences an
- Remediation
View remediation
Remediation Suggestions
-
Require
--itemfilenames to be plain basenames unless nested output directories are an intentional feature:python candidate = Path(filename) if candidate.is_absolute() or candidate.name != filename: raise ValueError("Export filename must be a plain filename") -
If nested directories must be supported, reject parent traversal and verify containment after canonicalization:
python base = out_dir.resolve() candidate = (base / filename).resolve() try: candidate.relative_to(base) except ValueError: raise ValueError("Export path escapes the output directory") -
Reject empty names,
.and..path components, absolute paths, drive-qualified paths, and Windows UNC paths before invoking COM export operations. -
Perform the overwrite check only after canonicalization and containment validation.
-
Consider validating that the filename extension agrees with
--formatto avoid misleading output names. -
Add automated tests covering:
../and Windows-style..\traversal.- Absolute and drive-qualified paths.
- UNC paths.
- Nested paths, if supported.
- Existing destinations with and without
--overwrite. - Valid filenames that remain inside the output directory.
-
