Commit 638f1e50154 for php
commit 638f1e5015410f3ff050defdd4abaa5351389cd4
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date: Sun Nov 8 10:24:52 2026 -0500
ext/pdo: Hide DSNs in connection exception traces (#25290)
A DSN may embed a password (password=... for most drivers, PWD=... for odbc),
so mark the $dsn argument of PDO::__construct() and PDO::connect() sensitive,
as $password already is. The Pdo\* driver subclasses inherit both methods and
get the same redaction.
diff --git a/ext/pdo/pdo_dbh.stub.php b/ext/pdo/pdo_dbh.stub.php
index 7fcec0226b0..520278d9512 100644
--- a/ext/pdo/pdo_dbh.stub.php
+++ b/ext/pdo/pdo_dbh.stub.php
@@ -164,10 +164,10 @@ class PDO
/** @cvalue LONG_CONST(PDO_CURSOR_SCROLL) */
public const int CURSOR_SCROLL = UNKNOWN;
- public function __construct(string $dsn, ?string $username = null, #[\SensitiveParameter] ?string $password = null, ?array $options = null) {}
+ public function __construct(#[\SensitiveParameter] string $dsn, ?string $username = null, #[\SensitiveParameter] ?string $password = null, ?array $options = null) {}
public static function connect(
- string $dsn,
+ #[\SensitiveParameter] string $dsn,
?string $username = null,
#[\SensitiveParameter] ?string $password = null,
?array $options = null
diff --git a/ext/pdo/pdo_dbh_arginfo.h b/ext/pdo/pdo_dbh_arginfo.h
index 1e4cc4328b9..dda15b0c7dc 100644
Binary files a/ext/pdo/pdo_dbh_arginfo.h and b/ext/pdo/pdo_dbh_arginfo.h differ
diff --git a/ext/pdo/tests/sensitive_parameter.phpt b/ext/pdo/tests/sensitive_parameter.phpt
index b9cf01baedf..ab2e628ac0b 100644
--- a/ext/pdo/tests/sensitive_parameter.phpt
+++ b/ext/pdo/tests/sensitive_parameter.phpt
@@ -1,17 +1,59 @@
--TEST--
-Test that sensitive parameters are marked sensitive.
+PDO connection DSNs and passwords are sensitive
--EXTENSIONS--
pdo
+--INI--
+zend.exception_ignore_args=0
--FILE--
<?php
+echo "Constructor:\n";
try {
- new PDO('dsn', 'username', 'password');
+ new PDO('missing:password=dsn-secret', 'username', 'password');
+} catch (\Throwable $e) {
+ echo $e, PHP_EOL;
+}
+
+echo "Connect with named arguments:\n";
+try {
+ PDO::connect(dsn: 'missing:password=dsn-secret', username: 'username', password: 'password');
+} catch (\Throwable $e) {
+ echo $e, PHP_EOL;
+}
+
+class TestPDO extends PDO {}
+
+echo "Inherited constructor:\n";
+try {
+ new TestPDO('missing:password=dsn-secret', 'username', 'password');
+} catch (\Throwable $e) {
+ echo $e, PHP_EOL;
+}
+
+echo "Inherited connect:\n";
+try {
+ TestPDO::connect('missing:password=dsn-secret', 'username', 'password');
} catch (\Throwable $e) {
echo $e, PHP_EOL;
}
?>
--EXPECTF--
-PDOException: PDO::__construct(): Argument #1 ($dsn) must be a valid data source name in %s:%d
+Constructor:
+PDOException: could not find driver in %s:%d
+Stack trace:
+#0 %s(%d): PDO->__construct(Object(SensitiveParameterValue), 'username', Object(SensitiveParameterValue))
+#1 {main}
+Connect with named arguments:
+PDOException: could not find driver in %s:%d
+Stack trace:
+#0 %s(%d): PDO::connect(Object(SensitiveParameterValue), 'username', Object(SensitiveParameterValue))
+#1 {main}
+Inherited constructor:
+PDOException: could not find driver in %s:%d
+Stack trace:
+#0 %s(%d): PDO->__construct(Object(SensitiveParameterValue), 'username', Object(SensitiveParameterValue))
+#1 {main}
+Inherited connect:
+PDOException: could not find driver in %s:%d
Stack trace:
-#0 %s(%d): PDO->__construct('dsn', 'username', Object(SensitiveParameterValue))
+#0 %s(%d): PDO::connect(Object(SensitiveParameterValue), 'username', Object(SensitiveParameterValue))
#1 {main}