From b4be78796e4372d6fef0ee0e3880da1b8911faae Mon Sep 17 00:00:00 2001 From: stianst Date: Tue, 30 Jan 2024 08:36:10 +0100 Subject: [PATCH] RestEasy Reactive sends SameSite cookie param with wrong case Closes #38465 (cherry picked from commit a280efc4500826071c6d45f6f0cb647bb0794948) --- .../common/headers/NewCookieHeaderDelegate.java | 15 ++++++++++++++- .../server/vertx/test/headers/CookiesTest.java | 6 +++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/NewCookieHeaderDelegate.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/NewCookieHeaderDelegate.java index 77bff616144ab..686170816ac23 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/NewCookieHeaderDelegate.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/NewCookieHeaderDelegate.java @@ -140,8 +140,21 @@ public String toString(Object value) { b.append(";HttpOnly"); if (cookie.getSameSite() != null) { b.append(";SameSite="); - b.append(cookie.getSameSite()); + appendCorrectCase(b, cookie.getSameSite()); } return b.toString(); } + + private static void appendCorrectCase(final StringBuilder sb, final Enum e) { + boolean first = true; + for (char c : e.name().toCharArray()) { + if (first) { + sb.append(c); + first = false; + } else { + sb.append(Character.toLowerCase(c)); + } + } + } + } diff --git a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/headers/CookiesTest.java b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/headers/CookiesTest.java index 3c6376fdc7713..0ed68ba267bbb 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/headers/CookiesTest.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/headers/CookiesTest.java @@ -108,7 +108,7 @@ void testSameSite() { .formParam("cookie", "greeting=\"hello\";SameSite=\"Lax\";") .post("/cookies/set-cookie") .then() - .cookie("greeting", detailedCookie().value("hello").sameSite("LAX")); + .cookie("greeting", detailedCookie().value("hello").sameSite("Lax")); } @Test @@ -119,7 +119,7 @@ void testSameSiteWithoutColon() { .formParam("cookie", "greeting=\"hello\";SameSite=\"None\"") .post("/cookies/set-cookie") .then() - .cookie("greeting", detailedCookie().value("hello").sameSite("NONE")); + .cookie("greeting", detailedCookie().value("hello").sameSite("None")); } @Test @@ -130,7 +130,7 @@ void testSameSiteLowercase() { .formParam("cookie", "greeting=\"hello\";samesite=\"Strict\"") .post("/cookies/set-cookie") .then() - .cookie("greeting", detailedCookie().value("hello").sameSite("STRICT")); + .cookie("greeting", detailedCookie().value("hello").sameSite("Strict")); } @Test