でデモ アプリケーションをrails new demo
作成し、 でスキャフォールディングされたユーザー コントローラーを生成しましたrails generate scaffold User name:string email:string
。スキャフォールディングされたコードにはApplicationController
withprotect_from_forgery
があり、 UserController
which から派生したものもありますApplicationController
。
webrick を実行し、ユーザーを追加します。Authenticity トークンは、/users の POST で約束どおりに機能します。
まだRails 3.0.5を使用しているため、次のことができます。
niedakh@twettek-laptop:~$ telnet 10.0.0.4 3000
PUT /users/3 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
user[name]=vvvvv&user[email]=shiaus.pl
そして、トークンを与えずにユーザー 3 を変更します。
Started PUT "/users/3" for 10.0.0.4 at 2011-04-02 14:51:24 +0200
Processing by UsersController#update as HTML
Parameters: {"user"=>{"name"=>"vvvvv", "email"=>"shiaus.pl\r"}, "id"=>"3"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
', "updated_at" = '2011-04-02 12:51:24.437267' WHERE "users"."id" = 3s.pl
Redirected to http://10.0.0.4:3000/users/3
Completed 302 Found in 92ms
また、DELETE でも同じことができます。
DELETE /users/3 HTTP/1.1
それは私に与えます:
Started DELETE "/users/3" for 10.0.0.4 at 2011-04-02 15:43:30 +0200
Processing by UsersController#destroy as HTML
Parameters: {"id"=>"3"}
SQL (0.7ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
AREL (0.5ms) DELETE FROM "users" WHERE "users"."id" = 3
Redirected to http://10.0.0.4:3000/users
Completed 302 Found in 180ms
それらのリクエストと一緒にトークンを送信しないのに、なぜこれらのことができるのか説明していただけますか?