Skip to content

fix: authenticate and session-bind the GitHub integration OAuth callback - #981

Merged
nimish-ks merged 1 commit into
mainfrom
fix/github-integration-callback-ssrf
Aug 19, 2026
Merged

nimish-ks merged 1 commit into
mainfrom
fix/github-integration-callback-ssrf

Conversation

@rohan-chaturvedi

Copy link
Copy Markdown
Member

🔍 Overview

Patches the GitHub secret-sync integration OAuth callback with various security hardening.

Full details are covered in a separate security advisory.

💡 Proposed Changes

  • New authenticated github_integration_authorize endpoint. It requires a logged-in user, checks the caller's IntegrationCredentials: create permission on the target org, generates a random state nonce, and binds the org / host / name / return URL to the server session before redirecting to GitHub.
  • Hardened github_integration_callback. It validates the state against the session nonce, reads all sensitive parameters from the session (never the request), consumes them (one-time use), and re-checks authentication + permission before exchanging the code. This is what closes the unauthenticated code path.
  • Host policy. On cloud the OAuth host is pinned to github.com; on self-hosted, admin-configured GitHub Enterprise Server URLs (incl. internal hosts) continue to work unchanged.
  • Frontend. SetupGhAuth.tsx now hands off to the backend authorize endpoint instead of building the OAuth state client-side.
  • Post-flow redirects are constrained to same-origin relative paths.

🖼️ Screenshots or Demo

N/A — no visible UI change; only the flow's initiation target and redirect handling change.

🧪 Testing

  • Added backend/tests/api/views/test_github_callback.py (13 tests): unauthenticated rejection, missing/forged state, permission enforcement (authorize + callback), cloud host-pinning + isEnterprise coercion, self-hosted internal GHE allowed, bad-scheme rejection, session-sourced (not query-sourced) host/org, one-time-use state, and the open-redirect guard.
  • tests/api/views/ passes (247), python manage.py check clean, frontend tsc --noEmit and eslint clean on the changed file.
  • Gap: the end-to-end OAuth round-trip against a live GitHub app has not been exercised in a browser yet.

🎯 Reviewer Focus

Start in backend/api/views/auth.py: the new github_integration_authorize and the rewritten github_integration_callback — specifically that every trusted value comes from request.session after the nonce check, and the cloud vs. self-hosted host policy. Then frontend/components/syncing/GitHub/SetupGhAuth.tsx for the initiation change.

➕ Additional Context

Supersedes #806, which added validate_url_is_safe only — insufficient here (doesn't stop exfiltration to a public host, leaves the endpoint unauthenticated, and would reject legitimate internal GHE). Full security advisory published separately.

✨ How to Test the Changes Locally

  1. Configure the GitHub integration OAuth env vars and start the dev stack (docker compose -f dev-docker-compose.yml up -d).
  2. As a user with IntegrationCredentials: create, connect a GitHub credential from an app's syncing/integrations screen — the flow should complete and store the credential.
  3. Negative check: an unauthenticated GET /service/oauth/github/callback?code=x&state=y should redirect to ?error=invalid_state and perform no token exchange.

💚 Did You...

  • Ensure linting passes (code style checks)?
  • Update dependencies and lockfiles (if required) — N/A
  • Update migrations (if required) — N/A (no model changes)
  • Regenerate graphql schema and types (if required) — N/A (no schema changes)
  • Verify the app builds locally? — django check + frontend tsc clean
  • Manually test the changes on different browsers/devices? — pending live OAuth round-trip

@nimish-ks nimish-ks self-assigned this Aug 18, 2026
Comment thread backend/api/views/auth.py Fixed
Comment thread backend/api/views/auth.py Fixed
Comment thread backend/api/views/auth.py Fixed
Comment thread backend/api/views/auth.py Fixed
Comment thread backend/api/views/auth.py Fixed
Comment thread backend/api/views/auth.py Fixed
@rohan-chaturvedi
rohan-chaturvedi force-pushed the fix/github-integration-callback-ssrf branch 4 times, most recently from 0d8c932 to 347ae3a Compare August 18, 2026 13:49
@rohan-chaturvedi
rohan-chaturvedi force-pushed the fix/github-integration-callback-ssrf branch from c463ce5 to 8935bf6 Compare August 18, 2026 18:10
@nimish-ks
nimish-ks merged commit 646ff21 into main Aug 19, 2026
15 checks passed
@nimish-ks
nimish-ks deleted the fix/github-integration-callback-ssrf branch August 19, 2026 07:25
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.

3 participants