加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 为什么validateantiforgerytoken cookie值和隐藏

发布时间:2020-12-16 09:53:47 所属栏目:asp.Net 来源:网络整理
导读:我已经完成了MVC4 [ValidateAntiForgeryToken]属性.但是,我不明白我在Fiddler看到的是什么.服务器发送到浏览器的cookie设置为此值: __RequestVerificationToken=FVcmfj07ZEuBdjGuqWu14KIzolxr0ArLgvbNdnq0c4DFywxSA31yIHbm2IzgTPMVhMl4STEh2re8oGmwsSjKtSBT
我已经完成了MVC4 [ValidateAntiForgeryToken]属性.但是,我不明白我在Fiddler看到的是什么.服务器发送到浏览器的cookie设置为此值:

__RequestVerificationToken=FVcmfj07ZEuBdjGuqWu14KIzolxr0ArLgvbNdnq0c4DFywxSA31yIHbm2IzgTPMVhMl4STEh2re8oGmwsSjKtSBTolCsmyGGRnLE1qurUqA1

但隐藏的表单输入设置为此值:

OxjO3NjS1ly-bqP9RnYK9Vx8ZJyLGVCuTQEuSCAQWofVmuJaRkEcnHAHWcDurXaH6DhUiZ6XY5wCgi70u19mPy9sydMrkuS9qlWMXxGL_401

即它们在匹配的地方看起来不同.我不能正确理解cookie,也许第一个字符串不是加密的cookie的实际“值”吗?

解决方法

来源 Pro ASP.NET MVC 3 Framework:

The __RequestVaerificationToken hidden field contains a random component (matching the one in the cookie),but that’s not all. If the user is logged in,then the hidden field value will also contain their user name (obtained from HttpContext.User.Identity.Name and then encrypted).

[ValidateAntiForgeryToken] checks that this matches the logged-in user. This adds protection in the unlikely scenario where an attacker can somehow write (but not read) cookies on your domain to a victim’s browser and tries to reuse a token generated for a different user.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读