sanic icon indicating copy to clipboard operation
sanic copied to clipboard

delete cookie doesn't support specifying the path.

Open ruckc opened this issue 3 years ago • 5 comments

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

ruckc avatar Feb 01 '21 16:02 ruckc

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

ruckc avatar Feb 05 '21 01:02 ruckc

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.

stale[bot] avatar Jun 04 '21 15:06 stale[bot]

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.

stale[bot] avatar Mar 02 '22 08:03 stale[bot]

...

ahopkins avatar Mar 02 '22 09:03 ahopkins

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.

stale[bot] avatar Jun 12 '22 21:06 stale[bot]