Skip to content

Unify repository visibility parsing across GitHub and enclave lookups - #17146

Merged
lpcox merged 5 commits into
mainfrom
copilot/duplicate-code-repo-visibility
Nov 23, 2026
Merged

lpcox merged 5 commits into
mainfrom
copilot/duplicate-code-repo-visibility

Conversation

@lpcox

@lpcox lpcox commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Repository visibility parsing had diverged: the shared lookup supported legacy GHES responses, while enclave access required explicit "public". This change gives both paths one parsing contract without changing enclave transport.

  • Shared parser: Extract githubhttp.ParseRepoVisibility for both callers.
  • Fallback semantics: Accept an explicit private boolean when visibility is missing or unrecognized. Reject unusable fields and malformed or trailing JSON rather than inferring public access.
  • Enclave safeguards: Preserve authenticated forwarding, the 1 MiB response limit, denial caching, and uncached positive results.
visibility, err := githubhttp.ParseRepoVisibility(bytes.NewReader(body))
if err != nil || visibility != githubhttp.RepoVisibilityPublic {
	s.cacheEnclaveVisibilityDenial(repo)
	return false
}

@lpcox lpcox changed the title [WIP] Fix duplicate repo-visibility lookup implementation Unify repository visibility parsing across GitHub and enclave lookups Nov 23, 2026
@lpcox
lpcox marked this pull request as ready for review November 23, 2026 05:02
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 05:02
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

New visibility parse errors preserve potentially permissive policies and private sink settings, allowing public workflows to bypass safeguards and expose private data.

1 open issue
What changed in this PR

This PR consolidates repository visibility parsing so the gateway’s GitHub lookups and enclave authorization share one contract, including support for older GitHub Enterprise Server responses.

Changes:

  • Extracts a shared parser with an explicit private boolean fallback and strict JSON validation.
  • Reuses the parser in enclave lookups while preserving authenticated forwarding, response limits, and caching behavior.
  • Expands tests for legacy responses, unresolved visibility, malformed or trailing JSON, and oversized responses.
File Description
internal/​proxy/​enclave.go Uses the shared visibility parser for enclave authorization.
internal/​proxy/​enclave_visibility_test.go Tests parsing outcomes, response limits, and denial caching.
internal/​proxy/​enclave_test.go Updates authorization scenarios for legacy public and denied repositories.
internal/​githubhttp/​visibility.go Extracts the shared parser and rejects unusable responses.
internal/​githubhttp/​visibility_test.go Expands lookup tests for fallback behavior and invalid responses.

Review effort: Max (adaptive)


var repo repoResponse
if err := json.NewDecoder(resp.Body).Decode(&repo); err != nil {
vis, err := ParseRepoVisibility(resp.Body)
@lpcox

lpcox commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

@lpcox

lpcox commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Copilot AI commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in 32ea2e8. Invalid visibility responses now trigger public safeguards; existing API-error and opt-out behavior remains unchanged.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and resolve conflicts

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in 32ea2e8: invalid visibility responses now force the public safeguards. Regression tests pass.

@copilot fix this failing lint check https://github.com/github/gh-aw-mcpg/actions/runs/45214443681/job/137832321657?pr=17146

Fixed in aa21c6e. The pinned golangci-lint now reports zero issues.

…e-repo-visibility

# Conflicts:
#	internal/cmd/proxy.go
#	internal/server/guard_visibility.go

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (add_issue_comment/star_repository/issue_write/create_branch/create_or_update_file/create_pull_request) all 6 targets absent from the 23-tool catalog (read-only toolset) BLOCKED ⚠️
C CLI reads (github CLI: list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh CLI not authenticated (not logged into any GitHub hosts) BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh CLI not authenticated, same as D BLOCKED ⚠️

Overall: INCONCLUSIVE

No write of any kind leaked (no reaction, star, issue, comment, branch, file, or PR created). Part B is INCONCLUSIVE because all targeted write tools were entirely absent from the exposed GitHub MCP catalog (23 read-only tools only) — this confirms gh-aw's backend GITHUB_READ_ONLY=1 wrapper but does not by itself exercise mcpg's own independent gateway-level DIFC/guard write-blocking layer, since no write-capable tool ever reached a call attempt. Parts D/E are INCONCLUSIVE because gh was not authenticated in this job, so the REST/GraphQL token-scope boundary could not be probed this run.

No FAIL conditions observed on either surface for the default runtime.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

Copilot AI commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main and resolve conflicts

Merged main and resolved conflicts in 371e925. Verification passed; golangci-lint was unavailable locally.

@lpcox
lpcox merged commit 77a4f23 into main Nov 23, 2026
29 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-repo-visibility branch November 23, 2026 16:36
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.

[duplicate-code] Duplicate Code Pattern: Repo-Visibility Lookup Implemented Twice (proxy vs githubhttp)

3 participants