2121package eu .openanalytics .containerproxy ;
2222
2323import com .fasterxml .jackson .datatype .jsr353 .JSR353Module ;
24- import eu .openanalytics .containerproxy .service .AppRecoveryService ;
2524import eu .openanalytics .containerproxy .util .ProxyMappingManager ;
2625import io .undertow .Handlers ;
26+ import io .undertow .server .handlers .SameSiteCookieHandler ;
2727import io .undertow .servlet .api .ServletSessionConfig ;
2828import io .undertow .servlet .api .SessionManagerFactory ;
2929import 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 }
@@ -118,15 +118,18 @@ public UndertowServletWebServerFactory servletContainer() {
118118 UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory ();
119119 factory .addDeploymentInfoCustomizers (info -> {
120120 info .setPreservePathOnForward (false ); // required for the /api/route/{id}/ endpoint to work properly
121- if (Boolean .valueOf (environment .getProperty ("logging.requestdump" , "false" ))) {
122- info .addOuterHandlerChainWrapper (defaultHandler -> Handlers . requestDump ( defaultHandler ) );
121+ if (Boolean .parseBoolean (environment .getProperty ("logging.requestdump" , "false" ))) {
122+ info .addOuterHandlerChainWrapper (Handlers :: requestDump );
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 );
129- sessionConfig .setSecure (Boolean .valueOf (environment .getProperty ("server.secureCookies " , "false" )));
132+ sessionConfig .setSecure (Boolean .parseBoolean (environment .getProperty ("server.secure-cookies " , "false" )));
130133 info .setServletSessionConfig (sessionConfig );
131134 if (sessionManagerFactory != null ) {
132135 info .setSessionManagerFactory (sessionManagerFactory );
0 commit comments