Amazon Ergo 1.0 · Heavy

github-oauth-security-enhancement-sentry

Sentry · Python · M · 100–299 lines · 2 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
5 of 7
Comments published
6
Comments matching a bug
5
Comments not matching
1
Cost of this PR
$2.572

Published comments (6)

highsecuritysrc/sentry/integrations/github/integration.py:402-413

Deterministic GitHub OAuth state defeats CSRF protection — Because `pipeline.signature` is identical across users and sessions, an attacker can supply a known `state` and bind their GitHub identity to a victim's pipeline. Generate a cryptographically random per-session value with `secrets.token_hex()`, store it via `pipeline.bind_state`, and validate it with `pipeline.fetch_state`, following `sentry/auth/providers/oauth2.py`.

highbugsrc/sentry/integrations/github/integration.py:480-481

New GitHub installations skip sender/authenticity verification — A victim's organization can be linked to an attacker's GitHub installation because the `Integration.DoesNotExist` branch skips the `github_authenticated_user` check. Verify the installer/sender in this branch too, or defer linking until that identity can be checked. **Also found in:** - `src/sentry/integrations/github/integration.py:493-498`

mediumsecuritysrc/sentry/integrations/github/integration.py:412

OAuth state uses a timing-unsafe comparison — A timing leak on this security token can reveal a valid `state` byte by byte. Replace the `!=` check with `django.utils.crypto.constant_time_compare`, matching the existing convention for token validation.

mediumbugsrc/sentry/integrations/github/integration.py:501-504

Missing sender metadata raises KeyError instead of showing error page — An existing integration without sender metadata raises `KeyError` and returns a 500 instead of the intended error page. Use safe `dict.get` lookups on `integration.metadata` and fail closed when `sender` or `login` is absent, matching `GitHubIntegrationsInstallationEndpoint` in `installation.py`.

mediumbugsrc/sentry/integrations/github/integration.py:423-429

GitHub token request failures escape the OAuth error handling — Token-endpoint failures can escape as unhandled exceptions and return a 500 instead of the intended error page. Move `safe_urlopen()` inside the `try` so connection and HTTP failures fall through to `error()`.

mediumbugtests/sentry/integrations/github/test_integration.py:388-396

test_installation_not_found uses an invalid OAuth state — The hard-coded callback `state` is rejected before installation lookup, so the test can pass even if installation-not-found handling is broken. Extract `state` from the OAuth redirect and assert the specific installation-not-found error.

Gold bugs found (5)

highThe GitHub OAuth state is pipeline.signature, a static md5 of the pipeline view names, instead of a per-attempt random nonce, so it gives no CSRF protection.
mediumThe new OAuth step's token exchange and user lookup are not wrapped in error handling, so GitHub/network failures surface as 500s instead of the installation-failed page.
highWhen no Integration exists yet for the installation_id the pipeline advances without comparing the OAuth user to the installer, bypassing the new ownership check.
highThe installer check indexes integration.metadata['sender']['login'] without checking that sender exists, raising KeyError for integrations created without sender metadata.
mediumtest_installation_not_found uses a wrong OAuth state, so it fails at the state check and never reaches the installation-not-found path it is meant to test.

Gold bugs missed (2)

mediumGitHubInstallation re-fetches the existing Integration filtered by status=ACTIVE and errors if not found; an Integration with this external_id that is not ACTIVE and has no OrganizationIntegration now gets the generic 'Invalid installation request' page instead of advancing so ensure_integration can reactivate it, blocking re-installs.
highThe new installer-ownership check stores and compares GitHub's mutable login (OAuth /user login vs metadata sender.login) instead of the immutable numeric id; after the installer renames, another account that claims the old login passes the check and can link the installation.