Skip to content

Commit

Permalink
Don't use redirect-query-check with the static resource list (apache#…
Browse files Browse the repository at this point in the history
…1034)

(cherry picked from commit b18d792)
(cherry picked from commit a7b7310)
(cherry picked from commit a1b5578)
  • Loading branch information
coheigea authored and jgallimore committed Dec 15, 2022
1 parent 7e616db commit 107a1ff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ public void service(ServletRequest req, ServletResponse res)
protected void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
if ((dispatcherServletPath != null || dispatcherServletName != null)
&& (redirectList != null && matchPath(redirectList, request)
&& (redirectList != null && matchPath(redirectQueryCheck, redirectList, request)
|| redirectList == null)) {
// if no redirectList is provided then this servlet is redirecting only
redirect(request, response, request.getPathInfo());
return;
}
boolean staticResourcesMatch = staticResourcesList != null
&& matchPath(staticResourcesList, request);
&& matchPath(false, staticResourcesList, request);
boolean staticWelcomeFileMatch = staticWelcomeFile != null
&& (StringUtils.isEmpty(request.getPathInfo()) || request.getPathInfo().equals("/"));
if (staticResourcesMatch || staticWelcomeFileMatch) {
Expand All @@ -266,12 +266,12 @@ protected void handleRequest(HttpServletRequest request, HttpServletResponse res
invoke(request, response);
}

private boolean matchPath(List<Pattern> values, HttpServletRequest request) {
private static boolean matchPath(boolean checkRedirect, List<Pattern> values, HttpServletRequest request) {
String path = request.getPathInfo();
if (path == null) {
path = "/";
}
if (redirectQueryCheck) {
if (checkRedirect) {
String queryString = request.getQueryString();
if (queryString != null && queryString.length() > 0) {
path += "?" + queryString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public void testGetServicesPageWithServletPatternMatchOnly2() throws Exception {
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/the/thebooks/bookstore"));
}

@Test
public void testStaticResourcesWithRedirectQueryCheck() throws Exception {
final String address = "http://localhost:" + PORT + "/services/?.html";
WebClient wc = WebClient.create(address).accept("text/*");
String s = wc.get(String.class);
// Check we don't have a directory listing
assertFalse(s.contains("META-INF"));
}

@Test
public void testGetGenericBook() throws Exception {
String baseAddress = "http://localhost:" + PORT + "/the/thebooks8/books";
Expand Down
20 changes: 20 additions & 0 deletions systests/jaxrs/src/test/resources/jaxrs/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,29 @@
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>CXFServlet4</servlet-name>
<display-name>CXF Servlet4</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<init-param>
<param-name>static-resources-list</param-name>
<param-value>.*\.html</param-value>
</init-param>
<init-param>
<param-name>redirect-query-check</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/the/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet4</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
<!-- END SNIPPET: webxml -->

0 comments on commit 107a1ff

Please sign in to comment.