Skip to content

Commit

Permalink
Merge pull request #4136 from cp2004/fix/samesite-none
Browse files Browse the repository at this point in the history
🐛 Fix SameSite=None cookie
  • Loading branch information
foosel authored May 18, 2021
2 parents f284585 + d83d4b1 commit c838436
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/configuration/config_yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,9 @@ Use the following settings to configure the server:
# 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.
# SameSite setting to use on the cookies. Possible values are None, Lax and Strict. Defaults to not set but
# be advised that many browsers now default to Lax unless set as Secure, explicitly setting the cookie type
# here and served over https, which causes issues with embedding OctoPrint in frames.
#
# See also https://www.chromestatus.com/feature/5088147346030592,
# https://www.chromestatus.com/feature/5633521622188032 and issue #3482
Expand Down
6 changes: 4 additions & 2 deletions src/octoprint/server/util/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,10 @@ def set_cookie(self, key, *args, **kwargs):
if samesite is not None:
samesite = samesite.lower()
if samesite == "none":
samesite = None
if samesite not in (None, "strict", "lax"):
# Must be string "None"
samesite = "None"
if samesite not in ("None", "strict", "lax"):
# If NoneType, the cookie is not set
samesite = None
kwargs["samesite"] = samesite

Expand Down
2 changes: 1 addition & 1 deletion tests/server/util/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def tearDown(self):

@data(
[None, None, False, None, None],
[None, None, False, "none", None],
[None, None, False, "none", "None"],
[None, None, False, "lax", "lax"],
[None, None, False, "StRiCt", "strict"],
[None, None, False, "INVALID", None],
Expand Down

0 comments on commit c838436

Please sign in to comment.