In my application, I’m working with a SQL Server containing numerous databases that share the same table structure. I need to execute queries similar to the following:
SELECT *
FROM {database}.dbo.tableA
WHERE fieldA = ?
Here, {database}
is substituted with a database name that is determined dynamically, derived from a server scan where users cannot provide input. VeraCode alerts that this implementation poses a potential SQL injection threat. Interestingly, queries without a dynamic database name or those lacking parameters do not raise any flags with VeraCode. I also attempted using connection.setCatalog
to circumvent the dynamic name issue, but that was also flagged. I’m perplexed by how VeraCode assesses this as a risk.