Tuesday, April 16, 2013

Secure Coding Principles

From speaker at Seattle Java User Group

#1 Validate all user controlled input

6/10 of OWASP Top vulnerabilities, 14/25 of Mitre/SANS Top 25 coding errors are due to some form of improper input validation.

Anything a user controls an attacker controls.

Check size before using, copying

Whitelist better than blacklist

Proper encoding - characters coming in as and should go out as

Files Too! - about 75% of office security errors = file fuzzing

If you are server, never trust the client

Boundary tests in unit tests

# 2 - Compile with strictest checking

- do not use deprecated classes and methods

- class libraries exposed in customer environment

- Only silence warning if you fully understand the implications

Static code analysis tools - use them

# 3 run apps with least privilege.

Most vulnerabilities in non-security related code

If must run in root do so temporarily

Use security manager, exception handling

Robust code is safer

Exploits occur via the logging system

Write clean code

- pay attention to compiler warnings
- use a standard structure