Skip to content

Commit b010f19

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

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
@@ -51,6 +51,8 @@
5151
import org.springframework.security.oauth2.core.user.OAuth2User;
5252
import org.springframework.security.web.SecurityFilterChain;
5353
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
54+
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
55+
import org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler;
5456
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
5557

5658
@Configuration
@@ -72,7 +74,21 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
7274
http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
7375
.requestCache(Customizer.withDefaults())
7476
.requestCache(cache -> cache.requestCache(new HttpSessionRequestCache()))
75-
.csrf(AbstractHttpConfigurer::disable)
77+
.csrf(
78+
csrf ->
79+
csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
80+
.csrfTokenRequestHandler(new XorCsrfTokenRequestAttributeHandler())
81+
.ignoringRequestMatchers(
82+
"/api/health",
83+
"/api/comcheck/**",
84+
"/api/player/**",
85+
"/api/settings",
86+
"/api/agent/**",
87+
"/api/implant/**",
88+
"/api/login",
89+
"/api/reset/**",
90+
"/api/**",
91+
"/actuator/**"))
7692
.formLogin(AbstractHttpConfigurer::disable)
7793
.securityContext(securityContext -> securityContext.requireExplicitSave(false))
7894
.authorizeHttpRequests(

0 commit comments

Comments
 (0)