This is my code:
DataTable proposedDealTable = new DataTable();
if (accountGroupList != null && accountGroupList.Count > 0)
{
Database database = SqlServerUtility.CreateDatabase();
string sqlQuery = DealQueries.GetTestExpanded + " ";
sqlQuery += DealQueries.GetTestExpandedWhereClauseCashBalances;
string inClause = CommonUtility.ConvertListToCsvString(accountGroupList.ConvertAll(c => c.i_account_group_id.ToString()));
sqlQuery = sqlQuery.Replace("@i_account_group_id_list", inClause);
DbCommand dbCommand = database.GetSqlStringCommand(sqlQuery.Replace("testSchemaName",
ConfigurationManager.AppSettings["SchemaName"].ToString()));
database.AddInParameter(dbCommand, "@s_row_insrt", DbType.DateTime2, localDayStartTimeInUtc);
database.AddInParameter(dbCommand, "@localdate", DbType.DateTime2, localdate.Date);
database.AddInParameter(dbCommand, "@dealtype", DbType.String, DealTypesClassification.IF);
dbCommand.CommandTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["SqlServerCommandTimeout"]);
DataSet dataSet = database.ExecuteDataSet(dbCommand);
proposedDealTable = dataSet.Tables[0];
}
Checkmarks scan alert:
A SQL Injection vulnerability was identified on test-home.
The application's
GetDealsCBalancesmethod executes a SQL query withdbCommand, at line 92 of \Service\Access\Dao\DealsDao.cs. The application constructs this SQL query by embedding an untrusted string into the query without proper sanitization. The concatenated string is submitted to the database, where it is parsed and executed accordingly.
An attacker would be able to inject arbitrary syntax and data into the SQL query, by crafting a malicious payload and providing it via the input request; this input is then read by the GetDeals method at line 59 of \Services\Imple\CService.cs. This input then flows through the code, into a query and to the database server - without sanitization. This may enable an SQL Injection attack.
Is it a code issue? Or is it a check marks scan issue? Please suggest if the code needs to be changed.