# Disable the CSRF

In 
Published 2023-06-24

This tutorial explains how we can disable the CSRF when using Spring Security.

This example start from My first Spring Boot Service using Spring Security You need to pass through this article before.

For disabling the CSRF we need to change the default implementation of SecurityFilterChain configuration class. For this, I added the "ProjectSpringSecurityConfig" class which modify the SecurityFilterChain Bean.

ProjectSpringSecurityConfig.java
package com.demo.springsecurity.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class ProjectSpringSecurityConfig {

    @Bean
    public SecurityFilterChain myFilterChain(HttpSecurity http) throws Exception {
        http.csrf(csrf -> csrf.disable());

        return http.build();
    }
}

Now we can run POST, PUT, DELETE, PATCH requests without taking care of the CSRF. Even if this is not a good approach for PROD, it is a good approach for testing and understanding Spring Security.