This is the implementation in code: the schema name comes from a configuration file and is different for each environment. Sonar throws SQL injection alert at this statement:
select *
from dbName.dbo.stu_name; <<dbname is the variable that comes from property file>>
I tried these solutions:
Using
query.setParameter(?,dbname). Tried passing dbname dynamically and vulnerability was fixed. When debugging, the query was throwing an error and did not execute.Used
String.format(select * from \'%s\',tablename.replace("\'","\'\'"))- vulnerability fixed, but query failed to execute
I tried various other solutions and nothing worked.
Can anyone please help me with this?
QUOTENAMEto properly quote it.