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
Improve cookie SameSite/secure handling #700
Conversation
Will need to write tests for this. |
Tagging @Lucas-C (because of #639), @Konzertheld (because of #558) in case any proxy configurations I haven't thought about ruin the day. I also hadn't thought too much about what happens when people host isso under a subfolder, e.g. |
Added tests
Note to self: Still need to set |
53ee943
to
e721c6c
Compare
The PR code & tests look good to me. Good job! However I am a bit worried about "hardcoding" While I agree that this should be the default behaviour, |
I've added a config option as suggested by @Lucas-C and @stefangehn and updated tests. |
Add new "samesite" option in [server] section to configure SameSite header for cookies. As a fallback, use local.host to detect URL scheme and set SameSite to "None" (https) or "Lax" (http) accordingly. Set `Secure` attribute in response header so that cookies will only be sent when requesting content from `https://` URLs. Fixes: ``` Cookie “isso-[id]” will be soon rejected because it has the “SameSite” attribute set to “None” ``` See: https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite and https://werkzeug.palletsprojects.com/en/1.0.x/http/#werkzeug.http.dump_cookie
Ensure that: > Set `Secure` attribute in response header so that cookies > will only be sent when requesting content from `https://` > URLs. And also: > Respect samesite conf item in [server] section. > As a fallback, use local.host to detect URL scheme and set > SameSite to "None" (https) or "Lax" (http) accordingly.
@Lucas-C @blatinier rebased, anything else you'd like to see changed or prevents you from merging? |
Sweet, thanks! |
Add new
samesite
option in[server]
section to configureSameSite
header for cookies.As a fallback, use
local.host
to detect URL scheme and setSameSite
toNone
(https) orLax
(http) accordingly.Set
Secure
attribute in response header so that cookies will only be sent when requesting content fromhttps://
URLs.
Fixes:
(werkzeug sets
SameSite
toNone
by default anyway)NOTE: This change might break quite a few local test setups!
Discussion: #682
See: https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite
and https://werkzeug.palletsprojects.com/en/1.0.x/http/#werkzeug.http.dump_cookie
Sidenote:
isso_host_script
should somehow be unified instead of duplicated in every function.local.host
is only available per-request though, so there cannot be a class variable such asself.isso_host_script
.