I'm assuming that "Service/mysql.php" is locked down on your servers behind authentication and HTTPS-only, right?
BTW, I have it up and running as a single board on my laptop. I'm currently doing a security audit, and although it looks like you've generally included what is probably reasonable code for avoiding injection attacks, my paranoia (having made and caught many mistakes over the years in this area) compels me to go through it and update all the query code using mysqli to eliminate any lingering doubts.
Something like:
var $mysqli_connection=false;
...
function connect($host,$user,$password,$database='',$prefix=''){
$link=mysql_connect($host,$user,$password);
$this->prefix=$prefix;
if ($link&&$database) $this->select_db($database);
$this->mysqli_connection = new mysqli($host, $user, $password, $database);
if (!$this->mysqli_connection) return false;
return $this->connected=$link;
}
...
function safequery($query_string /*, ... */ ) {
$my_argc = func_num_args();
$connection = $this->mysqli_connection;
$stmt = $connection->prepare($query_string);
if (!$stmt) return null;
$typestring = "";
$out_args = array();
if ($my_argc > 1) {
for ($i = 1; $i < $my_argc; $i++) {
// syslog(LOG_EMERG, "Bind: $i\n");
$value = func_get_arg($i);
$type = "s";
if (is_int($value)) $type = "i";
$typestring .= $type;
array_push($out_args, $value);
}
array_unshift($out_args, $typestring);
// syslog(LOG_EMERG, "TYPES: $typestring, OUT ARGS: ".print_r($out_args, true)."\n");
call_user_func_array(array($stmt, "bind_param"), $this->refValues($out_args));
}
if (!$stmt->execute()) {
$this->lastfailedstatement = $stmt;
return null;
}
return $stmt;
}
function refValues($arr)
{
$refs = array();
foreach ($arr as $key => $value) {
$refs[$key] = &$arr[$key];
}
return $refs;
}
Followed typically by replacing calls to *->query with *->safequery, e.g.
$foo->query("select * from foo where bar = `$i`;");
becomes
$foo->safequery("select * from foo where bar = ?;", $i);
and, of course, replacing the mysql_* calls with the matching mysqli_* calls afterwards. Note that this code is not yet tested.
If you're interested in incorporating such a patch when I get done, shout.
Edited by:
dgatwood
,
Jun 19th, 2013 @ 1:03 am