You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by GitBox <gi...@apache.org> on 2021/09/24 11:12:49 UTC

[GitHub] [tomcat] martin-g commented on a change in pull request #452: Introduce logs in RestCsrfPreventionFilter to improve troubleshooting.

martin-g commented on a change in pull request #452:
URL: https://github.com/apache/tomcat/pull/452#discussion_r715524193



##########
File path: java/org/apache/catalina/filters/RestCsrfPreventionFilter.java
##########
@@ -217,6 +238,10 @@ public boolean apply(HttpServletRequest request, HttpServletResponse response) {
                 }
                 storeNonceToResponse(response, Constants.CSRF_REST_NONCE_HEADER_NAME,
                         nonceFromSessionStr);
+                if (log.isDebugEnabled()) {
+                    log.debug("CSRF Fetch request is succesfully handled - nonce is added to the response."

Review comment:
       succes`s`fully

##########
File path: java/org/apache/catalina/filters/RestCsrfPreventionFilter.java
##########
@@ -155,17 +160,29 @@ protected void storeNonceToSession(HttpSession session, String key, Object value
         @Override
         public boolean apply(HttpServletRequest request, HttpServletResponse response)
                 throws IOException {
+            String nonceFromRequest = extractNonceFromRequest(request);
+            HttpSession session = request.getSession(false);
+            String nonceFromSession = extractNonceFromSession(session,
+                    Constants.CSRF_REST_NONCE_SESSION_ATTR_NAME);
             if (isValidStateChangingRequest(
-                    extractNonceFromRequest(request),
-                    extractNonceFromSession(request.getSession(false),
-                            Constants.CSRF_REST_NONCE_SESSION_ATTR_NAME))) {
+                    nonceFromRequest,
+                    nonceFromSession)) {
                 return true;
             }
 
             storeNonceToResponse(response, Constants.CSRF_REST_NONCE_HEADER_NAME,
                     Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
             response.sendError(getDenyStatus(),
                     sm.getString("restCsrfPreventionFilter.invalidNonce"));
+            if (log.isErrorEnabled()) {

Review comment:
       I agree with @ChristopherSchultz !




-- 
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: dev-unsubscribe@tomcat.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org