首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用HDIV的CSRF和XSS

不使用HDIV的CSRF和XSS
EN

Stack Overflow用户
提问于 2015-01-02 08:42:31
回答 2查看 1.3K关注 0票数 0

我在我的项目中使用HDIV来保护OWASP列表,但是文本框接受<script>alert(1);</script>作为输入并保存到db。

我想为所有的OWASP问题编写测试用例。

下面是项目配置

web.xml配置

代码语言:javascript
复制
<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配置

代码语言:javascript
复制
<import resource="applicationContext-hdiv.xml" />

applicationContext-hdiv.xml配置

代码语言:javascript
复制
<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配置

代码语言:javascript
复制
<?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> 
EN

回答 2

Stack Overflow用户

发布于 2015-01-03 09:17:38

XSS是一个输出问题,而不是输入问题。输入验证是根据域确定数据是正确的。因此,例如,您想要检查希望花费一年时间的字段是否实际收到了预期范围内的数字。您还可能希望确保只使用允许的字符。在许多情况下,这将阻止许多攻击。

然而,对于复杂的投入,这已不再可行。考虑一个要允许用户进行注释的文本字段。应该允许用户写一个注释,比如"An < 4“。现在,我们允许用于构建html标记的字符。

现在我们有两个选择:

  1. 使用工具排除危险的HTML --可能会在某个时候失败
  2. 使用OWASP预防备忘表中描述的上下文感知转义
票数 2
EN

Stack Overflow用户

发布于 2015-01-05 11:03:16

从'applicationContext-hdiv.xml‘文件中删除'requestDataValueProcessor’和'editableValidator‘bean,它们将由标记自动创建。

查看此项目配置的工作示例:https://github.com/hdiv/hdiv-spring-mvc-showcase

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27739502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档