Repository navigation
Security: where operator allowlist, JSON path injection, MySQL prepares/utf8mb4, bounded caches - #4
Open
DavidWilliamBalbino wants to merge 5 commits into
Open
DavidWilliamBalbino wants to merge 5 commits into
DavidWilliamBalbino wants to merge 5 commits into
Conversation
Compiler::condition() concatenated the operator string into the statement, so where($column, $_GET['op'], $value) with "= 1 OR 1=1 OR id =" was SQL injection. String operators are now checked against a list of known operators (comparison, LIKE/ILIKE, IN, BETWEEN, IS [NOT] [DISTINCT FROM], REGEXP, SIMILAR TO, Postgres and bitwise operators); others throw CompilerException. A Fragment still passes any operator explicitly.
JsonExpression::wrapPath() escaped quotes with the regex "/(\\+)?'/",
which PHP reads as (\+)?' and so matches a literal plus, not
backslashes: in MySQL's default sql_mode orderBy("data->x\\' OR
SLEEP(5) -- ") ended the string literal. Path segments with a quote,
double quote or backslash now throw DriverException instead of being
escaped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security fixes from the 2026-11-20 PAM/Nimbus/Arcano audit.
Findings fixed
whereoperators must be on an allowlist (Compiler::condition()), sowhere($col, $_GET['op'], $v)can no longer inject SQL. Anything else throwsCompilerException; use aFragment/Expressionfor exotic operators.',"or\are refused (DriverException) instead of escaped. The old regex(\+)?'matched+, not a backslash, which allowed blind injection on MySQL with the defaultsql_mode.PDO::ATTR_EMULATE_PREPARES => false(server-side prepares),SET NAMES utf8mb4andcharset=utf8mb4in the DSN for TCP and socket configs. Both stay overridable throughoptions/charset.Driver::QUERY_CACHE_LIMIT= 512 per connection) and the compiled SQL cache (CompilerCache::LIMIT= 2048) drop their oldest entry when full. The insert/update plan cache (StatementPlans) was already capped at 1024 per database; that cap now has a test.Tests
tests/Database/Unit/Driver/OperatorAllowlistTest.phptests/Database/Unit/Injection/JsonExpressionTest.php(new cases)tests/Database/Unit/Config/MySQL/SafeDefaultsTest.phptests/Database/Unit/Driver/BoundedCachesTest.phptests/ORM/Unit/Command/StatementPlansTest.phpResults run locally:
unit: OK (883 tests).postgres(postgres:17-alpine): OK (2796 tests).mysql(mysql:8.0): OK (2640 tests).sqlite: 1 error,SingleFileStrategyTest::testInit("Can't autowire Migration\OrmSecondary…"). It fails the same way onorigin/mainand passes when run alone, so it depends on test order and was there before this PR.