T09 · Insecure Skill Coding Practices
- Location
scripts/ip_intelligence.py:1455- Finding
Generated IP Intelligence Reports Are Written Without Restrictive File Permissions
- Content
View full analysis
- Remediation
View remediation
None: flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC fd = os.open(path, flags, 0o600) try: os.fchmod(fd, 0o600) with os.fdopen(fd, "w", encoding="utf-8") as handle: fd = -1 handle.write(content) finally: if fd >= 0: os.close(fd) ``` 3. Use the private writer for JSON, HTML, Markdown, and all `--output` paths. 4. Consider atomic replacement using a private temporary file in the destination directory, followed by `os.replace()`. Ensure the temporary file is also created with mode `0o600`. 5. Reject symbolic-link destinations or open files with `O_NOFOLLOW` where supported if output paths may be located in directories writable by untrusted users. 6. Add tests that set a permissive umask and verify: - Report directories have mode `0o700`. - Every generated report has mode `0o600`. - Pre-existing broadly readable output files are corrected to `0o600`. - Symlink destinations are rejected or handled safely. 7. Document that stdout output remains controlled by the caller and may be captured by shell history, pipelines, CI logs, or job schedulers. ]]>
