Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ server {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ftm.server.infrastructure.session;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.web.http.CookieSerializer;

@Configuration
public class CookieSerializerConfig {

@Bean
public CookieSerializer cookieSerializer() {
return new ProtocolAwareCookieSerializer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ftm.server.infrastructure.session;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.session.web.http.DefaultCookieSerializer;

public class ProtocolAwareCookieSerializer extends DefaultCookieSerializer {

@Override
public void writeCookieValue(CookieValue cookieValue) {
HttpServletRequest request = cookieValue.getRequest();
String proto = request.getHeader("X-Forwarded-Proto");

boolean isHttps = request.isSecure() || "https".equalsIgnoreCase(proto);

// HTTPS -> Secure O + SameSite=None
// HTTP -> Secure X + SameSite null
setUseSecureCookie(isHttps);
setSameSite(isHttps ? "None" : null);

super.writeCookieValue(cookieValue);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ spring:

jpa:
hibernate:
ddl-auto: none
ddl-auto: none

server:
forward-headers-strategy: native
Loading