Skip to content

[main] Polaris: Automated PR: Fix SQL Injection (CWE-89) in SqlInjection.java:11 - #171

Closed
chuckaude wants to merge 1 commit into
mainfrom
BDPR-main-Polaris-61A2DF5DC8A0B97A983FB355D3B23CAD-1789055732
Closed

chuckaude wants to merge 1 commit into
mainfrom
BDPR-main-Polaris-61A2DF5DC8A0B97A983FB355D3B23CAD-1789055732

Conversation

@chuckaude

Copy link
Copy Markdown

This pull request was automatically generated by Polaris to remediate a security issue.

The suggested fix is created by AI. Review the proposed changes carefully - AI-generated results should not be relied upon for any specific purpose without verifying their accuracy and completeness.

Issue

  • Severity: HIGH
  • CWE: CWE-89 (SQL Injection)
  • File: src/main/java/SqlInjection.java

Click Here To See More Details On Server

Issue summary

CWE-89: Untrusted user input is embedded in SQL without proper validation or escaping.
This can enable SQL injection, letting attackers alter queries or access unauthorized data.

Code analysis

  • Purpose: Demonstrates a database query method that fetches account_balance for a user based on an HTTP request parameter.
  • Flow: Reads customerName from HttpServletRequest, concatenates it into a SQL string, creates a Statement, executes the query, and returns a ResultSet.
  • Significance: Highlights a critical SQL injection vulnerability because untrusted input is inserted directly into SQL without quoting or parameterization.
  • Developer insight: Replace Statement with PreparedStatement, bind parameters safely, validate input, and close JDBC resources properly to improve security, correctness, and reliability.

Fix summary

What changed

The query construction was changed from string concatenation with user input to a parameterized SQL statement using PreparedStatement. The code now binds customerName with setString(1, customerName) and executes the prepared query directly.

Why

Using a parameterized query ensures the user-supplied value is treated as data rather than executable SQL, preventing SQL injection. This removes the unsafe insertion of untrusted input into the SQL statement.

Caveats

Verify the user_name column is a string type compatible with setString, and ensure JDBC resources such as the PreparedStatement and ResultSet are properly closed by the caller or via try-with-resources.

Confidence

High

@chuckaude chuckaude closed this Oct 23, 2026
@chuckaude
chuckaude deleted the BDPR-main-Polaris-61A2DF5DC8A0B97A983FB355D3B23CAD-1789055732 branch October 23, 2026 23:41
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.

1 participant