2015-08-08 6 views
4

Прежде чем я скажу, что я ищу google и много сообщений здесь, в Stackoverflow, но ничто не могло дать решение для моей проблемы. для этого я создаю новый пост.Rails 4 ActionController :: InvalidAuthenticityToken с несколькими подобластями

Я создаю приложение с двумя поддоменами: account.psantos.dev и app.psantos.dev.

В: config/initializers/session_store.rb у меня есть:

Rails.application.config.session_store :cookie_store, key: '_psantos.co.ao_session', domain: 'psantos.dev' 

И у меня есть следующие структуры папок:

- app
-- controllers
--- app1
---- welcome_controller.rb
--- account
---- welcome_controller.rb
--views
--- layout
---- app1.html.erb
---- account.html.erb
--- app1
---- welcome
----- index.html.erb
--- account
---- welcome
----- index.html.erb

на: app/views/layout/app1.html.erb (http://app1.psantos.dev) У меня есть следующие строки:

<li><%= "Logout", account_sign_out_url, method: :delete %></li> 

Когда я нажимаю эту ссылку (это перейдет к: http://account.psantos.dev), я получил следующее сообщение об ошибке:
ActionController::InvalidAuthenticityToken at /sign_out ActionController::InvalidAuthenticityToken

на обоих файлах макета (app1.html.erb и account.html.erb) Я эту строку перед < \ HEAD> тег:

<%= csrf_meta_tags %> 

как я могу решить эту проблему?

Update: отношение журнала

Started GET "/" for 127.0.0.1 at 2015-08-08 12:37:03 +0100 Processing 
by APP1::WelcomeController#index as HTML Parameters: 
{"subdomain"=>"app1"} Rendered app1/welcome/index.html.erb within 
layouts/app1 (0.4ms) [1m[35mEntity Load (0.3ms)[0m SELECT 
"entities".* FROM "entities" WHERE "entities"."user_token" = $1 LIMIT 
1 [["user_token", "xxxxxxxxxxxxxxxxxxxx"]] Completed 200 OK in 43ms 
(Views: 42.0ms | ActiveRecord: 0.3ms) 


Started DELETE "/sign_out" for 127.0.0.1 at 2015-08-08 12:37:05 +0100 
Processing by Account::SessionsController#destroy as HTML 
Parameters: {"subdomain"=>"account"} Can't verify CSRF token 
authenticity Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 
0.0ms) 

ActionController::InvalidAuthenticityToken - 
ActionController::InvalidAuthenticityToken: actionpack (4.2.3) 
lib/action_controller/metal/request_forgery_protection.rb:181:in 
`handle_unverified_request' actionpack (4.2.3) 
lib/action_controller/metal/request_forgery_protection.rb:209:in 
`handle_unverified_request' actionpack (4.2.3) 
lib/action_controller/metal/request_forgery_protection.rb:204:in 
`verify_authenticity_token' activesupport (4.2.3) 
lib/active_support/callbacks.rb:430:in `block in make_lambda' 
activesupport (4.2.3) lib/active_support/callbacks.rb:143:in `block in 
halting_and_conditional' activesupport (4.2.3) 
lib/active_support/callbacks.rb:502:in `block in call' activesupport 
(4.2.3) lib/active_support/callbacks.rb:502:in `call' 
+0

Пожалуйста, покажите нам код вида и соответствующий фрагмент файла журнала. –

+0

hi @ Зелёный, см. Журнал .. Я обновил сообщение. Какой вид вам нужен, чтобы показать код? – psantos

+0

попытайтесь включить 'app/controllerlers/application_controller.rb' в 'protect_from_forgery с:: null_session' и прочитать о [CSRF] (http://guides.rubyonrails.org/security.html#cross-site-request-forgery -csrf) в Rails. –

ответ

1

Теперь это невозможно сделать: удалить запрос на субдомен.

There is an vulnerability in jquery-ujs and jquery-rails that can be used to bypass CSP protections and allows attackers to send CSRF tokens to attacker domains. This vulnerability has been assigned the CVE identifier CVE-2015-1840. Versions Affected: All. Not affected: Applications which don't use jquery-ujs or jquery-rails. Fixed Versions: jquery-rails versions 4.0.4 and 3.1.3 and jquery-ujs 1.0.4. Impact ------ In the scenario where an attacker might be able to control the href attribute of an anchor tag or the action attribute of a form tag that will trigger a POST action, the attacker can set the href or action to " https://attacker.com " (note the leading space) that will be passed to JQuery, who will see this as a same origin request, and send the user's CSRF token to the attacker domain.

Это commit в Jquery-UJS: image with diff code in jquery-ugs

Вы можете прочитать больше here

Смежные вопросы