CsrfTokenRequestHandler is a Spring Security contract that controls how a generated CSRF token is associated with an HTTP request. It complements CsrfToken, which describes the token, and CsrfTokenRepository, which creates, stores, and loads it. section 9.3 section 9.4
Use it when customizing CSRF token management, such as pairing a database-backed repository with CsrfTokenRequestAttributeHandler in the security filter chain. The repository can store tokens outside the HTTP session, while the handler governs their request-facing association.
Configure a request handler
http.csrf(c -> { c.csrfTokenRepository(customTokenRepository); c.csrfTokenRequestHandler( new CsrfTokenRequestAttributeHandler() ); }); This configuration uses a custom repository and explicitly selects the request handler. A GET request can generate and store a token; a later POST must provide the matching X-CSRF-TOKEN value or receive HTTP 403.
