diff --git a/uportal-war/src/main/java/org/jasig/portal/utils/jsp/Util.java b/uportal-war/src/main/java/org/jasig/portal/utils/jsp/Util.java
index dceaf281646..23300d54f25 100644
--- a/uportal-war/src/main/java/org/jasig/portal/utils/jsp/Util.java
+++ b/uportal-war/src/main/java/org/jasig/portal/utils/jsp/Util.java
@@ -20,14 +20,16 @@
package org.jasig.portal.utils.jsp;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Map;
-import org.jasig.portal.spring.beans.factory.ObjectMapperFactoryBean;
-
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.jasig.portal.spring.beans.factory.ObjectMapperFactoryBean;
+import org.springframework.web.util.UriUtils;
+
/**
* JSP Static utility functions
@@ -74,4 +76,45 @@ public static boolean instanceOf(Object obj, String className) throws ClassNotFo
public static String json(Object obj) throws JsonGenerationException, JsonMappingException, IOException {
return OBJECT_MAPPER.writeValueAsString(obj);
}
+
+
+ /**
+ * URL encode a path segment. This is just a thin wrapper around UriUtils.encodePathSegment. It is intended
+ * for the case where you are building URLs in JS. c:url + escapeBody doesn't correctly escape
+ * the contents (especially ""), and fn:escapeXml incorrectly encodes the URL (it escapes chars
+ * like '<' as < instead of %3C). It should help avoid XSS attacks when building RESTful
+ * URLS in js. Example:
+ *
+ * Given: ${userId} -> "
+ *
+ * ...
+ *
+ *
+ * Will encode the URL as:
+ *
+ * /users/%3Cscript%3Ealert('test%')%3C%2Fscript%3E
+ *
+ * IMPORTANT:
+ * Note that this encodes the '/' in to %2F. Unfortunately, tomcat
+ * still does not interpret %2F correctly unless you relax some security
+ * settings (@see tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html#Security,
+ * the ALLOW_ENCODED_SLASH property). So, while this method does a better job
+ * at avoiding XSS issues than c:url, it's still not ideal. Unless the
+ * input is whitelisted to avoid invalid input chars, it's still possible to
+ * end up with REST URLs that won't work correctly (like the one above), but at
+ * least this will protect you from XSS attacks on the front end.
+ *
+ * @param val the path segment to encode
+ * @return the encoded path segment
+ */
+ public static String encodePathSegment(String val) {
+ try {
+ return UriUtils.encodePathSegment(val, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // should be unreachable...
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/uportal-war/src/main/webapp/WEB-INF/flows/edit-group/viewGroupPermissions.jsp b/uportal-war/src/main/webapp/WEB-INF/flows/edit-group/viewGroupPermissions.jsp
index 7d59291169d..1d08e9b41f2 100644
--- a/uportal-war/src/main/webapp/WEB-INF/flows/edit-group/viewGroupPermissions.jsp
+++ b/uportal-war/src/main/webapp/WEB-INF/flows/edit-group/viewGroupPermissions.jsp
@@ -163,8 +163,8 @@ up.jQuery(function() {
var pager;
var editUrl = "${editUrl}";
- var targetUrl = "";
- var principalUrl = "";
+ var targetUrl = "";
+ var principalUrl = "";
var getPermissionAssignments = function(url) {
var rslt;
diff --git a/uportal-war/src/main/webapp/WEB-INF/flows/user-manager/viewPermissions.jsp b/uportal-war/src/main/webapp/WEB-INF/flows/user-manager/viewPermissions.jsp
index e9d3e09e039..46fa29d110e 100644
--- a/uportal-war/src/main/webapp/WEB-INF/flows/user-manager/viewPermissions.jsp
+++ b/uportal-war/src/main/webapp/WEB-INF/flows/user-manager/viewPermissions.jsp
@@ -178,8 +178,8 @@ PORTLET DEVELOPMENT STANDARDS AND GUIDELINES
var $ = up.jQuery;
var pager;
- var targetUrl = "";
- var principalUrl = "";
+ var targetUrl = "";
+ var principalUrl = "";
var editUrl = "${editUrl}";
var deleteUrl = "${deleteUrl}";
diff --git a/uportal-war/src/main/webapp/WEB-INF/tag/uportal.tld b/uportal-war/src/main/webapp/WEB-INF/tag/uportal.tld
index 0884122120b..4785d2eefaa 100644
--- a/uportal-war/src/main/webapp/WEB-INF/tag/uportal.tld
+++ b/uportal-war/src/main/webapp/WEB-INF/tag/uportal.tld
@@ -115,4 +115,16 @@
${up:json(obj)}
+
+
+ URL encodes a single path segment. Intended for building RESTful URLs where
+ variable values may contain illegal characters.
+
+ encodePathSegment
+ org.jasig.portal.utils.jsp.Util
+ java.lang.String encodePathSegment(java.lang.String)
+
+ ${up:urlEncode("www.example.com/image.png")}
+
+
\ No newline at end of file