T09 · Insecure Skill Coding Practices
- Location
scripts/coding-with-cursor-ai.sh:53- Finding
Predictable Temporary File Enables Symlink-Based File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/coding-with-cursor-ai.sh, lines 53-54
Vulnerability Type: Predictable and insecure temporary-file creation
Risk Level: MediumVulnerable Code
bash TASK_FILE="/tmp/cursor-task-$(date +%s).txt" echo "# Task Request" > "$TASK_FILE"Technical Analysis
The script constructs a temporary filename using only the current Unix timestamp and writes to it using shell redirection. This filename is predictable and is not created atomically.
On a multi-user system, a local attacker can predict the filename and create a symbolic link at that location before the script opens it. Shell redirection follows symbolic links, so the script can overwrite the linked destination if the account running the skill has permission to modify that destination.
The script also does not set a restrictive
umask, so the confidentiality of task data depends on the invoking process's existing permission configuration.Attack Path
- A local attacker determines when the script will execute or repeatedly predicts filenames based on the current timestamp.
- The attacker creates
/tmp/cursor-task-<timestamp>.txtas a symbolic link to a target file. - A user, automated service, or privileged account runs the skill during the corresponding second.
- The first and subsequent output redirections follow the attacker's symbolic link.
- The target file is overwritten with task-file content, subject to the invoking account's filesystem permissions.
Impact Assessment
Successful exploitation permits modification or corruption of files writable by the account invoking the script. If the skill runs under a privileged or service account, the overwrite scope expands to files writable by that account and could potentially alter security-sensitive configuration or application state.
The predictable path may also expose project paths, task descriptions, and focused filenam ...[truncated 81 chars]
- Remediation
View remediation
Remediation Suggestions
Create the temporary file atomically with
mktemp, apply restrictive permissions, and reject creation failures:bash umask 077 TASK_FILE="$(mktemp /tmp/cursor-task.XXXXXX)" || { echo "Error: Unable to create temporary task file." >&2 exit 1 } trap 'rm -f -- "$TASK_FILE"' EXITAdditional hardening should include:
- Keep the temporary file owned and readable only by the invoking user.
- Do not construct temporary paths from timestamps, process IDs, or other predictable values.
- Quote the filename for every operation.
- Prefer a private runtime directory when one is available.
