【发布时间】:2011-09-28 14:19:37
【问题描述】:
如果我创建一个全新的 Rails 应用程序(使用 Rails 3.0.9)并快速搭建如下脚手架:
$ rails new testing
$ rails g scaffold thing name:string
那么 app/controllers/application_controller.rb 默认包含一个“protect_from_forgery”,所以它应该在 POST 创建期间检查authenticity_token。至少,这是我的理解。
那么,为什么在不提供令牌的情况下,这一行是否成功创建了新事物。
$ curl -F "thing[name]=abc123" http://localhost:3000/things
日志条目说:
Started POST "/things" for 127.0.0.1 at 2011-07-05 08:29:18 +0100
Processing by ThingsController#create as
Parameters: {"thing"=>{"name"=>"abc123"}}
AREL (0.3ms) INSERT INTO "things" ("name", "created_at", "updated_at") VALUES ('abc123', '2011-07-05 07:29:18.484457', '2011-07-05 07:29:18.484457')
Redirected to http://localhost:3000/things/18
Completed 302 Found in 89ms
我也可以这样做来删除记录:
$ curl -X DELETE http://localhost:3000/things/18
在生产模式中也会发生同样的事情。这不会让我的应用程序对 CSRF 开放吗?
【问题讨论】:
-
您是否根据会话 ID 对用户进行身份验证?
标签: ruby-on-rails csrf