fix: resolve #355 - PR Agent 无权限校验,存在密钥泄露与滥用风险#366
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough此PR修改了GitHub工作流配置文件,在 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
.github/workflows/pr-agent.yml (2)
8-28: 权限校验逻辑总体正确,但pull_request事件的检查对象需要注意此条件表达式有效地限制了工作流的执行权限,语法正确。但有一个潜在的逻辑细节需要确认:
issue_comment事件:检查github.event.comment.author_association(评论者权限)是正确的。
pull_request事件:当前检查的是github.event.pull_request.author_association(PR 作者的权限),而非触发事件的用户。
- 对于
opened事件,触发者就是作者,没有问题。- 对于
reopened和ready_for_review事件,如果一个协作者重新打开外部用户提交的 PR,工作流将不会运行(因为检查的是 PR 作者而非操作者)。请确认这是否符合预期行为。如果希望允许授权用户操作任意 PR 时都能触发工作流,需要改用 GitHub API 验证
github.actor的仓库权限。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/pr-agent.yml around lines 8 - 28, The current if-condition uses github.event.pull_request.author_association (checks PR author) which misses actions where a different authorized user triggers the event; update the pull_request branch to validate the actual actor instead—use github.actor (or call the GitHub REST API to check the actor's repo permission/association) rather than github.event.pull_request.author_association; keep the issue_comment branch using github.event.comment.author_association or similarly validate github.actor for consistency (ensure you adjust the contains(...) checks to use the actor/permission result).
15-16: 建议:确认是否需要包含CONTRIBUTOR角色当前仅允许
OWNER、MEMBER、COLLABORATOR三种角色。CONTRIBUTOR(曾为仓库贡献过代码的用户)被排除在外。如果项目希望允许历史贡献者触发 PR Agent,需要将
"CONTRIBUTOR"添加到列表中。如果当前设置符合安全策略,可以忽略此建议。Also applies to: 23-24
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/pr-agent.yml around lines 15 - 16, The workflow currently restricts allowed PR author roles in the condition using fromJSON('["OWNER","MEMBER","COLLABORATOR"]') against github.event.pull_request.author_association; decide whether historical contributors should be permitted and, if so, add "CONTRIBUTOR" to that JSON array (i.e. fromJSON('["OWNER","MEMBER","COLLABORATOR","CONTRIBUTOR"]')), and make the same change for the other identical occurrence noted in the file so both checks are updated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.github/workflows/pr-agent.yml:
- Around line 8-28: The current if-condition uses
github.event.pull_request.author_association (checks PR author) which misses
actions where a different authorized user triggers the event; update the
pull_request branch to validate the actual actor instead—use github.actor (or
call the GitHub REST API to check the actor's repo permission/association)
rather than github.event.pull_request.author_association; keep the issue_comment
branch using github.event.comment.author_association or similarly validate
github.actor for consistency (ensure you adjust the contains(...) checks to use
the actor/permission result).
- Around line 15-16: The workflow currently restricts allowed PR author roles in
the condition using fromJSON('["OWNER","MEMBER","COLLABORATOR"]') against
github.event.pull_request.author_association; decide whether historical
contributors should be permitted and, if so, add "CONTRIBUTOR" to that JSON
array (i.e. fromJSON('["OWNER","MEMBER","COLLABORATOR","CONTRIBUTOR"]')), and
make the same change for the other identical occurrence noted in the file so
both checks are updated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3405cb64-dac7-4911-b52f-76da081774f8
📒 Files selected for processing (1)
.github/workflows/pr-agent.yml
📜 Review details
🔇 Additional comments (2)
.github/workflows/pr-agent.yml (2)
21-21:github.event.issue.pull_request的存在性检查是正确的这个检查确保只有在 PR 相关的 issue 评论(而非普通 issue 评论)时才会触发工作流,符合预期。
38-45: 密钥使用方式符合安全最佳实践敏感信息通过
${{ secrets.* }}引用,不会在日志中暴露。结合上方新增的权限检查,有效降低了密钥滥用风险。
Automated Test ReportPR: #366 | Branch:
Overall: TESTS NOT RUNWorktree setup was blocked before any Go tests could run. Setup failure details
Because the branch could not be fetched into the local repository, the test worktree could not be created, so neither |
d5c12b9 to
f30e9ea
Compare
Closes #355
Summary by CodeRabbit
发行说明