Skip to content

Commit

Permalink
Conditionally set authentication cookie sameSite for training instanc…
Browse files Browse the repository at this point in the history
…es (#19356)

* Conditionally set authentication cookie sameSite value based on config values
  • Loading branch information
kingzacko1 committed May 17, 2024
1 parent 0b664a6 commit 030114c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class HttpConfiguration {
@Parameter(value = "http_allow_embedding")
private boolean httpAllowEmbedding = false;

@Parameter(value = "http_cookie_secure_override")
private boolean httpCookieSecureOverride = false;

@Parameter(value = "http_cookie_same_site_strict")
private boolean httpCookieSameSiteStrict = true;

public HostAndPort getHttpBindAddress() {
return httpBindAddress
.requireBracketsForIPv6()
Expand Down Expand Up @@ -214,6 +220,14 @@ public String getHttpTlsKeyPassword() {
return httpTlsKeyPassword;
}

public boolean getHttpCookieSameSiteStrict() {
return httpCookieSameSiteStrict;
}

public boolean getHttpCookieSecureOverride() {
return httpCookieSecureOverride;
}

public URI getHttpExternalUri() {
return httpExternalUri == null ? getHttpPublishUri() : httpExternalUri;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ public class CookieFactory {
private static final String HEADER_X_FORWARDED_PROTO = "X-Forwarded-Proto";
private static final CharMatcher PATH_MATCHER = ascii().and(isNot(';')).and(javaIsoControl().negate());
private final URI httpExternalUri;
private final boolean httpCookieSecureOverride;
private final boolean httpCookieSameSiteStrict;

@Inject
public CookieFactory(HttpConfiguration httpConfiguration) {
httpExternalUri = httpConfiguration.getHttpExternalUri();
httpCookieSecureOverride = httpConfiguration.getHttpCookieSecureOverride();
httpCookieSameSiteStrict = httpConfiguration.getHttpCookieSameSiteStrict();
}

NewCookie createAuthenticationCookie(SessionResponse token, ContainerRequestContext requestContext) {
Expand All @@ -70,9 +74,9 @@ private NewCookie makeCookie(String value, Date validUntil, ContainerRequestCont
.path(basePath)
.maxAge(maxAge)
.expiry(validUntil)
.secure(isSecure)
.secure(isSecure || httpCookieSecureOverride)
.httpOnly(true)
.sameSite(NewCookie.SameSite.STRICT)
.sameSite(httpCookieSameSiteStrict ? NewCookie.SameSite.STRICT : NewCookie.SameSite.NONE)
.build();
}

Expand Down

0 comments on commit 030114c

Please sign in to comment.