security - GraphQL 和 CSRF 保护

标签 security graphql csrf graphql-js csrf-protection

我读了很多书:

  1. https://github.com/pillarjs/understanding-csrf
  2. https://security.stackexchange.com/questions/10227/csrf-with-json-post
  3. Are JSON web services vulnerable to CSRF attacks?
  4. (ApolloServer 站点上没有任何内容: https://www.apollographql.com/docs/apollo-server/ )

但是,我尚无法了解我们的端点(“/graphql”)是否受到此类攻击的保护,或者是否有必要使用如下解决方案来保护它:https://github.com/expressjs/csurf .

我不清楚的是:https://github.com/pillarjs/understanding-csrf他们说:

When you're using CSRF tokens incorrectly: ... Adding them to JSON AJAX calls As noted above, if you do not support CORS and your APIs are strictly JSON, there is absolutely no point in adding CSRF tokens to your AJAX calls.

如果我们限制端点仅使用 Content-Type: application/json 我们安全吗?

最佳答案

If we restrict our endpoint to just use Content-Type: application/json are we safe?

JSON 不能免受 CSRF 攻击(但需要攻击者做一些额外的工作),并且扩展而言,如果配置不正确,GraphQL 也不会受到 CSRF 攻击。如果将其分解为请求/响应,则 CSRF 的常见场景将适用于此处:

  1. 受害者使用您的 GraphQL Web 服务进行身份验证。
  2. 攻击者向受害者发送恶意链接。
  3. 受害者点击链接并访问攻击者的恶意网站。
  4. 攻击者的网站使用受害者 cookie 发送 JSON 请求。
  5. Web 服务接收带有有效 session token /cookie 的 JSON 请求,并且受害者在不知情的情况下运行功能。

在这种情况下,您的服务容易受到 CSRF 的攻击。确保 CORS 配置为仅允许来自受信任域白名单的请求,并确保 CSRF token 正在使用。实现多重保护将降低成功攻击的风险。

以下链接提供了更详细的信息,您甚至可以自己尝试一下: https://blog.appsecco.com/exploiting-csrf-on-json-endpoints-with-flash-and-redirects-681d4ad6b31b

这个答案也很相关: Are JSON web services vulnerable to CSRF attacks?

关于security - GraphQL 和 CSRF 保护,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52060784/

相关文章:

javascript - 带有 XSS 的 CRSF 将 GET 请求中的 % 解析为 %25

angularjs - 使用 AngularJs 从响应中检索 header 并将其设置在所有请求上

php - php 中的安全和 mail() 函数

javascript - 单击后选择一个特定的待办事项 ID

javascript - GraphQL 使用字段值作为另一个查询的变量

axios - Shopify API GraphQL 在单个请求中获取多个图像缩略图

security - 如何在Struts2上实现CSR防伪代码?

C - 运行时代码在执行之间会发生变化吗?

iphone - 从 iPhone 上的应用程序到服务器的已验证 channel

git - 伪装成 github.com 用户