sanic
sanic copied to clipboard
delete cookie doesn't support specifying the path.
Describe the bug
Unable to delete a cookie set created with a non-default (/
) path.
Code snippet
With this cookie
response.cookie['token'] = "abcd" response.cookie['token']["path"] = "/api"
the subsequent delete of the cookie doesn't work
del response.cookie['token']
as it sends Set-Cookie: token=""; Path=/; Max-Age=0
where the original cookie was scoped to /api
.
Expected behavior A method to delete the cookie and specify the path for the set-cookie header.
Environment (please complete the following information):
- OS: Linux, Python 3.9
- Version: 20.12.1
Looking into this further... it looks like this is the right way, you do the delete, then set the attributes... since the delete creates the empty/max-age token cookie entry.
def logout(request):
response = empty()
del response.cookies["token"]
response.cookies["token"]["samesite"] = "None"
response.cookies["token"]["httponly"] = True
response.cookies["token"]["secure"] = True
response.cookies["token"]["path"] = "/api"
return response
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.
...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.