我的项目正在开发服务器上工作。它适用于以下两种情况:
- 使用源路径中的 .esapi 目录,使其最终位于 WEB-INF/classes
- 使用 lib 根目录中的 .esapi 目录,使其最终位于 WEB-INF/lib
但是,它在部署到 Google 时不起作用(使用上述两种策略中的任何一种)。
我收到关于无法找到 ESAPI 的常见消息。我第一次尝试使用 ESAPI 部署到 Google 时的属性文件。
Attempting to load ESAPI.properties via file I/O.
Attempting to load ESAPI.properties as resource file via file I/O.
Not found in 'org.owasp.esapi.resources' directory or file not readable: /base/data/home/ap
Not found in SystemResource Directory/resourceDirectory: .esapi/ESAPI.properties
Loading ESAPI.properties via file I/O failed. Exception was: java.io.FileNotFoundException
Attempting to load ESAPI.properties via the classpath.
ESAPI.properties could not be loaded by any means. Fail. Exception was: java.security.Acces
ESAPI 似乎确实包含支持 AppEngine http://goo.gl/rD8dz的更改
更新 问题是 org.owasp.esapi.reference.DefaultSecurityConfiguration 的第 603 行调用 ClassLoader.getSystemClassLoader() 这在 Google Appengine 中是非法的。这会导致上面的异常(对不起,它被裁剪了)。在代码尝试获取资源之前,预先将三个 ClassLoader 加载到一个数组中。
ClassLoader[] loaders = new ClassLoader[] {
Thread.currentThread().getContextClassLoader(),
ClassLoader.getSystemClassLoader(),
getClass().getClassLoader()
};
String[] classLoaderNames = {
"current thread context class loader",
"system class loader",
"class loader for DefaultSecurityConfiguration class"
};
我已经破解了我自己的 DefaultSecurityConfiguration 副本,我从 loadConfigurationFromClasspath 方法中删除了 SystemClassLoader(和相应的 classLoaderName)。
ClassLoader[] loaders = new ClassLoader[] {
Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader()
};
String[] classLoaderNames = {
"current thread context class loader",
"class loader for DefaultSecurityConfiguration class"
};
具有讽刺意味的是,这是因为他们通过循环通过类加载器使代码易于阅读/扩展(恕我直言),这种方法失败了。我很想提交一个带有内部类的补丁来延迟对 getSystemClassLoader 的调用(这在 AppEngine 上是做不到的)。
有趣的是,这之所以可行,是因为 esapi jar 没有密封。我原以为应该密封一个安全库 jar。也许我用错了!
更新 我通过 maven 使用 esapi jar,它已经被重新打包并且没有签名。不理想,但它的安全性不亚于我从 maven 获得的其他 40 个开源 jar!