Skip to content

Commit

Permalink
URL encode variables that go into a MySQL credentials URI
Browse files Browse the repository at this point in the history
See for reference:
- https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html#connecting-using-uri
- https://symfony.com/doc/current/doctrine.html
but note that we must use `rawurlencode` instead of `urlencode` which
differ in how they encode a space (as tested).

Fixes: #2651
Closes: #2502 as this is likely fixed but I couldn't reproduce it
  • Loading branch information
eldering committed Nov 24, 2024
1 parent 063b687 commit abeefb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion webapp/config/load_db_secrets.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function get_db_url(): string
break;
}

return sprintf('mysql://%s:%s@%s:%d/%s?serverVersion=5.7.0', $user, $pass, $host, $port ?? 3306, $db);
return sprintf(
'mysql://%s:%s@%s:%d/%s?serverVersion=5.7.0',
rawurlencode($user), rawurlencode($pass), rawurlencode($host),
$port ?? 3306, rawurlencode($db)
);
}

function get_app_secret(): string
Expand Down
2 changes: 1 addition & 1 deletion webapp/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ doctrine:
charset: utf8mb4
collate: utf8mb4_unicode_ci

url: '%env(resolve:DATABASE_URL)%'
url: '%env(DATABASE_URL)%'
profiling_collect_backtrace: '%kernel.debug%'
types:
tinyint: App\Doctrine\DBAL\Types\TinyIntType
Expand Down

0 comments on commit abeefb3

Please sign in to comment.