Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.8k
Apply lockdown check to pull_request_readget_diff/get_files#2883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SamMorrowDrums
merged 3 commits into
kerobbi/lockdown-shared-enforcement
from
kerobbi/lockdown-pr-read-pathsJul 16, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -123,13 +123,13 @@ Possible options: | ||
| result, err := GetPullRequest(ctx, client, deps, owner, repo, pullNumber) | ||
| return attachIFC(result), nil, err | ||
| case "get_diff": | ||
| result, err := GetPullRequestDiff(ctx, client, owner, repo, pullNumber) | ||
| result, err := GetPullRequestDiff(ctx, client, deps, owner, repo, pullNumber) | ||
| return attachIFC(result), nil, err | ||
| case "get_status": | ||
| result, err := GetPullRequestStatus(ctx, client, owner, repo, pullNumber) | ||
| return attachIFC(result), nil, err | ||
| case "get_files": | ||
| result, err := GetPullRequestFiles(ctx, client, owner, repo, pullNumber, pagination) | ||
| result, err := GetPullRequestFiles(ctx, client, deps, owner, repo, pullNumber, pagination) | ||
| return attachIFC(result), nil, err | ||
| case "get_commits": | ||
| result, err := GetPullRequestCommits(ctx, client, owner, repo, pullNumber, pagination) | ||
| @@ -206,7 +206,40 @@ func GetPullRequest(ctx context.Context, client *github.Client, deps ToolDepende | ||
| return MarshalledTextResult(minimalPR), nil | ||
| } | ||
| func GetPullRequestDiff(ctx context.Context, client *github.Client, owner, repo string, pullNumber int) (*mcp.CallToolResult, error) { | ||
| // enforcePullRequestLockdown returns a restricted tool result when lockdown mode is | ||
| // enabled and the pull request author is not a safe content source for owner/repo, | ||
| // and (nil, nil) otherwise. It fetches the pull request to resolve the author and is | ||
| // a no-op that performs no request when lockdown mode is disabled. | ||
| func enforcePullRequestLockdown(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int) (*mcp.CallToolResult, error) { | ||
| if !deps.GetFlags(ctx).LockdownMode { | ||
| return nil, nil | ||
| } | ||
| cache, err := deps.GetRepoAccessCache(ctx) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get repo access cache: %w", err) | ||
| } | ||
| pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber) | ||
| if err != nil { | ||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get pull request", resp, err), nil | ||
| } | ||
| defer func() { _ = resp.Body.Close() }() | ||
| if resp.StatusCode != http.StatusOK { | ||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read response body: %w", err) | ||
| } | ||
| return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get pull request", resp, body), nil | ||
| } | ||
| return authorLockdownResult(ctx, cache, owner, repo, pr.GetUser().GetLogin(), lockdownPullRequestRestrictedMessage) | ||
| } | ||
| func GetPullRequestDiff(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int) (*mcp.CallToolResult, error) { | ||
| if restricted, err := enforcePullRequestLockdown(ctx, client, deps, owner, repo, pullNumber); restricted != nil || err != nil { | ||
| return restricted, err | ||
| } | ||
| raw, resp, err := client.PullRequests.GetRaw( | ||
| ctx, | ||
| owner, | ||
| @@ -347,7 +380,11 @@ func GetPullRequestCheckRuns(ctx context.Context, client *github.Client, owner, | ||
| return utils.NewToolResultText(string(r)), nil | ||
| } | ||
| func GetPullRequestFiles(ctx context.Context, client *github.Client, owner, repo string, pullNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) { | ||
| func GetPullRequestFiles(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) { | ||
kerobbi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if restricted, err := enforcePullRequestLockdown(ctx, client, deps, owner, repo, pullNumber); restricted != nil || err != nil { | ||
| return restricted, err | ||
| } | ||
| opts := &github.ListOptions{ | ||
| PerPage: pagination.PerPage, | ||
| Page: pagination.Page, | ||
| @@ -552,17 +589,18 @@ func GetPullRequestReviews(ctx context.Context, client *github.Client, deps Tool | ||
| filteredReviews := make([]*github.PullRequestReview, 0, len(reviews)) | ||
| for _, review := range reviews { | ||
| login := review.GetUser().GetLogin() | ||
| if login != "" { | ||
| isSafeContent, err := cache.IsSafeContent(ctx, login, owner, repo) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to check lockdown mode: %w", err) | ||
| } | ||
| if isSafeContent { | ||
| filteredReviews = append(filteredReviews, review) | ||
| } | ||
| reviews = filteredReviews | ||
| if login == "" { | ||
| continue | ||
| } | ||
| isSafeContent, err := cache.IsSafeContent(ctx, login, owner, repo) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to check lockdown mode: %w", err) | ||
| } | ||
| if isSafeContent { | ||
| filteredReviews = append(filteredReviews, review) | ||
| } | ||
| } | ||
| reviews = filteredReviews | ||
| } | ||
| minimalReviews := make([]MinimalPullRequestReview, 0, len(reviews)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.