opencart - PHP SQL Injection Possibility -
i've been looking opencart, written in php.
if take @ following php file,
https://github.com/opencart/opencart/blob/master/upload/admin/model/customer/customer.php
the sql statement looks this
$this->db->query("insert " . db_prefix . "customer set customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode(array())) . "', newsletter = '" . (int)$data['newsletter'] . "', salt = '', password = '" . $this->db->escape(password_hash($data['password'], password_default)) . "', status = '" . (int)$data['status'] . "', safe = '" . (int)$data['safe'] . "', date_added = now()"); the recommended way avoid php sql injection use prepared statements.
my question considering how particular code isn't using prepared statements, code vulnerable sql injection?
i'm not a php expert might missing obvious here.
edit:
let me list reasons i'm bit apprehensive accept code vulnerable.
opencart (https://github.com/opencart/opencart) popular open source project on 200 forks.
it's shopping cart (e-commerce) solution, developer would've put thought security, , sql injections 1 of first things would've checked.
it kind of escaping done using
$this->db->escape($data['telephone'])
as either escaped or converted integer not vulnerable sql injection.
of course qirel right in comments using prepared statements better solution in imaginable ways. harder read , can made vulnerable mistake when modifying code in future.
edit: after bit of research seem true under assumption database character set has been set correctly. otherwise it might still vulnerable to multi-byte attacks.
opencart seems vulnerable when using mysql if improper character set set @ server level uses set character set query instead of mysql_real_escape_string. can see in latest v3.0.2.0 on github. details see mysql character sets in php manual.
i suggested fix of particular issue in !5812.
Comments
Post a Comment