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

OAuth exception is swallowed and overwritten on login #2643

Open
thekaveman opened this issue Jan 23, 2025 · 0 comments
Open

OAuth exception is swallowed and overwritten on login #2643

thekaveman opened this issue Jan 23, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@thekaveman
Copy link
Member

thekaveman commented Jan 23, 2025

The issue presents here: https://github.com/cal-itp/benefits/blob/main/benefits/oauth/views.py#L77

if result and result.status_code >= 400:
    exception = Exception(f"authorize_redirect error response [{result.status_code}]: {result.content.decode()}")
elif result is None:
    exception = Exception("authorize_redirect returned None")

The elif condition only checks result but does not look at exception.

The problem is, the previous line may have already caught and set exception: https://github.com/cal-itp/benefits/blob/main/benefits/oauth/views.py#L73

try:
    result = oauth_client.authorize_redirect(request, redirect_uri)
except Exception as ex:
    exception = ex

Thus, that original exception would be overwritten by exception = Exception("authorize_redirect returned None") which isn't necessarily true.

To Reproduce

Steps to reproduce the behavior:

  1. Misconfigure a ClaimsProvider with bad scheme etc.
  2. Place debug points on the above lines
  3. Attempt login
  4. See error

Expected behavior

The original exception is not overwritten and is the one that gets bubbled further.

@thekaveman thekaveman added the bug Something isn't working label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

1 participant