Back to all reviewers

Secure temporary files

ghostty-org/ghostty
Based on 1 comments
Other

Always use `mktemp` instead of manually constructing temporary file paths with random values. Manually constructed paths with elements like `$RANDOM` or timestamp values can be vulnerable to race conditions, predictability issues, and permission problems, potentially leading to security exploits.

Security Other

Reviewer Prompt

Always use mktemp instead of manually constructing temporary file paths with random values. Manually constructed paths with elements like $RANDOM or timestamp values can be vulnerable to race conditions, predictability issues, and permission problems, potentially leading to security exploits.

Instead of:

cpath="/tmp/ghostty-ssh-$USER-$RANDOM-$(date +%s)"

Use:

cpath=$(mktemp -d /tmp/ghostty-ssh-XXXXXX)
# or for a file
cpath=$(mktemp /tmp/ghostty-ssh-XXXXXX)

The mktemp utility creates unique temporary files/directories safely, sets appropriate permissions, and handles race conditions properly. This prevents potential security vulnerabilities like file-based race conditions, symbolic link attacks, and information disclosure that could occur with manually constructed paths.

1
Comments Analyzed
Other
Primary Language
Security
Category

Source Discussions