From 9831ecf543009ac8937716752d5da9f56ed15e0e Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 20 Mar 2012 09:10:37 +0000 Subject: [PATCH] Adds better way to handle JavaScript injection into request parameters git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1302803 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/struts2/views/util/UrlHelper.java | 5 ++-- .../struts2/views/util/UrlHelperTest.java | 29 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java b/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java index 751efeb67..f294a4b65 100644 --- a/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java +++ b/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java @@ -27,6 +27,7 @@ import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; +import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; @@ -176,8 +177,8 @@ public class UrlHelper { String result = link.toString(); - while (result.indexOf("","value3"); + + StringBuilder url = new StringBuilder("http://localhost:8080/myContext/myPage.jsp?initParam=initValue"); + + UrlHelper.buildParametersString(parameters, url); + + assertEquals( + expectedUrl, url.toString()); + } + public void testForceAddNullSchemeHostAndPort() throws Exception { String expectedUrl = "http://localhost/contextPath/path1/path2/myAction.action";