99jobs :
1010 review :
1111 name : " security review"
12- runs-on : ${{ github.repository_owner == 'astral-sh' && 'github- ubuntu-24.04-x86_64-4' || 'ubuntu-latest' }}
12+ runs-on : depot- ubuntu-24.04-16
1313 environment : automations
1414 timeout-minutes : 30
1515 permissions :
@@ -21,14 +21,15 @@ jobs:
2121 steps :
2222 - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2323 with :
24+ ref : ${{ github.event.pull_request.head.sha }}
2425 fetch-depth : 0
2526 persist-credentials : false
2627
2728 - name : " Checkout Codex Security plugin"
2829 uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2930 with :
3031 repository : openai/plugins
31- ref : 11c74d6ba24d3a6d48f54a194cd00ef3beea18f9
32+ ref : 1e285826e604f66f7208f7ac4dba0fe8341d1f57
3233 path : .codex-security-plugin
3334 sparse-checkout : |
3435 .agents/plugins
@@ -45,16 +46,43 @@ jobs:
4546
4647 - name : " Collect pull request context"
4748 run : |
48- set -o pipefail
49+ set -euo pipefail
50+
51+ if [ "$(git rev-parse HEAD)" != "$HEAD_SHA" ]; then
52+ echo "The checkout does not match the pull request head." >&2
53+ exit 1
54+ fi
4955
5056 gh pr view "$PULL_REQUEST_NUMBER" \
5157 --repo "$GITHUB_REPOSITORY" \
5258 --json number,title,body,author,baseRefName,baseRefOid,headRefName,headRefOid,isDraft,labels,files,additions,deletions,changedFiles \
5359 > .pull-request-review-event.json
5460
55- gh pr diff "$PULL_REQUEST_NUMBER" \
56- --repo "$GITHUB_REPOSITORY" \
57- > .pull-request-review.diff
61+ if ! jq --exit-status --arg head "$HEAD_SHA" \
62+ '.headRefOid == $head' .pull-request-review-event.json > /dev/null; then
63+ echo "The pull request head changed during review setup." >&2
64+ exit 1
65+ fi
66+
67+ merge_base="$(git merge-base "$BASE_SHA" "$HEAD_SHA")"
68+ jq --null-input --arg base "$merge_base" --arg base_tip "$BASE_SHA" \
69+ --arg head "$HEAD_SHA" \
70+ '{base: $base, base_tip: $base_tip, head: $head}' \
71+ > .pull-request-review-revisions.json
72+
73+ git diff --no-ext-diff --no-textconv --no-renames \
74+ "$merge_base..$HEAD_SHA" > .pull-request-review.diff
75+ git diff --no-ext-diff --no-textconv --no-renames --name-only -z \
76+ "$merge_base..$HEAD_SHA" > "$RUNNER_TEMP/pull-request-review-paths.z"
77+
78+ : > .pull-request-review-paths.txt
79+ while IFS= read -r -d '' path; do
80+ if [[ "$path" == *$'\n'* || "$path" == *$'\r'* ]]; then
81+ echo "A changed path cannot be represented in the scan inventory." >&2
82+ exit 1
83+ fi
84+ printf '%s\n' "$path" >> .pull-request-review-paths.txt
85+ done < "$RUNNER_TEMP/pull-request-review-paths.z"
5886
5987 gh api --paginate --slurp \
6088 "repos/$GITHUB_REPOSITORY/pulls/$PULL_REQUEST_NUMBER/comments?per_page=100" \
@@ -70,28 +98,71 @@ jobs:
7098 env :
7199 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72100 PULL_REQUEST_NUMBER : ${{ github.event.pull_request.number }}
101+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
102+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
73103
74104 - name : " Install cargo nextest"
75105 uses : taiki-e/install-action@6c6fd71fe4fb72c3697d269963d0e15df8adedad # v2.85.10
76106 with :
77107 tool : cargo-nextest
78108
109+ # codex-action configures these only on GitHub-hosted runners.
110+ - name : " Enable Linux user namespaces for bubblewrap"
111+ run : |
112+ current_userns="$(sysctl -n kernel.unprivileged_userns_clone 2>/dev/null || true)"
113+ if [ -n "$current_userns" ] && [ "$current_userns" != "1" ]; then
114+ sudo sysctl -w kernel.unprivileged_userns_clone=1
115+ fi
116+
117+ current_apparmor="$(sysctl -n kernel.apparmor_restrict_unprivileged_userns 2>/dev/null || true)"
118+ if [ -n "$current_apparmor" ] && [ "$current_apparmor" != "0" ]; then
119+ sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
120+ fi
121+
79122 - name : " Review pull request"
80123 id : review
81- uses : openai/codex-action@52fe01ec70a42f454c9d2ebd47598f9fd6893d56 # v1.11
124+ uses : openai/codex-action@c385816875cc2fc8e033ed9d1cba96f8c331210e # v1.11 + GitHub API retry
82125 env :
83126 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
84127 TMPDIR : ${{ runner.temp }}/codex-security
85128 with :
86129 openai-api-key : ${{ secrets.OPENAI_API_KEY }}
87- codex-version : " 0.147.0 "
130+ codex-version : " 0.153.4 "
88131 codex-home : " agents/codex"
89132 effort : high
90133 permission-profile : " pull-request-review"
91134 safety-strategy : drop-sudo
92135 allow-bot-users : " astral-automations-bot[bot],renovate[bot]"
93136 prompt-file : " ${{ runner.temp }}/pull-request-security-review-prompt.md"
94137 output-schema-file : " agents/schemas/pull-request-security-review.json"
138+ output-file : " ${{ runner.temp }}/pull-request-review-result.json"
139+
140+ - name : " Check review coverage"
141+ if : steps.review.outcome == 'success'
142+ env :
143+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
144+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
145+ run : |
146+ set -euo pipefail
147+
148+ if [ "$(git rev-parse HEAD)" != "$HEAD_SHA" ]; then
149+ echo "The review changed the checked-out revision." >&2
150+ exit 1
151+ fi
152+
153+ review="$RUNNER_TEMP/pull-request-review-result.json"
154+ merge_base="$(git merge-base "$BASE_SHA" "$HEAD_SHA")"
155+ git diff --no-ext-diff --no-textconv --no-renames --name-only -z \
156+ "$merge_base..$HEAD_SHA" | LC_ALL=C sort -z \
157+ > "$RUNNER_TEMP/expected-review-paths.z"
158+ jq --join-output '.reviewed_paths[] | . + "\u0000"' "$review" \
159+ | LC_ALL=C sort -z > "$RUNNER_TEMP/reviewed-paths.z"
160+
161+ if ! cmp --silent "$RUNNER_TEMP/expected-review-paths.z" \
162+ "$RUNNER_TEMP/reviewed-paths.z"; then
163+ echo "Infrastructure error: the security review did not account for every changed path" >&2
164+ exit 1
165+ fi
95166
96167 - name : " Upload Codex thread"
97168 if : always()
0 commit comments