是否可以将(加密强)会话cookie用作CSRF令牌? [英] Is it ok to use the (cryptographically strong) session cookie as CSRF token?

查看:85
本文介绍了是否可以将(加密强)会话cookie用作CSRF令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 OWASP CSRF预防备忘单,其中一个为防止这种攻击而提出的方法是同步器令牌模式。

Reading OWASP CSRF prevention cheat sheet, one of the methods proposed to prevent these kind of attacks is the synchronizer token pattern.

如果会话令牌在加密方面很强,它可以像下面的伪代码中所描述的那样加倍作为csrf令牌吗?

If the session token is cryptographically strong, can it double as the csrf token as described in the following pseudocode?

客户:

<script>
dom.replace(placeholder, getCookie("session-cookie"))
</script>

<form>
<input type="hidden" name="csrf-cookie" value="placeholder-value"/>
<input type="text" />
</form>

服务器:

if(request.getParameter("csrf-cookie") != user.getSessionCookie())
    print "get out you evil hacker"

在页面加载时使用javascript设置cookie,以防止用户意外泄漏会话cookie,例如通过电子邮件将该页面的副本发送给朋友。

The cookie is set with javascript on page load to prevent users from accidentally leaking the session cookie if they e.g. email a copy of the page to a friend.

推荐答案

外部网站无法检索到的任何内容都可以用作CSRF令牌。所以会话cookie的内容对此没问题。

Anything that cannot be retrieved by an external site can be used as a CSRF token. So contents of the session cookie is fine for this.

这篇关于是否可以将(加密强)会话cookie用作CSRF令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆