Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0bdc1d0
[backend] fix(security): add csrf token management (#1785)
gabriel-peze Feb 16, 2026
21f5eac
[frontend/backend] fix(csrf): review csrf activation (#1785)
gabriel-peze Feb 24, 2026
5b3faf9
[backend] fix(csrf): tests (#1785)
gabriel-peze Feb 24, 2026
a7e197a
[backend] fix(csrf): tests (#1785)
gabriel-peze Feb 24, 2026
8606cb1
[backend] fix(csrf): tests (#1785)
gabriel-peze Feb 24, 2026
0d2a0ee
[backend] fix(csrf): tests (#1785)
gabriel-peze Feb 24, 2026
ac3ef5c
[backend] fix(csrf): tests (#1785)
gabriel-peze Feb 24, 2026
2012306
[backend] fix(csrf): tests (#1785)
gabriel-peze Feb 24, 2026
477a844
[backend] feat(csrf): try to open all technical routes (#1785)
gabriel-peze Mar 24, 2026
929eaa7
[backend] feat(csrf): try to open all technical routes (#1785)
gabriel-peze Mar 24, 2026
aed2886
[backend] feat(csrf): add connector-instance ignoring matcher (#1785)
gabriel-peze Mar 24, 2026
5ef190b
[backend] feat(csrf): review tests (#1785)
gabriel-peze Mar 24, 2026
e8ffb51
[backend] feat(csrf): spotless (#1785)
gabriel-peze Mar 24, 2026
0efe22e
[backend] feat(csrf): review tests (#1785)
gabriel-peze Mar 24, 2026
21d50ea
[backend] fix(csrf): start to review url used by technical processes …
gabriel-peze Mar 25, 2026
36c9454
[backend] fix(csrf): add injectors urls (#1785)
gabriel-peze Mar 25, 2026
15f0cf0
[frontend/backend] fix(csrf): try to fix issue (#1785)
gabriel-peze Apr 10, 2026
f205241
[backend] feat(csrf): review complete csrf process (#1785)
gabriel-peze Apr 13, 2026
4fa610b
[frontend/backend] feat(security): lint and spotless (#1785)
gabriel-peze Apr 13, 2026
a42e0e9
[frontend/backend] feat(security): spotless (#1785)
gabriel-peze Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import io.openaev.service.UserMappingService;
import io.openaev.service.user_events.UserEventService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand All @@ -42,7 +44,10 @@
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
import org.springframework.security.web.util.matcher.RequestMatcher;

@Configuration
@EnableWebSecurity
Expand All @@ -63,7 +68,12 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.requestCache(Customizer.withDefaults())
.requestCache(cache -> cache.requestCache(new HttpSessionRequestCache()))
.csrf(AbstractHttpConfigurer::disable)
.csrf(
csrf ->
csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler())
.ignoringRequestMatchers("/api/health", "/api/login", "/actuator/**")
.ignoringRequestMatchers(bearerWithoutCookiesMatcher()))
.formLogin(AbstractHttpConfigurer::disable)
.securityContext(securityContext -> securityContext.requireExplicitSave(false))
.authorizeHttpRequests(
Expand Down Expand Up @@ -227,4 +237,14 @@ private OAuth2AuthorizationRequest customize(
}
};
}

private RequestMatcher bearerWithoutCookiesMatcher() {
return request -> {
String authorization = request.getHeader(HttpHeaders.AUTHORIZATION);
Cookie[] cookies = request.getCookies();
boolean hasBearer = authorization != null && authorization.startsWith("Bearer ");
boolean hasCookies = cookies != null && cookies.length > 0;
return hasBearer && !hasCookies;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static io.openaev.utilstest.ZipUtils.convertToJson;
import static io.openaev.utilstest.ZipUtils.extractAllFilesFromZip;
import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -60,7 +61,8 @@ void export_custom_dashboard_with_include_returns_custom_dashboard_with_relation
// -- EXECUTE --
byte[] response =
mockMvc
.perform(get(CUSTOM_DASHBOARDS_URI + "/" + wrapper.get().getId() + "/export"))
.perform(
get(CUSTOM_DASHBOARDS_URI + "/" + wrapper.get().getId() + "/export").with(csrf()))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static java.util.Collections.emptyMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -52,7 +53,7 @@ void import_custom_dashboard_with_include_returns_custom_dashboard_with_relation
// -- EXECUTE --
String response =
mockMvc
.perform(multipart(CUSTOM_DASHBOARDS_URI + "/import").file(zipFile))
.perform(multipart(CUSTOM_DASHBOARDS_URI + "/import").file(zipFile).with(csrf()))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse()
Expand Down
Loading
Loading