🐛 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
This commit is contained in:
1 parent
0ad9690abd
commit
2c03ecdfff
2 files changed
+5
-3
No files matched your search
@@ -567,8 +567,10 @@ class OctoPrintFlaskResponse(flask.Response):
|
||||
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
|
||||
|
||||
|
||||
@@ -503,7 +503,7 @@ class OctoPrintFlaskResponseTest(unittest.TestCase):
|
||||
|
||||
@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],
|
||||
|
||||
Reference in new issue
Block a user