T09 · Insecure Skill Coding Practices
- Location
scripts/send_audio.sh:38- Finding
Predictable Temporary File Permits Symlink Attacks and Cross-Run Interference
- Content
View full analysis
Vulnerability Details
File Location:
scripts/send_audio.sh, lines 38–41 and 107
Vulnerability Type: Predictable temporary file in a shared directory
Risk Level: MediumVulnerable Code
bash # Temporary file OPUS_FILE="/tmp/$(basename "$AUDIO_FILE" .mp3).opus" echo "Converting audio to opus format..." ffmpeg -i "$AUDIO_FILE" -c:a libopus -b:a 24k -ar 24000 -ac 1 -y "$OPUS_FILE" 2>/dev/nullThe file is removed only after successful completion:
bash rm -f "$OPUS_FILE"Technical Analysis
The script constructs its output path deterministically from the source filename and stores it directly in the shared, world-writable
/tmpdirectory. It does not use exclusive file creation, a private temporary directory, random path components, or checks that the destination is not a symbolic link.Because
ffmpegis invoked with-y, it is instructed to overwrite the destination without confirmation. A local attacker who can predict the source basename may pre-create/tmp/<basename>.opusas a symbolic link to another file writable by the victim account. Depending on the destination andffmpegbehavior, the target may then be overwritten with attacker-triggered audio output.The predictable path also permits concurrent executions using the same basename to read, overwrite, upload, or delete one another's output. Furthermore,
set -emay terminate the script before the finalrmcommand, leaving converted audio behind in/tmp.Attack Path
- The attacker determines or guesses the basename of an audio file likely to be processed, such as
voice.mp3. - The attacker creates the predictable path
/tmp/voice.opusas a symbolic link to a file writable by the account that will run the Skill. - The victim invokes the script with
voice.mp3. - The script runs
ffmpegwith-yagainst the attacker-controlled path. ffmpegmay follow the symbolic link and overwrite the linked target with converted audio data. 6 ...[truncated 1058 chars]
- The attacker determines or guesses the basename of an audio file likely to be processed, such as
- Remediation
View remediation
Remediation Suggestions
Create a randomly named, private temporary directory and guarantee cleanup with an exit trap:
bash TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/feishu-audio.XXXXXX")" chmod 700 "$TMP_DIR" trap 'rm -rf -- "$TMP_DIR"' EXIT HUP INT TERM OPUS_FILE="$TMP_DIR/audio.opus" ffmpeg -i "$AUDIO_FILE" \ -c:a libopus \ -b:a 24k \ -ar 24000 \ -ac 1 \ -y \ "$OPUS_FILE" 2>/dev/nullAdditional hardening measures should include:
- Apply
umask 077before creating temporary content so files are accessible only to the current user. - Keep the converted output inside the private directory rather than constructing a filename directly under
/tmp. - Retain the cleanup trap so temporary data is removed on success, errors, and common termination signals.
- Avoid relying on the input basename for uniqueness.
- Where practical, verify that the temporary output is a regular file owned by the current user before uploading it.
- Consider adding shell hardening such as
set -euo pipefail, while explicitly validating required environment variables to avoid ambiguous failures.
- Apply
