The following piece of code is being highlighted as a security vulnerability to SQL injection attacks.
StringBuilder sb = new StringBuilder();
sb.Append("DROP DATABASE IF EXISTS " + dbname);
String **sqlCommText** = sb.ToString();
using (SqlCommand command = new SqlCommand(**sqlCommText**, connection))
{
connection.Open();
Namely the sqlCommText
I'm aware of creating prepared statements on DML sql like insert and updates but i dont think this works on DDL sql - i cant parameterize the dbname into the sql.
Any suggestions how this should be fixed?
dbname- use a dictionary of sorts of predefined/known database names. Otherwise, select a list of databases and match the name in memory and then deleteDROPa database tends to have quite high permissions, @RBarryYoung , I can think of a few other things they could do.