-
Notifications
You must be signed in to change notification settings - Fork 0
Main #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Main #65
Changes from all commits
5a55db2
07711d1
56b855e
4966f37
ac65e1a
694e2c9
de9b4e7
a96a95d
b678d9b
7f939fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.annotation.Order; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
|
|
@@ -25,6 +26,8 @@ | |
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import static org.springframework.security.config.Customizer.withDefaults; | ||
|
|
||
| @Configuration | ||
| @EnableWebSecurity | ||
| @RequiredArgsConstructor | ||
|
|
@@ -73,38 +76,47 @@ public PasswordEncoder passwordEncoder() { | |
| }; | ||
|
|
||
| @Bean | ||
| public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
| @Order(1) | ||
| public SecurityFilterChain swaggerFilterChain(HttpSecurity http) throws Exception { | ||
| http | ||
| .securityMatcher(SwaggerPatterns) | ||
| .cors(c -> c.configurationSource(corsConfigurationSource())) | ||
| .csrf(AbstractHttpConfigurer::disable) | ||
| .httpBasic(AbstractHttpConfigurer::disable) | ||
| .formLogin(AbstractHttpConfigurer::disable); | ||
| .httpBasic(withDefaults()); | ||
|
|
||
| http.sessionManagement(session -> | ||
| session.sessionCreationPolicy(SessionCreationPolicy.STATELESS) | ||
| ); | ||
|
|
||
| if (environmentUtil.isProdProfile()) { | ||
| http | ||
| .authorizeHttpRequests(auth -> auth | ||
| .requestMatchers(SwaggerPatterns).authenticated() | ||
| ) | ||
| .httpBasic(basic -> {}); | ||
| } | ||
| else { | ||
| .authorizeHttpRequests(auth -> auth.anyRequest().authenticated()) | ||
| .httpBasic(withDefaults()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } else { | ||
| http | ||
| .authorizeHttpRequests(auth -> auth | ||
| .requestMatchers(SwaggerPatterns).permitAll() | ||
| ); | ||
| .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); | ||
| } | ||
|
|
||
| return http.build(); | ||
| } | ||
|
|
||
| @Bean | ||
| @Order(2) | ||
| public SecurityFilterChain apiFilterChain(HttpSecurity http) throws Exception { | ||
| http | ||
| .authorizeHttpRequests(auth -> auth | ||
| .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() | ||
| .requestMatchers(PermitAllPatterns).permitAll() | ||
| .requestMatchers(HttpMethod.GET, GetPermitPatterns).permitAll() | ||
| .anyRequest().authenticated() | ||
| ); | ||
| .securityMatcher("/api/**") | ||
| .csrf(AbstractHttpConfigurer::disable) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CSRF protection is explicitly disabled for the API ( |
||
| .httpBasic(AbstractHttpConfigurer::disable) | ||
| .formLogin(AbstractHttpConfigurer::disable) | ||
| .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
| .cors(c -> c.configurationSource(corsConfigurationSource())); | ||
|
|
||
| http.authorizeHttpRequests(auth -> auth | ||
| .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() | ||
| .requestMatchers(HttpMethod.GET, GetPermitPatterns).permitAll() | ||
| .requestMatchers(PermitAllPatterns).permitAll() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| .anyRequest().authenticated() | ||
| ); | ||
|
|
||
| http.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); | ||
|
|
||
|
|
@@ -136,4 +148,4 @@ public CorsConfigurationSource corsConfigurationSource() { | |
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
loginWithGooglemethod decodes thestateparameter and uses it as a redirect URL. The validation performed byvalidateRedirectUrlusesstartsWith, which can be bypassed (e.g.,http://localhost:3000.evil.comstarts withhttp://localhost:3000). This allows an attacker to redirect users to a malicious site after a successful login.