简体   繁体   English

我们如何使用安全标志来保护 cookie?

[英]How can we secure cookie by using secure flag?

I am storing token in cookie and want to secure by secure flag but when I console then secure flag is not showing.我将令牌存储在 cookie 中,并希望通过安全标志进行保护,但是当我控制台时,安全标志没有显示。

function setCookie(cname, cvalue) {

  document.cookie = cname + "=" + cvalue + ";" + "secure";
}

document.cookie> "token1=xxxxxxxxxxxxx; token2=yyyyyyyyy; " document.cookie>“token1=xxxxxxxxxxxxx;token2=yyyyyyyyy;”

It'll not print Secure when you do document.cookie but this can be verified by navigating to Application tab under developer console and Cookies under Storage当您执行document.cookie时,它不会打印Secure但这可以通过导航到开发人员控制台下的应用程序选项卡和存储下的Cookies来验证

Application -> Storage -> Cookies -> (Your site)应用 -> 存储 -> Cookies ->(您的站点)

In the right side you can see all the cookies set for the site, there you can check Secure flag whether it's set or not.在右侧,您可以看到为该站点设置的所有 cookies,在那里您可以检查是否设置了Secure标志。

Below I'm attaching the screenshots for the same下面我附上相同的屏幕截图

在此处输入图像描述 在此处输入图像描述

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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