You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2008/06/08 13:30:44 UTC
svn commit: r664483 - in /tomcat/trunk/java/org/apache/jasper:
security/SecurityUtil.java servlet/JspServlet.java
Author: markt
Date: Sun Jun 8 04:30:44 2008
New Revision: 664483
URL: http://svn.apache.org/viewvc?rev=664483&view=rev
Log:
Add an additional layer of protection in case app fails to protect against an XSS.
Copied filter code to jasper module so no new dependency is created.
Modified:
tomcat/trunk/java/org/apache/jasper/security/SecurityUtil.java
tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java
Modified: tomcat/trunk/java/org/apache/jasper/security/SecurityUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/security/SecurityUtil.java?rev=664483&r1=664482&r2=664483&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/security/SecurityUtil.java (original)
+++ tomcat/trunk/java/org/apache/jasper/security/SecurityUtil.java Sun Jun 8 04:30:44 2008
@@ -40,5 +40,42 @@
return false;
}
-
+
+ /**
+ * Filter the specified message string for characters that are sensitive
+ * in HTML. This avoids potential attacks caused by including JavaScript
+ * codes in the request URL that is often reported in error messages.
+ *
+ * @param message The message string to be filtered
+ */
+ public static String filter(String message) {
+
+ if (message == null)
+ return (null);
+
+ char content[] = new char[message.length()];
+ message.getChars(0, message.length(), content, 0);
+ StringBuffer result = new StringBuffer(content.length + 50);
+ for (int i = 0; i < content.length; i++) {
+ switch (content[i]) {
+ case '<':
+ result.append("<");
+ break;
+ case '>':
+ result.append(">");
+ break;
+ case '&':
+ result.append("&");
+ break;
+ case '"':
+ result.append(""");
+ break;
+ default:
+ result.append(content[i]);
+ }
+ }
+ return (result.toString());
+
+ }
+
}
Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java?rev=664483&r1=664482&r2=664483&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java (original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java Sun Jun 8 04:30:44 2008
@@ -35,6 +35,7 @@
import org.apache.jasper.Options;
import org.apache.jasper.compiler.JspRuntimeContext;
import org.apache.jasper.compiler.Localizer;
+import org.apache.jasper.security.SecurityUtil;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
@@ -311,8 +312,12 @@
if (includeRequestUri != null) {
// This file was included. Throw an exception as
// a response.sendError() will be ignored
- throw new ServletException(Localizer.getMessage(
- "jsp.error.file.not.found",jspUri));
+ String msg = Localizer.getMessage(
+ "jsp.error.file.not.found",jspUri);
+ // Strictly, filtering this is an application
+ // responsibility but just in case...
+ throw new ServletException(
+ SecurityUtil.filter(msg));
} else {
try {
response.sendError(
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org