Skip to content

Support DBAL 4, ORM 3, Collections 2 and Persistence 4, and taint the rows the database fetches - #166

Merged
danog merged 3 commits into
psalm:2.xfrom
danog:doctrine-latest-and-row-taints
Nov 18, 2026
Merged

danog merged 3 commits into
psalm:2.xfrom
danog:doctrine-latest-and-row-taints

Conversation

@danog

@danog danog commented Nov 18, 2026

Copy link
Copy Markdown
Member

The stubs describe DBAL 2/3 and ORM 2 only, so on the current majors they declare APIs that no longer exist, and the rows the database fetches aren't taint sources.

Before (DBAL 4, ORM 3, Collections 2)

<?php
connection()->quote(...);              // the stub's quote($input, int $type), not DBAL 4's quote(string $value)
\Doctrine\DBAL\ParameterType::STRING;  // an int constant, not DBAL 4's enum case
\Doctrine\ORM\Mapping\ClassMetadataInfo::class; // a class ORM 3 removed, declared by the stub
$c->map(fn (string $s): bool => true); // MixedArgumentTypeCoercion: the stub's TValue isn't the library's T

echo (string) connection()->fetchOne('SELECT name FROM users'); // no issue
connection()->executeQuery('SELECT * FROM t WHERE a = ' . $_GET['a']); // no issue

After

echo (string) connection()->fetchOne('SELECT name FROM users'); // TaintedHtml
connection()->executeQuery('SELECT * FROM t WHERE a = ' . $_GET['a']); // TaintedSql

The stubs of removed APIs load only for the versions that have them (stubs/DBAL/before-4, stubs/ORM/before-3, picked with Composer\InstalledVersions), DBAL 4 gets its own Connection stub, and CI's "high" deps now install DBAL 4, ORM 3, Collections 2 and Persistence 4 while "low" keeps ORM 2.6 and DBAL 2.13. The acceptance suite passes on DBAL 4/ORM 3 and on DBAL 3/ORM 2.

Psalm is about to require this plugin and enable it for every project requiring Doctrine (vimeo/psalm, follow-up PR), which is why the current majors must work out of the box.

… rows the database fetches

The stubs of the APIs a version removed load only for the versions that have
them (DBAL < 4: Connection::exec(), query() and executeUpdate(),
ExpressionBuilder::andX() and orX(), ParameterType, a class until it became an
enum; ORM < 3: ClassMetadataInfo), and DBAL 4 gets a Connection stub of its own.
The value template of the Collection stub is T, as in doctrine/collections,
which declares map() with a template of its own.

executeQuery() and the fetch*() and iterate*() methods of Connection take SQL,
and what they, Result and the array and scalar results of an ORM query return
is input: other requests may have written it.
danog added a commit to danog/psalm that referenced this pull request Nov 18, 2026
Psalm requires the plugin, which describes DBAL by version, and enables it for
the projects requiring Doctrine (psalm/psalm-plugin-doctrine#166).
InstalledVersions::satisfies() is false for any constraint with composer/semver
1.x, which the lowest dependencies install, so neither DBAL Connection stub was
loaded. The ORM query of the taint test is typed like the connection, which the
oldest Psalm 7 releases want pure.
DBAL 2.13 declares the fetch methods on the Driver\Result, Abstraction\Result
and Result interfaces, which executeQuery() returns; DBAL 3 makes Result a
class.
@danog
danog merged commit a94d55e into psalm:2.x Nov 18, 2026
15 checks passed
danog added a commit to danog/psalm that referenced this pull request Nov 18, 2026
Psalm requires the plugin, which describes DBAL by version, and enables it for
the projects requiring Doctrine (psalm/psalm-plugin-doctrine#166).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant