T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:23
- Finding
- Predictable Temporary Files Expose Runtime Dumps and Enable File-Clobbering Attacks<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 23, 29, and 38 **Vulnerability Type**: Unsafe predictable temporary-file creation **Risk Level**: Medium ### Vulnerable Code ```bash # Line 23 jstack $(pgrep -f 'java.*your-app') > /tmp/thread-dump.txt 2>&1 # Line 29 jcmd $(pgrep -f 'java.*your-app') Thread.print > /tmp/thread-dump.txt # Line 38 curl -s http://localhost:6060/debug/pprof/goroutine?debug=2 > /tmp/goroutine-dump.txt ``` ### Technical Analysis The Skill directs users or agents to write diagnostic output to fixed, predictable paths in the shared `/tmp` directory. It does not securely create the files, set a restrictive `umask`, verify file ownership or type, prevent symbolic-link traversal, or remove the files after use. Thread and goroutine dumps may contain sensitive operational information, including application class and function names, source paths, SQL operations, internal hostnames, request-processing states, lock identifiers, and stack-local data exposed by the runtime. Depending on the executing account's `umask`, these files may be readable by other local users. Shell output redirection follows an existing target path. A local attacker who can anticipate the documented names may attempt to pre-create the destination or replace it with a symbolic link. If the command runs under an account permitted to follow and write through that link, output could overwrite another file accessible to that account. Operating-system protections such as Linux `fs.protected_symlinks` can reduce this attack, but the Skill does not require or verify those protections. ### Attack Path 1. An attacker with local access observes that the Skill uses `/tmp/thread-dump.txt` or `/tmp/goroutine-dump.txt`. 2. The attacker monitors for creation of the predictable file and reads it if its resulting permissions permit cross-user access. 3. Alternatively, the attacker pre-creates the expected path as a symbolic link to another file. 4. A user ...[truncated 1219 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Create a private temporary directory using `mktemp`, apply owner-only permissions before collecting diagnostic data, quote variables, and delete the directory after analysis: ```bash umask 077 dump_dir="$(mktemp -d)" || exit 1 trap 'rm -rf -- "$dump_dir"' EXIT pid="$(pgrep -f 'java.*your-app' | head -n 1)" [ -n "$pid" ] || { echo "Target process not found" >&2 exit 1 } jstack "$pid" > "$dump_dir/thread-dump.txt" 2>&1 ``` For a Go dump: ```bash umask 077 dump_dir="$(mktemp -d)" || exit 1 trap 'rm -rf -- "$dump_dir"' EXIT curl --fail --silent --show-error \ 'http://localhost:6060/debug/pprof/goroutine?debug=2' \ > "$dump_dir/goroutine-dump.txt" ``` Additional hardening measures: 1. Avoid fixed filenames in shared temporary directories. 2. Set `umask 077` before creating diagnostic artifacts. 3. Verify that generated files are regular files owned by the executing account. 4. Run collection commands with the least-privileged account capable of inspecting the target process. 5. Retain dumps only as long as necessary and securely remove them afterward. 6. If dumps must be retained, store them in an access-controlled diagnostics directory rather than `/tmp`. 7. Select and confirm a single target PID instead of passing unchecked `pgrep -f` output directly to diagnostic commands. ]]>
