Skip to content

GitHub OAuth Security Enhancement#7

Open
adamsaimi wants to merge 1 commit intooauth-state-vulnerablefrom
oauth-state-secure
Open

GitHub OAuth Security Enhancement#7
adamsaimi wants to merge 1 commit intooauth-state-vulnerablefrom
oauth-state-secure

Conversation

@adamsaimi
Copy link
Owner

Test 4

…#67876)

We're adding one more step in the GitHub integration installation
pipeline, namely GitHub OAuth2 authorize. This is transparent from the
UX perspective as the data exchange happens without user interaction.

The pipeline will now fail in these cases:
- If there is a mismatch between currently authenticated GitHub user
(derived from OAuth2 authorize step) and the user who installed the
GitHub app (https://github.com/apps/sentry-io)
- If there is a mismatch between `state` parameter supplied by user and
pipeline signature
- If GitHub could not generate correct `access_token` from the `code`
(wrong or attempt of re-use of `code`).

In all those cases, this error is shown:

![image](https://github.com/getsentry/sentry/assets/1127549/18923861-2ead-4cf5-adda-7738aef801d7)
}

# similar to OAuth2CallbackView.exchange_token
req = safe_urlopen(url=ghip.get_oauth_access_token_url(), data=data)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Refactor] Overloaded OAuthLoginView

  • Problem: The OAuthLoginView mixes pipeline orchestration with low-level OAuth protocol details and direct HTTP requests, violating separation of concerns.
  • Fix: Refactor the view to delegate low-level OAuth protocol details and HTTP requests to a dedicated service or helper, making the view more focused and testable.


installation_id = request.GET.get("installation_id")
if installation_id:
pipeline.bind_state("installation_id", installation_id)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Security] Missing installation_id Validation

  • Problem: The installation_id is used directly from request.GET without immediate explicit validation, potentially allowing misuse before later database lookups.
  • Fix: Implement a basic type or format validation for installation_id immediately after retrieving it from request.GET.

# redirect to the integration install org picker.
if (
provider_id in FORWARD_INSTALL_FOR
provider_id == "github"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Refactor] Reduced Pipeline Advancer Extensibility

  • Problem: The pipeline_advancer logic is hardcoded for provider_id == "github", limiting its extensibility for other providers.
  • Fix: Restore a generic mechanism, such as the FORWARD_INSTALL_FOR list, to allow easier configuration for future providers.

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 this pull request may close these issues.

2 participants