Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private ResponseCookie(String name, @Nullable String value, Duration maxAge, @Nu
Rfc6265Utils.validateCookieValue(value);
Rfc6265Utils.validateDomain(domain);
Rfc6265Utils.validatePath(path);
Rfc6265Utils.validateSameSite(sameSite);
}


Expand Down Expand Up @@ -433,6 +434,18 @@ public static void validatePath(@Nullable String path) {
}
}
}

public static void validateSameSite(@Nullable String sameSite) {
if (sameSite == null) {
return;
}
for (int i = 0; i < sameSite.length(); i++) {
char c = sameSite.charAt(i);
if (c < 0x20 || c > 0x7E || c == ';') {
throw new IllegalArgumentException(sameSite + ": Invalid cookie SameSite char '" + c + "'");
}
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ void domainChecks() {
.hasMessageContaining("invalid cookie domain char"));
}

@Test
void sameSiteChecks() {

Arrays.asList("Strict", "Lax", "None")
.forEach(sameSite -> ResponseCookie.from("n", "v").sameSite(sameSite).build());

Arrays.asList("Lax\r\nSet-Cookie: x=y", "Lax\n", "La;x", "Lax\t", "Lax\u0005")
.forEach(sameSite -> assertThatThrownBy(() -> ResponseCookie.from("n", "v").sameSite(sameSite).build())
.hasMessageContaining("Invalid cookie SameSite char"));
}

@Test // gh-24663
void domainWithEmptyDoubleQuotes() {

Expand Down