Skip to main content
LowAI codeOWASP A07:2021CWE-697

How to fix: Loose Equality in Authentication Check

A loose equality comparison (== instead of ===) was detected in what appears to be an authentication or authorization check. In JavaScript, loose equality can produce unexpected coercion results that bypass security checks. Note: this pattern is scanned from client-delivered page scripts, where `role == 'admin'` is most often harmless UI-gating (show/hide an element) rather than the actual server-side authorization decision -- treat this as a prompt to check the real backend logic, not confirmation that a bypass exists.

Why it matters

JavaScript type coercion with == means that '0' == 0 (true), null == undefined (true), and '' == false (true). An authentication check using == instead of === can be bypassed with specially crafted input that evaluates as equal through coercion.

AI tools frequently generate authentication checks using == because it looks natural. The canonical bypass is sending JSON with `role: 0` instead of `role: false`, or exploiting array-to-string coercions in role checks.

How to fix it

  1. 1Use === (strict equality) everywhere, especially in security checks.
  2. 2Enable eslint's eqeqeq rule to prevent == usage.
  3. 3Validate and type-check input with a schema library before comparing.
  4. 4Be explicit about types: parseInt(userId, 10) === session.userId.

Code examples

Use strict equality

TypeScript
// Bad (AI-generated, loose equality, type coercion risk)
if (user.role == 'admin') { ... }
if (token == expectedToken) { ... }

// Good
if (user.role === 'admin') { ... }
// For secrets: constant-time comparison
if (!crypto.timingSafeEqual(Buffer.from(token), Buffer.from(expectedToken))) { ... }

References

Detected automatically by VulnRadar. The check id is vibe-loose-equality-auth, stable across every scan so you can filter or diff on it.

See every ai code check

Questions

How severe is Loose Equality in Authentication Check?
VulnRadar rates this low severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vibe-loose-equality-auth, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Loose Equality in Authentication Check map to?
It maps to CWE-697. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for loose equality in authentication check

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Loose Equality in Authentication Check fix | VulnRadar