Skip to content

fix: allow repositories where owner matches repo name (e.g. profile README repos) - #18

Merged
xcorail merged 3 commits into
GitHubSecurityLab:mainfrom
thedavidweng:fix-owner-equals-repo-name
Oct 2, 2026
Merged

xcorail merged 3 commits into
GitHubSecurityLab:mainfrom
thedavidweng:fix-owner-equals-repo-name

Conversation

@thedavidweng

Copy link
Copy Markdown
Contributor

Problem

When targeting a repository whose name matches the owner (such as GitHub profile README repositories like octocat/octocat or username/username), gh-secure aborts with:

Error: Repository must be in 'owner/repo' format

Root cause

In resolve_repo(), the script checked:

if [ "$OWNER" = "$REPO_NAME" ] || [ -z "$OWNER" ] || [ -z "$REPO_NAME" ]; then

This assumed that if no slash was provided in the input, ${REPO%%/*} and ${REPO##*/} would both evaluate to the full input string. However, on GitHub, profile README repositories legitimately have $OWNER == $REPO_NAME.

Additionally, in the interactive fallback (read -r REPO), the check only verified [ -z "$OWNER" ] || [ -z "$REPO_NAME" ], which did not enforce the presence of a slash if an unslashed single word was entered.

Fix

Replace [ "$OWNER" = "$REPO_NAME" ] with [[ "$REPO" != */* ]] in both argument-parsing and interactive prompt validation:

if [[ "$REPO" != */* ]] || [ -z "$OWNER" ] || [ -z "$REPO_NAME" ]; then

This properly ensures that a slash separates owner and repository while accepting repositories where the repository name is identical to the owner.

Testing

  • --repo username/username: Successfully accepted and proceeds to check security status.
  • --repo owner/repo: Works as expected.
  • --repo invalid: Correctly rejected with Error: Repository must be in 'owner/repo' format.
  • --repo /repo: Correctly rejected.
  • --repo owner/: Correctly rejected.
  • Interactive mode with username/username: Accepted.
  • Interactive mode with invalid: Rejected.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Multi-slash inputs remain valid and can silently target a different repository.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates repository parsing to support profile README repositories where owner and repository names match.

Changes:

  • Replaces equality-based rejection with slash validation.
  • Applies validation to argument and interactive inputs.
File Description
gh-secure Updates repository identifier validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread gh-secure Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
kevinbackhouse
kevinbackhouse previously approved these changes Oct 2, 2026
Comment thread gh-secure Resolved
@xcorail
xcorail merged commit a04d1c1 into GitHubSecurityLab:main Oct 2, 2026
@thedavidweng
thedavidweng deleted the fix-owner-equals-repo-name branch October 2, 2026 18:57
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.

4 participants