Solution for SQL Injection
Solution
* Limit input size
* Remove special character
* Remove reserved keywords
* Check the desired pattern
Solution for XML injection
Numbers
Overflow
The built-in integer operators in Java secretly wrap the result without
reporting overflow when a mathematical operation cannot be represented
using the provided integer types.
Solution for Number Overflow
Solutions:
* Upcasting: Consider a larger data type if possible
* Prediction testing: Find the boundaries, throw ArithmaticException when needed.
* BigIntger: Convert the inputs into objects of type BigInteger
Numbers
Precision
Solution:
* Use integer
* Use BigDecimal
Methods
Validate input parameters
* Might be costly
* Avoid inconsistent computation, runtime exceptions
Assertion
- test your assumptions about your program
Accessibility
* Method that check security should be private or final.
Defensive Programming
Minimise the scope of variables
Minimise the accessibility of classes
Wrapper methods
* Use private modifiers when it is possible
Conclusive Secure Coding