【发布时间】:2014-07-22 13:08:56
【问题描述】:
我在 jsf 实现方面遇到了问题,或者我有一些误解:
我有以下内容:(param 包含恶意 javascript 块)
<h:outputText value="#{param}"/> <!-- this block does not escape param block -->
#{param} <!-- Also, this one does not escape param -->
<weirdTag weirdParam="#{param}"/> <!-- WTF, this one is escaped -->
所以当 xhtml 标签中不包含 EL 时,我似乎面临一个问题,显然,当标签中发生替换时,这会产生一个大问题
<script>
var val="#{param}"; // This is not escaped, so XSS is possible
</script>
这是我的设置:
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>
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>
使用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("");"></kkk>
<!-- NOT ESCAPED -->
jsMethod("");jsMethod("");
<script>
<!-- NOT ESCAPED XSS -->jsMethod("");
</script>
</body>
</html>
【问题讨论】:
-
项目卡在 JSF 1.2 上,它是遗留的,此时更新不是一个选项,jsf 由 .xhtml 文件支持
-
用更新的 jsf 版本做了一个简单的空项目,同样的事情发生了,我用 pom.xml 和 xhtml 文件编辑了帖子
-
这是我建立的一个新项目,用于检查 2.1.29 是否发生这种情况,问题是我可以拥有一个包含以下内容的页面: 并且我不希望有人调用此 url,并在将执行的“参数”中传递一些有效的 javascript 代码,我需要转义此参数。我删除了这个测试项目中的所有jsp。