-
Notifications
You must be signed in to change notification settings - Fork 4
GitHub OAuth Security Enhancement #4
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
base: oauth-state-vulnerable
Are you sure you want to change the base?
Conversation
…#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: 
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
User description
PR #4
PR Type
Bug fix, Enhancement
Description
Add OAuth2 authorization step to GitHub integration installation pipeline
Validate authenticated GitHub user matches app installer to prevent unauthorized installations
Verify state parameter and access token validity during OAuth callback
Refactor error handling into reusable helper function with consistent error responses
Diagram Walkthrough
flowchart LR A["GitHub App Install"] --> B["OAuthLoginView"] B --> C["GitHub OAuth Authorize"] C --> D["Validate State Parameter"] D --> E["Exchange Code for Token"] E --> F["Get Authenticated User"] F --> G["GitHubInstallation"] G --> H["Verify User Matches Installer"] H --> I{Valid?} I -->|Yes| J["Complete Installation"] I -->|No| K["Error Response"]File Walkthrough
integration.py
Implement OAuth2 user validation for GitHub app installationsrc/sentry/integrations/github/integration.py
OAuthLoginViewpipeline step to handle GitHub OAuth2authorization before app installation
GitHub OAuth endpoint
app installer
error()helper functionand
get_document_origin()utilityGitHubInstallationto fetch installation_id from pipeline stateand verify authenticated user matches integration metadata
ERR_INTEGRATION_INVALID_INSTALLATION_REQUESTfor OAuth validation failures
pipeline_advancer.py
Simplify GitHub direct install redirect logicsrc/sentry/web/frontend/pipeline_advancer.py
method
FORWARD_INSTALL_FORto directstring comparison
test_integration.py
Add OAuth validation tests and update existing test flowstests/sentry/integrations/github/test_integration.py
_stub_github()method
assert_setup_flow()to verify OAuth authorize redirect andhandle OAuth callback with code/state parameters
test_github_user_mismatch()to verify installation failswhen authenticated user differs from app installer
and state parameters