Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix SameSite=None cookie #4136

Merged
merged 2 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
🐛 Fix SameSite=None cookie
When passing Python's NoneType down to Werkzeug, it uses this logic:

```python
if samesite is not None:
    samesite = samesite.title()

    if samesite not in {"Strict", "Lax", "None"}:
        raise ValueError("SameSite must be 'Strict', 'Lax', or 'None'.")
```

This means that when OctoPrint converted any strings 'None' into NoneType,
they would not show up in the Set-Cookie header.

Investigation: https://community.octoprint.org/t/unable-to-log-into-octoprint-through-an-iframe-on-home-assistant/33977/20?u=charlie_powell

Link to werkzeug source: https://github.com/pallets/werkzeug/blob/1dde4b1790f9c46b7122bb8225e6b48a5b22a615/src/werkzeug/http.py#L1213-L1217

Docs, while not explicitly clear, here: https://werkzeug.palletsprojects.com/en/1.0.x/http/?highlight=dump_cookie#werkzeug.http.dump_cookie
  • Loading branch information
cp2004 committed May 12, 2021
commit 2c03ecdfff8f111fd2f9d9db1bdb6a8d01fdfe84
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