exceptionfactory commented on code in PR #6715: URL: https://github.com/apache/nifi/pull/6715#discussion_r1032704628
########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/csrf/SkipReplicatedCsrfFilter.java: ########## @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.web.security.csrf; + +import org.springframework.security.web.csrf.CsrfFilter; +import org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Skip Replicated Cross-Site Request Forgery Filter disables subsequent filtering for matched requests + */ +public class SkipReplicatedCsrfFilter extends OncePerRequestFilter { + /** RequestReplicator.REQUEST_TRANSACTION_ID_HEADER applied to replicated cluster requests */ + protected static final String REPLICATED_REQUEST_HEADER = "X-RequestTransactionId"; + + /** Requests containing replicated header will be skipped */ + private static final RequestMatcher REQUEST_MATCHER = new RequestHeaderRequestMatcher(REPLICATED_REQUEST_HEADER); + + /** + * Set request attribute to disable standard CSRF Filter when request matches + * + * @param request HTTP Servlet Request + * @param response HTTP Servlet Response + * @param filterChain Filter Chain + * @throws ServletException Thrown on FilterChain.doFilter() + * @throws IOException Thrown on FilterChain.doFilter() + */ + @Override + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { + if (REQUEST_MATCHER.matches(request)) { + CsrfFilter.skipRequest(request); Review Comment: A Cross-Site Scripting vulnerability would be able to make use of existing JavaScript request processing that adds the custom request token header to all requests. The `__Secure-Authorization-Bearer` token is not accessible from JavaScript, so the impact of an XSS attack is somewhat limited in that regard. The introduction of this new filter for skipping replicated requests should not alter the impact of a theoretical XSS vulnerability. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
