Skip to content

pdo: Deprecate the uri: DSN scheme #19274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ PDO_API void php_pdo_internal_construct_driver(INTERNAL_FUNCTION_PARAMETERS, zen
}

if (!strncmp(data_source, "uri:", sizeof("uri:")-1)) {
zend_error(E_DEPRECATED, "Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs");
if (EG(exception)) {
RETURN_THROWS();
}

/* the specified URI holds connection details */
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
if (!data_source) {
Expand Down
5 changes: 4 additions & 1 deletion ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ MySQLPDOTest::skip();

print "done!";
?>
--EXPECT--
--EXPECTF--
Deprecated: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs in %s on line %d

Deprecated: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs in %s on line %d
done!
48 changes: 48 additions & 0 deletions ext/pdo_sqlite/tests/pdo_sqlite___construct_uri.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
PDO_sqlite: PDO->__construct() - URI
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
$dsnFile = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.dsn";
$dbFile = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.db";
file_put_contents($dsnFile, "sqlite:{$dbFile}");

clearstatcache();
var_dump(file_exists($dbFile));
new PDO("uri:{$dsnFile}");

clearstatcache();
var_dump(file_exists($dbFile));
unlink($dbFile);

set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
});

clearstatcache();
var_dump(file_exists($dbFile));

try {
new PDO("uri:{$dsnFile}");
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
}

clearstatcache();
var_dump(file_exists($dbFile));

?>
--CLEAN--
<?php
@unlink(__DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.dsn");
@unlink(__DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite___construct_uri.db");
?>
--EXPECTF--
bool(false)

Deprecated: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs in %s on line %d
bool(true)
bool(false)
ErrorException: Looking up the DSN from a URI is deprecated due to possible security concerns with DSNs coming from remote URIs
bool(false)