DeepSeek V4 Pro · 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
$0.436

Published comments (4)

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

OAuth state uses deterministic pipeline signature, enabling CSRF — A deterministic state provides no CSRF protection: an attacker can precompute it and inject their own authorization code into a victim's active pipeline. Generate a per-session token with `secrets.token_hex()`, bind it via `pipeline.bind_state("state", ...)`, and validate with `pipeline.fetch_state("state")` on return, as `OAuth2LoginView` and `OAuth2CallbackView` already do.

highbugsrc/sentry/integrations/github/integration.py:501-505

KeyError when GitHub integration metadata lacks sender — Integrations without `sender` exist and crash this path with a 500. Use `integration.metadata.get("sender", {}).get("login")` and return `error(...)` when the login is absent instead of indexing directly.

highsecuritysrc/sentry/integrations/github/integration.py:500-505

GitHub sender validation is skipped when Integration row does not exist — When the Integration row does not exist, the `except Integration.DoesNotExist` branch returns `pipeline.next_step()` before this validation, so the user match is never enforced if the webhook loses the race against the redirect. Move the sender check before that early return, or enforce it in `build_integration` before the integration is created.

mediumbugsrc/sentry/integrations/github/integration.py:434-436

get_user_info call can raise unhandled exceptions during OAuth — `get_user_info` can raise on 401/403/5xx via `raise_for_status()` and on invalid JSON via `resp.json()`, surfacing as an unhandled 500 rather than the user-facing error page. Wrap the call in try/except and return `error(request, self.active_organization)` on failure.

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.