Skip to content

Fix parseDsn() to URL-decode username and password credentials and database name - #19603

Open
webdevsamran wants to merge 1 commit into
cakephp:6.xfrom
webdevsamran:fix/parse-dsn-urldecode-credentials
Open

webdevsamran wants to merge 1 commit into
cakephp:6.xfrom
webdevsamran:fix/parse-dsn-urldecode-credentials

Conversation

@webdevsamran

Copy link
Copy Markdown

Description

URL-decodes the \username, \password, and \database\ name parsed from a DSN string in \StaticConfigTrait::parseDsn()\ and \ConnectionManager::parseDsn(). This prevents percent-encoded special characters (such as %21\ for !, %40\ for @, or %23\ for #) in credentials and database names from remaining encoded when establishing database connections.

Fixes #19557

@markstory markstory added this to the 6.0 milestone Aug 28, 2026
Comment on lines +280 to +285
if (isset($parsed['username'])) {
$parsed['username'] = urldecode($parsed['username']);
}
if (isset($parsed['password'])) {
$parsed['password'] = urldecode($parsed['password']);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't URL decoding be done on all non-query parts of the DSN? In the doctrine implementation you referenced they decode all components of the URL https://github.com/doctrine/dbal/blob/ff5c1863b4dc16ab900d6552c8401dcf1ae3975f/src/Tools/DsnParser.php#L52-L56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants