Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue StandardError makes all development errors failures #1030

Closed
pgwillia opened this issue Jan 26, 2021 · 16 comments · Fixed by #1035
Closed

Rescue StandardError makes all development errors failures #1030

pgwillia opened this issue Jan 26, 2021 · 16 comments · Fixed by #1035

Comments

@pgwillia
Copy link

Since bumping omniauth from 1.9.1 to 2.0.1 in our application all development errors have become failures. For example I purposefully introduce an error to a view. It is caught by omniauth and calls fail which means that we can no longer use better_errors to debug.

195:       rescue StandardError => e
    196:        binding.pry
 => 197:         return fail!(e.message, e)
    198:       end
    199: 
    200:       @app.call(env)
    201:     end

[1] pry(#<OmniAuth::Strategies::SAML>)> e
=> #<ActionView::Template::Error: undefined local variable or method `oops' for #<#<Class:0x00007f533c178068>:0x000055e0bcf640a8>>

Is there something that we misconfigured in omniauth setup? We catch the failures to give users a message in their browser
https://github.com/ualbertalib/jupiter/blob/fe8409b9d4b4345e409c91a0cf6744b9ce4b91ba/config/initializers/omniauth.rb#L22
We can make this conditional based on environment but wondering if there is a better way?

begin
return options_call if on_auth_path? && options_request?
return request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
return callback_call if on_callback_path?
return other_phase if respond_to?(:other_phase)
rescue StandardError => e
return fail!(e.message, e)
end

@BobbyMcWho
Copy link
Member

BobbyMcWho commented Jan 27, 2021

You’ll want to take a look at the OmniAuth.config.on_failure setting, by default it’s set to call the OmniAuth Failure Endpoint

@BobbyMcWho
Copy link
Member

If you're looking to preserve raising the errors out in development I'd suggest something like

on_failure do |env|
  if Rails.env.development?
    OmniAuth::FailureEndpoint.call(env)
  else
    SessionsController.action(:failure).call(env)
  end
end

@pgwillia
Copy link
Author

Yes. That's effectively what we've done. We still think it's strange that omniauth is intercepting all errors (not just the ones relevant to omniauth).

@BobbyMcWho
Copy link
Member

I'll look into it a bit more, it really should only be catching errors that occur during the auth process

@trysmr
Copy link

trysmr commented Feb 2, 2021

Hi, I have the same problem. I use a omniauth-saml gem.

I found the omniauth-saml gem calls the call_app! method in the other_phase method. All errors have become failures and logs as "(saml) Authentication failure!" in the fail! method if an error occurs regardless of the auth process.

@BobbyMcWho
Copy link
Member

Thanks for the report and additional information @trysmr, I think this is a bug in omniauth-saml and will release a patch for that gem.

@pgwillia
Copy link
Author

pgwillia commented Feb 5, 2021

I saw #1032 and it is similar. The error behaviour changed with the release of 2.0.2. Now the failure mode is a redirect loop and the error is printed in the console.

image

This is printed 21x in the console
image

@BobbyMcWho
Copy link
Member

I have been looking into this, I haven't decided the best course of action yet. @pgwillia it looks like your session controller isn't handling the error but just redirecting to root?

@pgwillia
Copy link
Author

pgwillia commented Feb 5, 2021

@BobbyMcWho good observation. That's what we've told it to do.
https://github.com/ualbertalib/jupiter/blob/7a5ce302771c471b5411bec24c4f4c2e61babb4d/app/controllers/sessions_controller.rb#L55-L57
That explains the redirect loop because the error I introduced is part of our welcome page.

@trysmr has summarized the issue that still persists.

@BobbyMcWho
Copy link
Member

So looking into a few strategies and how they have implemented the other_phase, it seems like they almost all call call_app! which is why this block will capture those application errors. I may have to pull that other phase out of the error handling capture.

@trysmr
Copy link

trysmr commented Feb 6, 2021

Since the other_phase is not a common process for each omniauth strategy, I think it is better to leave its error handling to each strategy.

I am facing the redirect loop problem too. Luckily, I don't implement /metadata, /slo, /spslo paths, so I have temporarily undefined it now.

@trysmr
Copy link

trysmr commented Feb 8, 2021

I just thought of one. How about adding an on_auth_path? method like this?

begin
  return options_call if on_auth_path? && options_request?
  return request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
  return callback_call if on_callback_path?
  return other_phase if on_auth_path? && respond_to?(:other_phase)
rescue StandardError => e
  return fail!(e.message, e)
end

@bisrael
Copy link

bisrael commented Feb 12, 2021

Ran into this today too, when when using omniauth with devise this totally masks any errors that happen.

It also makes it very very difficult to find out why things are failing.

Rescuing StandardError should be considered an anti-pattern; you could instead scope the errors you catch to specifically authentication errors.

@bisrael
Copy link

bisrael commented Feb 12, 2021

Unfortunately, the commit that adds the rescue does not explain why the rescue was added.

Perhaps just undo it since there's no rationale included?

ee2ef21

@BobbyMcWho
Copy link
Member

@bisrael this was the PR in which it was added #689

@BobbyMcWho
Copy link
Member

If anyone can try out the branch for this pr and let me know if it resolves it for you: #1035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants