Search code examples
esapi

How to get started with ESAPI out of a servlet container


Could anyone give some considerations to get started using the ESAPI on a no-web context? I came with this little test that validates a string with DefaultValidator.isValidCreditCard, but I got some web-container dependency errors.

The following method is consumed from a Junit Test:

@Override
public ValidationErrorList creditCard(String value) {
    this.value = value;
    ValidationErrorList errorList = new ValidationErrorList();
    try {
        isValid = validator.isValidCreditCard(null, value, false, errorList);
    }catch(Exception ie){
        System.out.println(">>> CCValidator: [ " + value + "] " +  ie.getMessage());
        messages = (ArrayList) errorList.errors();
    }
    return messages;
}

This is the error that I get (relevant part) of course I'm not running in a container:


Attempting to load ESAPI.properties via file I/O.
Attempting to load ESAPI.properties as resource file via file I/O.
Found in 'org.owasp.esapi.resources' directory: C:\foundation\validation\providers\esapi\ESAPI.properties
Loaded 'ESAPI.properties' properties file
Attempting to load validation.properties via file I/O.
Attempting to load validation.properties as resource file via file I/O.
Found in 'org.owasp.esapi.resources' directory: C:\foundation\validation\providers\esapi\validation.properties
Loaded 'validation.properties' properties file
SecurityConfiguration for Encoder.AllowMixedEncoding not found in ESAPI.properties. Using default: false
SecurityConfiguration for Encoder.AllowMixedEncoding not found in ESAPI.properties. Using default: false

javax/servlet/ServletRequest
java.lang.NoClassDefFoundError: javax/servlet/ServletRequest
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:74)
    at org.owasp.esapi.ESAPI.httpUtilities(ESAPI.java:121)
    at org.owasp.esapi.ESAPI.currentRequest(ESAPI.java:70)
    at org.owasp.esapi.reference.Log4JLogger.log(Log4JLogger.java:434)
...

Calls to ESAPI..xxxMethods() also raise dependency errors.

Any advice to get started will be appreciate.

Best,

jose


Solution

  • ESAPI has a servlet filter API that requires javax.servlet.ServletRequest to be on the classpath. ESAPI is owned by OWASP --> "Open Web Application Security Project." Therefore, ESAPI is designed with web applications in mind.

    If you're not writing a web application, then its either a console application or a rich client application. If you don't expect to use it to connect to the outside world, then the main secure practices you really need to worry about are ensuring that you always use safely parameterized queries, and that any data passed into your application from a source that IS connected to the outside world is properly escaped. For that, the only thing you need is OWASP's encoder project.