mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-04 04:46:59 +01:00
* chore: pnpm — the fleet has one package manager - packageManager pnpm@11.25.0; lockfile via pnpm import, package-lock.json gone - npm overrides moved to pnpm-workspace.yaml overrides (pnpm ignores package.json overrides); allowBuilds for @parcel/watcher, @sentry/cli, @swc/core, esbuild, puppeteer, unrs-resolver, and the ai-forms git dep (pnpm requires the exact resolved URL for git-dep prepare builds) - @tiptap/core added as a direct dependency: RichTextEditor.tsx augments 'module @tiptap/core' and tiptap-markdown's Storage augmentation rides on it — a phantom dependency npm's hoisting hid and pnpm's isolation exposed - all workflows: pnpm/action-setup@v6 before setup-node, cache: pnpm, store-dir pinned, pnpm install --frozen-lockfile; Next cache key now hashes pnpm-lock.yaml - scripts/ci/dependency-audit.sh: pnpm audit --prod (parses both npm-v2 'vulnerabilities' and pnpm's v1 'advisories' shapes) - selfhost-deploy-evig.sh, ship.sh, start-all.sh, e2e-inventory-prod.sh, husky pre-commit, Dockerfile.prod (node 24 + corepack) converted - engines: node >=22.13 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn * fix(deps): declare espree — eslint.config.mjs imports it directly npm's hoisting provided it as a phantom; pnpm's isolated node_modules exposed ERR_MODULE_NOT_FOUND in CI. Verified in a true clean room (parent node_modules masked): full verify green, 7783 tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn * fix(deps): declare tsx — npx fetched it on demand, pnpm exec does not e2e:seed (and the hirn:*/setup-admins scripts) ran 'npx tsx', which silently downloaded tsx because it was never in devDependencies. pnpm exec only resolves installed bins, so CI's Seed E2E step died with 'Command tsx not found'. Declare it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn * fix(ci): drop '--' separators — pnpm run forwards them verbatim npm strips the first '--' before handing args to the script; pnpm 11 passes it through, so 'pnpm run start -- -p 3001' executed 'next start -- -p 3001' and next read '-p' as a project directory. pnpm forwards everything after the script name anyway, so the separator is dead weight: remove it in ci.yml (start, e2e journeys, e2e guards) and ship.sh. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn --------- Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
153 lines
5.5 KiB
Bash
Executable File
153 lines
5.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Dependency advisory check.
|
|
#
|
|
# WHY THIS EXISTS
|
|
# ---------------
|
|
# 2026-08-06: three CRITICAL auth advisories (next-auth / @auth/core) sat open
|
|
# on `main` against a live site and nothing in CI was red. They were noticed
|
|
# only because `git push` happened to print GitHub's "found 10 vulnerabilities"
|
|
# banner. Nothing else surfaced them.
|
|
#
|
|
# The important part: advisories appear with NO code change. A check that only
|
|
# runs on push/PR cannot catch them — the tree that was green yesterday is
|
|
# vulnerable today because someone else published a GHSA. Hence two callers:
|
|
#
|
|
# * ci.yml's `security` job — blocks a PR that INTRODUCES a critical.
|
|
# * security-audit.yml (scheduled) — catches advisories published against
|
|
# code that already merged, and files an issue.
|
|
#
|
|
# WHY CRITICAL BLOCKS BUT HIGH ONLY REPORTS
|
|
# -----------------------------------------
|
|
# A third party publishing an advisory must not be able to halt all shipping:
|
|
# auto-merge refuses to merge onto a red base, so failing CI on every new
|
|
# advisory would jam the entire merge train on someone else's release schedule.
|
|
# Criticals are rare and genuinely urgent, so they block. Everything else is
|
|
# reported loudly and, on the scheduled run, filed as an issue.
|
|
#
|
|
# Inputs (env):
|
|
# FAIL_ON critical | high | none (default: critical)
|
|
# ALERT_ISSUE 1 = file/close a tracking issue for high+ (needs REPO, GH_TOKEN)
|
|
# REPO owner/name (only when ALERT_ISSUE=1)
|
|
|
|
set -euo pipefail
|
|
|
|
FAIL_ON="${FAIL_ON:-critical}"
|
|
ALERT_ISSUE="${ALERT_ISSUE:-0}"
|
|
|
|
tmp=$(mktemp -d)
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
report="$tmp/audit.json"
|
|
|
|
# --prod: a dev-only advisory cannot be reached by the running site, and
|
|
# treating it as production risk is how a gate earns a reputation for crying
|
|
# wolf and gets switched off. pnpm audit exits non-zero when it FINDS things, so
|
|
# its status is not an error signal here — the parsed counts are.
|
|
pnpm audit --prod --json > "$report" 2>/dev/null || true
|
|
|
|
if [ ! -s "$report" ]; then
|
|
echo "::error::pnpm audit produced no output — treating as a failure rather than a pass"
|
|
exit 1
|
|
fi
|
|
|
|
counts=$(python3 - "$report" <<'PY' || true
|
|
import json, sys
|
|
try:
|
|
with open(sys.argv[1]) as fh:
|
|
v = json.load(fh)["metadata"]["vulnerabilities"]
|
|
except Exception:
|
|
raise SystemExit(1)
|
|
print(v.get("critical", 0), v.get("high", 0), v.get("moderate", 0), v.get("low", 0))
|
|
PY
|
|
)
|
|
|
|
if [ -z "$counts" ]; then
|
|
echo "::error::could not parse pnpm audit output — treating as a failure rather than a pass"
|
|
exit 1
|
|
fi
|
|
|
|
read -r crit high mod low <<EOF
|
|
$counts
|
|
EOF
|
|
|
|
echo "runtime advisories — critical:$crit high:$high moderate:$mod low:$low"
|
|
|
|
# Rendered once, reused by the log and the issue body.
|
|
detail=$(python3 - "$report" <<'PY'
|
|
import json, sys
|
|
|
|
with open(sys.argv[1]) as fh:
|
|
data = json.load(fh)
|
|
|
|
# npm audit v2 shape: top-level "vulnerabilities" keyed by package name.
|
|
for name, v in sorted(data.get("vulnerabilities", {}).items()):
|
|
if v.get("severity") not in ("critical", "high"):
|
|
continue
|
|
titles = [x.get("title", "") for x in v.get("via", []) if isinstance(x, dict)]
|
|
title = titles[0][:110] if titles else ""
|
|
fix = v.get("fixAvailable")
|
|
if fix is True:
|
|
fix = "yes"
|
|
elif isinstance(fix, dict):
|
|
fix = "{}@{}".format(fix.get("name"), fix.get("version"))
|
|
else:
|
|
fix = "no"
|
|
print("- **{}** `{}` — {} (fix available: {})".format(v["severity"], name, title, fix))
|
|
|
|
# pnpm audit emits the older v1 shape: top-level "advisories" keyed by id.
|
|
for _id, a in sorted(data.get("advisories", {}).items()):
|
|
if a.get("severity") not in ("critical", "high"):
|
|
continue
|
|
title = (a.get("title") or "")[:110]
|
|
patched = a.get("patched_versions") or "none"
|
|
print("- **{}** `{}` — {} (patched: {})".format(a["severity"], a.get("module_name"), title, patched))
|
|
PY
|
|
)
|
|
|
|
if [ -n "$detail" ]; then
|
|
echo "--- critical/high detail ---"
|
|
printf '%s\n' "$detail"
|
|
fi
|
|
|
|
if [ "$ALERT_ISSUE" = "1" ]; then
|
|
: "${REPO:?REPO is required when ALERT_ISSUE=1}"
|
|
TITLE="🔐 dependency advisories open on main"
|
|
existing=$(gh issue list -R "$REPO" --state open --search "$TITLE in:title" \
|
|
--json number --jq '.[0].number // empty')
|
|
|
|
if [ "$((crit + high))" -gt 0 ]; then
|
|
BODY=$(printf '%s\n' \
|
|
"\`pnpm audit --prod\` on \`main\`: **critical:$crit high:$high** (moderate:$mod low:$low)." \
|
|
"" \
|
|
"$detail" \
|
|
"" \
|
|
"Advisories appear without any code change, so this is found on a schedule rather than on push." \
|
|
"" \
|
|
"Check for a **nested** copy before assuming a bump fixed it — a patched hoisted version can sit alongside a vulnerable one pinned by a dependency (\`npm ls <pkg>\`). That is how a critical survived the bump that was supposed to fix it on 2026-08-06." \
|
|
"" \
|
|
"This issue closes itself when critical and high both reach zero.")
|
|
if [ -n "$existing" ]; then
|
|
gh issue comment "$existing" -R "$REPO" --body "$BODY"
|
|
else
|
|
gh issue create -R "$REPO" --title "$TITLE" --body "$BODY"
|
|
fi
|
|
elif [ -n "$existing" ]; then
|
|
gh issue close "$existing" -R "$REPO" \
|
|
--comment "No critical or high runtime advisories remain (moderate:$mod low:$low)."
|
|
fi
|
|
fi
|
|
|
|
case "$FAIL_ON" in
|
|
critical) blocking=$crit ;;
|
|
high) blocking=$((crit + high)) ;;
|
|
none) blocking=0 ;;
|
|
*) echo "::error::unknown FAIL_ON '$FAIL_ON' (expected critical|high|none)"; exit 1 ;;
|
|
esac
|
|
|
|
if [ "$blocking" -gt 0 ]; then
|
|
echo "::error::dependency audit failed — $FAIL_ON-level advisories present"
|
|
exit 1
|
|
fi
|
|
|
|
echo "no $FAIL_ON-level runtime advisories"
|