✨ 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

+34
View File
@@ -1025,6 +1025,25 @@ Use the following settings to configure the server:
- 192.168.1.254
- 192.168.23.42
# Whether to allow OctoPrint to be embedded in a frame or not. Note that depending on your setup you might
# have to set SameSite to None, Secure to true and serve OctoPrint through a reverse proxy that enables https
# for cookies and thus logging in to work
allowFraming: true
# Settings for further configuration of the cookies that OctoPrint sets (login, remember me, ...)
cookies:
# SameSite setting to use on the cookies. Possible values are None, Lax and Strict. Defaults to None but
# be advised that browsers will soon force this to Lax unless also being set as Secure and served over
# https, which will cause issues with embedding OctoPrint in frames.
#
# See also https://www.chromestatus.com/feature/5088147346030592,
# https://www.chromestatus.com/feature/5633521622188032 and issue #3482
samesite: lax
# Whether to set the Secure flag to true on cookies. Defaults to false. Only set to true if you are running
# OctoPrint behind a reverse proxy taking care of SSL termination.
secure: false
# Settings for file uploads to OctoPrint, such as maximum allowed file size and
# header suffixes to use for streaming uploads. OctoPrint does some nifty things internally in
# order to allow streaming of large file uploads to the application rather than just storing
@@ -1129,6 +1148,21 @@ Use the following settings to configure the server:
`into OctoPrint's wiki <https://community.octoprint.org/t/reverse-proxy-configuration-examples/1107>`_ for some
examples on how to configure this.
.. note::
If you want to embed OctoPrint in a frame, you'll need to set ``allowFraming`` to ``true`` or your browser will
prevent this.
In future browser builds you will also have to make sure you frame is on the same domain as OctoPrint or that
OctoPrint is served via https through a reverse proxy and has set ``cookies.secure`` to ``true`` or your browser
will refuse to persist cookies and logging in will not work.
See also `Cookies default to SameSite=Lax <https://www.chromestatus.com/feature/5088147346030592>`_ and
`Reject insecure SameSite=None cookies <https://www.chromestatus.com/feature/5633521622188032>`_ as well as
`this ticket <https://github.com/OctoPrint/OctoPrint/issues/3482>`_,
and `this twitter thread <https://twitter.com/foosel/status/1022030752349913088>`_ on why OctoPrint cannot
solve this on its own/ship with https that doesn't cause scary warnings in your browser.
.. _sec-configuration-config_yaml-slicing:
Slicing
+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,