T09 · Insecure Skill Coding Practices
- Location
scripts/send_voice.py:151- Finding
Predictable Shared Temporary File Enables Arbitrary File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/send_voice.py, lines 19–20 and 151–153
Vulnerability Type: Predictable temporary file and unsafe file creation
Risk Level: MediumVulnerable Code
python AUDIO_OUT = os.path.join(tempfile.gettempdir(), "feishu-voice-out") os.makedirs(AUDIO_OUT, exist_ok=True)python mp3_path = os.path.join(AUDIO_OUT, "minimax.mp3") with open(mp3_path, "wb") as f: f.write(bytes.fromhex(audio_hex))Technical Analysis
The script creates a predictable subdirectory inside the system temporary directory and writes synthesized audio to the fixed filename
minimax.mp3. File creation uses ordinary write mode without exclusive creation, symbolic-link protection, ownership validation, or verification that the destination is a regular file.On systems where the temporary directory is shared among users or untrusted processes, an attacker can pre-create the expected file as a symbolic link to another file writable by the account running the Skill. Opening the path with
"wb"follows the symbolic link and truncates the linked destination before writing audio data.Other fixed output names, including
minimax.opusandedge.ogg, also permit concurrent invocations or local processes to interfere with generated output. This can cause cross-session data exposure, output corruption, or denial of service.Attack Path
- A local attacker determines that the Skill uses the predictable temporary path
/tmp/feishu-voice-out/minimax.mp3on a typical POSIX system. - The attacker creates the directory or waits for it to exist and places a symbolic link named
minimax.mp3pointing to a victim-writable target file. - The victim invokes
scripts/reply.pywhile MiniMax synthesis is enabled. - MiniMax returns synthesized audio, and
minimax_synth()opens the predictable path using"wb". - The operating system follows the attacker-created symbolic link, ...[truncated 642 chars]
- A local attacker determines that the Skill uses the predictable temporary path
- Remediation
View remediation
Remediation Suggestions
- Create a unique, private directory for each invocation using
tempfile.TemporaryDirectory()ortempfile.mkdtemp(). - Ensure the temporary directory is accessible only to the executing user, such as mode
0700on POSIX systems. - Generate unique filenames with
tempfile.NamedTemporaryFile()or securely generated random names instead of fixed names. - When direct file creation is necessary, use exclusive creation and no-follow semantics where supported.
- Verify that an existing destination is a regular file owned by the expected user before writing.
- Keep all intermediate artifacts inside the private per-invocation directory.
- Remove generated files and directories in a
finallyblock after copying the required output. - Avoid sharing output paths across concurrent invocations; use unique final media filenames or atomic replacement where a stable destination is required.
- Create a unique, private directory for each invocation using
