ChristopherSchultz commented on a change in pull request #452:
URL: https://github.com/apache/tomcat/pull/452#discussion_r712474343



##########
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 don't think this should be logged at ERROR level, because an attacker 
could fill-up your logs just by repeatedly sending-in garbage. I would 
recommend using DEBUG log-level for this.

##########
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()) {
+                log.error("CSRF validation for REST failed! Request with 
method [" + request.getMethod() + "] and URI ["
+                        + RequestUtil.filter(request.getRequestURI())

Review comment:
       I don't think there is a reason to use RequestUtil.filter() for this 
value; it's not going to be embedded in HTML so it's okay to use the value 
as-is.

##########
File path: java/org/apache/catalina/filters/RestCsrfPreventionFilter.java
##########
@@ -192,6 +209,10 @@ private String 
extractNonceFromRequestParams(HttpServletRequest request) {
                 String nonce = params[0];
                 for (String param : params) {
                     if (!Objects.equals(param, nonce)) {
+                        if (log.isErrorEnabled()) {

Review comment:
       Same: use DEBUG not ERROR.

##########
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()) {

Review comment:
       I might use TRACE, here.




-- 
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-unsubscr...@tomcat.apache.org

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



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

Reply via email to