4 ms·
Stored procedures aren't a panacea for SQL injection. The real answer is to use parameters for any user input. Otherwise if you're concatenating strings to inv
by koolba 10y ago
Stored procedures aren't a panacea for SQL injection. The real answer is to use parameters for any user input.
Otherwise if you're concatenating strings to invoke your stored proecedures you're in the same boat.
- kodablah 10y agoThe sad part is many libs force you to accept prepared statements with your parameters or you get no parameters at all.
- ThisIs_MyName 10y agoCare to elaborate?
- qaq 10y agoIt's extremely easy to validate in automatic way that only proper call's are used to call the sprocs also if you limit web app db user to only have permission to execute appropriate stored procedures you mitigate a good number of attacks even if someone did call the sproc in unsafe manner that allows sql injection now the attacker needs to guess sproc names and signatures and still limited in what he/she can do. This assumes that sprocs are themselves not written to concat sql and then execute it :)
- justinclift 10y agoAs a side note, it's not always possible to use parameter binding for all parts of a SQL query. :( For example, when querying user uploaded databases (not a typical use case), the SQL query needs to include the table name. At least with SQLite (unsure about PostgreSQL), table names can't be bound in a parameter. They need to be part of the non parameterised query string, thus string smashing. Field/column names are probably similar too, though I haven't checked (yet).
- koolba 10y agoIf you're doing anything that esoteric hopefully you understand proper identifier escaping. If not, there's bound to be much worse throughout your app.
- snuxoll 10y agoThat's what libraries like sequel, SQLAlchemy or Jooq are for. I'm looking at implementing some crazy dynamic queries in a CRM system I'm prototyping right now and SQLAlchemy is my saving grace to avoid shooting myself in the foot.
- true_religion 10y agoThat's true, but an ORM like ActiveRecord ought to protect you from this because you are required to specify valid column names and table names before using it. It should be able to check if an invalid column or table name is used.