All the code is already public on Github, so everyone can see these gaping security holes, right?
What if some honest, global actor could mass-commit a fix for all these repos in one fell swoop? For example, replace all references to:
$_GET
with:
some_safe_sanitizer($_GET)
All affected repos win a free fix, and the world becomes a better place due to having less security bugs. Essentially, what would the next abstraction layer, over all Github repository objects, look like? Ponder that.
To do it properly you'd want to use prepared statements[1] which requires a non-trivial, though not particularly complicated, syntax change. So your global actor would have to parse the PHP in a rather more intelligent way that just a string replace.
You could just use mysql_real_escape_string [2] but that's less secure than prepared statements, and may break some things (eg if the code is relying on certain things not being escaped, etc). Also that extension is deprecated in favour of prepared statements.
Also, some of the dodgy code is using $_GET vars for things other than values, like field and table names (!!!!) which would need a more significant refactoring in order to fix.
However it would be a great little problem to work on, and you could probably write a bot to fix 80% of the code pretty easily.
The other issue is how many people will understand and accept the pull requests...
The pull request could be done "stupidly", which may fix most problems (your 80% value), and for cases where it wouldn't "just work" the author could just reject the pull request but still be made aware of the problem.
I think what I'd do is write a bot that issues pull requests along with a commit message explaining what was fixed, why it needed fixing, how the automatic fix isn't perfect and that they should really consider rewriting it to use prepared statements.
Include a check to make sure multiple bugs in a single repo are handled by just one pull request too.
Quoting/escaping the table name in this case would break the code. (Backticks will work, but that's another story.) The variable has already been sanitized immediately before, so there's no injection possibility.
The case with $set_to is still pretty bad form, but it has been sanitized above by casting to an int.
Not saying this is great code, just pointing out the fact that there's no possible way to do a mass-commit fix.
All the code is already public on Github, so everyone can see these gaping security holes, right?
What if some honest, global actor could mass-commit a fix for all these repos in one fell swoop? For example, replace all references to:
with: All affected repos win a free fix, and the world becomes a better place due to having less security bugs. Essentially, what would the next abstraction layer, over all Github repository objects, look like? Ponder that.