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

SameSite cookie not being set Tornado #3

Closed
i-oden opened this issue Sep 17, 2019 · 0 comments
Closed

SameSite cookie not being set Tornado #3

i-oden opened this issue Sep 17, 2019 · 0 comments

Comments

@i-oden
Copy link

i-oden commented Sep 17, 2019

Hey,

I'm using Tornado 6.0.3 and apparently I have to use a patch (Morsel._reserved['samesite'] = 'SameSite') but the samesite cookies are not being set. Not sure I've understood how to use secure in my code but this is what I've done.

from http.cookies import Morsel
from secure import SecureHeaders
from secure import SecureCookie

Morsel._reserved['samesite'] = 'SameSite'
SECURE_HEADERS = SecureHeaders()
SECURE_COOKIE = SecureCookie(expires=1, samesite=SecureCookie.SameSite.LAX)

class BaseHandler(tornado.web.RequestHandler):
    """Main class used for general functions applying to entire application. """

    def set_default_headers(self):
        """docstring"""
        SECURE_HEADERS.tornado(self)

    def set_samesite_cookie(self, cookie_name, cookie_value):
        """Sets a samesite cookie"""

        SECURE_COOKIE.tornado(self, name=cookie_name, value=cookie_value)

and then I have used this in another class:

self.set_samesite_cookie("user", user_id)

Any suggestions to why it's not working is appreciated!
Thank you!

@i-oden i-oden closed this as completed Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant