T09 · Insecure Skill Coding Practices
- Location
scripts/bounty_hunter.sh:67- Finding
Predictable Temporary Queue File Allows Symlink-Based File Clobbering
- Content
View full analysis
"${QUEUE_FILE}.tmp" mv "${QUEUE_FILE}.tmp" "$QUEUE_FILE" ``` ### Technical Analysis The script writes queue updates to a predictable path, `${QUEUE_FILE}.tmp`, using ordinary shell redirection. Shell redirection follows symbolic links. If an attacker can write to the queue directory, they can create this predictable temporary path as a symbolic link to another file writable by the account running the script. When the script performs the redirection, `jq` output is written to the symlink target, truncating and replacing its contents. The subsequent `mv` operation does not prevent the initial target overwrite. The fixed temporary filename also creates a race condition between concurrent or scheduled script executions, potentially causing lost updates, corrupted queue state, or replacement of one execution's output by another. Successful exploitation requires the attacker to have write access to the skill's `data` directory or otherwise be able to create or replace `${QUEUE_FILE}.tmp`. ### Attack Path 1. The attacker obtains write access to the directory containing `data/queue.json`. 2. The attacker creates the predictable temporary path as a symbolic link: ```bash ln -s /path/to/target/file data/queue.json.tmp ``` 3. The skill runs `scripts/bounty_hunter.sh` under the victim account. 4. An eligible GitHub issue reaches `add_to_queue`. 5. Shell redirection follows `data/queue.json.tmp` and truncates the symlink target. 6. The generated queue JSON is written into the targ ...[truncated 763 chars]- Remediation
View remediation
"$tmp_file" chmod --reference="$QUEUE_FILE" "$tmp_file" 2>/dev/null || chmod 600 "$tmp_file" mv -f -- "$tmp_file" "$QUEUE_FILE" trap - RETURN ``` - Ensure the data directory is owned by the executing user and is not writable by untrusted users; use restrictive permissions such as `0700`. - Use `flock` around the complete read-modify-write operation so concurrent cron executions cannot overwrite each other's changes. - Validate that the queue directory and queue file are not symbolic links before performing updates. - Run the skill as an unprivileged dedicated account and avoid execution as `root`. ]]>
