Skip to content

Commit bf4ddbb

Browse files
committed
Fix #25757: ensure same-site-cookie is set in all cases
The property must be set in a different way when not using Redis and when using Redis for Session Persistence. In the first case the native method on Undertow is used, in the second case the DefaultCookieSerializer of Spring is used.
1 parent 341ce28 commit bf4ddbb

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/ContainerProxyApplication.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
package eu.openanalytics.containerproxy;
2222

2323
import com.fasterxml.jackson.datatype.jsr353.JSR353Module;
24-
import eu.openanalytics.containerproxy.service.AppRecoveryService;
2524
import eu.openanalytics.containerproxy.util.ProxyMappingManager;
2625
import io.undertow.Handlers;
26+
import io.undertow.server.handlers.SameSiteCookieHandler;
2727
import io.undertow.servlet.api.ServletSessionConfig;
2828
import io.undertow.servlet.api.SessionManagerFactory;
2929
import org.apache.logging.log4j.LogManager;
@@ -76,8 +76,8 @@ public class ContainerProxyApplication {
7676

7777
private final Logger log = LogManager.getLogger(getClass());
7878

79-
@Inject
80-
private AppRecoveryService appRecoveryService;
79+
private static final String PROP_PROXY_SAME_SITE_COOKIE = "proxy.same-site-cookie";
80+
private static final String SAME_SITE_COOKIE_DEFAULT_VALUE = "Lax";
8181

8282
public static void main(String[] args) {
8383
SpringApplication app = new SpringApplication(ContainerProxyApplication.class);
@@ -105,7 +105,7 @@ public void init() {
105105
log.warn("WARNING: Using server.use-forward-headers will not work in this ShinyProxy release, you need to change your configuration to use another property. See https://shinyproxy.io/documentation/security/#forward-headers on how to change your configuration.");
106106
}
107107

108-
String sameSiteCookie = environment.getProperty("proxy.same-site-cookie", "Lax");
108+
String sameSiteCookie = environment.getProperty(PROP_PROXY_SAME_SITE_COOKIE, SAME_SITE_COOKIE_DEFAULT_VALUE);
109109
log.debug("Setting sameSiteCookie policy to {}" , sameSiteCookie);
110110
defaultCookieSerializer.setSameSite(sameSiteCookie);
111111
}
@@ -121,9 +121,12 @@ public UndertowServletWebServerFactory servletContainer() {
121121
if (Boolean.valueOf(environment.getProperty("logging.requestdump", "false"))) {
122122
info.addOuterHandlerChainWrapper(defaultHandler -> Handlers.requestDump(defaultHandler));
123123
}
124-
info.addInnerHandlerChainWrapper(defaultHandler -> {
125-
return mappingManager.createHttpHandler(defaultHandler);
126-
});
124+
info.addInnerHandlerChainWrapper(defaultHandler -> mappingManager.createHttpHandler(defaultHandler));
125+
126+
String sameSiteCookie = environment.getProperty(PROP_PROXY_SAME_SITE_COOKIE, SAME_SITE_COOKIE_DEFAULT_VALUE);
127+
log.debug("Setting sameSiteCookie policy for session cookies to {}" , sameSiteCookie);
128+
info.addOuterHandlerChainWrapper(defaultHandler -> new SameSiteCookieHandler(defaultHandler, sameSiteCookie, null, true, true, true));
129+
127130
ServletSessionConfig sessionConfig = new ServletSessionConfig();
128131
sessionConfig.setHttpOnly(true);
129132
sessionConfig.setSecure(Boolean.valueOf(environment.getProperty("server.secureCookies", "false")));

src/main/java/eu/openanalytics/containerproxy/security/WebSecurityConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.context.annotation.Bean;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.core.env.Environment;
31-
import org.springframework.http.HttpStatus;
3231
import org.springframework.security.access.AccessDeniedException;
3332
import org.springframework.security.authentication.AuthenticationEventPublisher;
3433
import org.springframework.security.authentication.AuthenticationManager;
@@ -42,7 +41,6 @@
4241
import org.springframework.security.web.access.AccessDeniedHandler;
4342
import org.springframework.security.web.access.AccessDeniedHandlerImpl;
4443
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
45-
import org.springframework.security.web.csrf.InvalidCsrfTokenException;
4644
import org.springframework.security.web.csrf.MissingCsrfTokenException;
4745
import org.springframework.security.web.header.writers.StaticHeadersWriter;
4846
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

0 commit comments

Comments
 (0)