Search code examples
sqlsql-injectionrdbms

Is blocking query commands enough to prevent SQL injection?


I'm a beginner in the field of databases, and I'm about to understand, how free text inputs for queries might be used to compromise a database via SQL injection.

Actually, the relevant xckd sums it up perfectly:

enter image description here

This certain comic implies that if I don't allow users to form ANY kind of input that contains SQL commands (like DROP, UPDATE, INSERT INTO, etc.) then "illegal" SQL queries can't be done.

Is there anything I miss? Or am I right?


Solution

  • You don't have to ban all SQL commands from your inputs, you just need to make sure they are only ever treated as free text so that they cannot be accidentally executed as a command.

    This is probably a good place to start:

    https://en.wikipedia.org/wiki/SQL_injection