-
Notifications
You must be signed in to change notification settings - Fork 2
fully tested and working #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aed8444
implemented access-tokens -only manual steps required now / added pin…
iHildy b845d9b
updated agents and gemi rules / fixed all issues mentioned by coderabbit
iHildy 11a864c
Update jules-queueing-system.md - fix typo
iHildy e645137
address code review comments.
iHildy 090366a
Implement fallback rate limiting in GitHub callback API
iHildy 45fe6a4
Refactor Vercel configuration and simplify GitHub callback rate limiting
iHildy 12ff19a
Refactor GitHub OAuth flow and improve error handling
iHildy cf9ea72
Refactor logging and configuration in API routes
iHildy 9cf7629
Refactor GitHub installation handling and rate limit handling = fully…
iHildy aef6e83
Merge branch 'main' into prep-for-production
iHildy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main", "release/*"] | ||
| pull_request: | ||
| branches: ["main", "release/*"] | ||
|
|
||
| jobs: | ||
| lint-typecheck-build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18 | ||
| cache: "pnpm" | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Lint | ||
| run: pnpm lint | ||
| env: | ||
| SKIP_ENV_VALIDATION: true | ||
| - name: Typecheck | ||
| run: pnpm type-check | ||
| env: | ||
| SKIP_ENV_VALIDATION: true | ||
| - name: Build | ||
| run: pnpm build:selfhosted | ||
| env: | ||
| SKIP_ENV_VALIDATION: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: CodeQL | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main"] | ||
| pull_request: | ||
| branches: ["main"] | ||
| schedule: | ||
| - cron: "0 6 * * 1" | ||
|
|
||
| jobs: | ||
| analyze: | ||
| name: Analyze | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| security-events: write | ||
| actions: read | ||
| contents: read | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| language: ["javascript-typescript"] | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v3 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
| - name: Autobuild | ||
| uses: github/codeql-action/autobuild@v3 | ||
| - name: Perform CodeQL Analysis | ||
| uses: github/codeql-action/analyze@v3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 18 | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
prisma/migrations/20250721021416_rename_oauth_fields_to_camelcase/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - You are about to drop the column `refresh_token` on the `github_installations` table. All the data in the column will be lost. | ||
| - You are about to drop the column `refresh_token_expires_at` on the `github_installations` table. All the data in the column will be lost. | ||
| - You are about to drop the column `token_expires_at` on the `github_installations` table. All the data in the column will be lost. | ||
| - You are about to drop the column `user_access_token` on the `github_installations` table. All the data in the column will be lost. | ||
|
|
||
| */ | ||
| -- AlterTable | ||
| ALTER TABLE "github_installations" DROP COLUMN "refresh_token", | ||
| DROP COLUMN "refresh_token_expires_at", | ||
| DROP COLUMN "token_expires_at", | ||
| DROP COLUMN "user_access_token", | ||
| ADD COLUMN "refreshToken" TEXT, | ||
| ADD COLUMN "refreshTokenExpiresAt" TIMESTAMP(3), | ||
| ADD COLUMN "tokenExpiresAt" TIMESTAMP(3), | ||
| ADD COLUMN "userAccessToken" TEXT; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { env } from "@/lib/env"; | ||
| import logger from "@/lib/logger"; | ||
| import crypto from "crypto"; | ||
| import { cookies } from "next/headers"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| // Safe redirect URLs - only allow internal paths or whitelisted domains | ||
| const SAFE_REDIRECT_PATTERNS = [ | ||
| /^\/github-app\/success$/, // Internal success page | ||
| /^\/github-app\/label-setup$/, // Internal label setup page | ||
| /^\/$/, // Home page | ||
| ]; | ||
|
|
||
| function isValidRedirectUrl(redirectTo: string): boolean { | ||
| // Check if it's a relative URL (starts with /) | ||
| if (redirectTo.startsWith("/")) { | ||
| return SAFE_REDIRECT_PATTERNS.some((pattern) => pattern.test(redirectTo)); | ||
| } | ||
|
|
||
| // For absolute URLs, only allow same origin | ||
| try { | ||
| const redirectUrl = new URL(redirectTo); | ||
| const baseUrl = new URL(env.GITHUB_APP_CALLBACK_URL); | ||
| return redirectUrl.origin === baseUrl.origin; | ||
| } catch { | ||
| // Invalid URL format | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| const { searchParams } = new URL(request.url); | ||
| const installationId = searchParams.get("installation_id"); | ||
| const redirectTo = searchParams.get("redirect_to") || "/github-app/success"; | ||
|
|
||
| if (!installationId) { | ||
| return NextResponse.json( | ||
| { error: "Installation ID is required" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
||
| // Validate redirectTo to prevent open redirect vulnerabilities | ||
| if (!isValidRedirectUrl(redirectTo)) { | ||
| logger.warn( | ||
| { installationId, redirectTo }, | ||
| "Invalid redirect URL attempted in OAuth flow", | ||
| ); | ||
| return NextResponse.json( | ||
| { error: "Invalid redirect URL" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| // Generate CSRF state and encode installation_id and redirectTo using base64 | ||
| const state = crypto.randomBytes(32).toString("hex"); | ||
| const stateData = { | ||
| state, | ||
| installationId, | ||
| redirectTo, | ||
| }; | ||
| const stateWithInstallation = Buffer.from( | ||
| JSON.stringify(stateData), | ||
| ).toString("base64"); | ||
|
|
||
| // Set CSRF state cookie | ||
| const cookieStore = await cookies(); | ||
| cookieStore.set("oauth_state", stateWithInstallation, { | ||
| httpOnly: true, | ||
| secure: process.env.NODE_ENV === "production", | ||
| sameSite: "lax", | ||
| maxAge: 60 * 10, // 10 minutes | ||
| }); | ||
|
|
||
| // Build GitHub OAuth authorization URL | ||
| const githubAuthUrl = new URL("https://github.com/login/oauth/authorize"); | ||
| githubAuthUrl.searchParams.set("client_id", env.GITHUB_APP_CLIENT_ID); | ||
| githubAuthUrl.searchParams.set("redirect_uri", env.GITHUB_APP_CALLBACK_URL); | ||
| githubAuthUrl.searchParams.set("state", stateWithInstallation); | ||
| githubAuthUrl.searchParams.set("scope", "repo"); // Add required scopes | ||
|
|
||
| logger.info( | ||
| { installationId, redirectTo }, | ||
| "Redirecting to GitHub OAuth authorization", | ||
| ); | ||
|
|
||
| return NextResponse.redirect(githubAuthUrl.toString()); | ||
| } catch (error) { | ||
| logger.error({ error }, "Failed to create OAuth authorization URL"); | ||
| return NextResponse.json( | ||
| { error: "Failed to initiate OAuth flow" }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.