首页 > 解决方案 > 两个 webproject esapi 错误:未通过 ESAPI 验证配置设置所选类型

问题描述

我有一个 9 号服务器,有两个不同的 Web 应用程序,每个都有 esapi 2.1 库及其 ESAPI.properties 和 validation.properties 文件:

A\webcontent\web-inf\esapi\ESAPI.properties
A\webcontent\web-inf\esapi\validation.properties
B\webcontent\web-inf\esapi\ESAPI.properties
B\webcontent\web-inf\esapi\validation.properties

在应用程序 B 中,validation.properties 文件具有应用程序 A 中不存在的验证,当应用程序 B 单独工作时,当两个应用程序在一起时,B 应用程序获取 A 的属性文件并且不加载其验证,因此它给出了错误.

我测试更改 B 移动“src\esapi”和“src\org\owasp\esapi\resources”中的属性文件,并且总是出现相同的错误

所选类型未通过 ESAPI 验证配置设置

java.lang.IllegalArgumentException: The selected type was not set via the ESAPI validation configuration
at org.owasp.esapi.reference.DefaultValidator.getValidInput(DefaultValidator.java:208)
at org.owasp.esapi.reference.DefaultValidator.getValidInput(DefaultValidator.java:185)
   

我的 web.xml:

<context-param>
    <param-name>esapiProperties</param-name>
     <param-value>/esapi/ESAPI.properties</param-value>
</context-param>   
<context-param>
     <param-name>validationEsapiProperties</param-name>
     <param-value>/esapi/validation.properties</param-value>
</context-param>

或者:

<context-param>
  <param-name>esapiProperties</param-name>
  <param-value>/org/owasp/esapi/resources/ESAPI.properties</param-value>
</context-param>   

<context-param>
    <param-name>validationEsapiProperties</param-name>
    <param-value>/org/owasp/esapi/resources/validation.properties</param-value>
</context-param>

标签: javavalidationweb-applicationsesapiweb-project

解决方案


假设 ESAPI 2.1.0 和带有 src 文件夹的典型 Eclipse 动态 Web 应用程序:

  • 将 ESAPI 属性文件(ESAPI 和验证)移动到 src/esapi 并设置自定义文件名。
  • 删除 web.xml 中关于 ESAPI 属性的任何引用(它没有任何作用)
  • 创建一个扩展 DefaultSecurityConfiguration 类的类,覆盖 getResourceStream 方法(签名 InputStream getResourceName(String filename))并从应用类加载器返回资源流。由于“配置/验证文件加载”使用相同的方法(可能是 filename.indexOf("validation")),因此需要评估文件名参数
  • 创建一个类(实现 javax.servlet.Filter),在每个请求中调用(在 doFilter 中)ESAPI.override()。您必须在 web.xml 中声明您的新过滤器(根据需要映射请求)。

如果您需要更多信息,请查看覆盖方法中的javadoc 注释。


推荐阅读