Fix SQL injection in Schema::findViewNames()#463
Conversation
The $schema variable was interpolated directly into the SQL string in the heredoc, allowing potential SQL injection. While $schema typically comes from configuration (not user input), this is inconsistent with the rest of the codebase where all other Schema methods use parameterized queries (e.g., findTableComment uses :schemaName, findTableNames uses quoteSimpleTableName). Replace direct interpolation with a :schemaName bound parameter, consistent with the pattern used elsewhere in this file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #463 +/- ##
============================================
+ Coverage 98.73% 98.84% +0.11%
- Complexity 255 256 +1
============================================
Files 24 24
Lines 790 779 -11
============================================
- Hits 780 770 -10
+ Misses 10 9 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| SQL, | ||
| }; | ||
|
|
||
| $params = $schema !== '' ? [':schemaName' => $schema] : []; |
There was a problem hiding this comment.
It is better to combine two identical checks into one.
There was a problem hiding this comment.
There are different conditions in SQL: table_schema != 'sys' and table_schema = :schemaName.
vjik
left a comment
There was a problem hiding this comment.
I suggest refactor code to:
if ($schema === '') {
$sql = ...
$params = ...
} else {
$sql = ...
$params = ...
}I think it will be more clear.
That's what I meant. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a SQL injection risk in the MySQL/MariaDB schema introspection layer by replacing direct string interpolation in Schema::findViewNames() with a bound parameter, aligning the implementation with other schema metadata queries in the same class.
Changes:
- Replace
$schemastring interpolation in theinformation_schema.tablesquery with a:schemaNamebound parameter. - Pass bound parameters to
createCommand()when a non-empty schema is provided.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
👍 |
Summary
Schema::findViewNames()interpolates the$schemaparameter directly into a SQL heredoc string:This is a SQL injection risk. While
$schematypically comes from configuration rather than user input, this is inconsistent with the rest of the codebase where all other methods in this file use either parameterized queries or proper quoting:findTableComment()(line 164): uses:schemaNamebound parameterfindTableNames()(line 181): usesquoteSimpleTableName()loadTableConstraints(),loadTableIndexes(), etc.: all use:schemaNameFix
Replace direct string interpolation with a
:schemaNamebound parameter, consistent withfindTableComment()and other methods in the same file.Before
After
Risk
Very low — this is a direct replacement of string interpolation with parameter binding. The query behavior is identical.