skills/type-confusion-anti-pattern/SKILL.md
Security anti-pattern for type confusion vulnerabilities (CWE-843). Use when generating or reviewing code in dynamic languages that compares values, processes JSON/user input, or uses loose equality. Detects weak typing exploits and type coercion attacks.
npx skillsauth add igbuend/grimbard type-confusion-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
Programs misinterpret data types through loose comparisons, implicit coercion, or improper input handling. Attackers exploit type confusion in weakly-typed languages (JavaScript, PHP) and dynamic data structures (JSON) to bypass security checks, manipulate logic, or achieve code execution.
The anti-pattern is using loose equality (==) or trusting incoming data types without explicit validation.
// VULNERABLE: Loose equality comparison in authentication.
function checkAdminAccess(userId) {
// Expected: userId is string "123".
// Attacker input: userId is number 0.
// JavaScript: "0" == 0 evaluates to true (type coercion).
if (userId == 0) { // Loose equality
return true; // Grants admin access if userId is "0" or 0.
}
return false;
}
// Scenario 1: userId = "0" (string) gains admin access.
// Scenario 2: userId = 0 (number) bypasses the check.
// PHP example: "0e12345" == "0e56789" (both evaluate to 0).
// If password hash starts with "0e", attacker provides another
// hash starting with "0e" to bypass authentication.
// SECURE: Strict equality and explicit type validation.
// Option 1: Strict equality (===) checks both value AND type.
function checkAdminAccessSecure(userId) {
// "0" === 0 evaluates to false.
if (userId === 0) {
return true;
}
return false;
}
// Option 2: Explicitly validate input type.
function processProductId(productId) {
// Ensure productId is string matching expected format.
if (typeof productId !== 'string' || !/^\d+$/.test(productId)) {
throw new Error("Invalid product ID format.");
}
// Safe to use productId with known type and format.
return parseInt(productId, 10);
}
== in JavaScript or PHP code (prefer ===).$gt, $ne) by changing the input's type from a string to an object.=== instead of ==.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 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.