Class CsrfInterceptor

All Implemented Interfaces:
org.springframework.web.servlet.AsyncHandlerInterceptor, org.springframework.web.servlet.HandlerInterceptor

@Component public class CsrfInterceptor extends AbstractSessionAwareInterceptor
An interceptor which checks for Cross-Site Request Forgery (CSRF) tokens.

General Behaviour Link icon

This interceptor implements the enhanced Synchronizer-Token pattern. Each POST, PUT or DELETE request made to a controller that changes the state of an AquimaSession should contain an X-CSRF-Token header or request parameter with the value of the CSRF token for that AquimaSession.

If token verification fails, the target AquimaSession is closed and a 403 "Invalid CSRF token" error is sent to the client.

In order to determine the ID of the AquimaSession for which a request is intended, the controllers should annotate the request parameter corresponding to the AquimaSession ID with AquimaSessionId. This interceptor supports parameters given as PathVariable or RequestParam. If the AquimaSession ID cannot be determined from the request this interceptor has no effect.

Enabling or disabling the interceptor Link icon

The CSRF interceptor may be globally enabled or disabled by setting the property blueriq.security.csrf-protection.enabled to true or false in application.properties. Additionally, CSRF protection may be disabled for specific controller methods by annotating the methods with CSRF(ignore=true). See Csrf for further details on when this annotation should be used.

Since:
9.5.0, 9.7.3
Author:
Petru Galanton
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the header that will be checked for a CSRF token
    static final String
    The name of the request parameter that will be checked for a CSRF token
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    CsrfInterceptor(com.blueriq.component.api.IAquimaSessionsMap sessionManager, com.aquima.interactions.config.IConfiguration configuration)
     
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    boolean
    preHandle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler)
    This implementation always returns true.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.web.servlet.AsyncHandlerInterceptor Link icon

    afterConcurrentHandlingStarted

    Methods inherited from interface org.springframework.web.servlet.HandlerInterceptor Link icon

    afterCompletion, postHandle
  • Field Details Link icon

    • HEADER_NAME Link icon

      public static final String HEADER_NAME
      The name of the header that will be checked for a CSRF token
      See Also:
    • PARAMETER_NAME Link icon

      public static final String PARAMETER_NAME
      The name of the request parameter that will be checked for a CSRF token
      See Also:
  • Constructor Details Link icon

    • CsrfInterceptor Link icon

      @Autowired public CsrfInterceptor(com.blueriq.component.api.IAquimaSessionsMap sessionManager, com.aquima.interactions.config.IConfiguration configuration)
  • Method Details Link icon