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

Conversation

cp2004
Copy link
Member

@cp2004 cp2004 commented May 12, 2021

When passing Python's NoneType down to Werkzeug, it uses this logic:

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

What does this PR do and why is it necessary?

Adjusts the cookie-setting behaviour so that setting SameSite=None is possible.

How was it tested? How can it be tested by the reviewer?

Analysing the headers in the responses, to ensure this was visible.

The unit tests had to be adjusted, since they were testing the function worked as expected but not far enough into what the end result was.

Any background context you want to provide?

See links above, but also https://web.dev/samesite-cookies-explained/ which helped me to understand what I was looking for here.

What are the relevant tickets if any?

See forum link

Screenshots (if appropriate)

None

Further notes

I think I got this one right, but it needs a good look to double check that my logic is OK. I was never able to get the SameSite=None to show up in Set-Cookie without this change, now it should work OK.

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
@cp2004 cp2004 changed the title 🐛 Fix SameSite=None cookie 🐛 Fix SameSite=None cookie May 12, 2021
@github-actions github-actions bot added tests approved Issue has been approved by the bot or manually for further processing labels May 12, 2021
@github-actions github-actions bot added the docs Related to documentation label May 12, 2021
@foosel foosel added this to the 1.7.0 milestone May 18, 2021
@foosel foosel merged commit c838436 into OctoPrint:maintenance May 18, 2021
@foosel
Copy link
Member

foosel commented May 18, 2021

I was dead sure I had tested this, but apparently either I hadn't, or something changed somewhere. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Issue has been approved by the bot or manually for further processing docs Related to documentation tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants