Skip to content

Fix SQL injection in bStrArr() by binding each value - #12

Merged
ellisgl merged 1 commit into
releasefrom
fix-bstrarr-injection
Nov 25, 2026
Merged

ellisgl merged 1 commit into
releasefrom
fix-bstrarr-injection

Conversation

@ellisgl

@ellisgl ellisgl commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Security fix. Statement::bStrArr() pasted its values into the SQL between quotes without escaping them:

->sql('WHERE `location` IN (%%)')->bStrArr(['Estonia', "x') OR ('1'='1"])
// ran:  WHERE `location` IN ('Estonia', 'x') OR ('1'='1')   → every row

Each value is now bound as its own named parameter (:arr0, :arr1, …), and the %% placeholder becomes that list of names. Calling code doesn't change, and getComputed() still shows IN ('Germany', 'USA').

Details

  • Array parameters use their own :arrN names, so they never shift the positions of ? placeholders around them.
  • An empty array still inserts $default raw, as before. The README now warns not to pass untrusted input as $default.
  • NULL values become '', as they did with implode(). Arrays and objects throw InvalidArgumentException.
  • getComputed() now fills raw (%%) placeholders before named ones, matching what execute() does.
  • The binding-layer bStrArr() methods (StringBindingInterface, Bindings, MySQLStringBindings) are kept so custom binding classes don't break, but are marked @deprecated. Statement no longer calls them.
  • Adds the 4.0.11 CHANGELOG entry and README updates, covering this and the bInt() fix in Fix bInt() turning negative numbers into huge positive ones #11.

Tests: 4 new tests: injection attempt, mixed ? and array placeholders, empty array, non-scalar value. The full suite passes against MySQL 8.4 (54 tests), along with PHPStan level 8 and PSR-12.

🤖 Generated with Claude Code

Statement::bStrArr() pasted the values into the SQL between quotes
without escaping them, so a value containing a quote could change the
query. Each value is now bound as its own named parameter (:arr0,
:arr1, ...) and the %% placeholder becomes the list of those names.
The calling code and getComputed() output are unchanged.

getComputed() now fills raw placeholders before named ones, matching
execute(). The binding-layer bStrArr() methods are kept for custom
binding classes but marked deprecated.

Also adds the 4.0.11 CHANGELOG entry and README updates for this and
the bInt() fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellisgl
ellisgl merged commit a3d0698 into release Nov 25, 2026
7 checks passed
@ellisgl
ellisgl deleted the fix-bstrarr-injection branch November 25, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant