Commit 90e4d32
committed
# fix: Prevent SQL injection in
## Description
Previously, the `whereIn` method in the `Select` statement directly interpolated values into the SQL query string by wrapping them in single quotes. This approach is highly vulnerable to SQL injection, as malicious input in the `$value` array could alter the query's intent and potentially lead to unauthorized data access or manipulation.
This commit addresses this critical security vulnerability by switching to a prepared statement approach for the `WHERE IN` clause. Instead of direct string concatenation, values are now added to the internal `$this->params` array, and database-specific placeholders are generated using `Utilities::get_placeholder()`. This ensures that all values are properly escaped and bound by the underlying database driver, effectively preventing SQL injection attacks.
## Changes in the codebase
- **`src/Statement/Select.php`**:
- In the `whereIn` method, the anonymous function responsible for formatting the list of items for the `IN` clause has been modified.
- The line `return "'" . $item . "'";` has been replaced.
- Each `$item` from the input `$value` array is now first added to the `$this->params[]` array, making it available for parameter binding.
- `Utilities::get_placeholder($this->db, $item)` is now used to generate a database-agnostic placeholder for each item, ensuring safe parameterization regardless of the database system.whereIn clause1 parent c788ad7 commit 90e4d32
2 files changed
+3
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| |||
0 commit comments