简体   繁体   中英

Access cookie information in Javascript

Is there anyway to access the data associated with a cookie such as path, flags, and expiration date from javascript? All I've been able to find for cookie access is document.cookie , which only provides a list of name value pairs. Why is the interface for cookie access so limited?

No, there is none, in terms of safe, cross-browser support. Reasoning comes down to security.

The goal of cookies was to allow for communication back and forth from the browser to the server.
If you could allow any front-end script to manually edit the domain / path / expiration of a cookie, just for knowing its name, it would lead to a lot of potential security-holes, if not for spoofing access, then at least for invisibly tracking people.

That's not to say that cookies are inherently safe, or even particularly safe at all.
I mean to say that by allowing any and all JS to edit any and all cookie data sent to the server (moreso than just CRUD), any pretence of security would disappear in a heartbeat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM