fix: prevent SQL injection bypass in escapeIdentifiers and protectIdentifiers#10283
Open
gr8man wants to merge 1 commit into
Open
fix: prevent SQL injection bypass in escapeIdentifiers and protectIdentifiers#10283gr8man wants to merge 1 commit into
gr8man wants to merge 1 commit into
Conversation
Implemented strict regex validation for SQL function calls and string literals in BaseConnection::isSafeToBypassEscape() to prevent SQL injection vulnerabilities. Updated tests to match the new secure behavior and added explicit SQL injection test cases.
|
Hi there, gr8man! 👋 Thank you for sending this PR! We expect the following in all Pull Requests (PRs).
Important We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md Sincerely, the mergeable bot 🤖 |
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.
Description
This PR fixes a critical SQL injection bypass vulnerability within
BaseConnection::escapeIdentifiers()andBaseConnection::protectIdentifiers().Previously, the framework blindly bypassed identifier escaping if it encountered a parenthesis
(or a single quote'(relying onstrcspnandstr_contains), assuming it was a valid SQL function or subquery. This allowed attackers to inject malformed SQL strings (e.g.,COUNT(id) OR 1=1or unbalanced parentheses) that evaded escaping entirely.Changes made:
str_containsandstrcspnchecks.isSafeToBypassEscape()regex validation that ensures an identifier is either a valid balanced function call (with optional safe aliases) or a proper string literal before bypassing the escape logic.Checklist: