skills/weak-encryption-anti-pattern/SKILL.md
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.
npx skillsauth add igbuend/grimbard weak-encryption-anti-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Severity: High
Applications use outdated algorithms (DES, RC4), insecure modes (ECB), or mismanage IVs/nonces (static, reused), enabling easy decryption. AI models suggest these weak practices from older tutorials, leading to data breaches and compliance failures.
The anti-pattern involves using cryptographic techniques that are no longer considered secure for protecting sensitive data.
Using algorithms like DES, 3DES, or RC4 is a critical flaw. These algorithms have known vulnerabilities and are easily broken with modern computing power.
# VULNERABLE: Using the outdated DES algorithm.
from Crypto.Cipher import DES
from Crypto import Random
key = Random.get_random_bytes(8) # DES uses an 8-byte (64-bit) key, but only 56 bits are effective.
def encrypt_data_des(plaintext):
cipher = DES.new(key, DES.MODE_ECB) # ECB mode is also insecure.
# Pad the plaintext to be a multiple of 8 bytes (DES block size).
padded_plaintext = plaintext + (8 - len(plaintext) % 8) * chr(8 - len(plaintext) % 8)
ciphertext = cipher.encrypt(padded_plaintext.encode('utf-8'))
return ciphertext
# DES can be brute-forced in under 24 hours with commodity hardware.
Even if using a strong algorithm like AES, using it in Electronic Codebook (ECB) mode is highly insecure. ECB encrypts identical blocks of plaintext into identical blocks of ciphertext, revealing patterns in the data.
# VULNERABLE: Using AES in ECB mode.
from Crypto.Cipher import AES
from Crypto import Random
key = Random.get_random_bytes(16) # AES-128 key.
def encrypt_data_ecb(plaintext):
cipher = AES.new(key, AES.MODE_ECB)
# Pad the plaintext to be a multiple of 16 bytes (AES block size).
padded_plaintext = plaintext + (16 - len(plaintext) % 16) * chr(16 - len(plaintext) % 16)
ciphertext = cipher.encrypt(padded_plaintext.encode('utf-8'))
return ciphertext
# If you encrypt an image with many identical color blocks using AES-ECB,
# the encrypted image will still show the original image's outline and patterns.
# This leaks significant information about the plaintext.
# SECURE: Use a modern, authenticated encryption mode like AES-256-GCM.
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.exceptions import InvalidTag
import os
# Generate a strong, random key. AES-256 uses a 32-byte key.
key = AESGCM.generate_key(bit_length=256)
def encrypt_data_gcm(plaintext):
aesgcm = AESGCM(key)
# GCM requires a unique, unpredictable nonce (Initialization Vector).
# It must never be reused with the same key. A 12-byte nonce is standard.
nonce = os.urandom(12)
# AES-GCM performs both encryption and provides an authentication tag (integrity check).
ciphertext = aesgcm.encrypt(nonce, plaintext.encode('utf-8'), None)
# Store and transmit the nonce along with the ciphertext.
return nonce + ciphertext
def decrypt_data_gcm(encrypted_data_with_nonce):
aesgcm = AESGCM(key)
nonce = encrypted_data_with_nonce[:12]
ciphertext = encrypted_data_with_nonce[12:]
try:
# The decrypt method will also verify the authentication tag.
# If the data is tampered with, it will raise an `InvalidTag` exception.
plaintext = aesgcm.decrypt(nonce, ciphertext, None).decode('utf-8')
return plaintext
except InvalidTag:
raise ValueError("Decryption failed: data may have been tampered with or corrupted.")
# AES-256-GCM provides strong confidentiality, integrity, and authenticity.
# Each encryption is unique due to the nonce, preventing pattern leakage.
DES, 3DES, RC4, MD5 (for encryption), or SHA-1 (for encryption/signatures).ECB mode being used with block ciphers like AES.cryptography in Python, javax.crypto in Java).development
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
development
Security pattern for self-contained token authentication (e.g., JWT). Use when implementing stateless authentication, designing tokens with embedded claims, or building systems where tokens contain principal information and can be verified without server-side storage. Specialization of Authentication pattern.