Skip to content

fix: user token now correctly scans specified user repos instead of token owner's repos#4940

Open
mitre88 wants to merge 1 commit intotrufflesecurity:mainfrom
mitre88:fix/user-org-token-issue-4517
Open

fix: user token now correctly scans specified user repos instead of token owner's repos#4940
mitre88 wants to merge 1 commit intotrufflesecurity:mainfrom
mitre88:fix/user-org-token-issue-4517

Conversation

@mitre88
Copy link
Copy Markdown

@mitre88 mitre88 commented May 4, 2026

Description

When using --org $user --token $GITHUB_TOKEN, the tool was incorrectly scanning the token owner's repositories instead of the specified user's.

Root Cause

The issue was in getReposByOrgOrUser which passed the authenticated flag to getReposByUser. When authenticated=true, it used the ListByAuthenticatedUser API which returns the authenticated user's repos, not the target user's repos.

Fix

  • Removed the authenticated parameter from getReposByOrgOrUser
  • Always uses unauthenticated user listing (ListByUser) when looking up user repos, since the target is the specified user, not the token owner

Fixes #4517


Note

Low Risk
Low risk: small, localized change to GitHub repo enumeration that only affects which API endpoint is used for user repo listing; main risk is reduced visibility into private repos if the unauthenticated user listing lacks access.

Overview
Fixes GitHub enumeration so --org <user> --token <token> scans the specified user’s repositories rather than the token owner’s.

This removes the authenticated flag from getReposByOrgOrUser and always uses ListByUser (unauthenticated user listing) when falling back from org repos to user repos, updating all call sites accordingly.

Reviewed by Cursor Bugbot for commit bdeb027. Bugbot is set up for automated code reviews on this repo. Configure here.

…oken owner's repos

When using --org $user --token $GITHUB_TOKEN, the tool was incorrectly
scanning the token owner's repositories instead of the specified user's.

The issue was in getReposByOrgOrUser which passed the authenticated flag
to getReposByUser. When authenticated=true, it used the
ListByAuthenticatedUser API which returns the authenticated user's repos,
not the target user's repos.

This fix:
- Removes the authenticated parameter from getReposByOrgOrUser
- Always uses unauthenticated user listing (ListByUser) when looking up
  user repos, since the target is the specified user, not the token owner

Fixes trufflesecurity#4517
@mitre88 mitre88 requested a review from a team May 4, 2026 01:08
@mitre88 mitre88 requested a review from a team as a code owner May 4, 2026 01:08
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Open Source Contributor seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bdeb027d52

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Always use unauthenticated user listing since `name` is the target user,
// not the authenticated user. Using authenticated listing would incorrectly
// return the authenticated user's repos instead of the specified user's.
err = s.getReposByUser(ctx, name, false, reporter)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve authenticated listing for self user targets

The fallback now hard-codes authenticated=false when resolving a non-org account, which means token/basic-auth scans that target the credential owner (for example --org <my-username>) use ListByUser instead of ListByAuthenticatedUser. In this path, private repositories accessible to the authenticated account are no longer enumerated, so scans can silently miss private repos that were previously included. This regression is triggered whenever org lookup 404s and the target is actually the authenticated user.

Useful? React with 👍 / 👎.

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.

user (instead of org) with token is not working

2 participants