Skip to content

Commit 7c11745

Browse files
NFC-47 Configure session cookie with Secure, HttpOnly, and SameSite=Lax for mobile auth flow
1 parent 1a9d45a commit 7c11745

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

example/src/main/java/eu/webeid/example/config/SameSiteCookieConfiguration.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,27 @@
2424

2525
import org.apache.tomcat.util.http.Rfc6265CookieProcessor;
2626
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
27+
import org.springframework.boot.web.servlet.ServletContextInitializer;
2728
import org.springframework.context.annotation.Bean;
2829
import org.springframework.context.annotation.Configuration;
29-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
3030

3131
@Configuration
32-
public class SameSiteCookieConfiguration implements WebMvcConfigurer {
32+
public class SameSiteCookieConfiguration {
3333

3434
@Bean
35-
public TomcatContextCustomizer configureSameSiteCookies() {
35+
public TomcatContextCustomizer sameSiteCustomizer() {
3636
return context -> {
37-
final Rfc6265CookieProcessor cookieProcessor = new Rfc6265CookieProcessor();
37+
Rfc6265CookieProcessor cookieProcessor = new Rfc6265CookieProcessor();
3838
cookieProcessor.setSameSiteCookies("lax");
3939
context.setCookieProcessor(cookieProcessor);
4040
};
4141
}
42+
43+
@Bean
44+
public ServletContextInitializer cookieFlagsInitializer() {
45+
return servletContext -> {
46+
servletContext.getSessionCookieConfig().setSecure(true);
47+
servletContext.getSessionCookieConfig().setHttpOnly(true);
48+
};
49+
}
4250
}

0 commit comments

Comments
 (0)