SV.SPRING.FIXATION

セッション固定化保護が無効になっています。

セッション固定化保護は、デフォルトで常に有効になります。Klocwork は、セッション固定化保護が無効になる場合は、必ず SV.SPRING.FIXATION 欠陥を報告します。

脆弱性とリスク

攻撃者がセッション ID を使用して有効なユーザーセッションをハイジャックしないようにするため、セッションが作成されるたびにコードに ID を新規作成させることをお勧めします。

セッション固定化保護はデフォルトで有効になっていますが、sessionFixation().none() を設定することで無効にすることができます。

軽減と防止

新しいセッションが作成されるたびにセッション ID が新規作成されるようにします。前回のセッションのデータが必要な場合は、セッションを引き継ぐこともできます。

脆弱コード例

コピー
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
public class SpringFixation extends WebSecurityConfigurerAdapter {
 
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.sessionManagement().sessionFixation().none();
    }
}

Klocwork が 8 行目で SV.SPRING.FIXATION 欠陥を報告し、「sessionFixation().none() を使用すると、デフォルトで有効になっているセッション固定化保護が無効になる可能性があります」と通知します。セッション固定化保護を無効にすると、セキュリティが損なわれる可能性があります。

修正コード例 1

コピー
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
public class SpringFixation extends WebSecurityConfigurerAdapter {
 
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.sessionManagement().sessionFixation().newSession();
    }
}

新しいセッションが作成されるため、Klocwork は SV.SPRING.FIXATION 欠陥を報告しなくなります。

修正コード例 2

コピー
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
public class SpringFixation extends WebSecurityConfigurerAdapter {
 
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.sessionManagement().sessionFixation().migrateSession();
    }
}

セッションが新規作成され、古いセッションのすべてのデータが新しいセッションにコピーされるため、Klocwork は SV.SPRING.FIXATION 欠陥を報告しなくなります。

セキュリティトレーニング

Secure Code Warrior が提供しているアプリケーションセキュリティトレーニング教材。