Skip to content

Commit c335233

Browse files
committed
Only set Partitioned cookie attribute when true
The session cookie's Partitioned attribute was set to "" for any non-null value, so an explicit `partitioned=false` was rendered the same as `true`. PropertyMapper.to() only filters null, so Boolean.FALSE reached the consumer and the attribute was always set. Use whenTrue() so the attribute is set only when partitioned is true, leaving false and unset to fall through to the container default. Signed-off-by: Lee JiWon <dlwldnjs1009@gmail.com>
1 parent 262437f commit c335233

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/ServletContextInitializers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void configureSessionCookie(SessionCookieConfig config) {
9797
map.from(cookie::getHttpOnly).to(config::setHttpOnly);
9898
map.from(cookie::getSecure).to(config::setSecure);
9999
map.from(cookie::getMaxAge).asInt(Duration::getSeconds).to(config::setMaxAge);
100-
map.from(cookie::getPartitioned).to((partitioned) -> config.setAttribute("Partitioned", ""));
100+
map.from(cookie::getPartitioned).whenTrue().to((partitioned) -> config.setAttribute("Partitioned", ""));
101101
}
102102

103103
@Contract("!null -> !null")

module/spring-boot-web-server/src/testFixtures/java/org/springframework/boot/web/server/servlet/AbstractServletWebServerFactoryTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,20 @@ void sessionCookiePartitionedAttribute() throws Exception {
899899
(header) -> assertThat(header).isEqualTo("test=test"));
900900
}
901901

902+
@Test
903+
void sessionCookieNotPartitionedAttribute() throws Exception {
904+
ConfigurableServletWebServerFactory factory = getFactory();
905+
factory.getSettings().getSession().getCookie().setPartitioned(false);
906+
factory.addInitializers(new ServletRegistrationBean<>(new CookieServlet(false), "/"));
907+
this.webServer = factory.getWebServer();
908+
this.webServer.start();
909+
ClientHttpResponse clientResponse = getClientResponse(getLocalUrl("/"));
910+
List<String> setCookieHeaders = clientResponse.getHeaders().get("Set-Cookie");
911+
assertThat(setCookieHeaders).satisfiesExactlyInAnyOrder(
912+
(header) -> assertThat(header).startsWith("JSESSIONID=").doesNotContain("; Partitioned"),
913+
(header) -> assertThat(header).isEqualTo("test=test"));
914+
}
915+
902916
@ParameterizedTest
903917
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = "OMITTED")
904918
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception {
@@ -1226,7 +1240,7 @@ void sessionConfiguration() {
12261240
assertThat(sessionCookieConfig.isHttpOnly()).isTrue();
12271241
assertThat(sessionCookieConfig.isSecure()).isTrue();
12281242
assertThat(sessionCookieConfig.getMaxAge()).isEqualTo(60);
1229-
assertThat(sessionCookieConfig.getAttribute("Partitioned")).isEqualTo("");
1243+
assertThat(sessionCookieConfig.getAttribute("Partitioned")).isNull();
12301244
}
12311245

12321246
@Test

0 commit comments

Comments
 (0)