Skip to content

security(ci): pin PR-Agent action,降低 pull_request_target secrets 暴露面 #222

Closed

Description

@appergb

背景

当前 PR-Agent workflow 把多个供应链风险放在一个执行路径里:pull_request_target、repo secrets、写权限、第三方 action 的 mutable ref。这个 issue 只跟踪 PR-Agent workflow 的供应链与 secrets 暴露面。

风险

pull_request_target 使用 base repo 的安全上下文。当前 workflow 虽然没有 checkout PR 分支代码,但它执行的是 the-pr-agent/pr-agent@main。如果上游 action 的 main 分支被篡改、误发布或供应链被攻陷,该 action 会在本仓库上下文里拿到:

  • GITHUB_TOKEN
  • OPENAI_KEY
  • issues / pull-requests write 权限
  • repo contents read 权限

代码证据

  • .github/workflows/pr-agent.yml:3-7:使用 pull_request_target
  • .github/workflows/pr-agent.yml:16-19:授予 issues: write、pull-requests: write、contents: read
  • .github/workflows/pr-agent.yml:22-33:uses: the-pr-agent/pr-agent@main,并注入 GITHUB_TOKEN / OPENAI_KEY

建议修复

  • 把 the-pr-agent/pr-agent@main pin 到完整 commit SHA。
  • 复查 token permissions,能只读就只读,只有需要评论时才给最小写权限。
  • 评估外部 PR 是否必须走 secrets;如果不是,改成 pull_request 的无 secrets 路径或手动/allowlist 触发。
  • 对 issue_comment 触发路径做同样的权限与触发人校验。

验收标准

  • workflow 不再引用第三方 action 的 mutable branch/tag。
  • PR-Agent 运行时权限收敛到实际需要的最小集合。
  • 外部 PR 不会默认获得可读取 repo secrets 的执行路径,除非经过明确的可信触发条件。
  • workflow 注释更新为当前安全模型,避免“没 checkout PR 代码所以安全”的误导。

关联

Activity

  1. added
    bug
    on May 4, 2026
  2. H-Chris233 commented on May 5, 2026

    @H-Chris233
    Collaborator

    认领

  3. self-assigned this
    on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions