T09 · Insecure Skill Coding Practices
- Location
script.py:29- Finding
Unrestricted Local File Access in an Unsandboxed Execution Context
- Content
View full analysis
- Remediation
View remediation
Path: candidate = Path(raw_path).expanduser().resolve() if candidate != WORKSPACE and WORKSPACE not in candidate.parents: raise ValueError("Path is outside the approved workspace") return candidate ``` 3. Use separate validation policies for input and output files: - Require input files to exist and be regular files. - Reject device files, sockets, and directories. - Reject symbolic links or validate their resolved destinations. - Permit only expected document extensions where appropriate. 4. Avoid silent overwrites. Use exclusive creation mode or require an explicit overwrite option: ```python with output_path.open("x", encoding="utf-8") as output_file: output_file.write(content) ``` 5. If overwriting is necessary, write to a temporary file in the approved output directory and atomically replace the destination after validation. 6. Apply input-size limits before loading an entire file into memory. 7. Run the skill under a dedicated, least-privileged account with access only to its working directory. ]]>
