Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions .github/workflows/security-guard.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions .github/workflows/security-guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,29 @@ steps:
run: |
DELIM="GHAW_PR_FILES_$(date +%s)"
DIFF_LIMIT=100000
SECURITY_RE='host-iptables|setup-iptables|squid-config|docker-manager|seccomp-profile|domain-patterns|entrypoint\.sh|Dockerfile|(^|/)containers/'
DIFF_TMP="$(mktemp)"
# Include full patches only for security-relevant files (largest first);
# list every other changed file by name so large non-security refactors
# don't bloat the prompt.
gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}/files" --paginate --slurp \
| jq -r --arg re "$SECURITY_RE" '
([.[][]]) as $files
| ([$files[] | select(.filename | test($re))] | sort_by(-(.additions + .deletions))) as $sec
| ([$files[] | select(.filename | test($re) | not)]) as $other
| ( $sec[]
| "### " + .filename + " (+" + (.additions|tostring) + "/-" + (.deletions|tostring) + ") [security-relevant]\n" + (.patch // "(binary or no textual patch)") + "\n" ),
( if ($other | length) > 0
then "\n### Other changed files (not security-relevant — patches omitted to save context):\n"
+ ([$other[] | "- " + .filename + " (+" + (.additions|tostring) + "/-" + (.deletions|tostring) + ")"] | join("\n")) + "\n"
else empty end )
' > "$DIFF_TMP" || true
Comment on lines 69 to +87
DIFF_SIZE="$(wc -c < "$DIFF_TMP" | tr -d ' ')"
{
echo "PR_FILES<<${DELIM}"
gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}/files" \
--paginate --jq '.[] | "### " + .filename + " (+" + (.additions|tostring) + "/-" + (.deletions|tostring) + ")\n" + (.patch // "") + "\n"' \
> "$DIFF_TMP" || true
DIFF_SIZE="$(wc -c < "$DIFF_TMP" | tr -d ' ')"
head -c "$DIFF_LIMIT" "$DIFF_TMP" || true
if [ "$DIFF_SIZE" -gt "$DIFF_LIMIT" ]; then
echo -e "\n[DIFF TRUNCATED at ${DIFF_LIMIT} bytes — use mcp__github__get_pull_request_diff for full context]"
echo -e "\n[DIFF TRUNCATED at ${DIFF_LIMIT} bytes — security-relevant patches are shown first; fetch a still-missing security-relevant file via mcp__github__get_pull_request_diff only if needed]"
fi
echo ""
echo "${DELIM}"
Expand Down Expand Up @@ -126,7 +139,7 @@ steps:

## ⚡ Fast Path

Read the pre-fetched diff below first. If you see `[DIFF TRUNCATED ...]`, fetch full context once with `mcp__github__get_pull_request_diff` before deciding to noop. Only use the fast path when the full diff contains **no** security-weakening changes: no weakened DROP/REJECT or expanded ACCEPT, no egress/domain allowlist expansion, no firewall chain changes, no capability additions, no ACL regressions, no seccomp relaxations, no DNS/wildcard bypass, no input validation weakening, and no secrets. Then call `safeoutputs noop` immediately — do not read additional files or make further tool calls.
Read the pre-fetched diff below first. Security-relevant files are included in full; other changed files are listed by name only. If you see `[DIFF TRUNCATED ...]` and a **security-relevant** patch is missing, fetch just that file's context once with `mcp__github__get_pull_request_diff` before deciding to noop. Only use the fast path when the security-relevant changes contain **no** security-weakening changes: no weakened DROP/REJECT or expanded ACCEPT, no egress/domain allowlist expansion, no firewall chain changes, no capability additions, no ACL regressions, no seccomp relaxations, no DNS/wildcard bypass, no input validation weakening, and no secrets. Then call `safeoutputs noop` immediately — do not read additional files or make further tool calls.

## Repository Context

Expand All @@ -137,9 +150,9 @@ Security-critical files: `src/host-iptables.ts`, `containers/agent/setup-iptable

Analyze PR #${{ github.event.pull_request.number }} in repository ${{ github.repository }}.

1. **Review the pre-fetched diff below** (up to 100 KB of changes are included)
1. **Review the pre-fetched diff below** (security-relevant files in full; other files listed by name)
2. **Batch all independent reads** in a single tool-use block rather than making sequential calls
3. **Use ONLY the pre-fetched diff below.** Do NOT call `gh pr diff`, `gh pr view`, `gh api`, `git diff`, `git log`, or `git show`. Do NOT read files from the checkout. If `[DIFF TRUNCATED ...]` appears, call `mcp__github__get_pull_request_diff` once — then stop making tool calls and analyze inline.
3. **Use ONLY the pre-fetched diff below.** Do NOT call `gh pr diff`, `gh pr view`, `gh api`, `git diff`, `git log`, or `git show`. Do NOT read files from the checkout. If `[DIFF TRUNCATED ...]` appears and a security-relevant patch is missing, call `mcp__github__get_pull_request_diff` once — then stop making tool calls and analyze inline.
4. **Collect evidence** with specific file names, line numbers, and code snippets

## Security Checks
Expand All @@ -149,7 +162,7 @@ Focus: weakened DROP/REJECT, added capabilities (SYS_ADMIN/NET_RAW), expanded AC
## Output Format

**IMPORTANT: Be concise.** Report each security finding in ≤ 150 words. Maximum 5 findings total.
If `[DIFF TRUNCATED ...]` is present, fetch full context once with `mcp__github__get_pull_request_diff` before deciding to noop.
If `[DIFF TRUNCATED ...]` is present and a security-relevant patch is missing, fetch just that file's context once with `mcp__github__get_pull_request_diff` before deciding to noop.

If you find security concerns:
1. Add a comment to the PR explaining each concern
Expand All @@ -165,7 +178,7 @@ If no security issues are found:

**SECURITY**: Be thorough but avoid false positives. Focus on actual security weakening, not code style or refactoring that maintains the same security level.

## Changed Files (Pre-fetched, up to 100 KB)
## Changed Files (Pre-fetched; security-relevant patches in full)

The following PR diff has been pre-computed. Focus your security analysis on these changes:

Expand Down
Loading