T09 · Insecure Skill Coding Practices
- Location
research_logger.sh:78- Finding
Predictable Shared Temporary File Enables Symlink and Race Attacks
- Content
View full analysis
/tmp/research_logger_results.txt 2>/dev/null || true if [[ -s /tmp/research_logger_results.txt ]]; then FINDING1="$(sed -n '1p' /tmp/research_logger_results.txt | head -c 200 || echo 'No result')" FINDING2="$(sed -n '2p' /tmp/research_logger_results.txt | head -c 200 || echo 'No result')" FINDING3="$(sed -n '3p' /tmp/research_logger_results.txt | head -c 200 || echo 'No result')" LINKS="$(sed -n '/^---LINKS---$/,$ p' /tmp/research_logger_results.txt | tail -n +2 || echo '- (none)')" SUMMARY="Research on '$TOPIC' — ${FINDING1:0:100}" fi rm -f /tmp/research_logger_results.txt ``` ### Technical Analysis The script stores API response data in the fixed path `/tmp/research_logger_results.txt`. The file is created through ordinary shell redirection without exclusive creation, randomized naming, ownership validation, restrictive permissions, or locking. Because `/tmp` is normally shared by all local users, another process can predict and manipulate this path before or during execution. This creates several risks: - A symbolic link can redirect the output operation to another file writable by the user running the Skill. - Concurrent executions can overwrite or read each other's search results. - An attacker can replace the file between the write and read operations, causing attacker-controlled content to be inserted into the generated research note. - The process's current `umask` determines file permissions, so search-result data may be exposed to other local users on permissively configured systems. Modern operating-system symlink protections may restrict some cross-user attacks, but they do not eliminate concurrent-run corruption or all same-user attacks. ### Attack Path 1. A local attacker predicts that the Skill will use `/tmp/res ...[truncated 1170 chars]- Remediation
View remediation
"$RESULTS_FILE" if [[ -s "$RESULTS_FILE" ]]; then FINDING1="$(sed -n '1p' "$RESULTS_FILE" | head -c 200 || echo 'No result')" fi ``` Additional hardening measures: 1. Do not reuse a temporary filename across executions. 2. Retain `umask 077` while handling temporary research data. 3. Quote the temporary path on every access. 4. Use the `EXIT` trap so cleanup also occurs after errors or signals. 5. Where practical, avoid a temporary file entirely by parsing the response in one process and returning structured output safely. ]]>
