Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use redirect-query-check with the static resource list #1034

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,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()) || "/".equals(request.getPathInfo()));
if (staticResourcesMatch || staticWelcomeFileMatch) {
Expand Down Expand Up @@ -328,12 +328,12 @@ protected HttpServletRequest checkXForwardedHeaders(HttpServletRequest request)
}


private boolean matchPath(List<Pattern> values, HttpServletRequest request) {
coheigea marked this conversation as resolved.
Show resolved Hide resolved
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.isEmpty()) {
path += "?" + queryString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void testGetServicesPageWithServletPatternMatchOnly() throws Exception {
assertFalse(s.contains(";a=b"));
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/the/"));
}

@Test
public void testGetServicesPageWithServletPatternMatchOnly2() throws Exception {
final String address = "http://localhost:" + PORT + "/services;a=b;/list;a=b/;a=b";
Expand All @@ -158,6 +159,15 @@ public void testGetServicesPageWithServletPatternMatchOnly2() throws Exception {
assertTrue(s.contains("<a href=\"http://localhost:" + PORT + "/services/list/"));
}

@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 testEchoBookForm() throws Exception {
String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform";
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 @@ -60,6 +60,22 @@
</servlet-class>
<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>
Expand All @@ -72,5 +88,9 @@
<servlet-name>CXFServlet3</servlet-name>
<url-pattern>/services/list/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet4</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
<!-- END SNIPPET: webxml -->