Svajjarapu023153 (Community Member) asked a question.

Why does SQL batch shows as flaw under CWE-ID: 89-SQL injection even though SQL is hard coded and dynamically set all parameters by applying the parameter prepared statement.

Here is the SQL query hard coded and used the prepared statment dynamically to set the parameters, and add batch. Finally execute the batch.

Batch SQL execution already constructed with parameter queries and SQL is hard coded and no chance of external input in alter the query.

However, Veracode shows this two lines as flaws.

 

try{

private final String addUser = "insert into users(id, organization_id, username, autocopy, enabled) values (%s,%1$s,?,?,?)";

PreparedStatement psAddUser psAddUser = myConn.prepareStatement(addUser);

 

for (final UserAndOrgID nu : usersToAdd) {

        final AegisUUID newidVal = AegisUUID.randomUUID();

        DatabaseUtilities.setValue(psAddUser, 1, newidVal);

        DatabaseUtilities.setValue(psAddUser, 2, nu.orgID);

        psAddUser.setString(3, nu.name);

        psAddUser.setNull(4, java.sql.Types.VARCHAR);

        psAddUser.setBoolean(5, false);

        psAddUser.setBoolean(6, true);

        psAddUser.addBatch();         

        psAddWorkspace.setString(3, "default");

        psAddWorkspace.addBatch();

      }

      psAddUser.executeBatch();

myConn.commit();

    } finally {

      DatabaseUtilities.close(psAddUser);

      DatabaseUtilities.close(psAddWorkspace);

      myConn.close();

    }

Please provide recommendation to fix this flaw, thanks in advance.


  • Hi @Svajjarapu023153 (Community Member)​ ,

     

    Could you share more about what DatabaseUtilities.setValue is doing?

     

    If you are not able to share more details I would recommend creating a support case by clicking your avatar in the top right corner of the community and selecting "Contact Support" and in that mention the URL to the Veracode Platform Triage Flaws page as well as the flaw id.

     

    Thank you,

    Boy Baukema

    Expand Post
    • Svajjarapu023153 (Community Member)

      Hi Boy,

      Thank you for the response, DatabaseUtilities.setValue() just sets the value in prepared statement.

      Here is the code snippet.  preparedStatement.setString(index, value.toString()). Please provide your suggestion to resolve this flaw. Thanks in advanced.

       

       

      Expand Post

Topics (2)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.