2014-03-13 70 views
0

因此,在我們的應用程序中,我們正在對api(相同的域,相同的服務器)進行少量的ajax調用。ajax調用失去會話

通常這些Ajax調用是「自我暗示」,上傳圖片,...

它好工作在軌道3,它工作正常軌道4局部ENV(本地主機),但我們的開發服務器上它不工作了。

我懷疑csrf有什麼問題,但我在頁面中有csrf標記,並且ajax調用也發送了令牌。

但是這裏是我在日誌中

Started GET "/api/v1/services/get_suggestions/289" for 50.16.6.85 at 2014-03-13 18:40:24 +0000 
Processing by Api::V1::ServiceController#get_suggestions as JSON 
    Parameters: {"service_id"=>"289"} 
Completed 401 Unauthorized in 2ms 
Started GET "/user/sign_in.json" for 50.16.6.85 at 2014-03-13 18:40:24 +0000 
Processing by SessionsController#new as JSON 
Redirected to http://dev.myapp.com/ 
Filter chain halted as :require_no_authentication rendered or redirected 
Completed 302 Found in 466ms (ActiveRecord: 1.3ms) 

任何想法?

回答

0

是否有可能您的會話與另一個子域關聯? CSRF令牌與會話相關聯,並且會話可以與特定的子域相關聯。

例如,如果你的會話是域myapp.com域名

但請求作出dev.myapp.com的CSRF令牌是無效的,因爲它僅適用於在域http://maypp.com會話。