Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Spring Security's CSRF feature for stateless endpoints?

I'm using Spring Security with a stateless web service. I'd like to use the CSRF features in Spring Security 3.2. Is that possible with a stateless web app?

This is the relevant Java Config, since I've had to disable CSRF for the time being.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .sessionFixation().none().and()
            .csrf().disable();
}
like image 743
checketts Avatar asked Dec 16 '13 23:12

checketts


1 Answers

If your service is really stateless, CSRF protection might not make sense at all. As long as the server does not use cookies to identify/authenticate the user, your service is not vulnerable to CSRF attacks.

For a detailed explanation, see http://sitr.us/2011/08/26/cookies-are-bad-for-you.html

like image 66
CrimsonCricket Avatar answered Sep 22 '22 12:09

CrimsonCricket