cookpad / omniauth-rails_csrf_protection

Provides CSRF protection on OmniAuth request endpoint on Rails application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is TokenVerifier#call reentrant?

nevans opened this issue · comments

In the railtie, we assign a new token verifier to a global config value:

OmniAuth.config.request_validation_phase = TokenVerifier.new

Omniauth doesn't protect against concurrent calls to this global object (omniauth/strategy.rb):

      OmniAuth.config.request_validation_phase.call(env) if OmniAuth.config.request_validation_phase

TokenVerifier#call sets an ivar on this global object, before calling verified_request?:

def call(env)
@request = ActionDispatch::Request.new(env.dup)
unless verified_request?
raise ActionController::InvalidAuthenticityToken
end
end

In a multi-threaded app, two threads might update @request before either thread is able to evaluate verified_request?. (With fibers, this should be safe... so long as no fiber transfers are triggered by ActionDispatch::Request.new, verified_request?, TracePoint, etc.)

What do you think? Am I missing something that would make this safe?