Amazon Ergo 1.0 · Balanced

github-oauth-security-enhancement-sentry

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

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
4 of 7
Comments published
4
Comments matching a bug
4
Comments not matching
0
Cost of this PR
$1.077

Published comments (4)

highsecuritysrc/sentry/integrations/github/integration.py:481-482

Missing Integration row bypasses installer verification — An attacker can attach a victim’s GitHub installation to their organization without verifying the installer. Return `error(request, self.active_organization)` when `Integration.DoesNotExist` occurs instead of calling `pipeline.next_step()`.

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

OAuth state is predictable and shared across GitHub installations — Generate a random per-pipeline state with `secrets.token_urlsafe(32)`, store it with `pipeline.bind_state()`, and compare it with `pipeline.fetch_state()`.

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

safe_urlopen called outside try block, uncaught connection errors cause 500 — A connection error or timeout from GitHub’s token endpoint leaves a `requests` exception uncaught, producing a 500 instead of the installation-failed response. Move `safe_urlopen()` inside the existing `try`, as in `OAuth2CallbackView.exchange_token`.

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

Missing sender metadata causes KeyError instead of error page — A missing `sender` raises `KeyError`, returning a 500 instead of the intended error page. Replace `integration.metadata["sender"]["login"]` with a guarded `sender_login` lookup, returning `error()` when it is absent or does not match.

Gold bugs found (4)

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.

Gold bugs missed (3)

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.
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.