Esapi Jug
Esapi Jug
What is it?
ESAPI (The OWASP Enterprise Security API) is a free, open source, web application security control library that makes it easier for programmers to write lower-risk applications. The ESAPI libraries are designed to make it easier for programmers to retrofit security into existing applications. The ESAPI libraries also serve as a solid foundation for new development.
Who cares?
Tyranny of Choice
Write Spring Custom Java Jasypt Java Code URL Pattern Commons xml-enc EncoderLog4j Validator Cryptix JAAS Stinger JCE ACEGI Struts BouncyCastle Reform Many Anti-XSS More HDIV Java xml-dsig Logging
Standard Control
Vulnerability Theory
Threat Agent
Vector
Vector
Vulnerability
Control
Technical Impact
Business Impact
Business Impact
Vector
Vulnerability
Vector
Vulnerability
Vector
Business Impact
Vulnerability Asset
Vector
Vulnerability
Control
Broken Controls
Weak hash algorithm Fail open
Ignored Controls
Failure to use encryption Forgot to use output encoding
ESAPI Solves
Missing Broken
Process Solves
Ignored
Randomizer
Exception Handling Logger IntrusionDetector SecurityConfiguration
Encoder
Typical output in most web frameworks leads to XSS and CSRF vulnerabilities. The ESAPI encoder allows direct encoding depending on context.
Web (HTML, JavaScript, CSS) Databases (MySQL, Oracle) URL Shells (Unix, Windows) XML LDAP
<p>Hello, <%=name%></p> <p>Hello, <%=ESAPI.encoder().encodeForHTML(name)%> </p>
User
Controller
Business Functions
Data Layer
Backend
isValidCreditCard isValidDataFromBrowser isValidDirectoryPath isValidFileContent isValidFileName isValidHTTPRequest isValidListItem isValidRedirectLocation isValidSafeHTML isValidPrintable safeReadLine
Validator
Encoder
encodeForJavaScript encodeForVBScript encodeForURL encodeForHTML encodeForHTMLAttribute encodeForLDAP encodeForDN encodeForSQL encodeForXML encodeForXMLAttribute encodeForXPath
Validator
EXAMPLE: <script>alert(document.cookie)</script> ESAPI.validator().getValidInput(String context,String input,String type,int maxLength,boolean allowNull,ValidationErrorList errorList)
The Validator interface defines a set of methods for canonicalizing and validating untrusted input.
Returns booleans as not all validation problems are security issues.
Invalid input will generate a descriptive ValidationException which will be stored in the ValidationErrorList Input that is clearly an attack will generate a descriptive IntrusionException
Validator Example
ESAPI provides the ValidationRule and Validator interfaces. Implement your own validators for your data. Reference Regex codes in the ESAPI properties from generic to specific.
Any Interpreter
Any Encoding
Controller
User
Business Functions
Data Layer
Etc
User Interface Set Character Set Encode For HTML File System Canonicalize Validate
Authenticator
Interface with a simple, file based example implementation Log In / Log Out Password Verification Create User Password Generation Change Password Expirations Logging Per User Session Anonymous User Locale Roles Disable / Enable Locked / Unlocked CSRF Tokens Last Login Last Invalid Login Password Age Screen Name Failed Log In Count Last Logged in Host
User
Controller
Business Functions
Data Layer
Backend
ESAPI
Users
Note that the ESAPI project does not have out of the box support for projects like Spring, but can be made to work.
Authentication
Intrusion Detection
Logging
Access Control
isAuthorizedForURL
isAuthorizedForFunction Controller
User
Business Functions
Data Layer
Etc
isAuthorizedForFunction
Encryption
Encryption failures can lead to violations of the Big Three
Confidentiality Integrity Availability (maybe)
The Encryptor interface provides a set of methods for performing common encryption, random number, and hashing operations.
encrypted = ESAPI.encryptor().encrypt( decrypted );
decrypted = ESAPI.encryptor().decrypt( encrypted );
User
Controller
Business Functions
Data Layer
Backend
Encrypted Properties
Encryptor
Random Tokens
Timestamp
Salted Hash
ESAPI provides a random access map which also helps protect against CSRF.
String directReference = "This is a direct reference.";
RandomAccessReferenceMap instance = new RandomAccessReferenceMap(); String ind = instance.addDirectReference((Object)directReference);
ref=jfo8we4oji
Acct:9182374
User
Etc
Report123.xls
File System
Indirect References
Direct References
ESAPI provides a logging implementation that integrates with the security substructure.
Logs security exceptions that are ESAPI generated with identify information Can be used by normal business code to log security exceptions or just log information with identify
Integrates an intrusion detection system that can respond to different types of intrusions by disabling accounts or other actions.
User
Controller
Business Functions
Data Layer
Backend
Logger
Intrusion Detector
Handling HTTP
Many applications make heavy use of HTTP for functionality
Classic ASP uses redirects for flow control, error handing, etc.
The use of data from the request accounts for most web security defects ESAPI provides methods to interact with the request
Helper methods for encryption CSRF tokens Etc.
User
Controller
Business Functions
Data Layer
Backend
Add Safe Header No Cache Headers Set Content Type Add Safe Cookie Kill Cookie Change SessionID CSRF Tokens isSecureChannel Safe Request Logging Safe File Uploads
HTTP Utilities
sendSafeForward sendSafeRedirect
OWASP ESAPI
Validator, Encoder Encoder HTTPUtilities (Safe Upload) AccessReferenceMap, AccessController User (CSRF Token) EnterpriseSecurityException, HTTPUtils Authenticator, User, HTTPUtils Encryptor HTTPUtilities (Secure Cookie, Channel) AccessController
Special Thanks
Supports OWASP and ESAPI Many of the diagrams for in the slides are from a similar presentation by Aspect.