# Type Coercion Security Bugs - ID: javascript-type-coercion-bugs - Severity: MEDIUM - CWE: CWE-1024 (CWE-1024) - Languages: JavaScript, TypeScript - Frameworks: all ## Description Detects unsafe use of loose equality operators (==, !=) and type coercion patterns that can lead to security vulnerabilities. JavaScript's type coercion can cause unexpected behavior in security-critical code. Common security issues from type coercion: 1. Authentication bypass: password == null matches both null AND undefined 2. Authorization bypass: role == "admin" can be bypassed with role = true 3. Input validation bypass: value == 0 matches "", [], false, "0" 4. SQL/NoSQL injection: params == {} doesn't check for actual object properties Type coercion rules in JavaScript: - null == undefined (true) - 0 == "" == false == [] (all true) - "0" == 0 (true) - " \t\n" == 0 (true) - But: "0" != false (because string vs boolean) Security implications are severe when used in: - Authentication/authorization checks - Input validation - Null/undefined checks - Role/permission comparisons ## Detection Message Loose equality operator {operator} used in security-critical context: {context} ## Remediation Use strict equality (===, !==) to avoid type coercion bugs. ## Documentation [object Object]