diff --git a/src/Plugin.php b/src/Plugin.php index f279a59..be8f666 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -24,8 +24,6 @@ class Plugin implements PluginEntryPointInterface * stubs => [package, operator of version_compare(), version] */ private const VERSIONED_STUBS = [ - 'DBAL/before-3' => ['doctrine/dbal', '<', '3.0'], - 'DBAL/since-3' => ['doctrine/dbal', '>=', '3.0'], 'DBAL/before-4' => ['doctrine/dbal', '<', '4.0'], 'DBAL/since-4' => ['doctrine/dbal', '>=', '4.0'], 'ORM/before-3' => ['doctrine/orm', '<', '3.0'], diff --git a/stubs/AbstractQuery.phpstub b/stubs/AbstractQuery.phpstub deleted file mode 100644 index be627c1..0000000 --- a/stubs/AbstractQuery.phpstub +++ /dev/null @@ -1,57 +0,0 @@ -|false - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchNumeric(); - - /** - * Returns the next row of the result as an associative array or FALSE if there are no more rows. - * - * @return array|false - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAssociative(); - - /** - * Returns the first value of the next row of the result or FALSE if there are no more rows. - * - * @return mixed|false - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchOne(); - - /** - * Returns an array containing all of the result rows represented as numeric arrays. - * - * @return array> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllNumeric(): array; - - /** - * Returns an array containing all of the result rows represented as associative arrays. - * - * @return array> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllAssociative(): array; - - /** - * Returns an array containing the values of the first column of the result. - * - * @return array - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchFirstColumn(): array; - } -} - -namespace Doctrine\DBAL\Abstraction -{ - use Traversable; - - interface Result extends \Doctrine\DBAL\Driver\Result - { - /** - * Returns an iterator over the result set rows represented as numeric arrays. - * - * @return Traversable> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateNumeric(): Traversable; - - /** - * Returns an iterator over the result set rows represented as associative arrays. - * - * @return Traversable> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateAssociative(): Traversable; - - /** - * Returns an iterator over the values of the first column of the result set. - * - * @return Traversable - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateColumn(): Traversable; - } -} - -namespace Doctrine\DBAL -{ - use Traversable; - - interface Result extends \Doctrine\DBAL\Abstraction\Result - { - /** - * Returns an array containing the values of the first column of the result. - * - * @return array - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllKeyValue(): array; - - /** - * Returns an associative array with the keys mapped to the first column and the values being - * an associative array representing the rest of the columns and their values. - * - * @return array> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllAssociativeIndexed(): array; - - /** - * Returns an iterator over the result set with the values of the first column of the result - * - * @return Traversable - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateKeyValue(): Traversable; - - /** - * Returns an iterator over the result set with the keys mapped to the first column and the values being - * an associative array representing the rest of the columns and their values. - * - * @return Traversable> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateAssociativeIndexed(): Traversable; - } -} diff --git a/stubs/DBAL/before-4/Connection.phpstub b/stubs/DBAL/before-4/Connection.phpstub index 385d1c5..88d6223 100644 --- a/stubs/DBAL/before-4/Connection.phpstub +++ b/stubs/DBAL/before-4/Connection.phpstub @@ -114,7 +114,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAssociative(string $query, array $params = [], array $types = []) {} @@ -131,7 +130,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchNumeric(string $query, array $params = [], array $types = []) {} @@ -148,7 +146,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchOne(string $query, array $params = [], array $types = []) {} @@ -164,7 +161,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllNumeric(string $query, array $params = [], array $types = []): array {} @@ -180,7 +176,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllAssociative(string $query, array $params = [], array $types = []): array {} @@ -197,7 +192,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array {} @@ -215,7 +209,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array {} @@ -231,7 +224,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchFirstColumn(string $query, array $params = [], array $types = []): array {} @@ -247,7 +239,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable {} @@ -264,7 +255,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable {} @@ -281,7 +271,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable {} @@ -299,7 +288,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable {} @@ -315,7 +303,6 @@ class Connection implements DriverConnection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateColumn(string $query, array $params = [], array $types = []): Traversable {} } diff --git a/stubs/DBAL/since-3/Result.phpstub b/stubs/DBAL/since-3/Result.phpstub deleted file mode 100644 index 2bc48d8..0000000 --- a/stubs/DBAL/since-3/Result.phpstub +++ /dev/null @@ -1,146 +0,0 @@ -|false - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAssociative() {} - - /** - * Returns the next row of the result as a numeric array or FALSE if there are no more rows. - * - * @return list|false - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchNumeric() {} - - /** - * Returns the first value of the next row of the result or FALSE if there are no more rows. - * - * @return mixed|false - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchOne() {} - - /** - * Returns an array containing all of the result rows represented as numeric arrays. - * - * @return list> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllNumeric(): array {} - - /** - * Returns an array containing all of the result rows represented as associative arrays. - * - * @return list> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllAssociative(): array {} - - /** - * Returns an array containing the values of the first column of the result. - * - * @return array - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllKeyValue(): array {} - - /** - * Returns an associative array with the keys mapped to the first column and the values being - * an associative array representing the rest of the columns and their values. - * - * @return array> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchAllAssociativeIndexed(): array {} - - /** - * @return list - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function fetchFirstColumn(): array {} - - /** - * @return Traversable> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateNumeric(): Traversable {} - - /** - * @return Traversable> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateAssociative(): Traversable {} - - /** - * @return Traversable - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateKeyValue(): Traversable {} - - /** - * Returns an iterator over the result set with the keys mapped to the first column and the values being - * an associative array representing the rest of the columns and their values. - * - * @return Traversable> - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateAssociativeIndexed(): Traversable {} - - /** - * @return Traversable - * - * @throws Exception - * - * @psalm-taint-source input - */ - public function iterateColumn(): Traversable {} -} diff --git a/stubs/DBAL/since-4/Connection.phpstub b/stubs/DBAL/since-4/Connection.phpstub index cf448c5..8091cec 100644 --- a/stubs/DBAL/since-4/Connection.phpstub +++ b/stubs/DBAL/since-4/Connection.phpstub @@ -7,8 +7,7 @@ use Doctrine\DBAL\Types\Type; use Traversable; /** - * The queries of doctrine/dbal 4 are SQL sinks, and what a database holds may have been written by other requests - * (stored input): the rows a query fetches are input. + * The queries of doctrine/dbal 4 are SQL sinks. */ class Connection { @@ -88,7 +87,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAssociative(string $query, array $params = [], array $types = []): array|false {} @@ -104,7 +102,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchNumeric(string $query, array $params = [], array $types = []): array|false {} @@ -120,7 +117,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchOne(string $query, array $params = [], array $types = []): mixed {} @@ -135,7 +131,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllNumeric(string $query, array $params = [], array $types = []): array {} @@ -150,7 +145,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllAssociative(string $query, array $params = [], array $types = []): array {} @@ -166,7 +160,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array {} @@ -183,7 +176,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array {} @@ -198,7 +190,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function fetchFirstColumn(string $query, array $params = [], array $types = []): array {} @@ -213,7 +204,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable {} @@ -229,7 +219,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable {} @@ -245,7 +234,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable {} @@ -262,7 +250,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable {} @@ -277,7 +264,6 @@ class Connection * @throws Exception * * @psalm-taint-sink sql $query - * @psalm-taint-source input */ public function iterateColumn(string $query, array $params = [], array $types = []): Traversable {} } diff --git a/tests/acceptance/Tainting.feature b/tests/acceptance/Tainting.feature index 5899fbd..00fecd6 100644 --- a/tests/acceptance/Tainting.feature +++ b/tests/acceptance/Tainting.feature @@ -83,28 +83,9 @@ Feature: Tainting Then I see no errors @Connection::fetchOne - @Connection::fetchAssociative @Connection::fetchAllAssociative - Scenario Outline: A row the connection fetches is printed - Given I have the following code - """ - echo (string) ; - """ - When I run Psalm with taint analysis - Then I see these errors - | Type | Message | - | TaintedHtml | Detected tainted HTML | - | TaintedTextWithQuotes | Detected tainted text with possible quotes | - And I see no other errors - Examples: - | expression | - | connection()->fetchOne('SELECT name FROM users') | - | (connection()->fetchAllAssociative('SELECT name FROM users')[0] ?? [])['name'] | - | (connection()->executeQuery('SELECT name FROM users')->fetchAllAssociative()[0] ?? [])['name'] | - | connection()->executeQuery('SELECT name FROM users')->fetchOne() | - @AbstractQuery::getSingleScalarResult - Scenario Outline: A result of an ORM query is printed + Scenario Outline: A row the database gives is no taint source Given I have the following code """ function query(): \Doctrine\ORM\Query { @@ -114,11 +95,10 @@ Feature: Tainting echo (string) ; """ When I run Psalm with taint analysis - Then I see these errors - | Type | Message | - | TaintedHtml | Detected tainted HTML | - | TaintedTextWithQuotes | Detected tainted text with possible quotes | - And I see no other errors + Then I see no errors Examples: - | expression | - | query()->getSingleScalarResult() | + | expression | + | connection()->fetchOne('SELECT name FROM users') | + | (connection()->fetchAllAssociative('SELECT name FROM users')[0] ?? [])['name'] | + | connection()->executeQuery('SELECT name FROM users')->fetchOne() | + | query()->getSingleScalarResult() |