Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 70 additions & 18 deletions .github/workflows/security-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ name: Security-Review
# pull_request with a shell. The shell runs in the sandbox of
# Claude Code: a process namespace of its own, without the variables that
# request an identity token, without the token file, without sudo and
# Docker, writing only in the checkout and reaching nothing but the npm
# registry. Nothing of the pull request runs outside it in this job, and
# the checkout, the one place the agent could write, is gone before the
# job runs anything in it again. Where the calling repository names its
# Docker, and reaching nothing but the npm registry. It writes in the
# checkout and, by the rules of the pinned Claude Code, in parts of the
# home and system folders; no program outside the sandbox reads its
# configuration from there (curl -q, jq with a home of its own, Claude Code
# with a configuration folder of its own). Nothing of the pull request runs
# outside it in this job, and the checkout is gone before the job runs
# anything in it again. Where the calling repository names its
# test database (input database), the agent starts a PostgreSQL of its own
# inside that sandbox, for the length of one command; none runs beside it.
# The organisation variable SECURITY_REVIEW_DATABASE, set to "aus",
Expand Down Expand Up @@ -1479,6 +1482,10 @@ jobs:
# unclear (the event unread, issues unread, more than 50 issues, a
# text cut short).
gaps = []
# The issues the pull request closes whose text stays out (written
# from outside, or in a repository of another owner): the report
# names them.
outside_issues = []
try:
with open(os.environ['GITHUB_EVENT_PATH'], encoding='utf-8') as handle:
pull = json.load(handle).get('pull_request') or {}
Expand Down Expand Up @@ -1513,6 +1520,7 @@ jobs:
else:
requirements += ['', f'## Issue {where}#{issue["number"]}',
'', '(Von außerhalb der Organisation geschrieben; der Text ist hier nicht übernommen.)']
outside_issues.append(f'{where}#{issue["number"]}')
if closing['totalCount'] > len(closing['nodes']):
# The rest is not read: a clean result is then unclear.
gaps.append('more than 50')
Expand Down Expand Up @@ -1625,6 +1633,7 @@ jobs:
# Whether the author may write, for the step that stores private
# findings: only such a run counts as checked there.
write(os.path.join(state, 'writer.json'), writer)
write(os.path.join(state, 'issues-outside.json'), outside_issues)

# The call that checks the alerts reads a copy of the base the diff
# runs against: an alert closes on the base branch, so whether it is
Expand Down Expand Up @@ -2664,12 +2673,23 @@ jobs:
AUTHOR_TYPE: ${{ github.event.pull_request.user.type }}
run: |
token_file="$RUNNER_TEMP/anthropic-identity-token"
# The sandbox lets the agent write in parts of the home of the runner,
# and programs this step runs outside it must read no configuration
# from there: jq would load ~/.jq into every filter, the one that
# decides about the credit and the second account included. It gets
# a home of its own here, where the sandbox writes nothing; curl runs
# with -q, and every call of Claude Code with a folder of its own.
tool_home="$RUNNER_TEMP/tool-home"
mkdir -p "$tool_home"
jq() { HOME="$tool_home" command jq "$@"; }
fetch_token() {
# Thirty seconds at most: a hanging request must not eat the time
# of the review, nor of the call for the alerts after it. A failed
# refresh leaves the token there as it is: only a value replaces it.
local value
value="$(curl -sS --fail --max-time 30 -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
# -q first: no .curlrc, which could write the request with its
# token into a file the agent reads.
value="$(curl -q -sS --fail --max-time 30 -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=https://api.anthropic.com" | jq -r '.value // empty')" \
&& [ -n "$value" ] || return 1
# A file of its own for each fetch: the loop in the background and
Expand All @@ -2692,13 +2712,24 @@ jobs:
deny_write=()
# The folder of the helper scripts too: Claude Code starts programs
# by name outside the sandbox, and the agent must leave none there.
# And the whole .git of the checkout: the git Claude Code runs
# outside the sandbox reads its configuration, that of submodules
# under .git/modules included, whose filters it would start; the
# agent only reads there, and the copy for tests has no .git.
# The tool cache both where the runner names it (RUNNER_TOOL_CACHE,
# on the runners of GitHub /opt/hostedtoolcache, where node and
# claude lie) and where a runner of one's own keeps it, beside the
# temp directory. Not the .git of the checkout: the sandbox lays a
# guard of its own over .git/config and creates a file in .git for
# it, and with .git locked it does not start at all
# (OpenGewerk/opengewerk#1177).
# And the folders where Node looks for a module that the bundle of
# an action does not carry: node_modules in every folder above the
# actions and ~/.node_modules and ~/.node_libraries. The actions
# after the agent run outside the sandbox. Made empty here, since
# the lock takes only what exists; those above /home the runner
# user cannot create, and the agent neither.
node_folders=("$(dirname "$RUNNER_TEMP")/node_modules" "$HOME/node_modules" "$HOME/.node_modules" "$HOME/.node_libraries")
mkdir -p "${node_folders[@]}"
for path in "$RUNNER_TEMP" "$(dirname "$RUNNER_TEMP")/_actions" "$(dirname "$RUNNER_TEMP")/_tool" \
"$GITHUB_WORKSPACE/pr/.security-review/bin" "$GITHUB_WORKSPACE/pr/.git"; do
if [ -e "$path" ]; then
"${RUNNER_TOOL_CACHE:-}" "$GITHUB_WORKSPACE/pr/.security-review/bin" "${node_folders[@]}"; do
if [ -n "$path" ] && [ -e "$path" ]; then
deny_write+=("$path")
fi
done
Expand Down Expand Up @@ -2785,15 +2816,21 @@ jobs:
# write there (deny_write above). Its scripts have names of their own.
search_path="$PATH:$GITHUB_WORKSPACE/pr/.security-review/bin"
# Claude Code runs git itself, outside the sandbox, in a checkout the
# agent writes in. Two layers keep a configuration the agent leaves
# from starting anything there: the sandbox locks .git for the agent
# (above), and Claude Code runs its git with hooks and fsmonitor off
# and status without the work trees of submodules. The second is the
# pinned version's own (CLAUDE_CODE_VERSION) and clears any
# GIT_CONFIG_* of this environment: check it when raising the pin.
# agent writes in. Three layers keep a configuration the agent leaves
# from starting anything there: the sandbox guards .git/config itself;
# Claude Code runs its git with hooks and fsmonitor off and status
# without the work trees of submodules; and once the agent has used a
# tool, no second run starts in this checkout (used_tools below). The
# first two are the pinned version's own (CLAUDE_CODE_VERSION), and it
# clears any GIT_CONFIG_* of this environment: check them when raising
# the pin.
# Check then too that it reads neither bunfig.toml nor .env from the
# folder it starts in, the checkout of the pull request: a preload
# that leaves a mark, an .env that names another API address.
# A configuration folder of its own for each call, where the sandbox
# writes nothing: the settings and hooks a later call reads are never
# what the agent of an earlier one left in the home of the runner.
config_dir="$RUNNER_TEMP/claude-main"
run_review() {
env -u ACTIONS_ID_TOKEN_REQUEST_TOKEN -u ACTIONS_ID_TOKEN_REQUEST_URL \
ANTHROPIC_IDENTITY_TOKEN_FILE="$token_file" \
Expand All @@ -2805,6 +2842,7 @@ jobs:
npm_config_store_dir="$cache/pnpm-store" \
XDG_CACHE_HOME="$cache/xdg" \
DISABLE_AUTOUPDATER=1 BUN_RUNTIME_TRANSPILER_CACHE_PATH=0 \
CLAUDE_CONFIG_DIR="$config_dir" \
"$@" \
"${limit[@]}" claude -p --safe-mode --setting-sources user --strict-mcp-config --no-session-persistence \
--settings "$run_settings" \
Expand Down Expand Up @@ -2870,8 +2908,8 @@ jobs:
ANTHROPIC_ORGANIZATION_ID="$FALLBACK_ORGANIZATION_ID"
ANTHROPIC_SERVICE_ACCOUNT_ID="$FALLBACK_SERVICE_ACCOUNT_ID"
ANTHROPIC_WORKSPACE_ID="$FALLBACK_WORKSPACE_ID"
CLAUDE_CONFIG_DIR="$RUNNER_TEMP/claude-fallback"
)
config_dir="$RUNNER_TEMP/claude-fallback"
run_review "${account[@]}"
code=$?
if out_of_credit; then
Expand Down Expand Up @@ -2921,6 +2959,7 @@ jobs:
denied=(Bash WebFetch WebSearch Write Edit NotebookEdit)
search_path="$PATH"
cache="$RUNNER_TEMP/alerts-cache"
config_dir="$RUNNER_TEMP/claude-alerts"
(cd "$RUNNER_TEMP/alerts-base" && scrub=0 && run_review "${account[@]}")
echo "Die Prüfung der privaten Befunde endete mit Exit $?."
fi
Expand Down Expand Up @@ -3254,6 +3293,16 @@ jobs:
# does not say clean where the check fails.
closing_lines = ['Der Workflow wertet dieses Ergebnis als unklar: ' + ' '.join(doubts), '',
'REVIEW_RESULT: unclear', 'REVIEW_COMPLETE']
# Issues the pull request closes whose text did not go to the review:
# named, so that a clean result does not read as measured against
# them, whatever the result. No doubt: a fix of a report from outside
# would never be clean.
outside = [entry for entry in load('issues-outside.json', []) if isinstance(entry, str)
and re.fullmatch(r'[A-Za-z0-9._-]+/[A-Za-z0-9._-]+#[0-9]+', entry)][:50]
if outside and closing_lines:
closing_lines = ['Nicht gemessen an ' + ', '.join(outside) + ': Der Text ging nicht an das Review '
'(von außerhalb der Organisation geschrieben oder aus einem fremden Repository).',
''] + closing_lines
# The dispositions of the private findings of earlier runs, from the
# call of their own after the review; only the last block counts, only
# numbers handed over, each once.
Expand Down Expand Up @@ -3325,6 +3374,9 @@ jobs:
- name: Private Befunde als Code-Scanning-Alerts ablegen
env:
GH_TOKEN: ${{ github.token }}
# A configuration folder of its own: the sandbox let the agent write
# in parts of the home, and gh reads its configuration from there.
GH_CONFIG_DIR: ${{ runner.temp }}/gh-config
PR_NUMBER: ${{ github.event.pull_request.number }}
AUTHOR_TYPE: ${{ github.event.pull_request.user.type }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Das gilt für jede Datei in jedem Repository der Organisation, und die CI prüft
3. Pull Request eröffnen, die Vorlage ausfüllen und auf das zugehörige Issue verweisen. Soll der Pull Request ein Issue schließen, gehört unter den deutschen Text eine englische Zeile `Closes #<Nummer>`: GitHub erkennt nur die englischen Schlüsselwörter, ein „Schließt #12“ bewirkt nichts.
4. Auf die Prüfung warten. `main` ist geschützt, direkte Pushes gibt es nicht.

Jeder Pull Request bekommt dazu ein automatisches Security-Review, ein Entwurf erst, wenn er bereit zur Prüfung ist. Es erscheint als Review am Pull Request und als Prüfung `PR-Security-Review`. Als Befund am Pull Request gilt nur, was er einführt, ändert oder neu erreichbar macht. Steht die Zeile eines solchen Befunds im Diff, hängt es einen Kommentar an diese Zeile, liegt sie sonst in einer geänderten Datei, an die Datei, höchstens 50 neue je Lauf; was darüber hinausgeht, außerhalb der geänderten Dateien liegt oder in einer Datei, die GitHub bei sehr großen Pull Requests nicht mehr auflistet, steht nur im Review. Eine Schwachstelle, die schon vorher bestand und die der Pull Request weder ändert noch neu erreichbar macht, bleibt privat, auch wenn er ihre Datei ändert: Sie steht als Code-Scanning-Alert im Repository, den nur sieht, wer dort schreiben darf. Ist der Befund eines solchen Kommentars behoben, stellt ein späterer Lauf das fest, antwortet im Thread und schließt ihn. Ein Fehler, der schon vorher bestand und keine Schwachstelle ist, steht im Review unter "Nebenbei gefunden" und macht die Prüfung nicht rot. Konnte das Review mangels Guthaben nicht abschließen, bleibt die Prüfung neutral, und am Pull Request erscheint kein Review. Geprüft wird jeweils der neueste Commit. Ändern sich Head oder Zielzweig, während das Review läuft, wird die Prüfung nicht grün: neutral, wenn es nichts findet und keinen Thread offen lässt, sonst rot. Wird der Pull Request erst danach auf einen anderen Zielzweig umgestellt, prüft erst ein neuer Push oder das Wiederöffnen neu. Kommt der Pull Request aus einem Fork oder von außerhalb der Organisation, liest das Review den Code nur und führt nichts davon aus, und es startet erst, wenn ein Maintainer es freigibt. Pull Requests des Coding-Agents von CodeRabbit aus einem Branch des Repositorys prüft es wie die eines Mitglieds, ohne Freigabe. Ein Approve gibt es ihnen nie: Findet das Review etwas oder bleibt es unklar, bittet es um Änderungen, sonst bleibt es bei einem Kommentar. Das Review ist ein Hinweis, keine Freigabe: gemergt wird nach dem Blick eines Menschen.
Jeder Pull Request bekommt dazu ein automatisches Security-Review, ein Entwurf erst, wenn er bereit zur Prüfung ist. Es erscheint als Review am Pull Request und als Prüfung `PR-Security-Review`. Als Befund am Pull Request gilt nur, was er einführt, ändert oder neu erreichbar macht. Steht die Zeile eines solchen Befunds im Diff, hängt es einen Kommentar an diese Zeile, liegt sie sonst in einer geänderten Datei, an die Datei, höchstens 50 neue je Lauf; was darüber hinausgeht, außerhalb der geänderten Dateien liegt oder in einer Datei, die GitHub bei sehr großen Pull Requests nicht mehr auflistet, steht nur im Review. Eine Schwachstelle, die schon vorher bestand und die der Pull Request weder ändert noch neu erreichbar macht, bleibt privat, auch wenn er ihre Datei ändert: Sie steht als Code-Scanning-Alert im Repository, den nur sieht, wer dort schreiben darf. Ist der Befund eines solchen Kommentars behoben, stellt ein späterer Lauf das fest, antwortet im Thread und schließt ihn. Ein Fehler, der schon vorher bestand und keine Schwachstelle ist, steht im Review unter "Nebenbei gefunden" und macht die Prüfung nicht rot. Konnte das Review mangels Guthaben nicht abschließen, bleibt die Prüfung neutral, und am Pull Request erscheint kein Review. Geprüft wird jeweils der neueste Commit; wird nur Titel oder Beschreibung geändert, startet kein neues Review. Issues, die der Pull Request schließt und die jemand von außerhalb der Organisation geschrieben hat oder die in einem Repository eines anderen Eigentümers liegen, misst es nicht, und das Review nennt sie. Ändern sich Head oder Zielzweig, während das Review läuft, wird die Prüfung nicht grün: neutral, wenn es nichts findet und keinen Thread offen lässt, sonst rot. Wird der Pull Request erst danach auf einen anderen Zielzweig umgestellt, prüft erst ein neuer Push oder das Wiederöffnen neu. Kommt der Pull Request aus einem Fork oder von außerhalb der Organisation, liest das Review den Code nur und führt nichts davon aus, und es startet erst, wenn ein Maintainer es freigibt. Pull Requests des Coding-Agents von CodeRabbit aus einem Branch des Repositorys prüft es wie die eines Mitglieds, ohne Freigabe. Ein Approve gibt es ihnen nie: Findet das Review etwas oder bleibt es unklar, bittet es um Änderungen, sonst bleibt es bei einem Kommentar. Das Review ist ein Hinweis, keine Freigabe: gemergt wird nach dem Blick eines Menschen.

Große Änderungen bitte vorher als Issue oder Discussion abstimmen. Ein fertiger Pull Request, dessen Richtung nicht passt, ist für beide Seiten ärgerlich.

Expand Down