Skip to content

Commit

Permalink
fix(DB): Sanitize host parameter for postgres databases when IPv6 a…
Browse files Browse the repository at this point in the history
…ddress is passed

Doctrine is using `pg_connect` with the `host` parameter, this does not allow IPv6 addresses in URI notation.
So we need to extract the IP address and pass it directly

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Mar 21, 2024
1 parent 45efd28 commit e74b0f5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public function getConnection($type, $additionalConnectionParams) {
$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
Expand Down

0 comments on commit e74b0f5

Please sign in to comment.