警告:在 API 开发的情况下无法验证 CSRF 令牌的真实性 [英] WARNING: Can't verify CSRF token authenticity in case of API development

查看:48
本文介绍了警告:在 API 开发的情况下无法验证 CSRF 令牌的真实性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用 Ruby on Rails 开发 Web API.当 Rails 应用收到没有任何 csrf 令牌的 POST 请求时,将出现以下错误消息.因为该应用没有视图.

I am right now developing web APIs with Ruby on Rails. When the Rails app receives POST request without any csrf token, the following error message shall happen. Because the app has no views.

WARNING: Can't verify CSRF token authenticity

所以我的问题是在这种情况下如何安全地逃避 csrf 令牌检查?

So my question is how can I escape csrf token check safely in this case?

非常感谢您.

推荐答案

你可以通过添加

skip_before_filter  :verify_authenticity_token

到您的控制器.这样,所有传入控制器的请求都会跳过 :verify_authenticity_token 过滤器.

to your controller. This way all incoming requests to the controller skips the :verify_authenticity_token filter.

这篇关于警告:在 API 开发的情况下无法验证 CSRF 令牌的真实性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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