Sanitizing user input
- Keep the database server from interpreting user input completely.
-
This is the preferred way eliminating security issues completely as being discussed in the section called “
java.sql.PreparedStatement
”.May not be possible in legacy applications due to required efforts.
- Let the application check user input beforehand
-
Malicious user input is being rejected from being embedded into SQL statements.
Regular expression matching user names.
Regular expression | User input |
---|---|
[a-zA-Z]+ |
Matches
“Jennifer ” |
Does not match “DROP TABLE
Users ” |
So we have an “interceptor” sitting between user input fields and SQL generating code:
No. 8
Using regular expressions in Java™
Q: |
This exercise is a preparation for Input validation by regular expressions . The aim is to deal with regular expressions and to use them in Java™. If you don't know yet about regular expressions / pattern matching you may want to read either of: Complete the implementation of the following skeleton:
As being noted in the Java™ above
you may want to read the documentation of class
The expression '[A-K].*' matches 'Eric' The expression '[^0-9]+.*' ... ... |
A: |
A possible implementation is given by:
|
No. 9
Input validation by regular expressions
Q: |
The application of Attack from the dark side proved to be vulnerable to SQL injection. Sanitize the two user input field's values to prevent such behaviour.
TipVaadin does provide regular expression based
validation support. You may want to consider |
A: |
Validation will be based on both on regular
expressions and Vaadins built in
|