dur*_*dur 5 java rest jax-rs csrf spring-security
是否有必要保护JAX-RS请求免受CSRF的侵害?
根据定义, REST是无状态的,因此不存在会话ID(会话cookie),因为根本没有会话(另请参阅/sf/answers/1102264761/).
我的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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我发现了以下博客:无状态弹簧安全第1部分:无状态CSRF保护.不幸的是,博客没有解释,为什么需要CSRF保护.
没有会话cookie,还有其他CSRF攻击吗?
CSRF 攻击不需要会话的存在。CSRF 攻击包括代表用户执行某些操作,方法是诱骗他/她单击链接或提交转到用户登录的应用程序的表单。
使用基本身份验证还是会话 cookie 来识别用户都无关紧要。
请注意,使用 cookie 并不意味着应用程序不是无状态的。Cookie 与基本身份验证一样,只是随每个 HTTP 请求发送一个附加标头。
归档时间: |
|
查看次数: |
1123 次 |
最近记录: |