Skip to content

Fix guard-policy rendering for repos="all" and repos="public"#20764

Merged
lpcox merged 5 commits intomainfrom
claude/fix-guard-policies-renderer
Mar 13, 2026
Merged

Fix guard-policy rendering for repos="all" and repos="public"#20764
lpcox merged 5 commits intomainfrom
claude/fix-guard-policies-renderer

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 13, 2026

Fixed the safeoutputs guard-policy rendering to correctly handle repos="all" and repos="public" according to the MCP Gateway specification.

Changes Made

  • Updated deriveSafeOutputsGuardPolicyFromGitHub() to return nil for repos="all" and repos="public" (previously returned empty array)
  • When nil is returned, no guard-policies object is attached to safeoutputs
  • Added comprehensive test coverage for array handling with multiple pattern types
  • Modernized code to use strings.CutSuffix() for efficient suffix checking

Specification Compliance

According to the specification, when repos="all" or repos="public", the agent has no secrecy tags ([]), so the write-sink policy is not required. The implementation now correctly returns nil in these cases.

allow-only.repos Agent secrecy tags write-sink.accept Implementation
"all" [] (none) Not needed ✅ Returns nil
"public" [] (none) Not needed ✅ Returns nil
["owner/repo"] ["private:owner/repo"] ["private:owner/repo"] ✅ Correct
["owner/*"] ["private:owner"] ["private:owner"] ✅ Strips wildcard
["owner/prefix*"] ["private:owner/prefix*"] ["private:owner/prefix*"] ✅ Preserves wildcard

Testing

All guard-policy tests pass, including new test cases for:

  • Arrays with all three pattern types (owner wildcard, prefix wildcard, specific repo)
  • Arrays with multiple owner wildcards
  • Correct nil return for repos="all" and repos="public"

Claude AI and others added 5 commits March 13, 2026 03:14
Fixed a bug where repos="public" in GitHub guard-policy was incorrectly
rendered as "public:*" in safeoutputs write-sink policy. It should be
rendered as just "public" (without the :* wildcard suffix).

The bug was in deriveSafeOutputsGuardPolicyFromGitHub() which treated
both "all" and "public" the same way, mapping both to "private:*".
Now they are handled correctly:
- repos="all" → write-sink accept=["private:*"]
- repos="public" → write-sink accept=["public"]
- repos="pattern" → write-sink accept=["private:pattern"]

Also updated the code to use a tagged switch statement as suggested by
the staticcheck linter (QF1003).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated deriveSafeOutputsGuardPolicyFromGitHub() to implement the
correct transformation rules based on DIFC (Decentralized Information
Flow Control) principles:

- repos="all" or "public" → accept=[] (agent secrecy is empty)
- repos="O/*" → accept=["private:O"] (owner wildcard strips wildcard)
- repos="O/P*" → accept=["private:O/P*"] (prefix wildcard keeps wildcard)
- repos="O/R" → accept=["private:O/R"] (specific repo keeps pattern)

Added transformRepoPattern() helper function to handle owner wildcard
detection and stripping. Updated all test cases to match specification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added test cases to ensure comprehensive coverage of array handling
with multiple entries:

- Array with all three pattern types (owner wildcard, prefix wildcard, specific repo)
- Array with multiple owner wildcards

These tests verify that the transformRepoPattern() function correctly
handles different combinations of patterns in arrays, ensuring each
pattern type is transformed according to the specification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox
Copy link
Collaborator

lpcox commented Mar 13, 2026

@claude[agent] fix the title and summary.

Also make sure that for a github guard-policies object with repos="all" and repos="public" no guard-policies object is attached to safeoutputs

@Claude
Copy link
Contributor Author

Claude AI commented Mar 13, 2026

@claude[agent] fix the title and summary.

Also make sure that for a github guard-policies object with repos="all" and repos="public" no guard-policies object is attached to safeoutputs

Fixed the PR title and description.

The implementation correctly ensures that when repos="all" or repos="public", no guard-policies object is attached to safeoutputs:

  1. deriveSafeOutputsGuardPolicyFromGitHub() returns nil for these cases (line 298 in mcp_github_config.go)
  2. Both call sites check if len(guardPolicies) > 0 before rendering, so nil results in no guard-policies being added
  3. Tests confirm this behavior with expectNil: true for both "all" and "public" cases

Commit: a6e714f

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr view claude/fix-guard-policies-renderer --json title,body,commits /home/REDACTED/.nvm/install.sh /home/REDACTED/.nvm/nvm-exec /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test (http block)
    • Triggering command: /usr/bin/gh gh pr edit claude/fix-guard-policies-renderer --title Fix guard-policy rendering for repos=&#34;all&#34; and repos=&#34;public&#34; --body-file /tmp/pr_description.md /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test -c &#34;mcp-server-playwright&#34; --viewport-size &#39;1280, 720&#39; --output-dir /tmp/playwright-logs --allowed-base64 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Claude Claude AI changed the title Completing task Fix guard-policy rendering for repos="all" and repos="public" Mar 13, 2026
@Claude Claude AI requested a review from lpcox March 13, 2026 04:29
@lpcox lpcox marked this pull request as ready for review March 13, 2026 04:34
Copilot AI review requested due to automatic review settings March 13, 2026 04:34
@lpcox lpcox merged commit 7aee142 into main Mar 13, 2026
3 checks passed
@lpcox lpcox deleted the claude/fix-guard-policies-renderer branch March 13, 2026 04:34
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

Adjusts safeoutputs guard-policy derivation to comply with the MCP Gateway spec when GitHub guard-policy repos is set to "all" or "public".

Changes:

  • Updates deriveSafeOutputsGuardPolicyFromGitHub() to return nil (and thus omit safeoutputs guard-policies) for repos="all" and repos="public".
  • Adds transformRepoPattern() to correctly map repo patterns (including owner/*private:owner) using strings.CutSuffix().
  • Expands unit tests to cover owner wildcards, prefix wildcards, and mixed arrays, plus the new nil behavior for "all"/"public".

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/workflow/mcp_github_config.go Implements spec-compliant derivation (return nil for "all"/"public") and adds pattern transformation helper.
pkg/workflow/safeoutputs_guard_policy_test.go Adds/updates test cases for "all"/"public" returning nil and mixed pattern arrays including owner wildcard handling.

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

You can also share your feedback on Copilot code review. Take the survey.

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