Skip to content

Commit 64cdb00

Browse files
author
manico.james
committed
I believe I've found a bug introduced in 2.0-rc6 .Here is the environment:
1. using esapi in a web application 2. *not* setting "org.owasp.esapi.resources" system property 3. ".esapi" folder not in user.home or classpath (2.0-rc6 download didn't include it in the jar either) When I invoke ESAPI.securityConfiguration().setResourceDirectory(esapiResourceDir) rc6 blows up with a NullPointerException. The problem appears to be that the "if ( shouldPrintProperties() ) {" block still gets executed when a file isn't found during the securityConfiguration() invocation and the properties is thus null, never allowing setResourceDirectory() to be called. To fix this, the " if ( shouldPrintProperties() ) {" block should be moved up a few lines to be included inside the "if (properties != null) {" block. Although fixing the exception from occurring, using setResourceDirectory() from inside a web application is still somewhat useless because resourceDirectory is only used when checking ClassLoader.getSystemResource() which typically isn't your webapp context's classloader. I would suggest adding a check to resourceDirectory inside loadConfigurationFromClasspath() when it loops through the classloaders. I made the change locally and it seems to work well, doing this one can specify a custom directory name inside a web application's context. Attached is a diff patch file for the details... Thanks, ~Josh
1 parent 9e746ae commit 64cdb00

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

‎src/main/java/org/owasp/esapi/reference/DefaultSecurityConfiguration.java‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -447,26 +447,26 @@ private void loadConfiguration() throws IOException {
447447
properties.put( key, value);
448448
}
449449
}
450+
451+
if ( shouldPrintProperties() ) {
452+
453+
//FIXME - make this chunk configurable
454+
/*
455+
logSpecial(" ========Master Configuration========", null);
456+
//logSpecial( " ResourceDirectory: " + DefaultSecurityConfiguration.resourceDirectory );
457+
Iterator j = new TreeSet( properties.keySet() ).iterator();
458+
while (j.hasNext()) {
459+
String key = (String)j.next();
460+
// print out properties, but not sensitive ones like MasterKey and MasterSalt
461+
if ( !key.contains( "Master" ) ) {
462+
logSpecial(" | " + key + "=" + properties.get(key), null);
463+
}
464+
}
465+
*/
466+
467+
}
450468
}
451-
452-
if ( shouldPrintProperties() ) {
453-
454-
//FIXME - make this chunk configurable
455-
/*
456-
logSpecial(" ========Master Configuration========", null);
457-
//logSpecial( " ResourceDirectory: " + DefaultSecurityConfiguration.resourceDirectory );
458-
Iterator j = new TreeSet( properties.keySet() ).iterator();
459-
while (j.hasNext()) {
460-
String key = (String)j.next();
461-
// print out properties, but not sensitive ones like MasterKey and MasterSalt
462-
if ( !key.contains( "Master" ) ) {
463-
logSpecial(" | " + key + "=" + properties.get(key), null);
464-
}
465-
}
466-
*/
467-
468-
}
469-
}
469+
}
470470

471471
/**
472472
* @param filename
@@ -566,6 +566,11 @@ private Properties loadConfigurationFromClasspath(String fileName) throws Illega
566566
// try root
567567
in = loaders[i].getResourceAsStream(fileName);
568568

569+
// try resourceDirectory folder
570+
if (in == null) {
571+
in = currentLoader.getResourceAsStream(resourceDirectory + "/" + fileName);
572+
}
573+
569574
// try .esapi folder
570575
if (in == null) {
571576
in = currentLoader.getResourceAsStream(".esapi/" + fileName);

0 commit comments

Comments
 (0)