2

Having the JWT token required for every request to the API, should I keep CSRF protection? Considering no one has access to other's jwtoken, of course.

If yes, how could I get the csrf token since I don't use django templates (I'm using Vue separately).

If not, is it ok to completely delete the CSRF middleware from settings?

Thanks in advance.

4

2 回答 2

1

如果您将 JWT 存储在 localStorage 中,则不会受到 CSRF 的攻击,因为 localStorage 无法跨域访问。但是,您应该知道,将 JWT 保存在 localStorage 中是否明智存在争议,因为如果您成为 XSS 的受害者,它可能会被盗。另一种方法是将令牌存储在 httpOnly cookie 中,在这种情况下,您必须使用 CSRF 保护。

于 2018-09-25T23:23:46.700 回答
1

如果您使用的是 Django,csrf_token则将在您的站点 cookie 中。您可以从 cookie 访问它并将其与请求一起传递。

于 2018-09-22T06:46:27.047 回答