是否有必要针对CSRF来保护JAX-RS请求?是否有必要保护针对CSRF的JAX-RS请求?
通过definition REST是无状态的,因此不存在会话ID(会话cookie),因为根本没有会话(另请参阅https://stackoverflow.com/a/15746639/5277820)。
我的春季安全的Java配置:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Configuration
@Order(1)
public static class JaxRsWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.antMatcher("/services/**")
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/services/**").permitAll()
.anyRequest().hasAuthority("ROLE_user")
.and()
.httpBasic()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
}
}
但我发现例如以下博客:Stateless Spring Security Part 1: Stateless CSRF protection。不幸的是,博客没有解释为什么需要CSRF保护。
有没有其他CSRF攻击没有会话cookie?
如果您的网站被网页浏览器使用,您只需要保护它们免受CSRF攻击。如果它只能用于卷曲,那么您不需要担心CSRF –