Replies: 2 comments
-
|
Use the app.config["SESSION_COOKIE_SAMESITE"] = 'None' |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
The order is intended. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, there. I've got some interesting situation. I have cross site request from browser to python flask that establishes flask session and therefore flask sets cookie header "Set-Cookie" with encrypted session key.
However, assuming the request is cross site, the browser refuses to store this cookie and send it afterwards within the next requests.
So, I need to patch this cookie with SameSite='None' property on flask side just before sending it to the client.
AFAIU the last resort to do this - flask @app.after_request hook where I potentially could change the response. But, analyzing the source code of flask I noticed that set cookie by flask framework is happening later than @app.after_request is being triggered.
`for func in ctx._after_request_functions:
response = self.ensure_sync(func)(response)
In the snippet above, the save session is placed in the end, as calling 'after_request' functions do not have session cookie yet.
So, my question to community - is it a bug or everything works as planned? Could we potentially change the calling order in flask for such cases?
P.S. I have a solution for now - I did it on my NGINX server proxy, however it's some kind of workaround rather that the solution.
I know it's possible to set SameSite cookie property on all flask app level for all requests, but It's strongly needed for particular request(s).
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions