Class CSRFProtector


  • public class CSRFProtector
    extends Object
    This class generates a CSRF token for a valid session and protects the request against that token. This also implements the logic to inject a javascript for the response, to enforce that the generated token is added as a hidden parameter in every form.
    • Method Detail

      • skipUrl

        public boolean skipUrl​(String uri)
      • applyProtection

        public void applyProtection​(javax.servlet.http.HttpServletRequest request,
                                    CSRFResponseWrapper responseWrapper)
                             throws CSRFException
        Validates POST requests for CSRF token
        Parameters:
        request - HTTPServerRequest instance
        responseWrapper - HTTPServerletResponseWrapper instance
        Throws:
        CSRFException - exception is thrown when there is a probable attack
      • enforceProtection

        public void enforceProtection​(javax.servlet.http.HttpServletRequest request,
                                      CSRFResponseWrapper responseWrapper)
                               throws IOException
        Generates and injects CSRF Token in the response as a hidden parameter
        Parameters:
        request - HTTPServerRequest instance
        responseWrapper - HTTPServerletResponseWrapper instance
        Throws:
        IOException