Preventing SQL injection
So far, we have secured our web application using filters and a CSRF token. And as we are using Joomla! MVC classes, which deal with lots of cleaning for us, we are pretty safe now.
A web application is as secure as the weakest of its parts, so we need to keep adding measures to prevent vulnerabilities in our development.
One of the biggest fears in web development is suffering from SQL injection. The classic example of this attack is when you get the data from your user and you inject it directly into your database. A typical example of vulnerable code looks like this:
$userid = $_POST['userid']; $query = "SELECT * FROM users_table WHERE userid = $userid";
As you can see, there is no filtering to get the $userid
value directly from the $_POST
superglobal, so a malicious user can send the "1; DROP TABLE users_table;"
string. When the query is created, the result will be as follows:
$query = "SELECT * FROM users_table...