简体   繁体   English

如何在 React JS 中使用 Symfony CSRF 令牌

[英]How to use Symfony CSRF Tokens with React JS

I'm doing a SPA with Symfony and React JS, and my ask is how can I use the Symfony CSRF Token generator with react to avoid CSRF Attacks?我正在使用 Symfony 和 React JS 进行 SPA,我的问题是如何使用 Symfony CSRF 令牌生成器来避免 CSRF 攻击?

If you develop an SPA, then you're also building an API on Symfony side.如果您开发 SPA,那么您也在 Symfony 端构建 API。 (that's usually what people do) (这通常是人们所做的)

Since CSRF issue is only related to forms and not APIs (because they usually are stateless), then you just do not manage CSRF issue.由于 CSRF 问题仅与 forms 而不是 API 相关(因为它们通常是无状态的),所以您只需不管理 CSRF 问题。 If we usually do not have this problem, keep in mind that you still need to deal with it if you use cookies/sessions .如果我们通常没有这个问题,请记住,如果您使用 cookie/sessions ,您仍然需要处理它。 If you do so, then I recommand you to read the documentation of the csrf component of Symfony .如果您这样做,那么我建议您阅读Symfony 的 csrf 组件的文档

More insights here: https://security.stackexchange.com/questions/166724/should-i-use-csrf-protection-on-rest-api-endpoints更多见解在这里: https://security.stackexchange.com/questions/166724/should-i-use-csrf-protection-on-rest-api-endpoints

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

相关问题 如何为 CRUD REACT JS 使用访问令牌 - how to use Access-Tokens for CRUD REACT JS react.js / axios-如何在cookie中存储csrf令牌 - react.js / axios - How to store csrf token in cookies 在不使用 CORS 或 CSRF 令牌的情况下设置 React/DRF - Setup React/DRF without using CORS or CSRF tokens "如何在 Django RESTful API 和 React 中使用 csrf_token?" - How to use csrf_token in Django RESTful API and React? 如何在 react/next.js 应用程序中安全地存储 JWT 令牌? - How to securely store JWT tokens in react/next.js application? 如何在 React.js 应用程序中刷新 JWT 令牌? - How to refresh JWT tokens in React.js Application? React / CSRF:不使用表单和隐藏的输入值而传回CSRF令牌 - React/CSRF: Passing Back CSRF tokens without using forms and hidden input values 如何在 django rest 框架中实现 CSRF 令牌? - How do you implement CSRF tokens in django rest framework? 是否可以将 Symfony 表单组件与 React.js 一起使用? - Is it possible to use the Symfony form component with React.js? 如何通过 express js 服务器和 csrf 令牌成功地为 react 应用程序提供服务 - How to successfully serve the react app through express js server and csrf token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM