Skip to content

Commit 9d74754

Browse files
Security Hotspot fix
1 parent a2bc624 commit 9d74754

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/main/java/com/iemr/ecd/utils/mapper/SecurityConfig.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ public SecurityConfig(RoleAuthenticationFilter roleAuthenticationFilter,
2929
this.customAccessDeniedHandler = customAccessDeniedHandler;
3030
}
3131

32-
@Bean
33-
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
34-
http
35-
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
36-
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
37-
.authorizeHttpRequests(auth -> auth
38-
.requestMatchers("/user/*").permitAll()
39-
.anyRequest().authenticated()
40-
).exceptionHandling(ex -> ex
41-
.authenticationEntryPoint(customAuthenticationEntryPoint)
42-
.accessDeniedHandler(customAccessDeniedHandler)
43-
)
44-
.addFilterBefore(roleAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
32+
@Bean
33+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
34+
CookieCsrfTokenRepository csrfTokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
35+
csrfTokenRepository.setCookieHttpOnly(true); // Fixes the security hotspot
4536

46-
return http.build();
47-
}
37+
http
38+
.csrf(csrf -> csrf.csrfTokenRepository(csrfTokenRepository))
39+
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
40+
.authorizeHttpRequests(auth -> auth
41+
.requestMatchers("/user/*").permitAll()
42+
.anyRequest().authenticated()
43+
)
44+
.exceptionHandling(ex -> ex
45+
.authenticationEntryPoint(customAuthenticationEntryPoint)
46+
.accessDeniedHandler(customAccessDeniedHandler)
47+
)
48+
.addFilterBefore(roleAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
49+
50+
return http.build();
51+
}
4852
}

0 commit comments

Comments
 (0)