As an extension to How to protect user specified table name from SQL Injection in C#, using MySQL, I'm trying to figure out how to protect the user-specified-table-query from SQL Injection:
string createEventSQL = "INSERT INTO " + TableNameFromUser +
" (" + TableColumnNames + ") " +
"VALUES(" + ParametrizedTableColumnParams + ")";
To be clear: I would love to use a predefined library to parametrize the input, but I can't find one.
I don't want additional queries (e.g. SHOW TABLES LIKE @TableNameFromUser;
) to secure this, since performance is an issue.
It seems to me that many people claim that it isn't possible to to make a 100% secure solution, but that doesn't make sense to me, since resorting to parametrization should be just as "insecure" as doing all the work yourself. Essentially, I just want to replicate what the MySQL Connector would do, if it supported parametrized table names.
I'm not very experienced with SQL yet, but so far I've found that I need to:
- Escape/disable all escapable characters.
- Disable "--"
What else is can be done to protect from SQL Injection?