Skip to content

fix: correct baseline_scope for scoped integrity labels and discussion tool integrity#2281

Merged
lpcox merged 2 commits intofeat/guard-tool-coveragefrom
copilot/sub-pr-2280
Mar 21, 2026
Merged

fix: correct baseline_scope for scoped integrity labels and discussion tool integrity#2281
lpcox merged 2 commits intofeat/guard-tool-coveragefrom
copilot/sub-pr-2280

Conversation

Copy link
Contributor

Copilot AI commented Mar 21, 2026

ensure_integrity_baseline ranks integrity labels by matching the baseline_scope against label scopes. When baseline_scope stays as repo_id (often empty) but integrity was assigned with a different scope, the rank comparison returns 0 and the labels get replaced by none.

Fixes

baseline_scope not set for project:github-scoped tools

project_github_label(ctx) calls writer_integrity("github", ctx), producing labels like approved:github. Without baseline_scope = "github", ensure_integrity_baseline downgrades these to none:.

Affected tools: get_me, get_teams, get_team_members, list_starred_repositories, search_orgs, list_global_security_advisories, get_global_security_advisory.

baseline_scope not set for user-scoped tools

reader_integrity("user", ctx) produces unapproved:user — same downgrade issue without baseline_scope = "user".

Affected tools: list_gists, get_gist.

Discussion tools silently producing none integrity for public repos

private_writer_integrity returns [] for public repos, which ensure_integrity_baseline converts to none. No label_response_paths/label_response_items fallback exists for these tools, so public discussion content was permanently stuck at none and filtered at any min-integrity > none. Replaced with writer_integrity(repo_id, ctx) to assign approved at the resource level unconditionally.

Affected tools: list_discussions, get_discussion, get_discussion_comments.

Test updates

  • Removed repo_id = "github" / repo_id = "user" workarounds in 9 tests that were compensating for the missing baseline_scope assignments — tests now use realistic empty repo_id
  • Updated discussion assertions from none_integritywriter_integrity

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI changed the title [WIP] Add guard tool coverage for 22 missing GitHub MCP server tools fix: correct baseline_scope for scoped integrity labels and discussion tool integrity Mar 21, 2026
Copilot AI requested a review from lpcox March 21, 2026 19:29
@lpcox lpcox marked this pull request as ready for review March 21, 2026 19:36
Copilot AI review requested due to automatic review settings March 21, 2026 19:36
@lpcox lpcox merged commit 262ad20 into feat/guard-tool-coverage Mar 21, 2026
@lpcox lpcox deleted the copilot/sub-pr-2280 branch March 21, 2026 19:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes integrity label downgrades caused by ensure_integrity_baseline when tool rules emit scoped integrity labels (e.g., approved:github, unapproved:user) but baseline_scope remains the default repo_id (often empty), causing integrity to collapse to none.

Changes:

  • Set baseline_scope explicitly for project:github-scoped tools and user-scoped gist tools so scoped integrity labels are preserved.
  • Change discussion-related tools to assign writer_integrity at the resource level (instead of private_writer_integrity) to avoid none integrity in public repos.
  • Update unit tests to remove prior repo_id = "github"/"user" workarounds and to reflect the new discussion integrity behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
guards/github-guard/rust-guard/src/labels/tool_rules.rs Aligns baseline_scope with integrity label scope for several tools; changes discussion tool integrity assignment.
guards/github-guard/rust-guard/src/labels/mod.rs Updates tests to use realistic empty repo_id and adjusts discussion integrity expectations.
Comments suppressed due to low confidence (1)

guards/github-guard/rust-guard/src/labels/tool_rules.rs:435

  • get_discussion_comments now uses writer_integrity(repo_id, ctx) for discussion comments as well. Since these are explicitly user-submitted and can be the lowest-trust content, treating them as approved at the repo scope can let untrusted public comments pass filters when min-integrity > none. A safer pattern would mirror issues: keep resource-level integrity conservative (e.g., private_writer_integrity or reader_integrity) and add response labeling to compute integrity from author association / approval labels per comment.
        "get_discussion_comments" => {
            // Discussion comments are user-submitted, lowest-trust user content.
            // S = inherits from repo visibility
            // I = approved — treat discussion comments as approved at the resource level
            secrecy = apply_repo_visibility_secrecy(&owner, &repo, repo_id, secrecy, ctx);
            integrity = writer_integrity(repo_id, ctx);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 422 to +427
"list_discussions" | "get_discussion" => {
// Discussions are user-submitted content, similar to issues.
// S = inherits from repo visibility
// I = private repos get approved; public repos deferred to response labeling
// I = approved — treat discussion content as approved at the resource level
secrecy = apply_repo_visibility_secrecy(&owner, &repo, repo_id, secrecy, ctx);
integrity = private_writer_integrity(repo_id, repo_private, ctx);
integrity = writer_integrity(repo_id, ctx);
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

list_discussions / get_discussion now assign writer_integrity(repo_id, ctx) unconditionally. This elevates user-generated discussion content to approved integrity even for public repos, which differs from the existing approach for other user-submitted repo content (e.g., issues use private_writer_integrity + per-item issue_integrity in response labeling). Consider keeping resource-level integrity at private_writer_integrity(repo_id, repo_private, ctx) (or reader_integrity for public) and adding response labeling for discussions to compute integrity per item (similar to issue_integrity), so min-integrity policies aren’t bypassed for untrusted public content.

This issue also appears on line 430 of the same file.

See below for a potential fix:

            // I = reader — resource-level integrity reflects read access; per-item
            //     labeling should be used to elevate trusted content if needed
            secrecy = apply_repo_visibility_secrecy(&owner, &repo, repo_id, secrecy, ctx);
            integrity = reader_integrity(repo_id, ctx);
        }

        "get_discussion_comments" => {
            // Discussion comments are user-submitted, lowest-trust user content.
            // S = inherits from repo visibility
            // I = reader — resource-level integrity reflects read access; per-item
            //     labeling should be used to elevate trusted content if needed
            secrecy = apply_repo_visibility_secrecy(&owner, &repo, repo_id, secrecy, ctx);
            integrity = reader_integrity(repo_id, ctx);

Copilot uses AI. Check for mistakes.
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.

3 participants