mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Use psalm literal-string type, to address Injection Vulnerabilities
#6809
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @craigfrancis on GitHub (Aug 22, 2021).
Feature Request
Summary
Psalm 4.8 introduced a new
literal-stringtype, which addresses the main source of Injection Vulnerabilities - developers incorrectly including user-input in sensitive strings, before they are provided to Doctrine, e.g.literal-stringworks by distinguishing strings from a trusted developer, from strings that may be attacker controlled.Considering
QueryBuilder::add()already usesstring|object|arrayfor $dqlPart, the same could be used forwhere()$predicates.However, by using
literal-string|object|arrayforwhere($predicates), theliteral-stringtype will check the developer wrote that string, and gets them to usesetParameter()for user-input (as they should).The
literal-stringtype could be used in a few other locations as well (especially with the Injection risks that come with DQL); but I'd like to start the discussion withwhere().The only issue I can see is
Connection::quoteIdentifier(), for those rare times when user-input is used for table/field/etc names. Because it can return a nonliteral-stringvalue, it cannot be concatenated into$predicates; so maybe there should be aQueryBuilder::setIdentifier()to ensure these values are always quoted correctly, something like:@craigfrancis commented on GitHub (Sep 4, 2021):
The
literal-stringis also available in PHPStan 0.12.97