Skip to content

fix: add repo scope to GitHub OAuth for private repository access#38

Open
arpita-1111 wants to merge 2 commits into
Rishabhworkspace:mainfrom
arpita-1111:fix/github-oauth-private-repo-scope
Open

fix: add repo scope to GitHub OAuth for private repository access#38
arpita-1111 wants to merge 2 commits into
Rishabhworkspace:mainfrom
arpita-1111:fix/github-oauth-private-repo-scope

Conversation

@arpita-1111

@arpita-1111 arpita-1111 commented Jun 7, 2026

Copy link
Copy Markdown

Closes #22

What this PR does

  • Changed OAuth scope from public_repo to repo in auth.ts
  • Added "(incl. private repos)" note on GitHub login button
  • Updated .env.example with scope requirement note

Changes Made

  • src/lib/auth.ts - scope updated to repo
  • src/app/login/page.tsx - GitHub button updated
  • .env.example - added scope note

Summary by CodeRabbit

  • New Features
    • GitHub authentication now requests access to private repositories in addition to public ones.
    • Login button updated to display a small note indicating private-repo access is requested.

@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the rishabhjtripathi2903-3434's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "tone"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f584c5f-e2bf-4601-a1fa-592e89b5dfe1

📥 Commits

Reviewing files that changed from the base of the PR and between 095990c and e37b1fe.

📒 Files selected for processing (1)
  • src/app/login/page.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/login/page.tsx

📝 Walkthrough

Walkthrough

GitHub OAuth now requests the repo scope (replacing public_repo), the login button shows a note "(needed to analyze private repos)", and .env.example includes a comment stating the required repo scope.

Changes

GitHub OAuth Private Repository Access

Layer / File(s) Summary
GitHub OAuth scope configuration
src/lib/auth.ts
GitHub provider OAuth scope updated from read:user user:email public_repo to read:user user:email repo.
Sign-in UI permission disclosure
src/app/login/page.tsx
GitHub sign-in button content now shows GitHub plus a small note: "(needed to analyze private repos)"; click handler and styling unchanged.
Environment configuration documentation
.env.example
Added comment documenting that the GitHub OAuth scope must be set to \"repo\" (not \"public_repo\") to access private repositories.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The changes address most requirements from #22: scope updated to 'repo' in GithubProvider, login button updated with private repo note, and .env.example documented. However, GitHub OAuth App settings update and private repo functionality testing are not reflected in code changes. Verify that GitHub OAuth App settings have been updated separately for the 'repo' scope, and confirm testing of private repo access in the dashboard was completed.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding the 'repo' scope to GitHub OAuth to enable private repository access.
Out of Scope Changes check ✅ Passed All changes are directly related to addressing issue #22: updating OAuth scope, documenting requirements, and clarifying permissions on the login page.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/login/page.tsx`:
- Around line 269-276: The GitHub sign-in button currently shows “(incl. private
repos)” without a rationale; update the UI around the button in page.tsx so the
GitHub sign-in (signIn('github', ...)) includes a short, clear rationale (e.g.,
“Needed to analyze your private repositories for Traceon features”) visible next
to or under the button and ensure it is accessible (use an inline sentence,
aria-describedby, or a small help text element associated with the button/Github
icon). Locate the button rendering (the element containing signIn('github', {
callbackUrl: '/home' }), Github component, and the “(incl. private repos)” span)
and replace or augment that span with the concise rationale text and accessible
attributes so users understand why private repo access is requested.

In `@src/lib/auth.ts`:
- Line 54: Remove the client-visible GitHub token by stopping assignment of
token.accessToken -> session.user.accessToken in the callbacks.session
implementation in src/lib/auth.ts (do not add accessToken to session.user);
reduce the OAuth scopes string (remove or narrow the 'repo' scope) to the
minimum required; and update the server API handler that needs GitHub auth (the
GET/POST handler in src/app/api/github/route.ts) to retrieve the access token
server-side via getToken from 'next-auth/jwt' (or read it from the server-side
NextAuth JWT) and use that token for the Authorization header instead of relying
on session.user.accessToken.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 17c16118-dff2-4de6-a5ad-2777f746a447

📥 Commits

Reviewing files that changed from the base of the PR and between b7702ad and 095990c.

📒 Files selected for processing (3)
  • .env.example
  • src/app/login/page.tsx
  • src/lib/auth.ts

Comment thread src/app/login/page.tsx
Comment thread src/lib/auth.ts
authorization: {
params: {
scope: 'read:user user:email public_repo',
scope: 'read:user user:email repo',

@coderabbitai coderabbitai Bot Jun 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether client code depends on exposed session token before removing it.
rg -nP --type=ts --type=tsx -C2 '\bsession\.user\.accessToken\b|\buser\.accessToken\b|\btoken\.accessToken\b'

Repository: Rishabhworkspace/Traceon

Length of output: 96


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Show the relevant sections of src/lib/auth.ts
echo "---- src/lib/auth.ts (around scope line 54) ----"
sed -n '35,80p' src/lib/auth.ts

echo "---- src/lib/auth.ts (around token/session callbacks lines ~120-170) ----"
sed -n '95,170p' src/lib/auth.ts


# 2) Re-run searches without relying on rg --type=tsx (which failed earlier)
echo "---- usage: session.user.accessToken ----"
rg -n "session\.user\.accessToken" . || true

echo "---- usage: user.accessToken ----"
rg -n "\buser\.accessToken\b" . || true

echo "---- usage: token.accessToken ----"
rg -n "\btoken\.accessToken\b" . || true

Repository: Rishabhworkspace/Traceon

Length of output: 5627


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,140p' src/app/api/github/route.ts

Repository: Rishabhworkspace/Traceon

Length of output: 4632


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- accessToken occurrences (ts/tsx) ----"
rg -n --glob '*.ts' --glob '*.tsx' '\baccessToken\b' src || true

echo "---- session?.user?.accessToken patterns ----"
rg -n --glob '*.ts' --glob '*.tsx' 'session\?\.[^\n]*user\?\.[^\n]*accessToken|user\?\.[^\n]*accessToken' src || true

echo "---- useSession usage with accessToken near it (±10 lines) ----"
rg -n --glob '*.ts' --glob '*.tsx' 'useSession' src -C 10 | rg -n 'accessToken' || true

Repository: Rishabhworkspace/Traceon

Length of output: 613


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n --glob '*.ts' --glob '*.tsx' "getToken|next-auth/jwt" src || true
rg -n --glob '*.ts' --glob '*.tsx' "useSession|getSession|session\W" src || true

Repository: Rishabhworkspace/Traceon

Length of output: 9501


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n --glob '*.ts' --glob '*.tsx' "declare module 'next-auth'|module 'next-auth'|Session.*accessToken|accessToken.*Session" src || true

Repository: Rishabhworkspace/Traceon

Length of output: 50


Do not expose GitHub OAuth repo access tokens in client-visible NextAuth session data

  • src/lib/auth.ts requests scope: 'read:user user:email repo', stores account.access_token into token.accessToken, and then forwards it to session.user.accessToken.
  • The app uses useSession() in client components, so this makes a high-privilege GitHub token part of the client-visible session payload (increasing compromise impact for private repo access).
  • src/app/api/github/route.ts relies on session.user.accessToken server-side, so the server flow needs to change to fetch the access token without putting it on session.user.
Suggested direction
  • In src/lib/auth.ts callbacks.session, stop setting session.user.accessToken.
  • In src/app/api/github/route.ts, read the GitHub access token from the server-side NextAuth JWT (e.g., via getToken from next-auth/jwt) and use it for the Authorization header.
  • Reduce OAuth scopes to the minimum required (avoid the broad repo scope unless it’s strictly necessary).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/auth.ts` at line 54, Remove the client-visible GitHub token by
stopping assignment of token.accessToken -> session.user.accessToken in the
callbacks.session implementation in src/lib/auth.ts (do not add accessToken to
session.user); reduce the OAuth scopes string (remove or narrow the 'repo'
scope) to the minimum required; and update the server API handler that needs
GitHub auth (the GET/POST handler in src/app/api/github/route.ts) to retrieve
the access token server-side via getToken from 'next-auth/jwt' (or read it from
the server-side NextAuth JWT) and use that token for the Authorization header
instead of relying on session.user.accessToken.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@arpita-1111 If you need help refactoring the token storage to avoid client-side exposure, here's a quick suggestion:

Current risky code (in src/lib/auth.ts):

session.user.accessToken = token.accessToken; // ❌ exposes token to client

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@Rishabhworkspace

Copy link
Copy Markdown
Owner

@arpita-1111 look for coderabbit suggestions

@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
traceon Ready Ready Preview, Comment Jun 8, 2026 5:36am

@adikulkarni006

Copy link
Copy Markdown
Collaborator

**_@arpita-1111 Thanks for the PR. However, there's a security concern raised by CodeRabbit:

Exposing the repo scope access token in client-visible session data is risky. A compromised client could access private repos.

Please consider:

  1. Storing the token only on the server (e.g., in the session but not forwarded to session.user).
  2. Using a separate API route that uses the token server-side without exposing it to the browser.

This is a blocker for merging. Let me know if you need help refactoring._**

@adikulkarni006

adikulkarni006 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@arpita-1111 & @Rishabhworkspace If you need help refactoring the token storage to avoid client-side exposure, here's a quick suggestion:

Current risky code (in src/lib/auth.ts):

session.user.accessToken = token.accessToken; // ❌ exposes token to client

@adikulkarni006

Copy link
Copy Markdown
Collaborator

work done!

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.

Missing Private Repository Scope in GitHub OAuth

3 participants