Query about accessing HttpOnly Cookie & Secure cookie

折月煮酒 提交于 2019-12-01 10:41:09

问题


I am working on RESTful SPA app using angularJS. Currently initial REST call is setting a "token" cookie on xyz.com ( secured response cookie) after successful user login. I am not able to read this cookie in Javascript/angular as I am working on localhost.

What I understood here , unless I run this app from xyz.com , i wont be able to access this cookie OR do I need a secured connection ?

Is my Understanding correct ?

Secondly, my understanding about "httponly" cookie is that , it wont be accessible from javascript even though you are on same host.

Please correct my understanding.


回答1:


As the author of a website:

  • You cannot read a cookie for a different site (ever)
  • You cannot read an HTTP Only cookie with JavaScript
  • You cannot read a Secure cookie unless it is served over HTTPS

That's three separate conditions, with independent effects, and none, some or all of them can apply to any given cookie.

Therefore if a cookie is secure and for a different site then you can't read it no matter if you use HTTPS or not (since different site blocks you even if secure does not).



来源:https://stackoverflow.com/questions/21143875/query-about-accessing-httponly-cookie-secure-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!