Reputation: 187
I need to update a C# .NET Framework library which handles most of our SQL tasks. Currently this library is vulnerable for SQL injection.
I found out that using parametrized queries safeguards against SQL injection. However, for a lot of our programs we are using variable tableNames, variable columnNames and sometimes even a dynamic range of columns (i.e. after deployment, extra columns can be added to a table and the software can perform CRUD-actions on those).
From what I understand, when using parametrized queries, it is not possible to use a parameter for a columnName or tableName, unless you use EXEC(N''), but if I understand correctly this would make us vulnerable again to SQL injection?
Lastly, because of the need to support adding columns in a table post-deployment, I don't think it is possible to use a DAL like Entity Framework (without having to recompile the code after adding a column post-deployment).
I am a bit at a loss how I can resolve the vulnerability regarding SQL injection whilst still providing all the current 'dynamic' functionality.
Does anyone have an idea?
Upvotes: 0
Views: 68
Reputation: 169338
In general, by stringently validating the user-entered data that can't be parametrized otherwise.
^[a-z_]+$
, there's little chance for any shenanigans.Upvotes: 3