我在我的项目中使用HDIV来保护OWASP列表,但是文本框接受<script>alert(1);</script>作为输入并保存到db。
我想为所有的OWASP问题编写测试用例。
下面是项目配置
web.xml配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/spring/applicationContext-db.xml
WEB-INF/spring/spring-security.xml
WEB-INF/spring/hdiv-config.xml
</param-value>
</context-param>webmvc-config.xml配置
<import resource="applicationContext-hdiv.xml" />applicationContext-hdiv.xml配置
<beans>
<bean id="requestDataValueProcessor" class="org.springframework.security.web.servlet.support.csrf.CsrfRequestDataValueProcessor" />
<bean id="editableValidator" class="org.hdiv.web.validator.EditableParameterValidator"/>
<mvc:annotation-driven validator="editableValidator" />
</beans>hdiv-config.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hdiv="http://www.hdiv.org/schema/hdiv" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.hdiv.org/schema/hdiv http://www.hdiv.org/schema/hdiv/hdiv.xsd">
<hdiv:config excludedExtensions="css,js,ttf" errorPage="/manage/security-error" maxPagesPerSession="10" confidentiality="true" strategy="memory" randomName="true">
<hdiv:sessionExpired loginPage="/main/common" homePage="/"/>
<hdiv:startPages method="get">/,/.*,/manage/.*,/login</hdiv:startPages>
</hdiv:config>
<hdiv:validation id="customValidation" componentType="text">
<hdiv:acceptedPattern><![CDATA[^[a-zA-Z0-9@.\-_]*$]]></hdiv:acceptedPattern>
<hdiv:rejectedPattern><![CDATA[(\s|\S)*(--)(\s|\S)*]]></hdiv:rejectedPattern>
</hdiv:validation>
<hdiv:editableValidations registerDefaults="true">
<hdiv:validationRule url=".*" enableDefaults="false">customValidation</hdiv:validationRule>
</hdiv:editableValidations>
</beans> 发布于 2015-01-03 09:17:38
XSS是一个输出问题,而不是输入问题。输入验证是根据域确定数据是正确的。因此,例如,您想要检查希望花费一年时间的字段是否实际收到了预期范围内的数字。您还可能希望确保只使用允许的字符。在许多情况下,这将阻止许多攻击。
然而,对于复杂的投入,这已不再可行。考虑一个要允许用户进行注释的文本字段。应该允许用户写一个注释,比如"An < 4“。现在,我们允许用于构建html标记的字符。
现在我们有两个选择:
发布于 2015-01-05 11:03:16
从'applicationContext-hdiv.xml‘文件中删除'requestDataValueProcessor’和'editableValidator‘bean,它们将由标记自动创建。
查看此项目配置的工作示例:https://github.com/hdiv/hdiv-spring-mvc-showcase
https://stackoverflow.com/questions/27739502
复制相似问题