Propel2 SQL injection possible with limit() on MySQL
Impact
The limit() query method is susceptible to catastrophic SQL injection with MySQL.
Source excerpt · OSVAffected packages
Start with the recorded fix for your release branch. Check your installed version and test compatibility before upgrading. Fixing this advisory does not rule out other vulnerabilities in the release.
| Affected range | Recorded fix |
|---|---|
| From 2.0.0-alpha1 before 2.0.0-alpha8Ecosystem versions | 2.0.0-alpha8 |
Version evidence: OSV · GHSA-7vw7-qx38-37vr
View original version evidence (7 explicit versions)
Original source description
The limit() query method is susceptible to catastrophic SQL injection with MySQL.
For example, given a model User for a table users:
UserQuery::create()->limit('1;DROP TABLE users')->find();
This will drop the users table!
The cause appears to be a lack of integer casting of the limit input in either Propel\Runtime\ActiveQuery\Criteria::setLimit() or in Propel\Runtime\Adapter\Pdo\MysqlAdapter::applyLimit(). The code comments there seem to imply that casting was avoided due to overflow issues with 32-bit integers.
This is surprising behavior since one of the primary purposes of an ORM is to prevent basic SQL injection.
This affects all versions of Propel: 1.x, 2.x, and 3.
References
- Source reference github.com/propelorm/Propel2/issues/1463
- Patch github.com/propelorm/Propel2/pull/1464
- Patch github.com/propelorm/Propel2/commit/cd23d7384a15cfe203e23b3a835c8ab1d81d9246
- Security advisory github.com/FriendsOfPHP/security-advisories/blob/master/propel/propel/2018-02-14.yaml
- Source reference github.com/propelorm/Propel2