Repository navigation
fix(lockdown): check bot accounts with [bot] suffix in review comments - #3783
yunusarda-sudo wants to merge 7 commits into
Conversation
When lockdown mode filters pull request review comments, author logins retrieved via the GraphQL API (Actor interface) omit the [bot] suffix for bot accounts. Calling the REST collaborator permission endpoint without the [bot] suffix returns 404, causing get_review_comments to fail prematurely. - Update reviewCommentNode.Author to query __typename - Normalize bot logins by restoring [bot] suffix in getPullRequestReviewComments - Add fallback handling in RepoAccessCache.checkPushAccess for 404 on bot logins - Add unit tests for bot permissions under lockdown mode Fixes github#3777 Reported-by: Martin Nowak <dawg@users.noreply.github.com> Signed-off-by: Yunus Ardaguney <yunusarda-sudo@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The untyped permission-lookup fallback can apply another account’s permissions or trusted status to the original author, while bot normalization also breaks recognition of the explicitly trusted Copilot identity.
2 open issues
What changed in this PR
Addresses #3777 by normalizing GraphQL bot logins for lockdown permission checks on pull request review comments.
Changes:
- Fetch author types and append
[bot]to bot logins before permission checks. - Add a suffix-based retry when REST permission lookups return 404.
- Add regression tests for trusted bots and differing repository permissions.
| File | Description |
|---|---|
pkg/lockdown/lockdown.go |
Adds the 404-triggered bot-login retry. |
pkg/lockdown/lockdown_test.go |
Tests bot permissions and raw-login fallback. |
pkg/github/pullrequests.go |
Fetches actor types and normalizes review-comment authors. |
pkg/github/pullrequests_test.go |
Tests lockdown filtering for bot review comments. |
pkg/github/lockdown.go |
Adds the bot-login normalization helper. |
Review effort: Max (auto)
| if resp != nil && resp.StatusCode == http.StatusNotFound && !strings.HasSuffix(username, "[bot]") { | ||
| botUsername := username + "[bot]" | ||
| if c.isTrustedBot(botUsername) { | ||
| return true, nil |
There was a problem hiding this comment.
Done — the untyped 404 fallback is gone. A permission-lookup 404 is treated as a lookup failure, and the [bot] suffix is applied only for actors positively identified as Bot.
| if login != "" && typename == "Bot" && !strings.HasSuffix(login, "[bot]") { | ||
| return login + "[bot]" | ||
| } |
There was a problem hiding this comment.
Done — a Bot actor whose login is copilot (matched case-insensitively) is left unchanged, so it still matches the trusted-bot list. Other Bot actors such as GitHub Actions still get the [bot] suffix. Added a regression test for that rewrite.
…allback - Preserve built-in trusted 'copilot' identity case-insensitively in actorLoginWithBotSuffix - Remove untyped 404 fallback in RepoAccessCache.checkPushAccess to strictly rely on Bot actor typing - Add test coverage for copilot review comment preservation under lockdown mode Signed-off-by: Yunus Ardaguney <yunusarda-sudo@users.noreply.github.com>
|
Updated in
|
52efc90 to
1deabab
Compare
actorLoginWithBotSuffix already leaves the built-in "copilot" identity alone, case-insensitively, while still suffixing other Bot actors such as GitHub Actions. Add a regression test so that rewrite cannot silently change.


Summary
Fixes lockdown mode failure when checking repository permissions for bot accounts in
get_review_comments.Why
Fixes #3777
When lockdown mode filters pull request review comments, author logins retrieved via GraphQL (Actor interface) omit the
[bot]suffix. The REST collaborator permission endpoint requires the canonical[bot]suffix for bot/app accounts, returning a 404 (<bot-user> is not a user) and causing theget_review_commentstool to fail.What changed
__typenametoreviewCommentNode.Authorinpkg/github/pullrequests.go.actorLoginWithBotSuffixhelper inpkg/github/lockdown.goto append[bot]when GraphQL actor typename isBot.getPullRequestReviewCommentsbefore queryingRepoAccessCache.IsSafeContent.RepoAccessCache.checkPushAccess(pkg/lockdown/lockdown.go) to retry with[bot]suffix when receiving a 404 for an actor login lacking[bot].pkg/github/pullrequests_test.goandpkg/lockdown/lockdown_test.go.MCP impact
Lockdown mode now correctly verifies permissions for bot authors instead of failing with 404.
Prompts tested (tool changes only)
Security / limits
Bot authors now have their permissions accurately validated via their canonical bot logins, ensuring unauthorized bot content remains filtered while authorized bots are safely displayed.
Tool renaming
Lint & tests
./script/lint./script/testDocs