Skip to content

Commit 1c1708f

Browse files
committed
Use secure cookies by default only if served over HTTPS
1 parent fdfd494 commit 1c1708f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

api/app/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def project_overrides(request: Request) -> HttpResponse:
6060
}
6161
is_secure_request = request.is_secure()
6262
override_data["useSecureCookies"] = is_secure_request or settings.USE_SECURE_COOKIES
63-
if settings.COOKIE_SAME_SITE is not None:
63+
if settings.COOKIE_SAME_SITE:
6464
same_site = settings.COOKIE_SAME_SITE
6565
elif is_secure_request:
6666
same_site = "None"

api/custom_auth/jwt_cookie/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
def authorise_response(user: FFAdminUser, response: Response, secure=False) -> Response: # type: ignore[no-untyped-def]
1010
sliding_token = SlidingToken.for_user(user)
11+
same_site = "None" if secure else "Lax"
1112
response.set_cookie(
1213
JWT_SLIDING_COOKIE_KEY,
1314
str(sliding_token),
1415
httponly=True,
1516
secure=secure,
16-
samesite=settings.COOKIE_SAME_SITE, # type: ignore[arg-type]
17+
samesite=settings.COOKIE_SAME_SITE or same_site, # type: ignore[arg-type]
1718
)
1819
return response

docs/docs/deployment/hosting/locally-frontend.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ Current variables used between 'frontend/environment.js' and 'frontend/common/pr
9595
- `SENTRY_API_KEY`: Sentry key for error reporting.
9696
- `ALBACROSS_CLIENT_ID`: Albacross client ID key for behaviour tracking.
9797
- `BASE_URL`: Used for specifying a base url path that's ignored during routing if serving from a subdirectory.
98-
- `USE_SECURE_COOKIES`: Enable / disable the use of secure cookies. If deploying the FE in a private network without a
99-
domain / SSL cert, disable secure cookies to ensure that session token is persisted. Default: true.
100-
- `COOKIE_SAME_SITE`: Define the value of the samesite attribute for the session token cookie set by the frontend.
101-
Further reading on this value is available [here](https://web.dev/articles/samesite-cookies-explained). Default:
102-
'none'.
98+
- `USE_SECURE_COOKIES`: If set to `true`, forces the use of secure (i.e. HTTPS-only) session cookies.
99+
- `COOKIE_SAME_SITE`: The
100+
[SameSite attribute](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value)
101+
value to use for the Flagsmith session cookie. Defaults to `None` if authenticating via HTTPS, or `Lax` otherwise.
103102

104103
### GitHub Integration Environment Variables
105104

0 commit comments

Comments
 (0)