Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/pdo/pdo_dbh.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion ext/pdo/pdo_dbh_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 46 additions & 4 deletions ext/pdo/tests/sensitive_parameter.phpt
Original file line number Diff line number Diff line change
@@ -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}
Loading