- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我想对 Stormpath post 中的 JWT token 和 CSRF 提出疑问解释了将 JWT 存储在 localStorage 或 cookie 中的优点和缺点。
[...] if you are reading values out of a cookie using JS, that means youcan't set the Httponly flag on the cookie, so now any JS on your sitecan read it, thus making it the exact same security-level as storingsomething in localStorage.
I'm trying to understand why they recommend adding the xsrfToken tothe JWT. Doesn't storing your JWT in the cookie and then extracting itout and placing the JWT in the HTTP header and authenticating therequest based on the HTTP header accomplish the same thing asAngular's X-XSRF-TOKEN? No other domain could make requests on auser's behalf if you authenticate based on the JWT in the header,since other domains cannot extract the JWT from the cookie. I don'tunderstand the purpose of the xsrfToken in the JWT - perhaps its justan additional layer of defense - meaning that attackers would have tohave a compromised script on your site and CSRF a user at the time. Sothey'd have to hit you in both ways to be able to pull of an attack.
帖子链接在this answer哪里说:
The last thing is to ensure that you have CSRF protection on everyHTTP request to ensure that external domains initiating requests toyour site cannot function.
[...] Then, on every request into your server, ensure that your ownJavaScript code reads the cookie value and sets this in a customheader, e.g. X-CSRF-Token and verify that value on every request inthe server. External domain clients cannot set custom headers forrequests to your domain unless the external client gets authorizationvia an HTTP Options request, so any attempt at a CSRF attack (e.g. inan IFrame, whatever) will fail for them.
即使他们可以设置自定义 header ,他们也无法访问存储 JWT token 的 cookie,因为只有在同一域上运行的 JavaScript 才能读取该 cookie。
他们唯一的方法是通过 XSS,但是如果存在 XSS 漏洞,JWT 中的 xsrfToken 也会受到损害,因为在受信任的客户端域中运行的恶意脚本可以访问 cookie 中的 JWT 并在请求中包含 header 使用 xsrfToken。
所以等式应该是:
如果客户端和服务器在不同的域中运行,则服务器应发送 JWT,客户端应使用 JWT 创建 cookie。我认为这个等式对于这种情况仍然有效。
更新: MvdD agree with me :
As the browser does not automatically add the header to your request,it is not vulnerable to a CSRF attack
最佳答案
我是 Stormpath 博客文章的作者。在 JWT 中存储 XSRF token 并不是关于它在 JWT 中,而是关于它在 cookie 中。 cookie 应该是 httpOnly,所以你不能从 Javascript 读取它。
现在,我认为引起一点困惑的一点是我谈论 Angular 地方。 Angular 也将它设置为仅 XSRF cookie(不是 httpOnly)以在请求时将其放入 header (这只能由同一域上的 javascript 完成)。这些不是同一个 cookie。
如果您考虑在您的应用程序中实现 XSRF 支持,这已经通过存储服务器端状态和存储 XSRF 的点来完成。将它存储在 httpOnly cookie 中是关于 XSRF 的无状态。在这里,您将验证 JWT 签名,从声明中获取 XSRF,并将其与 header 进行比较。
您的问题的答案是您不需要在服务器上存储状态。
关于javascript - 为什么要将 CSRF token 放入 JWT token 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35013781/
我试图在 Eclipse v3.7.2 中将 loopj .jar 库添加到我的项目中 首先,我将 .jar 添加到“lib”目录中,右键单击它并选择“添加到构建路径”。它编译得很好,但在执行时出现错
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Passing two-dimensional array via pointer int table[20
我在 Grafana 中的图表每隔几秒钟就会自动更新一次。随着数据的进入,右侧的最后一个数据点会暂时下降。最终会显示正确的值,但在几次更新时该值较低。这是正常的吗?可以修复吗? 最佳答案 也许,这会有
我不明白为什么我会收到臭名昭著的“IllegalStateException”以及以下代码: private void mergeQueryStrings(String url, Map parame
您好,我正在通过 .php 文件中的 JSON 回显将测试 Android 应用程序链接到 MySQL 数据库。 我能够用整个数据填充 ArrayList,但现在我想将数据分离到变量中,但我无法真正找
我想仅将对象的数据成员的值写入文件,因此这里我不能使用序列化,因为它会写入很多内容其他我不需要的信息。这是我通过两种方式实现的。一种使用字节缓冲区,另一种则不使用它。 不使用 ByteBuffer:第
可能是个简单的问题,但我似乎找不到答案。我正在动态创建一个页面,我可以在其中共享 Twitter 链接。 var twitter = document.createElement('a'); tw
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
尝试获取我在末尾为 $_SESSION 设置的值作为查询中的 user_id,而不是 $username。我似乎无法修改查询。我确信这对于这里的一些专家来说是非常简单的。 if(isset($_POS
有没有人可以帮助我,我有 mysql 查询,我已经在 phpmyadmin 中测试了它: select items.name, items.category, items.supplier_id, i
我正在尝试 push_back()一个„ std::vector 的符号. 我一直收到错误: character too large for enclosing character literal t
我有一个存储在 char * 中的压缩图像,我想将它放回 AVPacket,以便我可以将它放入 ffmpeg 解码器。有人可以展示如何做到这一点吗?任何示例或教程将不胜感激。 提前致谢 最佳答案 我向
password = str() while password != "changeme": password = input("Password: ") print("Thou Shall
所以我有一个 Map,其中有一些值被传递到一个方法中: public String doThis(Map context){ ..... } 我正在尝试向该 map 插入附加属性 String abc
我遇到了一些我无法弄清楚的问题...我正在编写一个带有接受拖放的 JList 的 Swing Java 应用程序。我想在将文件或文件夹从我的系统拖到 Java 应用程序上时更改光标。 最佳答案 我自己
我正在尝试确定一些关于如何编写异常消息的指南。 例如,让我们假设一个假设的函数必须接收恒定数量的字节(作为 bytes 对象),我们用 [1, 2, 3]。以下是所有可能的异常(exception)情
使用 JSONObject 发送到网络服务当我们将 double(整数)放入零时,该点将被删除 代码 double d = 123.00; JSONObject json = new JSONObje
在 WPF 中,如何将 DataGrid 放在 ComboBox 中以显示多列?像下面这样的东西似乎没有做任何事情:
我正在尝试使用自定义 QStandardItem 在两个 QListViews 之间进行拖放。 除了this document,我在网上找不到我需要的信息这有点帮助,但现在我被困住了。 从一个 QLi
如何将 PDF 放入 NSData 中?我在应用程序的文档目录中以字符串形式找到了 PDF 的位置。当我尝试通过电子邮件发送时,我在电子邮件正文中看到 PDF(而不是看到附件图标。我不知道这是否正常)
我是一名优秀的程序员,十分优秀!