Skip to content

Commit

Permalink
πŸ› Fix SameSite cookie property. (#793)
Browse files Browse the repository at this point in the history
* Fix `SameSite` cookie property.

* Fix samesite value.

* Add secure=True for samesite=None

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: Raruto <[email protected]>
  • Loading branch information
3 people authored Apr 30, 2024
1 parent 4b50d5f commit d9d8bde
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion g3w-admin/client/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ def render_to_response(self, context, **response_kwargs):

# Add G3W_CLIENT_COOKIE_SESSION_TOKEN cookie to response
response = super().render_to_response(context)
response.set_cookie(settings.G3W_CLIENT_COOKIE_SESSION_TOKEN, secrets.token_hex(16))

# Only with https set samesite='None' for cross-site requests, i.e. for cross-site iframe
kwargs = {'samesite': 'None', 'secure': True} if self.request.is_secure() else {'samesite': 'Strict'}
response.set_cookie(settings.G3W_CLIENT_COOKIE_SESSION_TOKEN, secrets.token_hex(16), **kwargs)

return response

Expand Down

0 comments on commit d9d8bde

Please sign in to comment.