Skip to content

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

FieldValue
IDCODE-0786
CategoryInsecureConfig
SeverityMEDIUM
CWECWE-378
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagstemporary files, insecure permissions
OWASPA5:2017-Broken Access Control, A01:2021-Broken Access Control