Normal SQL injections are no problem since I always use prepared statements, but how to protect oneself from second order SQL injections?
|
|
A second order SQL injection is an injection where the payload is already stored in the database (instead of say being delivered in a GET parameter). In that sense it is somewhat similar to stored XSS (and ordinary "first order" SQL injection would be analogous to reflected XSS). How does it work? Lets say you let users pick any username. So an attacker could choose the name
So, how do you deal with this? Always use parametrized querires, always, always, always. Treat all variables as untrusted user data even if they originate from the database. Just pretend everything is GET parameters, and behave accordingly by binding them as parameters. You can also sanitize and limit the input (e.g. only allow alphanumeric usernames) before it is stored in the database as well as after it is retrieved from the database. But I would not rely on that as my only line of defence, so use parametrized queries as well. |
|||||||||||||||||||||
|