mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
normalize urls for BaseUrlFilter to prevent redirect loops, see issue #311
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.filter;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -74,6 +75,22 @@ public class BaseUrlFilter extends HttpFilter
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param requestUrl
|
||||
* @param baseUrl
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean startsWith(String requestUrl, String baseUrl)
|
||||
{
|
||||
return HttpUtil.normalizeUrl(requestUrl).startsWith(
|
||||
HttpUtil.normalizeUrl(baseUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -87,8 +104,8 @@ public class BaseUrlFilter extends HttpFilter
|
||||
*/
|
||||
@Override
|
||||
protected void doFilter(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException
|
||||
HttpServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
if (Util.isEmpty(configuration.getBaseUrl()))
|
||||
{
|
||||
@@ -139,8 +156,8 @@ public class BaseUrlFilter extends HttpFilter
|
||||
*/
|
||||
private boolean isBaseUrl(HttpServletRequest request)
|
||||
{
|
||||
return request.getRequestURL().toString().startsWith(
|
||||
configuration.getBaseUrl());
|
||||
return startsWith(request.getRequestURL().toString(),
|
||||
configuration.getBaseUrl());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user