Skip to content

fix(Om): fix updateCollection/set() when string contains SQL operators#271

Open
Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Ibochkarev:fix/54-update-collection-set
Open

fix(Om): fix updateCollection/set() when string contains SQL operators#271
Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Ibochkarev:fix/54-update-collection-set

Conversation

@Ibochkarev
Copy link
Contributor

Fix updateCollection/set() when string value contains SQL operator keywords (e.g. IN, LIKE)

Previously, xPDOQuery::set() used isConditionalClause() to detect raw SQL expressions. String values containing SQL keywords like "IN", "LIKE", "BETWEEN", or "=" were incorrectly treated as raw SQL and not quoted, causing malformed queries and potential SQL injection.

Changes:

  • Remove isConditionalClause check in set() — string fields are now always treated as PARAM_STR and properly quoted
  • Simplify duplicate condition: replace redundant elseif (in_array(...)) with else
  • Add null type handling in driver-specific construct() for robustness
  • Add test cases: LIKE, BETWEEN, =, empty string, apostrophe (O'Brien)
  • Add descriptive names to providerUpdateCollection data sets for clearer failure messages

Security: Proper quoting via quote() reduces SQL injection risk. isConditionalClause remains used in where() and other places where SQL expressions are expected.

Fixes #54

- Remove isConditionalClause check in set() that incorrectly treated string
  values with SQL keywords (IN, LIKE, BETWEEN, =) as raw SQL expressions
- String fields are now always quoted via PARAM_STR, preventing both
  incorrect query construction and SQL injection
- Add null type handling in driver-specific construct() for robustness
- Add test cases for LIKE, BETWEEN, =, empty string, and apostrophe
- Add descriptive names to providerUpdateCollection data sets

Fixes modxcms#54
@Ibochkarev Ibochkarev marked this pull request as ready for review March 11, 2026 07:10
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.

updateCollection fails when 'set' string contains operator

1 participant