Iam developing a web application in Spring boot with spring security.
Here are the codes that I used for implementing csrf
Configuration class....
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity security) throws Exception {
// TODO Auto-generated method stub
security.httpBasic().disable();
security.authorizeRequests()
.antMatchers("/DDR/**").permitAll()
.antMatchers("/assets/**").permitAll();
}
}
Added the below comments in JSP
<meta name="_csrf" content="${_csrf.token}" />
<meta name="_csrf_header" content="${_csrf.headerName}" />
getting the values in js
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
And finally added the header in Ajax request
headers : {
"X-CSRF-TOKEN" : token
},
Do we need any other coding in server side(java side) for validating the CSRF??or will the spring security handle that?? Thanks in advance.