T09 · Insecure Skill Coding Practices
- Location
cad_generator.py:25- Finding
Path Traversal Through Unvalidated Project Names
- Content
View full analysis
- Remediation
View remediation
str: if not PROJECT_NAME_PATTERN.fullmatch(name): raise ValueError("Invalid project name") return name ``` 2. Resolve every generated path and verify that it remains inside the project directory: ```python from pathlib import Path PROJECTS_DIR = Path(__file__).resolve().parent / "projects" def project_path(name: str, suffix: str) -> Path: validate_project_name(name) candidate = (PROJECTS_DIR / f"{name}{suffix}").resolve() if candidate.parent != PROJECTS_DIR.resolve(): raise ValueError("Project path escapes the project directory") return candidate ``` 3. Apply the same centralized path-construction function to JSON, DXF, and SVG operations. 4. Reject absolute paths, path separators, `.` and `..` components, control characters, and names exceeding a documented maximum length. 5. Where attacker-accessible directories are possible, protect against symbolic-link attacks by checking path components and using secure file-opening techniques supported by the target platform. 6. Use atomic writes through a temporary file in the verified destination directory followed by a controlled rename, reducing corruption and race-condition risks. ]]>
