...
Fortunately, the JDBC library provides an API for building SQL commands that sanitize untrusted data. The java.sql.PreparedStatement
class properly escapes input strings, preventing SQL injection when used correctly. This is an example of component-based sanitization.
This compliant solution modifies the doPrivilegedAction()
method to use a PreparedStatement
instead of java.sql.Statement
. This code also validates the length of the username
argument, preventing an attacker from submitting an arbitrarily long user name.
...