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/19 20:43:14 UTC

[GitHub] [tomcat] PolinaGeorgieva opened a new pull request #452: Introduce logs in RestCsrfPreventionFilter to improve troubleshooting.

PolinaGeorgieva opened a new pull request #452:
URL: https://github.com/apache/tomcat/pull/452


   Add some logs in RestCsrfPreventionFilter that would improve troubleshooting in case of failed CSRF validation.
   Note that the RequestUtil.filter method is used only to apply some basic sensitive characters filtering of the requested path.
   But as this method is deprecated in v.8.5.x and removed in v.9.0.x, would you recommend an alternative method I could use in this case?
   


-- 
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


[GitHub] [tomcat] markt-asf commented on pull request #452: Introduce logs in RestCsrfPreventionFilter to improve troubleshooting.

Posted by GitBox <gi...@apache.org>.
markt-asf commented on pull request #452:
URL: https://github.com/apache/tomcat/pull/452#issuecomment-979431354


   It has been 2 months and the requested changes have not been made. I made the changes and a number of other fixes and applied this manually.


-- 
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


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

Posted by GitBox <gi...@apache.org>.
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-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


[GitHub] [tomcat] markt-asf closed pull request #452: Introduce logs in RestCsrfPreventionFilter to improve troubleshooting.

Posted by GitBox <gi...@apache.org>.
markt-asf closed pull request #452:
URL: https://github.com/apache/tomcat/pull/452


   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
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