T09 · Insecure Skill Coding Practices
- Location
scripts/extract-prompts.sh:8- Finding
Predictable Temporary Report File Permits Symlink Overwrite and Information Disclosure
- Content
View full analysis
Vulnerability Details
File Location:
scripts/extract-prompts.sh, lines 8 and 14–16
Vulnerability Type: Unsafe temporary-file handling
Risk Level: MediumVulnerable Code
bash OUTPUT_DIR="${2:-/tmp/source-analysis}" # ... mkdir -p "$OUTPUT_DIR" BASENAME=$(basename "$BINARY") REPORT="$OUTPUT_DIR/extracted-${BASENAME}.txt" echo "=== Source Analysis Extract ===" > "$REPORT"Technical Analysis
The script uses the shared
/tmphierarchy by default and derives the report filename predictably from the input file's basename. It creates or truncates that report using ordinary shell redirection without:- Creating a private temporary directory;
- Verifying directory ownership and permissions;
- Rejecting symbolic links;
- Creating the report atomically and exclusively;
- Enforcing restrictive report permissions.
Shell redirection follows symbolic links. Consequently, another local user who can predict the analyzed file's basename may pre-create
/tmp/source-analysis/extracted-<basename>.txtas a symbolic link. When a victim runs the script, the initial redirection follows that link and truncates the linked file if the victim has permission to write it. Later redirections append extracted data through the same link.In addition, report permissions depend on the invoking user's
umask. The report may contain proprietary system prompts, behavioral instructions, tool names, environment-variable names, and other strings extracted from the supplied binary. A permissiveumaskor attacker-controlled output directory may expose this information to other local users.Attack Path
- A local attacker determines or predicts the basename of a binary that a victim will analyze.
- The attacker creates
/tmp/source-analysisbefore the victim, if necessary, and places a symbolic link at/tmp/source-analysis/extracted-<basename>.txt. - The symbolic link targets a file writab ...[truncated 1217 chars]
- Remediation
View remediation
Remediation Suggestions
-
Set a restrictive permission mask before creating output artifacts:
bash umask 077 -
Create a private temporary directory with
mktemprather than using a predictable shared directory:bash OUTPUT_DIR="${2:-$(mktemp -d "${TMPDIR:-/tmp}/source-analysis.XXXXXXXX")}" -
If a caller supplies an output directory, verify that it is a real directory, is owned by the invoking user, and is not writable by untrusted users.
-
Create the report atomically with exclusive-creation and no-symbolic-link semantics. Avoid directly redirecting to a predictable path. Where available, use a small helper in a language that supports
O_CREAT | O_EXCL | O_NOFOLLOW, or first create a secure temporary report withmktempinside the validated directory. -
Before publishing a final predictable filename, verify that the destination does not exist and use an atomic operation that cannot overwrite an attacker-created entry. Prefer retaining a random report name if predictable naming is unnecessary.
-
Explicitly apply mode
0600to report files and mode0700to generated directories. -
Add cleanup handling for partially generated reports and private temporary directories:
bash trap 'rm -f -- "$REPORT_TMP"' EXIT
-
