Skip to content

feat: verify GitHub installation access outside sign-in - #46

Merged
hyochan merged 1 commit into
mainfrom
feat/github-access-verification
Nov 20, 2026
Merged

hyochan merged 1 commit into
mainfrom
feat/github-access-verification

Conversation

@hyochan

@hyochan hyochan commented Nov 20, 2026

Copy link
Copy Markdown
Member

Summary

Gitdog records which GitHub App installations a user can reach (githubOAuthInstallationAttestations, valid 15 minutes) from the user's own GitHub token. Today that happens only inside sign-in. @convex-dev/auth 2.0 keeps the GitHub token inside its component, so this moves the check into its own flow first; the 2.0 migration follows in a separate PR.

Verify GitHub access

  • github/action:startAccessVerification({ returnPath }) (signed in): creates a random OAuth state (stored only as a SHA-256 hash) and a PKCE verifier, and returns the GitHub App authorize URL. A user has at most one pending verification; it expires after 10 minutes.
  • GET /github/access/callback: consumes the state once, exchanges the code with the client secret and verifier, reads /user and /user/installations, saves the installations only if the GitHub account is the one linked to that user, revokes the token, and redirects to the return path on Gitdog's site with ?githubAccess=verified|account_mismatch|cancelled|failed.
  • The redirect URI uses the sign-in callback's host (CUSTOM_AUTH_SITE_URL, else CONVEX_SITE_URL), so production uses https://auth.gitdog.dev/github/access/callback. Both callbacks are now documented in docs/github-app-setup.md.
  • Return paths are checked after normalization (/..//evil.example is refused) and the final redirect must stay on SITE_URL.

Web and CLI

  • The repository connect page's "Refresh GitHub authorization" button starts this flow and shows a message when it is cancelled, fails, or uses another GitHub account. The consent page's re-authorization-through-sign-in path is removed.
  • CLI: new gitdog github verify; github recover points to it instead of login.

Shared

  • Sign-in and the new flow use one saveInstallationAttestation and one readLinkedGitHubAccountId, the single place to change when accounts move into the auth component.

Before merging

Both GitHub Apps must list the new callback URL, or GitHub stops the flow with a redirect_uri error:

  • gitdogbot-dev: https://fortunate-chihuahua-679.convex.site/github/access/callback
  • gitdogai: https://auth.gitdog.dev/github/access/callback

Checks

  • bun run lint, bun run typecheck, prettier --check ., bun run build, bun run test (2122 passed), bun run check:api, bun run test:cli (116 passed)
  • New tests: start and stored state hash, PKCE, success with token revocation, another GitHub account (token still revoked), reused and expired state, declined vs other GitHub errors, return paths that try to leave the site, CLI github verify.
  • An independent security review found an open redirect through dot segments in the return path (fixed and tested) and smaller items (PKCE, error classification, logging, shared headers), all addressed.

🤖 Generated with Claude Code

Recording which GitHub App installations a user can reach no longer depends
on the sign-in library, which @convex-dev/auth 2.0 needs because its GitHub
sign-in keeps the user token to itself.

- "Verify GitHub access": an authenticated action starts a GitHub App user
  authorization (state stored only as a hash, PKCE S256, 10-minute expiry);
  the /github/access/callback route exchanges the code, records the
  installations only for the GitHub account linked to that user, revokes
  the token and returns to a path on Gitdog's site.
- The redirect URI uses the same host as the sign-in callback
  (CUSTOM_AUTH_SITE_URL or CONVEX_SITE_URL); both callbacks are documented
  for the GitHub App.
- The connect page starts it and reports cancelled, failed or mismatched
  accounts; the consent page's sign-in re-authorization path is removed.
- CLI: new github verify command; github recover points to it.
- Sign-in and the new flow share one attestation save and linked-account
  lookup.
@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit cf492c3):

https://codeyou-df251--pr46-feat-github-access-v-1ild3inm.web.app

(expires Fri, 27 Nov 2026 10:42:45 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 844dad9c62537d028cabc21008e4e2e4031ce4e5

@gitdogai gitdogai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found in cf492c3

Approved because no issues were found in fully reviewed changes. Tests were not run. Gitdog

@hyochan
hyochan merged commit 98adaa9 into main Nov 20, 2026
9 checks passed
@hyochan
hyochan deleted the feat/github-access-verification branch November 20, 2026 11:23
hyochan added a commit that referenced this pull request Nov 20, 2026
## Summary

Follow-ups found reviewing today's auth 2.0 work (#46, #47, #48) and
own-key cost UI (#45).

- **Connect page**: after 2.0, installation recovery reports
`reauth_required` whenever no fresh attestation exists, so a brand-new
user saw "Finishing GitHub connection" instead of Install. Users without
an installation now see Install, with "Already installed? Verify GitHub
access" as a secondary action. The verification screen is shown only
while an installation callback is pending. Screen choice moved into
`resolveConnectScreen` with a table test.
- **Usage**: the own-key section said reviews run on Gitdog tokens
whenever no key worked, but saved keys never fall back. It now
distinguishes no key / no working key / temporary outage. The page waits
for own-key cost before rendering.
- **Consent page**: shows why a GitHub sign-in failed
(`useOauth().flowError`).
- **CLI**: `github verify` reuses `validateAuthRedirect` (also handles a
missing URL); install hints mention `github verify` before `github
recover`.
- **Smaller**: `getTicketUsage` and recent own-key runs respect
`githubLifecycleOnly`; long-context price note in the model picker;
per-provider "this period" wording; shared `actionTypeLabel`;
screen-reader request count on the usage chip; unused
`repositories[].actions` removed.
- **Docs**: `getAuthUserId` import path, CLI fixed ports, verify-access
architecture line, `CUSTOM_AUTH_SITE_URL` comment.
- **Tests**: session auth rejects a bare user-id subject and a revoked
session; sign-in redirect allow/deny at the mutation; CLI port fallback
and all-ports-busy; consent flow errors. `CONVEX_CLOUD_URL` moved to
test setup.

## Verification

`bun run lint`, `typecheck`, `build`, `format:check`, `check:api`,
`typecheck:cli`, `test:cli` (118 pass), `vitest run` (2124 pass).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

1 participant