PHP-Windows上的PDO在密码为空时会忽略主机名和用户名

我不确定我的设置是否有问题,或者这是Windows PDO中的错误

<?PHP 

$dsn = 'MysqL:host=127.0.0.1;dbname=mydb;charset=UTF8';
$username = 'myuser';
$password = '';
$pdo = new PDO($dsn, $username, $password);

我的错误出现在:

Fatal error: Uncaught exception ‘PDOException’ with message
sqlSTATE[42000] [1044] Access denied for user ”@’localhost’ to
database ‘mydb” in C:\ampps\www\test.PHP:6 Stack trace: #0
C:\ampps\www\test.PHP(6): PDO->__construct(‘MysqL:host=127….’,
‘myuser’, ”) #1 {main} thrown in C:\ampps\www\test.PHP on line 6

我已经能够在所有3台Windows开发机上重现此信息,但在所有Linux服务器上均没有.

任何人都可以确认或指出可能有问题吗?

谢谢!

编辑:使用空密码在用户上正确设置了特权.

EDIT2:有报告说,该问题在运行MAMP 3.0.3的Mac上可重现

EDIT3:之前有几份报告,但看来它尚未得到解决

https://bugs.php.net/bug.php?id=43493

https://bugs.php.net/bug.php?id=46457

我的报告:https://bugs.php.net/bug.php?id=67026

EDIT4:当权限被授予“ myuser” @“ localhost”时有效,但是在没有密码的情况下授予“ myuser” @“%”权限时也会出现问题-在Linux上也是如此

解决方法:

我想确认一下.

在测试之前,请确保满足条件:

>确保nonexistent_user不是数据库中的用户.
>确保root设置了密码.
>确保单独运行这些测试.
>确保在Windows(或任何受影响的计算机)上运行这些测试.

我已经将有关的用户名加粗了.

测试#1

不存在的用户空密码=错误消息的空用户名

$MysqLi = new MysqLi('localhost', 'nonexistent_user', '', 'database');
$pdo    = new PDO('MysqL:host=localhost;dbname=database;charset=UTF8', 'nonexistent_user', '');

Warning: MysqLi::MysqLi(): (HY000/1044): Access denied for user ”@’localhost’ to database ‘database’ in test.PHP

Fatal error: Uncaught exception ‘PDOException’ with message ‘sqlSTATE[HY000] [1044] Access denied for user ”@’localhost’ to database ‘database” in test.PHP Stack trace: #0 test.PHP(): PDO->__construct(‘MysqL:host=loca…’, ‘nonexistent_use…’, ”) #1 {main} thrown in test.PHP

测试#2

存在空密码的用户=为错误消息设置了用户名

$MysqLi = new MysqLi('localhost', 'root', '', 'database');
$pdo    = new PDO('MysqL:host=localhost;dbname=database;charset=UTF8', 'root', '');

Warning: MysqLi::MysqLi(): (HY000/1045): Access denied for user ‘root’@’localhost’ (using password: NO) in test.PHP

Fatal error: Uncaught exception ‘PDOException’ with message ‘sqlSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO)’ in test.PHP Stack trace: #0 test.PHP(): PDO->__construct(‘MysqL:host=loca…’, ‘root’, ”) #1 {main} thrown in test.PHP

测试#3

不存在的用户设置密码=为错误消息设置用户名

$MysqLi = new MysqLi('localhost', 'nonexistent_user', 'password', 'database');
$pdo    = new PDO('MysqL:host=localhost;dbname=database;charset=UTF8', 'nonexistent_user', 'password');

Warning: MysqLi::MysqLi(): (HY000/1045): Access denied for user ‘nonexistent_user’@’localhost’ (using password: YES) in test.PHP

Fatal error: Uncaught exception ‘PDOException’ with message ‘sqlSTATE[HY000] [1045] Access denied for user ‘nonexistent_user’@’localhost’ (using password: YES)’ in test.PHP Stack trace: #0 test.PHP(): PDO->__construct(‘MysqL:host=loca…’, ‘nonexistent_use…’, ‘password’) #1 {main} thrown in test.PHP

用户不存在并且提供空密码时,错误消息将显示空白的用户名.

我认为这将带来安全风险,因为攻击者可以通过发送带有空密码的测试用户名来测试哪些用户有效,并查看错误响应是否为该用户名为空.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...