Validation of Input and Mutable Objects
Input-validation
If you are short on time, I would recommend understanding the problem which the guidelines are trying to solve, and try to remember as many of the guideline names as you can and how they relates to the particular problem.
An exam question may present you with the guideline that exists, but is not related to the particular problem the question is referencing.
Validation of Input and Mutable Objects
Guideline 1: Validation Inputs
Important Points: Maliciously crafted inputs are the cause of many problems:
- These can originate as method arguments or external streams.
- Examples include:
- Overflow of Integer values
- Directory traversal attacks by including
../security/
slash sequences and filenames
- Input from untrusted sources must be validated before use
- Input validation must occur after any defensive copying of an input
Guideline 2: Validate output from untrusted objects as input.
Important Points:
In general method arguments should be validated but not return values.
- In the case of an upcall (invoking a method of higher level code) the return value should be validated.
- Especially vulnerable are calling methods on ClassLoaders
- An attacker might be able to control ClassLoader instances that get passed as arguments
- Multiple invocations of ClassLoader.loadClass() are not guaranteed to return the same Class instance or definition.
Guideline 3: Define wrappers around native methods
Important Points:
Java code is subject to runtime checks for type, array bounds in library usage. Native code generally is not
- Java code is effectively immune to traditional buffer overflow attacks, well native methods are not.
- Do not declare a native method public.
- Declare a native method private and expose functionality through public Java based wrapper method.