-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mysqli: error on invalid escaping #562
Comments
@craigfrancis do you agree that these are cases we should report errors for, as they hide errors in wrong escaping? do other php apis have the same problem? |
I think I have seen similar code like this in my life somewhere: wrong (sql injection vulnerable): $query = sprintf('SELECT CountryCode FROM City WHERE name="%s"',
addslashes($mysqli, $city)); // invalid escaping method
$query = sprintf('SELECT CountryCode FROM City WHERE name="%s"',
addcslashes($city)); // invalid escaping method |
Yep, missing quotes is a common problem... a code base with many thousands of values being escaped, and all it takes is 1 mistake. The It's even more fun when developers try escaping field names, e.g. As to similar API's...
And when you say you have seen similar code before, we kinda discussed this last year, ref issue 316. In your examples, a Extra bonus point for parameterised queries... the developer defined SQL is sent to the database first, the query execution plan is created from it (sometimes that can be cached)... then the user values are accepted/used; this means the user values cannot have any affect on the query execution plan, so even if there was an implementation issue, it's far too late to change it... in contrast, (escaped) user values are mixed in with the SQL, and separating them again is tricky. |
thanks. I agree that prepared statements is a must have. still there is a lot of vulnerable code out there, where I want to point out security issues. I will add a "phpstan-tip" to the rule that escaping should be prevented. you had a website somewhere, where all the problems and solutions are described in detail, right? |
That works. As to the website, yep, although it's more of a quick summary (so people are more likely to read): https://eiv.dev/ It does link to pages on my GitHub repo with some typical examples: https://github.com/craigfrancis/php-is-literal-rfc/blob/main/justification/escaping.php And yes, there is a lot of vulnerable code out there, and why I'm so glad you're tackling it from another angle... hopefully, with enough people working on this problem, we can stop boring injection vulnerabilities. and I can move on to more interesting problems :-) |
wrong (sql injection vulnerable):
correct:
refs
might take inspiration from https://github.com/complex-gmbh/php-clx-symplify/pull/257 (closed source)
The text was updated successfully, but these errors were encountered: