是否有必要针对 CSRF 保护 JAX-RS 请求?
通过 definition REST 是无状态的,因此不存在 session ID( session cookie),因为根本没有 session (另请参见 https://stackoverflow.com/a/15746639/5277820 )。
我的 Spring Security 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 保护。
没有session cookie还有其他CSRF攻击吗?
最佳答案
CSRF 攻击不需要 session 存在。 CSRF 攻击包括代表用户做某事,方法是诱使他/她单击链接或提交表单,该表单转到用户登录的应用程序。
使用基本身份验证还是 session cookie 来识别用户是无关紧要的。
请注意,使用 cookie 并不意味着该应用不是无状态的。 Cookie 与基本身份验证一样,只是在每个 HTTP 请求中发送一个额外的 header 。
关于java - 是否有必要保护 JAX-RS 请求免受 CSRF 攻击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33211562/