How do I delete a cookie from a specific domain using Javascript?

前端 未结 3 941
天涯浪人
天涯浪人 2020-12-30 06:31

Let\'s say I am at http://www.example.com and I want to delete a cookie whose domain is .example.com and another one whose domain is www.example.com

3条回答
  •  我在风中等你
    2020-12-30 07:28

    For security, you're not allowed to edit (or delete) a cookie on another site. Since there's no guarantee that you own both foo.domain.com and bar.domain.com, you won't be allowed to edit the cookies of foo.domain.com from bar.domain.com and vice versa.

    Consider if you were allowed to do that and went to a malicious site, then back to your bank where you were about to deposit a cheque into your bank account. But while being on the malicious site, they updated your bank cookie with their own bank information. Now, suddenly, the cheque would be deposited into the malicious site's owner's bank account.

提交回复
热议问题