2012-02-07 41 views
1

我的印象是,在任何POST,PUT或DELETE操作後Rails都會重新生成form_authenticity_token。但由於某種原因,POST成功後,用戶資源form_authenticity_token不會重新生成。我可以自由發佈儘可能多的時間,因爲我一次又一次地使用同一個CSRF令牌。Rails form_authenticity_token在POST請求後不再生

我有一個名稱空間API,我使用RABL gem來構建我的迴應。這是我所擁有的一切設置...

class Api::V1::UsersController < Api::V1::ApplicationController 
    ... 
    def create 
    @user = User.new(params[:user]) 
    render "show", :status => (@user.save ? :ok : :unprocessable_entity) 
    end 
    ... 
end 

class Api::V1::ApplicationController < ApplicationController 
    layout '/api/v1/layouts/application.json.erb' 
    respond_to :json 
    before_filter :authenticate_user! 
    ... 
end 

class ApplicationController < ActionController::Base 
    protect_from_forgery 
end 

的後經過精細,有在development.log或安慰$ rails s日誌中沒有錯誤或警告。

我檢查了create方法中的verified_request?,它返回true。我已經移除了渲染並使用與show.json.rabl視圖相同的代碼設置了create.json.rabl視圖...沒有骰子。

我正在運行Rails 3.1.3 w/Ruby 1.9.2p290 w/cookie會話存儲。

真實性令牌經由請求頭(X-CSRF令牌)

回答

4

你是錯誤的曝光下發送。正如您從rails source的相關位所看到的,表單真實性令牌在會話的整個生命週期內保持不變。