Skip to content

Conversation

@ffalqui
Copy link
Collaborator

@ffalqui ffalqui commented Jan 23, 2026

No description provided.

- fix mail plugin ssl protocol;
- add basicAuth for /api/* when keycloak.enabled false
- add basicAuth in swagger config when keycloak.enabled false
- update keycloak dockercompose
@ffalqui ffalqui requested a review from MEM2677 January 23, 2026 11:05
Comment on lines +100 to +104
http.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.ALWAYS))
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
.addFilterBefore(basicAuthFilter, BasicAuthenticationFilter.class)
.anonymous(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable) //NOSONAR

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.

Copilot Autofix

AI 2 days ago

In general, the fix is to stop globally disabling CSRF and to configure CSRF protection in a way that is compatible with the existing API usage. For APIs that are called from browsers with session/cookie-based authentication, CSRF should remain enabled, with appropriate mechanisms for obtaining and sending the CSRF token (e.g., using CookieCsrfTokenRepository). For specific endpoints that must be exempt (such as read‑only APIs or non‑browser callback endpoints), those paths can be explicitly ignored by CSRF rather than disabling it entirely.

The best fix here, without changing the existing authorization behavior, is to replace .csrf(AbstractHttpConfigurer::disable) with a CSRF configuration that (a) keeps CSRF protection enabled by default, and (b) uses a cookie-based CSRF token repository suitable for browser clients. A common pattern is:

.csrf(csrf -> csrf
    .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
)

This preserves current URL access rules and filters while re‑enabling CSRF. We will make this same change in both the Keycloak‑enabled and Keycloak‑disabled branches, touching only the .csrf(...) lines and adding the necessary import for CookieCsrfTokenRepository. Concretely:

  • In KeycloakSecurityConfig.keycloakSecurityFilterChain, in the Keycloak‑enabled branch (around line 79), replace .csrf(AbstractHttpConfigurer::disable) with a lambda configuring CookieCsrfTokenRepository.
  • In the Keycloak‑disabled (BasicAuth) branch (around line 104), do the same.
  • Add an import for org.springframework.security.web.csrf.CookieCsrfTokenRepository; at the top of the file.
Suggested changeset 1
keycloak-plugin/src/main/java/org/entando/entando/aps/servlet/security/KeycloakSecurityConfig.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/keycloak-plugin/src/main/java/org/entando/entando/aps/servlet/security/KeycloakSecurityConfig.java b/keycloak-plugin/src/main/java/org/entando/entando/aps/servlet/security/KeycloakSecurityConfig.java
--- a/keycloak-plugin/src/main/java/org/entando/entando/aps/servlet/security/KeycloakSecurityConfig.java
+++ b/keycloak-plugin/src/main/java/org/entando/entando/aps/servlet/security/KeycloakSecurityConfig.java
@@ -16,6 +16,7 @@
 import org.springframework.security.config.http.SessionCreationPolicy;
 import org.springframework.security.web.SecurityFilterChain;
 import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
+import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
 import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
 
 @Order(70)
@@ -76,7 +77,7 @@
                     .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
                     .addFilterBefore(keycloakAuthenticationFilter, BasicAuthenticationFilter.class)
                     .anonymous(AbstractHttpConfigurer::disable)
-                    .csrf(AbstractHttpConfigurer::disable) //NOSONAR
+                    .csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
                     .cors(cors -> cors.configurationSource(corsConfigurationSource()));
             return http.build();
         } else {
@@ -101,7 +102,7 @@
                     .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
                     .addFilterBefore(basicAuthFilter, BasicAuthenticationFilter.class)
                     .anonymous(AbstractHttpConfigurer::disable)
-                    .csrf(AbstractHttpConfigurer::disable) //NOSONAR
+                    .csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
                     .cors(cors -> cors.configurationSource(corsConfigurationSource()));
 
             return http.build();
EOF
@@ -16,6 +16,7 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Order(70)
@@ -76,7 +77,7 @@
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
.addFilterBefore(keycloakAuthenticationFilter, BasicAuthenticationFilter.class)
.anonymous(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable) //NOSONAR
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
.cors(cors -> cors.configurationSource(corsConfigurationSource()));
return http.build();
} else {
@@ -101,7 +102,7 @@
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
.addFilterBefore(basicAuthFilter, BasicAuthenticationFilter.class)
.anonymous(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable) //NOSONAR
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
.cors(cors -> cors.configurationSource(corsConfigurationSource()));

return http.build();
Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions
Copy link

PUBLICATION for COMMIT ID ``

IMG/TAG: entando/entando-de-app-tomcat:7.5.0-ESB-917-PR323
IMG/SHA: entando/entando-de-app-tomcat@sha256:5995ca7bb44d1b1d8620d3aa4ba7383da508de7aed00c5101fe2d84d0cab2df4

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
77.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants