Insecure Temporary File Creation
Description
The application creates files in shared system temporary directories (`/tmp` or `/var/tmp`) without using the `os.CreateTemp` function, which may allow an attacker to create symlinks that point to other files prior to the application creating or writing to the target file, leading to unintended files being created or overwritten.
Examples
Insecure Code
go
os.WriteFile("/tmp/example.txt", []byte("example"), 0644)Secure Code
go
f, err := os.CreateTemp("/opt/appdir/restricted", "temp-*.txt")Remediation
Use `os.CreateTemp` in a restricted directory to create temporary files, ensuring the directory is properly secured and the file is cleaned up after use.
Rule Details
| Field | Value |
|---|---|
| ID | CODE-0786 |
| Category | InsecureConfig |
| Severity | MEDIUM |
| CWE | CWE-378 |
| Confidence | HIGH |
| Impact | MEDIUM |
| Likelihood | MEDIUM |
| Exploitability | MODERATE |
| Tags | temporary files, insecure permissions |
| OWASP | A5:2017-Broken Access Control, A01:2021-Broken Access Control |