✨ config flag to configure SameSite and Secure cookie headers

Provides one part of the solution to #3482. The other part is sadly
on the shoulders of the user, who needs to setup either a whole domain
hierarchy to not run into "third party page" issues that would trigger
SameSite=Lax blocking, or needs to reconfigure their setup to use
https and make sure to set Secure to true.

Closes #3482 (there's nothing else I can do here)
This commit is contained in:
Gina Häußge committed 2020-04-15 13:27:56 +02:00
1 parent 2bed65d819
commit 00a5243ec9
3 files changed
+53 -2

No files matched your search

+12
View File
@@ -505,6 +505,18 @@ class OctoPrintFlaskResponse(flask.Response):
# restrict cookie path to script root
kwargs["path"] = flask.request.script_root + kwargs.get("path", "/")
# set same-site header
samesite = settings().get(["server", "cookies", "samesite"])
if samesite is not None:
samesite = samesite.lower()
if samesite == "none":
samesite = None
if samesite in (None, "strict", "lax"):
kwargs["samesite"] = samesite
# set secure if necessary
kwargs["secure"] = settings().getBoolean(["server", "cookies", "secure"])
# add request specific cookie suffix to name
flask.Response.set_cookie(self, key + flask.request.cookie_suffix, *args, **kwargs)
+7 -2
View File
@@ -223,7 +223,11 @@ default_settings = {
"enabled": True,
"trustedSubnets": []
},
"allowFraming": False
"allowFraming": False,
"cookies": {
"secure": False,
"samesite": None
},
},
"webcam": {
"webcamEnabled": True,
@@ -410,7 +414,8 @@ default_settings = {
},
"webassets": {
"bundle": True,
"clean_on_startup": True
"clean_on_startup": True,
"minify": True
},
"useFrozenDictForPrinterState": True,
"showLoadingAnimation": True,