fix(ci): close the fail-open gate, enforce read-only sandbox
PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / ESLint (pull_request) Successful in 35s
PR Check / Typecheck (pull_request) Canceled after 21s
PR Check / Secret scan (gitleaks) (pull_request) Canceled after 0s
PR Check / Dependency audit (pull_request) Canceled after 0s
PR Check / Dockerfile lint (droast) (pull_request) Canceled after 0s
PR Check / AI code review (opencode) (pull_request) Canceled after 0s

Findings validated from review comments 71 and 75:

- [BLOCKER] the no-verdict branch exited \${EXIT_CODE:-1} which is 0
  when opencode succeeded without a verdict - job went green and the
  post step published non-review output. The else branch now exits 1
  unconditionally, the verdict is anchored to the last five lines (the
  prompt itself contains VERDICT lines), and the post step re-verifies
  the contract before posting.
- [BLOCKER] the v1 'permission' object is ignored by the opencode v2
  CLI - shell commands executed in both review runs despite deny. The
  config now uses the v2 'permissions' array with 'shell' as the
  action name, denying edit/shell/webfetch/websearch/external_directory.
- hygiene: droast linting prunes node_modules, audit comment names the
  exact key to re-add, shell blocks verified with sh -n.
This commit is contained in:
Noel Sabia committed 2026-10-18 18:24:06 +02:00
1 parent cefdb34d7e
commit 3e68e630df
1 file changed
+34 -13
+34 -13
View File
@@ -109,8 +109,9 @@ jobs:
- name: Audit dependencies for known vulnerabilities
working-directory: ${{ env.APP_DIR }}
run: pnpm audit --prod --audit-level moderate
# blocks the PR on vulnerabilities - flip to true only if a CVE fix
# is genuinely blocked, never to make red pipelines "go away"
# blocks the PR on vulnerabilities - re-add `continue-on-error: true`
# here only if a CVE fix is genuinely blocked upstream, never to
# make a red pipeline green
# ------------------------------------------------------- dockerfile lint --
dockerfile-lint:
@@ -164,7 +165,13 @@ jobs:
run: |
# --no-roast = technical output for CI; --min-severity warning so
# info-level findings don't block the PR
droast --no-roast --min-severity warning .
# lint exactly the tree the discovery step sees: prune node_modules
# and .git so vendored Dockerfiles in dependencies cannot produce
# findings on third-party code
find . \
-path ./.git -prune -o -path ./node_modules -prune -o \
-type f \( -iname 'Dockerfile*' -o -iname '*dockerfile' -o -iname 'Containerfile*' \) \
-print0 | xargs -0 -r droast --no-roast --min-severity warning
# ------------------------------------------------------- snyk security ----
# DISABLED: Snyk free plan only includes ~100 test credits/month, which the
@@ -257,17 +264,19 @@ jobs:
# prompt-inject the agent into quoting the key in the review
# comment (publicly visible). Env vars are invisible to file reads.
# Permissions live in a global config OUTSIDE the checkout (no
# secrets in it, so nothing can leak): denying edit/bash/webfetch
# means no headless permission prompts can hang or kill the run,
# and the reviewer physically cannot modify the repo.
mkdir -p "$HOME/.config/opencode"
# OpenCode v2 permission schema: ordered array of
# secrets in it, so nothing can leak). OpenCode v2 schema: the
# field is "permissions" (plural) - an ordered array of
# {action, resource, effect}; "bash" was renamed "shell" in v2.
# websearch is a distinct action from webfetch - deny both, plus
# external directories.
# The singular v1 "permission" object is ignored by the v2 CLI
# (verified empirically: shell commands executed despite deny).
# Denying shell/edit/webfetch/websearch/external_directory means
# no headless permission prompts can hang or kill the run, and
# the reviewer physically cannot modify the repo or browse
# attacker-controlled URLs.
mkdir -p "$HOME/.config/opencode"
printf '{
"$schema": "https://opencode.ai/config.json",
"permission": [
"permissions": [
{ "action": "edit", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
@@ -355,12 +364,18 @@ jobs:
# dumps never do. opencode can exit 1 on benign tool denials
# even after a full review, so a present verdict means post;
# anything else means the review did not complete.
if grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)' /tmp/review.md; then
# Anchored to the tail: the prompt itself contains VERDICT
# lines, so scanning the whole file could pass on echoed
# prompt text or injected quotes - only the last lines count.
if tail -n 5 /tmp/review.md | grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)'; then
[ "$EXIT_CODE" -ne 0 ] && echo "::warning::opencode exited ${EXIT_CODE} but produced a valid verdict - posting review"
echo "Review completed with verdict."
else
# fail closed: no verdict = no review. exit 1 unconditionally -
# falling back to EXIT_CODE would exit 0 when opencode succeeded
# but produced no review, and the job would go green.
echo "::error::opencode produced no valid review (exit ${EXIT_CODE:-1}) - NOT posting this output as a review comment"
exit "${EXIT_CODE:-1}"
exit 1
fi
- name: Post review as PR comment
@@ -371,6 +386,12 @@ jobs:
REPO: ${{ github.repository }}
# Gitea sets GITHUB_API_URL, e.g. https://gitea.example.com/api/v1
run: |
# re-verify the output contract here: never post anything that is
# not a completed review, regardless of how the previous step ended
if ! tail -n 5 /tmp/review.md | grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)'; then
echo "::error::no verdict in review output - nothing to post"
exit 1
fi
# jq is not in the node image - use node for JSON encoding
BODY=$(node -e 'process.stdout.write(JSON.stringify(require("fs").readFileSync("/tmp/review.md","utf8")))')
HTTP_CODE=$(curl -s -o /tmp/comment-response.json -w "%{http_code}" \