T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/config.sh:17
- Finding
- Private WeChat Data Stored in an Unsafe Predictable Temporary Directory<![CDATA[ ## Vulnerability Details **File Location**: `scripts/config.sh:17-21`; sensitive writes occur at `scripts/wechat_proxy.sh:145-147`, `scripts/wechat_proxy.sh:165-173`, and `scripts/wechat_proxy.sh:317-329` **Vulnerability Type**: Predictable temporary directory, insufficient permission enforcement, and potential symlink attacks **Risk Level**: Medium ### Vulnerable Code ```bash TEMP_DIR="/tmp/wechat_proxy" mkdir -p "$TEMP_DIR" # Log file LOG_FILE="$TEMP_DIR/wechat_proxy.log" ``` Sensitive chat screenshots and analysis results are subsequently written beneath this directory: ```bash local chat_screenshot="$TEMP_DIR/chat_${contact_name}_$(date +%s).png" screenshot "$chat_screenshot" local list_screenshot="$TEMP_DIR/chat_list_$(date +%s).png" screenshot "$list_screenshot" local analysis_output="$TEMP_DIR/analysis_$(date +%s).txt" peekaboo see --path "$list_screenshot" --analyze "Find chats with new messages and list contact names and new-message counts" > "$analysis_output" 2>/dev/null ``` Chat exports are also placed beneath the same directory: ```bash local export_dir="$TEMP_DIR/export/$contact_name" mkdir -p "$export_dir" local timestamp=$(date '+%Y%m%d_%H%M%S') local md_file="$export_dir/${contact_name}_${timestamp}.md" ``` ### Technical Analysis The application uses a fixed path under the globally shared `/tmp` namespace. It does not: - Create the directory atomically. - Verify that the directory is owned by the current user. - Reject a symbolic link in place of the expected directory. - Set an owner-only `umask`. - Explicitly assign mode `0700` to directories or `0600` to files. - Remove sensitive screenshots and exports after use. The directory stores screenshots of the entire screen, chat-list analysis, exported chat history, message-bearing logs, and a process ID file. These artifacts can contain highly sensitive personal or business communications. Because `mkdir -p` succeeds when the path already exists, an attacker with local acc ...[truncated 1428 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create a private runtime directory atomically: ```bash umask 077 TEMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/wechat_proxy.XXXXXXXX")" || exit 1 chmod 700 "$TEMP_DIR" ``` 2. If a stable directory is required, place it beneath an owner-controlled location such as `${XDG_RUNTIME_DIR}` or `$HOME/Library/Caches`, and verify it before every use: ```bash [ -d "$TEMP_DIR" ] || exit 1 [ ! -L "$TEMP_DIR" ] || exit 1 [ "$(stat -f '%u' "$TEMP_DIR")" -eq "$(id -u)" ] || exit 1 chmod 700 "$TEMP_DIR" ``` 3. Create files with mode `0600` and avoid following symbolic links where supported. 4. Separate runtime state, logs, and exported conversations into distinct protected directories. 5. Delete transient screenshots and analysis files after use, ideally through an `EXIT` trap. 6. Document the sensitivity and retention period of exported conversation data. ]]>
