When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
Hi skumar211968!
Unfortunately we will need a bit more information to help you. If your able to provide details of the "query" object, what is it? what library is it from?
A traditional usage of SQL prepareStatement would look like the below.
String query = "SELECT account_balance FROM user_data WHERE user_name = ? ";
PreparedStatement pstmt = connection.prepareStatement( query );
pstmt.setString( 1, custname); // This is where the variable is safely inserted into the query
ResultSet results = pstmt.executeQuery( );
In your code snippet, there doesn't appear to be any parameters being added to the prepared statement. If this code is working for you, it must mean the SQL query has been created before being passed through prepareStatement, which means you are getting no protection. Without understanding more about the "query" object, I think it's likely this code is vulnerable to SQLi.
As this is dynamic SQL, it's likely to be too complex for a forum post to understand how we might mitigate this. In the first instance I would read the below OWASP article and see if the code can be refactored to use preparedStatement correctly. I suspect you may need more in-depth guidance for this scenario and would recommend a call with a member of the ASC team. You can schedule a consultation through the Veracode platform.
Resources:
https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
Hope that helps! Seb
How can we use EXECUTE IMMEDIATE statement for dynamic DDL and still pass veracode scan ?
We tried using DBMS_ASSERT package but still the scan is failing..