From 3a4620da8af82b727e2fd91756318c5aa3cf9910 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Fri, 15 Nov 2024 13:13:15 +0530 Subject: [PATCH] chore: Require form data for login endpoint --- .../server/configurations/SecurityConfig.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java index 4621f364e233..2c7bd27e2cb4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java @@ -28,6 +28,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; +import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; @@ -42,6 +43,7 @@ import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler; import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler; import org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher; +import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; @@ -228,8 +230,16 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { .authenticationFailureHandler(failureHandler) .loginPage(Url.LOGIN_URL) .authenticationEntryPoint(authenticationEntryPoint) - .requiresAuthenticationMatcher( - ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, Url.LOGIN_URL)) + .requiresAuthenticationMatcher(exchange -> { + final ServerHttpRequest request = exchange.getRequest(); + return HttpMethod.POST.equals(request.getMethod()) + && Url.LOGIN_URL.equals( + request.getPath().toString()) + && MediaType.APPLICATION_FORM_URLENCODED.equalsTypeAndSubtype( + request.getHeaders().getContentType()) + ? ServerWebExchangeMatcher.MatchResult.match() + : ServerWebExchangeMatcher.MatchResult.notMatch(); + }) .authenticationSuccessHandler(authenticationSuccessHandler) .authenticationFailureHandler(authenticationFailureHandler)) // For Github SSO Login, check transformation class: CustomOAuth2UserServiceImpl