简体   繁体   English

尝试使用OWASP ESAPI时找不到antisamy-esapi.xml

[英]antisamy-esapi.xml not found when trying to use OWASP ESAPI

I have been trying to eval the OWASP ESAPI library, but have been having issues just getting it to initialize properly. 我一直在尝试评估OWASP ESAPI库,但一直有问题只是让它正确初始化。 I set up a resources folder for ESAPI.properties and validation.properties and those are loaded from the classpath without issue. 我为ESAPI.properties和validation.properties设置了一个资源文件夹,这些文件夹从类路径加载而没有问题。 However the antisamy-esapi.xml file is not loaded from classpath, and I found a bug from 2010 mentioning this. 但是,antisamy-esapi.xml文件没有从classpath加载,我发现2010年提到这个错误。 The errors I get are: 我得到的错误是:

Attempting to load antisamy-esapi.xml as resource file via file I/O. 尝试通过文件I / O加载antisamy-esapi.xml作为资源文件。 Not found in 'org.owasp.esapi.resources' directory or file not readable: C:\\Users\\mydir\\resin-pro-4.0.27\\antisamy-esapi.xml Not found in SystemResource Directory/resourceDirectory: .esapi\\antisamy-esapi.xml Not found in 'user.home' (C:\\Users\\mydir) directory: C:\\Users\\mydir\\esapi\\antisamy-esapi.xml 在'org.owasp.esapi.resources'目录中找不到或文件不可读:C:\\ Users \\ mydir \\ resin-pro-4.0.27 \\ antisamy-esapi.xml在SystemResource Directory / resourceDirectory中找不到:.esapi \\ antisamy -esapi.xml在'user.home'(C:\\ Users \\ mydir)目录中找不到:C:\\ Users \\ mydir \\ esapi \\ antisamy-esapi.xml

I am deploying the application using this library to resin. 我正在使用这个库部署应用程序树脂。 I have tried manually placing the xml file in all of the locations above, and the only one that finally worked was my home directory, which doesn't work very well for a production deploy. 我已经尝试手动将xml文件放在上面的所有位置,唯一一个最终工作的是我的主目录,这对于生产部署来说效果不佳。

I also followed a recommendation found elsewhere that says to set the -Dorg.owasp.esapi.resources property. 我还遵循其他地方发现的建议,即设置-Dorg.owasp.esapi.resources属性。 This didn't work either, but more interestingly the error did not change, which makes me think that the setting was not picked up for some reason. 这也没有用,但更有趣的是错误没有改变,这让我觉得设置没有因为某些原因而被选中。

Any pointers on where this file needs to be located in my project so that it is loaded properly once deployed to the container? 有关此文件需要在我的项目中的位置的任何指针,以便在部署到容器后正确加载它?

Thanks in advance. 提前致谢。

Update: 更新:

So from digging through the code it appears that there is specialized function for loading ESAPI.properties, which is why that file is able to be loaded from a standard resources (or any other src dir) directory which is deployed to the container. 因此,通过挖掘代码,似乎存在用于加载ESAPI.properties的专用函数,这就是为什么该文件能够从部署到容器的标准资源(或任何其他src目录)目录加载的原因。 However the loading function for antisamy-esapi.xml just checks a particular directory under user.home, a configured custom directory, or via the result of ClassLoader.getSystemResource(). 但是,antisamy-esapi.xml的加载函数只检查user.home下的特定目录,已配置的自定义目录,或者通过ClassLoader.getSystemResource()的结果。 Not sure why these routines are separate. 不确定为什么这些例程是分开的。 After hours of messing with this I lost patience and copied DefaultSecurityConfiguration.java and corrected the getResourceFile() method to use the same lookup code as loadConfigurationFromClasspath(). 经过几个小时的搞乱,我失去了耐心并复制了DefaultSecurityConfiguration.java并更正了getResourceFile()方法,以使用与loadConfigurationFromClasspath()相同的查找代码。 I then call ESAPI.override() with this class and it seems to work properly now. 然后我用这个类调用ESAPI.override(),它现在似乎正常工作。

I managed to make it work by adding the following line for esapi resources: 我设法通过为esapi资源添加以下行来使其工作:

System.setProperty("org.owasp.esapi.resources", "src/main/resources");

DefaultSecurityConfiguration.java DefaultSecurityConfiguration.java

At least now I am able to use instance.getValidSafeHTML 至少现在我能够使用instance.getValidSafeHTML

However, it wont work when one deploy to web server. 但是,当部署到Web服务器时,它不会工作。 I guess the patch is required to load the antisamy-esapi.xml to load from the class path. 我想补丁需要加载antisamy-esapi.xml才能从类路径加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM