Type Juggling (Loose Type Comparison)
Concept
Vulnerable Scenario
Example Code (Vulnerable)
<?php
$username = $_POST['username'];
$password = $_POST['password'];
// Retrieve the stored user record from the database
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($connection, $query);
$user = mysqli_fetch_assoc($result);
// Compare the provided password with the stored password
if ($password == $user['password']) {
// Authentication successful
session_start();
$_SESSION['user_id'] = $user['id'];
header('Location: dashboard.php');
exit();
} else {
// Authentication failed
echo 'Invalid username or password';
}Explanation
Prevention
Example Code (Secure)
Conclusion
Semgrep Rule
Last updated