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...
[1] http://php.net/manual/en/pdo.prepared-statements.php
[2] http://php.net/manual/en/function.mysql-real-escape-string.p...
I'm not able to see why the parent's suggestion to just escape the strings is not a valid solution from a security perspective.
Include a check to make sure multiple bugs in a single repo are handled by just one pull request too.
$table_name = $_GET['from'];
if (!in_array($table_name, $VALID_TABLES)) {
die('Invalid table name');
}
$set_to = (int)$_GET['set_to'];
mysql_query("INSERT INTO $table_name (value) " .
"VALUES ($set_to);
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.