r/PHPhelp • u/jstarkweather83 • Dec 15 '22
mysqli_connect security
I am wondering if this function is vulnerable to timing attacks and whether or not I need to add additional code for added security or does mysqli_connect work in a way that would prevent a timing attack? I assume it does but was wondering if someone can verify if this is a safe way to authenticate someones credentials?
$connection = mysqli_connect($servername, $username, $password, $database_name);
if (mysqli_connect_errno()) {
echo "Failed to connect" . mysqli_connect_error(); }
else {
echo "connected";
mysqli_close($connection); }
?>
2
u/MateusAzevedo Dec 15 '22 edited Dec 15 '22
MySQL functions in PHP are just a wrapper for the mysqlnd C library. If something is implemented for timing attacks, it's likely to be on the underlying code.
In any case, you code example is unsafe for another reason: one shouldn't just print errors unconditionally.
This article shows the correct way of connecting to MySQL, including the proper error reporting mode.
1
u/CyberJack77 Dec 16 '22
Can you describe what you consider a "timing attack" and why you think (or suspect) connecting to a database might be vulnerable?