Skip to content

Conversation

@tecservicesgda
Copy link

The code was corrected by replacing the dynamically generated SQL queries with prepared statements. This change addresses the SQL Injection vulnerability by ensuring that user inputs are properly parameterized and not directly concatenated into SQL strings.

  1. Use of Prepared Statements:

    • The PreparedStatement class is used to create SQL statements with placeholders (?) for parameters. This prevents SQL injection by separating SQL logic from data.
    • For the transaction insertion, a prepared statement is created with placeholders for ACCOUNTID, DATE, TYPE, and AMOUNT. The actual values are set using the setInt, setString, and setDouble methods.
  2. Parameter Binding:

    • Parameters such as account IDs, dates, transaction types, and amounts are bound to the prepared statement using specific setter methods. This ensures that the inputs are treated as data, not executable code.
  3. Separate Statements for Different Operations:

    • Separate prepared statements are used for inserting transactions and updating account balances. This modular approach enhances clarity and security.
  4. Consistent Use of Prepared Statements:

    • All SQL operations, including the insertion of the cash advance fee and updating account balances, are performed using prepared statements, ensuring consistent protection against SQL injection across the code.

By implementing these changes, the code now safely handles user inputs, preventing attackers from injecting malicious SQL code. This significantly reduces the risk of unauthorized data access and manipulation.

Created by: plexicus@plexicus.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants