Merge pull request #44394 from nextcloud/fix/ipv6-postgres

fix(DB): Sanitize `host` parameter for postgres databases when IPv6 address is passed
pull/44467/head
Ferdinand Thiessen 2 months ago committed by GitHub
commit 0d7bb0b664
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -112,9 +112,9 @@ $CONFIG = [
/**
* Your host server name, for example ``localhost``, ``hostname``,
* ``hostname.example.com``, or the IP address. To specify a port use
* ``hostname:####``; to specify a Unix socket use
* ``/path/to/directory/containing/socket`` e.g. ``/run/postgresql/``.
* ``hostname.example.com``, or the IP address.
* To specify a port use ``hostname:####``, for IPv6 addresses use the URI notation ``[ip]:port``.
* To specify a Unix socket use ``/path/to/directory/containing/socket``, e.g. ``/run/postgresql/``.
*/
'dbhost' => '',

@ -128,6 +128,15 @@ class ConnectionFactory {
$eventManager->addEventSubscriber(new SetTransactionIsolationLevel());
$additionalConnectionParams = array_merge($this->createConnectionParams(), $additionalConnectionParams);
switch ($normalizedType) {
case 'pgsql':
// pg_connect used by Doctrine DBAL does not support URI notation (enclosed in brackets)
$matches = [];
if (preg_match('/^\[([^\]]+)\]$/', $additionalConnectionParams['host'], $matches)) {
// Host variable carries a port or socket.
$additionalConnectionParams['host'] = $matches[1];
}
break;
case 'oci':
$eventManager->addEventSubscriber(new OracleSessionInit);
// the driverOptions are unused in dbal and need to be mapped to the parameters

Loading…
Cancel
Save