Why if i change the value of the CSFR cookie my requests are still valid?

I’m trying to understand how CSRF protection works in spring security 6.x.

I have an angular SPA that logs in the spring boot 3.0 backend with formLogin.

I have this configuration in the SecurityConfiguration:

public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        CookieCsrfTokenRepository tokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
        CsrfTokenRequestAttributeHandler requestHandler = new CsrfTokenRequestAttributeHandler();
             requestHandler.setCsrfRequestAttributeName("_csrf");
        return http.csrf((csrf) ->
                           csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                               .csrfTokenRequestHandler(requestHandler)
                               .ignoringRequestMatchers("/login", "/logout")
                   )
                   .cors(cors -> cors.configurationSource(corsConfigurationSourceWithCsfr()))
                   .authorizeHttpRequests(authRequest ->
                           authRequest
                                   .requestMatchers(HttpMethod.OPTIONS)
                                   .permitAll()
                                   .requestMatchers("/login", "/logout")
                                   .permitAll()
                                   .anyRequest()
                                   .authenticated()
                   )
                   .formLogin(formLogin -> formLogin
                           .successHandler((request, response, authentication) ->
                                   response.setStatus(HttpStatus.OK.value())
                           )
                           .failureHandler((request, response, exception) ->
                                   response.setStatus(HttpStatus.FORBIDDEN.value())
                           )
                           .loginProcessingUrl("/login")
                           .permitAll())
                   .logout(logout -> logout.logoutUrl("/logout")
                                           .clearAuthentication(true)
                                           .addLogoutHandler((request, response, authentication) -> {
                                               response.setStatus(HttpStatus.OK.value());
                                           })
                                           .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
                                           .deleteCookies("JSESSIONID"))
                   .sessionManagement(sessionManager ->
                           sessionManager
                                   .sessionCreationPolicy(SessionCreationPolicy.ALWAYS))
                   .authenticationProvider(authProvider)
                .addFilterAfter(new CsrfTokenResponseHeaderBindingFilter(), CsrfFilter.class)
                   .build();
    }

And this is my CsrfTokenResponseHeaderBindingFilter

public class CsrfTokenResponseHeaderBindingFilter extends OncePerRequestFilter {

    protected static final String REQUEST_ATTRIBUTE_NAME = "_csrf";
    protected static final String RESPONSE_HEADER_NAME = "X-CSRF-HEADER";
    protected static final String RESPONSE_PARAM_NAME = "X-CSRF-PARAM";
    protected static final String RESPONSE_TOKEN_NAME = "X-CSRF-TOKEN";

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
        CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME);

        if (token != null) {
            response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName());
            response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName());
            response.setHeader(RESPONSE_TOKEN_NAME, token.getToken());
            log.info("for request: {}", request.getRequestURI());
            log.info("added token {}", token.getToken());
        }

        filterChain.doFilter(request, response);
    }

}

It is properly setting and UUID with the CSRF token in the cookies of the front end and this token is sent to the server.

This is how a request looks like:

My concern is around the fact that if i change the value of the CSRF token in the frontend cookies it still works. Is this the right way to work?

I’ve been trying all the solutions i’ve found in SO and in the official documentation.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật