T09 · Insecure Skill Coding Practices
- Location
secure-messenger.sh:100- Finding
Cryptographic failures are suppressed and reported as successful authenticated encryption
- Content
View full analysis
/dev/null) # 使用对方公钥加密会话密钥 local encrypted_key=$(echo -n "$session_key" | openssl rsautl -encrypt -pubin -inkey "$CONTACTS_DIR/$recipient.pub" -oaep | base64 -w0) # 创建消息包 local message_package=$(cat </dev/null) echo -e "${GREEN}✅ 消息解密成功!${NC}" echo "" echo -e "${YELLOW}📨 来自 $sender 的消息:${NC}" echo "$decrypted_msg" ``` ### Technical Analysis The script redirects OpenSSL error output to `/dev/null` and does not inspect the exit status of either the encryption or decryption command. Standard `openssl enc` implementations do not support AEAD modes such as GCM, so the command can fail without producing valid ciphertext. Nevertheless, the script continues and reports that encryption or decryption succeeded. The generated package also has no authentication-tag field. AES-GCM requires an authentication tag to verify ciphertext integrity. Without producing, transporting, and verifying that tag, the implementation does not provide its advertised authenticated-encryption guarantee. The shell does not enable `set -e` or `set -o pipefail` in the main script. A failure inside a command substitution or pipeline therefore does not reliably stop execution. ### Attack Path 1. A user invokes `secure-messenger.sh send` with sensitive plaintext. 2. The `ope ...[truncated 1064 chars]- Remediation
View remediation
/dev/null` suppression or capture and report sanitized errors. - Enable strict shell behavior, including `set -euo pipefail`, while explicitly handling expected failures. - Refuse to emit a message package if encryption, key wrapping, JSON construction, or Base64 encoding fails. - Refuse to display a success message unless decryption and authentication both complete successfully. - Add negative tests for malformed ciphertext, missing tags, invalid IVs, invalid keys, and unsupported OpenSSL versions. ]]>
