Ir al contenido

Loose Type Comparison (ARCH7138)

Esta página aún no está disponible en tu idioma.

Key php.security.loose-type-comparison · Severity warning · Category security · CWE CWE-697

In PHP, loose equality (==) coerces types; cases like "0e123" == "0e456" return true. In a token or hash comparison this type juggling leads to an authentication bypass.

<?php
if ($_POST['token'] == $storedToken) { // bypassable via type juggling
grantAccess();
}
<?php
if (hash_equals($storedToken, $_POST['token'])) { // constant-time, type-strict
grantAccess();
}

In security comparisons use strict === instead of ==, or constant-time hash_equals() for secret values.