Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp JSF无法逃避内容和XSS攻击_Jsp_Jsf_Xss - Fatal编程技术网

Jsp JSF无法逃避内容和XSS攻击

Jsp JSF无法逃避内容和XSS攻击,jsp,jsf,xss,Jsp,Jsf,Xss,我在jsf实现方面遇到了问题,或者我有一些误解: 我有以下内容:(param包含恶意javascript块) #{param} 因此,当EL不包含在xhtml标记中时,我似乎面临一个问题,显然,当标记中发生替换时,这会产生一个大问题 <script> var val="#{param}"; // This is not escaped, so XSS is possible </script> var val=“#{param}”//这不是转义的,所以XSS是可能

我在jsf实现方面遇到了问题,或者我有一些误解:

我有以下内容:(param包含恶意javascript块)


#{param}
因此,当EL不包含在xhtml标记中时,我似乎面临一个问题,显然,当标记中发生替换时,这会产生一个大问题

<script>
var val="#{param}"; // This is not escaped, so XSS is possible
</script>

var val=“#{param}”//这不是转义的,所以XSS是可能的
以下是我的设置:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.drm.test</groupId>
    <artifactId>web_test</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>web_test Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.29</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.29</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.facelets</groupId>
            <artifactId>jsf-facelets</artifactId>
            <version>1.1.14</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>web_test</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
com.drm.test
网络测试
战争
1.0-快照
web_测试专家Webapp
http://maven.apache.org
朱尼特
朱尼特
3.8.1
测试
com.sun.faces
JSFAPI
2.1.29
com.sun.faces
jsf impl
2.1.29
javax.servlet
servlet api
2.5
假如
塔格利布
标准
1.1.2
javax.servlet
jstl
1.1.2
com.sun.facelets
jsf facelets
1.1.14
网络测试
org.apache.maven.plugins
maven编译器插件
2.3.1
1.6
1.6
index.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<body>
    #{param['requestParam']}
    <!-- ESCAPED!! -->
    <kkk value="#{param['requestParam']}" />
    <!--  NOT ESCAPED -->
    #{param['requestParam']}
    <h:outputText value="#{param['requestParam']}" escape="true" />
    <script>
    <!-- NOT ESCAPED XSS -->
        <h:outputText value="#{param['requestParam']}" escape="true"/>
    </script>
</body>
</html>

#{param['requestParam']}
#{param['requestParam']}
使用url调用时输出html(在浏览器中查看源代码):

http://localhost:8080/web_test/index.jsf?requestParam=jsMethod("")

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    jsMethod("");
    <!-- ESCAPED!! -->
    <kkk value="jsMethod(&quot;&quot;);"></kkk>
    <!--  NOT ESCAPED -->
    jsMethod("");jsMethod("");
    <script>
    <!-- NOT ESCAPED XSS -->jsMethod("");
    </script>
</body>
</html>
http://localhost:8080/web_test/index.jsf?requestParam=jsMethod("")
方法(“”);
方法(“”);方法(“”);
方法(“”);

标记有一个属性
escape

这将转义标记输出中的任何敏感HTML。这在默认情况下是正确的,并且单独使用不会阻止XSS注入攻击。为此,您需要实现ServletFilter,它从所有请求参数中过滤XSS注入尝试

下面的项目可以用来清理您的请求参数,在您的web应用程序中编写一个利用该项目的servlet过滤器应该不会太困难


项目被困在JSF 1.2上,这是一个遗留项目,目前还不能进行更新,JSF得到了支持。xhtml文件使用更新的JSF版本创建了一个简单的空项目,同样的情况也发生了,我用pom.xml和xhtml文件编辑了这篇文章。这是我创建的一个新项目,用于检查这是否发生在2.1.29中,问题是我可以有一个包含以下内容的页面:var kk=#{param};我不希望有人通过将要执行的'param'中的一些有效javascript代码调用这个url,我需要这个param转义。我删除了这个测试项目中的所有内容。
http://localhost:8080/web_test/index.jsf?requestParam=jsMethod("")

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    jsMethod("");
    <!-- ESCAPED!! -->
    <kkk value="jsMethod(&quot;&quot;);"></kkk>
    <!--  NOT ESCAPED -->
    jsMethod("");jsMethod("");
    <script>
    <!-- NOT ESCAPED XSS -->jsMethod("");
    </script>
</body>
</html>