Skip to content

Regression: ResourceUrlEncodingFilter can throw StringIndexOutOfBoundsException with relative URL [SPR-13847] #18420

Closed
@spring-projects-issues

Description

@spring-projects-issues

Dallas Hopewell opened SPR-13847 and commented

I have a web application that is throwing the following exception after updating from Spring Framework version 4.1.7 to 4.2.4

Caused by java.lang.StringIndexOutOfBoundsException: String index out of range: -3
  java.lang.String.substring(String.java:1967)
  org.springframework.web.servlet.resource.ResourceUrlEncodingFilter$ResourceUrlEncodingResponseWrapper.encodeURL(ResourceUrlEncodingFilter.java:80)
  javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
  javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
  org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper.encodeURL(SaveContextOnUpdateOrErrorResponseWrapper.java:118)
  javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
  org.apache.taglibs.standard.tag.common.core.UrlSupport.doEndTag(UrlSupport.java:117)
  org.apache.jsp.WEB_002dINF.jsp.tasks.context_jsp._jspx_meth_c_005furl_005f0(context_jsp.java:400)
  org.apache.jsp.WEB_002dINF.jsp.tasks.context_jsp._jspService(context_jsp.java:153)

The part of the JSP where the error occurs is: -

<c:url var="reviewUrl" value="review.html"><c:param name="referrer" value="${referrer}"/></c:url>

The problem seems to be when the javax.servlet.http.HttpServletResponseWrapper#encodeURL(String) method is invoked with a 'relative' URL path including a query string, and that query string index in the URL path is less than the number of characters in the web application's context path then the exception is thrown.


Affects: 4.2.4

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions