You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Resolving CVE 2015 9284" needs to be adapted for OmniAuth 2 #1031
Back when using OmniAuth 1.9.1, I had written CVE-2015-9284 non-regression tests as instructed. One test asserts that ActionController::InvalidAuthenticityToken is raised when making a POST request without CSRF token.
I expected this test to continue passing after upgrading, or finding instructions in the release notes on how it should be adapted after upgrading to OmniAuth 2.
Actual Behavior
After upgrading to OmniAuth 2.0.1, this test fails as no exception is caught. However the log shows that the exception was indeed raised:
Details
D, [2021-02-01T11:20:49.328866 #13095] DEBUG -- omniauth: (facebook) Request phase initiated.
E, [2021-02-01T11:20:49.332406 #13095] ERROR -- omniauth: (facebook) Authentication failure! ActionController::InvalidAuthenticityToken: ActionController::InvalidAuthenticityToken, ActionController::InvalidAuthenticityToken
Minitest::Assertion: ActionController::InvalidAuthenticityToken expected but nothing was raised.
To my understanding, the cause is that OmniAuth now catches the exception and sends it to its OmniAuth.config.on_failure. How should the test be adapted? Or is the new recommendation to just delete these tests?
Steps to Reproduce
Install omniauth 2.0.1, omniauth-rails_csrf_protection 1.0.0, copy and run the test linked from the Wiki (direct link).
Reacted by Sascha Hoellger, Ian Neubert, Fábio Gomes, Marcelo Lauxen, Zane Pickett, thatguysimon, MothOnMars, DeedleFake and Martijn Lafeber
@thatguysimon I've configured OmniAuth.config.on_failure to raise an error during tests:
require'test_helper'# Make sure that https://nvd.nist.gov/vuln/detail/CVE-2015-9284 is mitigatedclassOmniauth_CVE_2015_9284_Test < ActionDispatch::IntegrationTesttest'GET /auth/facebook'doget'/auth/facebook'assert_response:not_foundendclassPostTest < ActionDispatch::IntegrationTestsetupdo@allow_forgery_protection=ActionController::Base.allow_forgery_protectionActionController::Base.allow_forgery_protection=true@omni_auth_test_mode=OmniAuth.config.test_modeOmniAuth.config.test_mode=false@omni_auth_on_failure=OmniAuth.config.on_failureOmniAuth.config.on_failure=proc{raise"test auth failure!"}endtest'POST /auth/facebook without CSRF token'doassert_raises("test auth failure!")dopost'/auth/facebook'endendteardowndoActionController::Base.allow_forgery_protection=@allow_forgery_protectionOmniAuth.config.test_mode=@omni_auth_test_modeOmniAuth.config.on_failure=@omni_auth_on_failureendendend
Note: using Omniauth 2.1.0, the updated spec continues to pass even without the omniauth-rails_csrf_protection gem installed. Is that gem still required to protect against this vulnerability? If so, is there a different spec that better illustrates the remaining vulnerability to confirm the fix?
@MothOnMars I observe the same, the test still passes when removing omniauth-rails_csrf_protection. Does this mean the gem is not required any more? Tested with omniauth 2.1.0, omniauth-apple 1.0.2, devise 4.8.1.
Hi, as I updated omniauth in my project to 2.x, I found same situation and I dug it some degree.
Omniauth 2.x implemented their own csrf protection, but Rails do it other way. So you need to implement your own csrf protection code or use omniauth-rails_csrf_protection #1010.
Without Rails specific implementation, POST /auth/:provider wil always fail with OmniAuth::AuthenticityError.
I updated rspec snippet I posted before: #809 (comment)
to the following. (The issue is locked. I cannot edit even my own comment...)
The with valid authenticity_token context will fail if you don't have omniauth-rails_csrf_protection or your own OmniAuth.config.request_validation_phase.
Thanks for opening this and for sharing your updated test. The Resolving CVE-2015-9284 wiki page now has a regression-testing section for OmniAuth 2, based on your example, and the Upgrading to 2.0 guide explains that request-phase exceptions are sent to on_failure. I'm closing this as resolved, but please open a new issue if the docs are still unclear.
Activity
thatguysimon commentedon Mar 2, 2021
Having the same issue.
@sedubois Did you figure out a workaround for this?
Maybe asserting that the response is a redirect to
/auth/failure?sedubois commentedon Mar 2, 2021
@thatguysimon I've configured
OmniAuth.config.on_failureto raise an error during tests:MothOnMars commentedon Sep 2, 2022
Thanks, @sedubois ! I added your example to the wiki page on that vulnerability:
https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284#regression-testing
MothOnMars commentedon Sep 2, 2022
Note: using Omniauth 2.1.0, the updated spec continues to pass even without the
omniauth-rails_csrf_protectiongem installed. Is that gem still required to protect against this vulnerability? If so, is there a different spec that better illustrates the remaining vulnerability to confirm the fix?sedubois commentedon Sep 6, 2022
@MothOnMars I observe the same, the test still passes when removing
omniauth-rails_csrf_protection. Does this mean the gem is not required any more? Tested with omniauth 2.1.0, omniauth-apple 1.0.2, devise 4.8.1.hiroshi commentedon Dec 7, 2022
Hi, as I updated omniauth in my project to 2.x, I found same situation and I dug it some degree.
Omniauth 2.x implemented their own csrf protection, but Rails do it other way. So you need to implement your own csrf protection code or use omniauth-rails_csrf_protection #1010.
Without Rails specific implementation, POST /auth/:provider wil always fail with OmniAuth::AuthenticityError.
I updated rspec snippet I posted before:
#809 (comment)
to the following. (The issue is locked. I cannot edit even my own comment...)
The
with valid authenticity_tokencontext will fail if you don't haveomniauth-rails_csrf_protectionor your own OmniAuth.config.request_validation_phase.sferik commentedon Oct 17, 2026
Thanks for opening this and for sharing your updated test. The Resolving CVE-2015-9284 wiki page now has a regression-testing section for OmniAuth 2, based on your example, and the Upgrading to 2.0 guide explains that request-phase exceptions are sent to
on_failure. I'm closing this as resolved, but please open a new issue if the docs are still unclear.