Skip to content

Conversation

@pixeebot
Copy link

@pixeebot pixeebot bot commented Nov 9, 2024

This change refactors SQL statements to be parameterized, rather than built by hand.

Without parameterization, developers must remember to escape inputs using the rules for that database. It's usually buggy, at the least -- and sometimes vulnerable.

Our changes look something like this:

- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE name = '" + user + "'");
+ PreparedStatement stmt = connection.prepareStatement("SELECT * FROM users WHERE name = ?");
+ stmt.setString(1, user);
+ ResultSet rs = stmt.executeQuery();
More reading

🧚🤖 Powered by Pixeebot

Feedback | Community | Docs | Codemod ID: pixee:java/sql-parameterizer

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 9, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
E Reliability Rating on New Code (required ≥ A)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@pixeebot
Copy link
Author

pixeebot bot commented Nov 17, 2024

I'm confident in this change, but I'm not a maintainer of this project. Do you see any reason not to merge it?

If this change was not helpful, or you have suggestions for improvements, please let me know!

@pixeebot
Copy link
Author

pixeebot bot commented Nov 18, 2024

Some folks find the idea that a hacker could exploit their SQL to exfiltrate data fanciful. It's unfortunately not as difficult as you might think. It's consistently in the OWASP Top 10 in one form or another for a good reason.

Attackers don't need your schema or understand your query structure to terminate the existing query and run SQL functions like xp_cmdshell() to run a new system process and give themselves shell access.

Attackers can also can also introduce sleep() statements in combination with queries to your DB metadata in order to enumerate your schema remotely and make exfiltration of your customer data easy.

Attackers also don't really need to know how to do any of these things, because there are great automated tools that do all these things for them. The risk is real, as many real-life companies have found out the hard way.

If there are other concerns about this change, I'd love to hear about them!

@pixeebot
Copy link
Author

pixeebot bot commented Nov 24, 2024

This change may not be a priority right now, so I'll close it. If there was something I could have done better, please let me know!

You can also customize me to make sure I'm working with you in the way you want.

@pixeebot pixeebot bot closed this Nov 24, 2024
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.

0 participants