Skip to content

Fail closed on unclassified GitHub API writes - #16034

Merged
lpcox merged 3 commits into
mainfrom
copilot/guard-coverage-fix
Nov 5, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/guard-coverage-fix

Conversation

Copilot AI commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Arbitrary gh api REST and GraphQL mutations could bypass operation-name guard classification, including implicit POSTs triggered by request fields.

  • Proxy enforcement: Replace unguarded write passthrough with HTTP 403 (github_api_write_denied). Writes must use named, guard-covered MCP tools.
  • GraphQL validation: Require a valid selected query before routing; strip unselected operations and reject mutations, subscriptions, ambiguous documents, and operation-overriding URL parameters.
  • Guard classification: Add github_api_write to CLI write operations with repository/organization-scoped writer integrity and conservative private secrecy. Block missing-scope calls after integrity baseline enforcement.
  • Compatibility and documentation: Preserve REST GET handling and supported GraphQL reads; document the changed default in proxy guidance and release notes.

Example of an implicit POST now rejected by the proxy:

gh api repos/OWNER/REPO/issues -f title=example
# HTTP 403: github_api_write_denied

Copilot AI changed the title [WIP] Fix guard coverage gap for GitHub CLI operations Fail closed on unclassified GitHub API writes Nov 5, 2026
Copilot AI requested a review from lpcox November 5, 2026 17:51
@lpcox
lpcox marked this pull request as ready for review November 5, 2026 17:58
Copilot AI adaptive review requested due to automatic review settings November 5, 2026 17:58

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

Critical labeling and authorization flaws can expose private data in public repositories and allow scoped generic writes to bypass blocked-operation restrictions.

4 open issues
What changed in this PR

Changes the GitHub proxy to reject unclassified API writes instead of forwarding them outside the guard pipeline, addressing the coverage gap in #16029.

Changes:

  • Rejects REST writes and requires GraphQL requests to select a valid query.
  • Adds scoped github_api_write guard classification and blocks calls without scope.
  • Adds regression coverage and documents the new proxy behavior.
File Description
internal/​proxy/​handler.go Rejects writes and validates GraphQL before routing.
internal/​proxy/​handler_test.go Changes write-operation expectations from passthrough to denial.
internal/​proxy/​graphql.go Detects operation-overriding URL parameters.
internal/​proxy/​api_write_test.go Covers denied writes and preserved read handling.
guards/​github-guard/​rust-guard/​src/​tools.rs Classifies github_api_write as a CLI write operation.
guards/​github-guard/​rust-guard/​src/​lib.rs Infers write scope and blocks unscoped calls.
guards/​github-guard/​rust-guard/​src/​labels/​tool_rules.rs Adds scoped secrecy and writer-integrity labels.
guards/​github-guard/​rust-guard/​src/​labels/​constants.rs Defines the synthetic API-write identifier.
docs/​RELEASE_NOTES.md Announces the fail-closed write behavior.
docs/​PROXY_MODE.md Documents write restrictions and synthetic-operation scope.

Review effort: Max (auto)

if !owner.is_empty() && !repo.is_empty() {
// Generic endpoints may change access-sensitive state even in public repos.
secrecy = policy_private_scope_label(&owner, &repo, repo_id, ctx);
integrity = writer_integrity(repo_id, ctx);
Comment on lines +1162 to +1166
// Generic endpoints may change access-sensitive state even in public repos.
secrecy = policy_private_scope_label(&owner, &repo, repo_id, ctx);
integrity = writer_integrity(repo_id, ctx);
} else if !org.is_empty() {
secrecy = private_scope_label(org);
Comment thread internal/proxy/handler.go
return
}

graphQLBody, err = selectReadOnlyGraphQLOperation(graphQLBody)
Comment thread internal/proxy/handler.go
return
}

graphQLBody, err = selectReadOnlyGraphQLOperation(graphQLBody)
@lpcox

lpcox commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed the review feedback in commit 1428263: generic API writes now fail closed with public destination secrecy; GraphQL reconstruction uses precomputed spans and a builder; and operationName: null is accepted for a single query.

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.

[guard-coverage] Guard coverage gap: 1 operation from github-mcp-server / GitHub CLI not fully covered

3 participants