@Test public void testProxyRemoteAddressAllowedFirstIpAllowedNoSpace() throws IOException, ServletException { doReturn(REMOTE_ADDRESS_LIST_FIRST_IP_ALLOWED_NO_SPACE).when(request).getHeader(FORWARD_HEADER); filter.doFilter(request, response, new MockFilterChain()); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getRequestURI() .replace(request.getContextPath(), StringUtils.EMPTY) .replace(URL_PATTERN, StringUtils.EMPTY); boolean checkOrigin = shouldCheckOrigin(path); if (!checkOrigin) { filterChain.doFilter(servletRequest, servletResponse); return; } String integrationType = path.substring(0, path.indexOf("/")); Set<String> whiteList = getWhiteListByApplication(integrationType); if (whiteList.isEmpty()) { filterChain.doFilter(servletRequest, servletResponse); } else { String remoteAddressInfo = getOriginatingAddressInfo(request); boolean allowedOrigin = verifyOrigin(remoteAddressInfo, whiteList, integrationType); if (allowedOrigin) { filterChain.doFilter(servletRequest, servletResponse); } else { LOGGER.warn(ExceptionMessageFormatter.format(WEBHOOK_FILTER, logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED, remoteAddressInfo), logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED_SOLUTION, integrationType))); writeResponse(response, remoteAddressInfo); } } }
WebHookOriginCheckFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getRequestURI() .replace(request.getContextPath(), StringUtils.EMPTY) .replace(URL_PATTERN, StringUtils.EMPTY); boolean checkOrigin = shouldCheckOrigin(path); if (!checkOrigin) { filterChain.doFilter(servletRequest, servletResponse); return; } String integrationType = path.substring(0, path.indexOf("/")); Set<String> whiteList = getWhiteListByApplication(integrationType); if (whiteList.isEmpty()) { filterChain.doFilter(servletRequest, servletResponse); } else { String remoteAddressInfo = getOriginatingAddressInfo(request); boolean allowedOrigin = verifyOrigin(remoteAddressInfo, whiteList, integrationType); if (allowedOrigin) { filterChain.doFilter(servletRequest, servletResponse); } else { LOGGER.warn(ExceptionMessageFormatter.format(WEBHOOK_FILTER, logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED, remoteAddressInfo), logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED_SOLUTION, integrationType))); writeResponse(response, remoteAddressInfo); } } } }
WebHookOriginCheckFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getRequestURI() .replace(request.getContextPath(), StringUtils.EMPTY) .replace(URL_PATTERN, StringUtils.EMPTY); boolean checkOrigin = shouldCheckOrigin(path); if (!checkOrigin) { filterChain.doFilter(servletRequest, servletResponse); return; } String integrationType = path.substring(0, path.indexOf("/")); Set<String> whiteList = getWhiteListByApplication(integrationType); if (whiteList.isEmpty()) { filterChain.doFilter(servletRequest, servletResponse); } else { String remoteAddressInfo = getOriginatingAddressInfo(request); boolean allowedOrigin = verifyOrigin(remoteAddressInfo, whiteList, integrationType); if (allowedOrigin) { filterChain.doFilter(servletRequest, servletResponse); } else { LOGGER.warn(ExceptionMessageFormatter.format(WEBHOOK_FILTER, logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED, remoteAddressInfo), logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED_SOLUTION, integrationType))); writeResponse(response, remoteAddressInfo); } } }  }
WebHookOriginCheckFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getRequestURI() .replace(request.getContextPath(), StringUtils.EMPTY) .replace(URL_PATTERN, StringUtils.EMPTY); boolean checkOrigin = shouldCheckOrigin(path); if (!checkOrigin) { filterChain.doFilter(servletRequest, servletResponse); return; } String integrationType = path.substring(0, path.indexOf("/")); Set<String> whiteList = getWhiteListByApplication(integrationType); if (whiteList.isEmpty()) { filterChain.doFilter(servletRequest, servletResponse); } else { String remoteAddressInfo = getOriginatingAddressInfo(request); boolean allowedOrigin = verifyOrigin(remoteAddressInfo, whiteList, integrationType); if (allowedOrigin) { filterChain.doFilter(servletRequest, servletResponse); } else { LOGGER.warn(ExceptionMessageFormatter.format(WEBHOOK_FILTER, logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED, remoteAddressInfo), logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED_SOLUTION, integrationType))); writeResponse(response, remoteAddressInfo); } } }  @Override void init(FilterConfig config); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
      FilterChain filterChain); @Override void destroy(); }
WebHookOriginCheckFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getRequestURI() .replace(request.getContextPath(), StringUtils.EMPTY) .replace(URL_PATTERN, StringUtils.EMPTY); boolean checkOrigin = shouldCheckOrigin(path); if (!checkOrigin) { filterChain.doFilter(servletRequest, servletResponse); return; } String integrationType = path.substring(0, path.indexOf("/")); Set<String> whiteList = getWhiteListByApplication(integrationType); if (whiteList.isEmpty()) { filterChain.doFilter(servletRequest, servletResponse); } else { String remoteAddressInfo = getOriginatingAddressInfo(request); boolean allowedOrigin = verifyOrigin(remoteAddressInfo, whiteList, integrationType); if (allowedOrigin) { filterChain.doFilter(servletRequest, servletResponse); } else { LOGGER.warn(ExceptionMessageFormatter.format(WEBHOOK_FILTER, logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED, remoteAddressInfo), logMessage.getMessage(WEBHOOK_REQUEST_BLOCKED_SOLUTION, integrationType))); writeResponse(response, remoteAddressInfo); } } }  @Override void init(FilterConfig config); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
      FilterChain filterChain); @Override void destroy(); static final String URL_PATTERN; }