How to set SameSite attribute?
It turns out that using setHeader()
method remove all previous headers with the same name so I just create simple for loop in doFilter()
method. It adds SameSite=Strict
attribute to every cookie that is set.
boolean firstHeader = true;
for (String header : cookiesHeaders) {
if (firstHeader) {
httpResponse.setHeader("Set-Cookie",
String.format("%s; %s", header, "SameSite=Strict"));
firstHeader = false;
continue;
}
httpResponse.addHeader("Set-Cookie",
String.format("%s; %s", header, "SameSite=Strict"));
}