【问题标题】:CSRF token authencity for sub controller子控制器的 CSRF 令牌真实性
【发布时间】:2013-03-27 10:12:55
【问题描述】:

每当我发布到我的 api_controller.rb 时,我都会在我的 Rails 应用程序中收到 CSRF 警告(重置我的会话)。

我的应用程序在 windows phone 8 的 phonegap 中的 iframe 上运行,在我的 application_controller 中,我有一个 p3p 标头来解决这个问题。但在这种情况下它似乎不起作用。它就像p3p不存在......?有人遇到过吗?

class ApplicationController < ActionController::Base

protect_from_forgery
before_filter :header_fix

protected
  def header_fix
    headers['P3P'] = 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"'
  end
end




class Api::ApiController < ApplicationController
before_filter :login_required

skip_before_filter :detect_device
skip_before_filter :detect_browser
skip_before_filter :record_log

skip_before_filter :assign_packages
skip_before_filter :assign_daily_bonus

end


[2646 - 2013/04/05 13:04:23] (INFO) Started POST "/api/chests" for 60.50.19.249 at 2013-04-05 13:04:23 +0800
[2646 - 2013/04/05 13:04:23] (INFO) Processing by Api::ChestsController#create as */*
[2646 - 2013/04/05 13:04:23] (INFO)   Parameters: {"force_new"=>"true"}
[2646 - 2013/04/05 13:04:23] (WARN) WARNING: Can't verify CSRF token authenticity
[2646 - 2013/04/05 13:04:23] (INFO) User agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)
[2646 - 2013/04/05 13:04:23] (DEBUG)   User Load (4.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[2646 - 2013/04/05 13:04:23] (DEBUG)   KeyPackage Load (1.2ms)  SELECT `packages`.* FROM `packages` WHERE `packages`.`type` IN ('KeyPackage') ORDER BY cost
[2646 - 2013/04/05 13:04:23] (DEBUG)   CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[2646 - 2013/04/05 13:04:23] (DEBUG)   CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[2646 - 2013/04/05 13:04:23] (WARN) Lost session [60.50.19.249] (/api/chests) - Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)

【问题讨论】:

  • 用户是否在请求之前登录?
  • 是的,用户正在登录,rails 控制台在发布之前显示所有事件的用户 ID
  • 当您直接访问 iframe 的内容时(没有使用浏览器的 iframe),它是否有效?
  • 是的,当我这样做时它会起作用
  • 也许这对你有帮助:stackoverflow.com/questions/7203304/…

标签: ruby-on-rails iframe controller csrf-protection


【解决方案1】:

此 gem 适用于 Ruby on Rails (https://github.com/grosser/ie_iframe_cookies)。解决问题。

即使我的 p3p 标头有效并且我的用户可以登录,但我不确定 IE10 为何这样做。

【讨论】:

    猜你喜欢
    • 2021-12-10
    • 2012-07-29
    • 2014-07-15
    • 1970-01-01
    • 2017-07-15
    • 2015-07-24
    • 1970-01-01
    • 2014-06-16
    • 2012-05-08
    相关资源
    最近更新 更多