Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark java.sql.Statement enquoteIdentifer, enquoteLiteral, and enquoteNCharLiteral SQL_INJECTION_SAFE #721

Open
jim-bentler opened this issue Jan 23, 2024 · 3 comments
Labels
false-positive Something that should not report. good first issue

Comments

@jim-bentler
Copy link

There is no built-in support for java.sql.Statement enquoteIdentifer, enquoteLiteral, or enquoteNCharLiteral. They should be defined as SQL_INJECTION_SAFE:

java/sql/Statement.enquoteLiteral(Ljava/lang/String;)Ljava/lang/String;:0|+SQL_INJECTION_SAFE
java/sql/Statement.enquoteIdentifier(Ljava/lang/String;Z)Ljava/lang/String;:1|+SQL_INJECTION_SAFE
java/sql/Statement.enquoteNCharLiteral(Ljava/lang/String;)Ljava/lang/String;:0|+SQL_INJECTION_SAFE
@h3xstream h3xstream added false-positive Something that should not report. good first issue labels Feb 26, 2024
@jackoske
Copy link

why SQL_INJECTION_SAFE?
It's highlighting the risk of SQL injection due to the lack of built-in escaping mechanisms.
The annotations don't magically make custom escaping methods safe.
consider switching to Prepared Statements as this is the recommended and most secure approach. Prepared statements separate data from the SQL query, and the database handles escaping, mitigating injection risks.

@jimbentler
Copy link

I'm quite aware of all that.

The columns involved in the query are dynamic. The escape methods are the best that can be done.

@jimbentler
Copy link

That said, these also aren't custom escaping methods. They are escaping methods implemented either by the JDBC driver or by Java (if the driver hasn't overridden the default implementation).

We are using PreparedStatements to the degree allowed. So values are always supplied via bind variables, but column names are escaped using the appropriate method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive Something that should not report. good first issue
Projects
None yet
Development

No branches or pull requests

4 participants