mirror of
https://github.com/block/buzz.git
synced 2026-10-28 13:01:10 +00:00
fix(ci): gate security review on repo write access (#7986)
🤖 The Codex Security Review gate trusted GitHub's `author_association` (`MEMBER`/`OWNER`), but GitHub only reports `MEMBER` to viewers who can see the membership. The workflow `GITHUB_TOKEN` cannot see private `block` org membership, which is GitHub's default, so most Block employees read as `CONTRIBUTOR` and their PRs never reviewed automatically. The same applied to the comment path, where private members could not authorize a review with `@buzz-security-review <sha>`. Trust is now repo write access, read from `GET /repos/{owner}/{repo}/collaborators/{user}/permission` via `getCollaboratorPermissionLevel`, which is independent of membership visibility and works with the authorize job's existing `contents: read` and `pull-requests: read` permissions. A user is trusted only when `permission` is `write` (which includes `maintain`) or `admin`. A successful lookup is not enough: on this public repository, an account with no relationship to it returns `200` with `read`, not 404. Outside contributors can only push to forks and come back `read`, so they still need an explicit command from a trusted user. The check covers the PR author on `pull_request_target`, the commenter on `issue_comment` (the job-level `author_association` filter is removed so the trusted script makes that decision), and the stale-marking path on PR updates. Transient API errors are retried. Authorization fails closed: any lookup error other than 404 fails the job instead of authorizing. Stale-marking is conservative: an existing review is always marked stale without consulting permissions, and a failed lookup counts as untrusted, so a previous range's review can never appear current for a new head. A commenter without write access is logged and ignored instead of failing the run. --------- Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
This commit is contained in:
14
.github/workflows/codex-security-review.yml
vendored
14
.github/workflows/codex-security-review.yml
vendored
@@ -16,10 +16,10 @@ jobs:
|
||||
name: Authorize Security Review
|
||||
# This workflow posts an advisory review; its skipped jobs are not a merge
|
||||
# gate and must not be configured as required status checks.
|
||||
# MEMBER and OWNER are GitHub's associations for members of the `block`
|
||||
# organization. The trusted prepare step checks the live PR instead of the
|
||||
# event snapshot. Outside contributors require this exact command from one
|
||||
# of those members: @buzz-security-review <full-head-sha>
|
||||
# The trusted prepare step checks the live PR author's repo permission
|
||||
# (write, maintain, or admin), not author_association, which hides private
|
||||
# org membership from the workflow token. Other PRs require this exact
|
||||
# command from a user with write access: @buzz-security-review <full-head-sha>
|
||||
if: >-
|
||||
github.repository == 'block/buzz' && (
|
||||
(
|
||||
@@ -28,8 +28,7 @@ jobs:
|
||||
) || (
|
||||
github.event_name == 'issue_comment' &&
|
||||
github.event.issue.pull_request &&
|
||||
startsWith(github.event.comment.body, '@buzz-security-review ') &&
|
||||
contains(fromJSON('["MEMBER", "OWNER"]'), github.event.comment.author_association)
|
||||
startsWith(github.event.comment.body, '@buzz-security-review ')
|
||||
)
|
||||
)
|
||||
runs-on: ubuntu-latest
|
||||
@@ -307,7 +306,8 @@ jobs:
|
||||
codex-version: '0.150.1'
|
||||
model: ${{ env.CODEX_MODEL }}
|
||||
codex-args: '["-c","model_reasoning_effort=${{ env.CODEX_REASONING_EFFORT }}"]'
|
||||
# The trusted authorization job already enforced repository membership.
|
||||
# The trusted authorization job already required repo write access for the
|
||||
# PR author or the authorizing commenter.
|
||||
allow-users: '*'
|
||||
safety-strategy: drop-sudo
|
||||
permission-profile: ':read-only'
|
||||
|
||||
Reference in New Issue
Block a user