afnf.net

Spring Securityのdisable順序

Spring Security Spring Boot Java 2015/05/10 02:46

Java ConfigでSpring Security(ver3.2.7)の設定をする場合、disableする順序に癖がありそうです。

うまくいかないケース

有効→無効の順番で指定すると、全部無効扱いになってしまいました。

@EnableWebSecurity
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
       // 有効
      .and()
      .headers().contentTypeOptions().frameOptions().xssProtection()
       // 無効
      .and()
      .csrf().disable()
      .headers().cacheControl().disable()
      .headers().httpStrictTransportSecurity().disable()
    ;
  }

20150510_ssec_bad

x-frame-optionsなどが設定されていません。

うまくいくケース

無効→有効の順番で指定すると、意図した通りになりました。

@EnableWebSecurity
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
      .and()
       // 無効
      .csrf().disable()
      .headers().cacheControl().disable()
      .headers().httpStrictTransportSecurity().disable()
       // 有効
      .headers().contentTypeOptions().frameOptions().xssProtection()
    ;
  }

20150510_ssec_fixed

意図したとおり、X-XSS-Protectionx-content-type-optionsx-frame-optionsが有効になり、 Strict-Transport-SecurityCache-Controlが無効になりました。

リファレンスには・・・

上記の件について、記載は見つかりませんでした。

http://docs.spring.io/spring-security/site/docs/3.2.7.RELEASE/reference/htmlsingle/#headers

Spring Security Spring Boot Java 2015/05/10 02:46
comments (0)

blog-java2 engine (build:2019-02-23 17:57 JST)