Skip to content

Commit 3a44585

Browse files
committed
[backend] fix(security): add csrf token management (#1785)
1 parent b17d944 commit 3a44585

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

openaev-api/src/main/java/io/openaev/config/AppSecurityConfig.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.springframework.security.oauth2.core.user.OAuth2User;
4444
import org.springframework.security.web.SecurityFilterChain;
4545
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
46+
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
47+
import org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler;
4648
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
4749

4850
@Configuration
@@ -64,7 +66,21 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
6466
http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
6567
.requestCache(Customizer.withDefaults())
6668
.requestCache(cache -> cache.requestCache(new HttpSessionRequestCache()))
67-
.csrf(AbstractHttpConfigurer::disable)
69+
.csrf(
70+
csrf ->
71+
csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
72+
.csrfTokenRequestHandler(new XorCsrfTokenRequestAttributeHandler())
73+
.ignoringRequestMatchers(
74+
"/api/health",
75+
"/api/comcheck/**",
76+
"/api/player/**",
77+
"/api/settings",
78+
"/api/agent/**",
79+
"/api/implant/**",
80+
"/api/login",
81+
"/api/reset/**",
82+
"/api/**",
83+
"/actuator/**"))
6884
.formLogin(AbstractHttpConfigurer::disable)
6985
.securityContext(securityContext -> securityContext.requireExplicitSave(false))
7086
.authorizeHttpRequests(

0 commit comments

Comments
 (0)