Contents
1 Answer. Yes, javascript can delete a cookie set by HTTP headers unless it is specifically a HTTPOnly cookie. The cookie must also be from the same domain as the javascript.
Delete specific cookies
- On your computer, open Chrome.
- At the top right, click More. Settings.
- Under “Privacy and security,” click Cookies and other site data.
- Click See all cookies and site data.
- At the top right, search for the website’s name.
- To the right of the site, click Remove .
How do I clear cookies on my server?
Using an Expires attribute in the past to delete a cookie is correct and is the way to remove cookies dictated by the spec. The examples section of RFC 6255 states: Finally, to remove a cookie, the server returns a Set-Cookie header with an expiration date in the past.
How to delete cookie or set HttpOnly and?
Have the server invalidate the authentication token (cookie) but setting it to some junk value. For example, Set-Cookie: token=loggedout. Deleting a cookie may be a client side action, but setting a cookie can be done on the server side and you can still maintain HTTPOnly and Secure (which, as 8zero2.ops pointed out, is unrelated to this issue).
In order to delete a cookie from JS, therefore, you need to ensure that you are addressing the correct cookie by both name and flag values, and that it doesn’t have HTTPOnly flag set, and that you’re on a page with a HTTPS certificate. If any of these are not true, you won’t be able to edit/delete it.
I can’t find any (security related) reasons for choosing to delete a cookie over setting Secure and HttpOnly. Secure flag has nothing to do with javascript involvement . It only enables or disable the transmission of cookies over insecure plain-text in case the server entertain http and https requests.
How to use HTTP-only Cookies with CherryPy sessions?
Python Code (cherryPy): To use HTTP-Only cookies with Cherrypy sessions just add the following line in your configuration file: tools.sessions.httponly = True If you use SLL you can also make your cookies secure (encrypted) to avoid “manipulator-in-the-middle” cookies reading with: tools.sessions.secure = True