Skip to content

Fix persistent PDO hash key colliding on colon in credentials - #23354

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/pdo-persistent-hash-key
Open

Fix persistent PDO hash key colliding on colon in credentials#23354
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/pdo-persistent-hash-key

Conversation

@iliaal

@iliaal iliaal commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Persistent PDO built the connection cache key by joining DSN, username, and password with colons, so admin/s:ecret and admin:s/ecret reused one handle. Each field is now length-prefixed, including a string ATTR_PERSISTENT key.

Comment thread ext/pdo/pdo_dbh.c
The persistent handle key joined DSN, username, and password with
unescaped colons, so distinct pairs such as admin/s:ecret and
admin:s/ecret reused one connection. Length-prefix each field.

Audited both ATTR_PERSISTENT encodings (boolean and user string key).
No other PDO:DBH key builders; every driver uses this constructor.
@iliaal
iliaal force-pushed the fix/pdo-persistent-hash-key branch from 4688203 to f05bde7 Compare August 18, 2026 19:15
@iliaal

iliaal commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Moved to ext/pdo_sqlite/tests with sqlite::memory: directly.

On the NUL prefix, it predates the patch and the length prefix narrows it. Unpatched, "k" and "k\0a" key identically; with the prefix they are 1:k and 3:k. What still collides is two keys sharing both a declared length and a pre-NUL prefix, so "k\0aaa" and "k\0bbb" as you showed. Keeping Z_STRLEN_P(v) and leaving 8.4 here; I'll do the smart_str version on master with the merge-up.

mysqli goes in its own PR. (thanks Claude :-))

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