# good
-weight: 500;">npm ci # bad
-weight: 500;">npm -weight: 500;">install
# good
-weight: 500;">npm ci # bad
-weight: 500;">npm -weight: 500;">install
# good
-weight: 500;">npm ci # bad
-weight: 500;">npm -weight: 500;">install
#!/usr/bin/env bash
# scan--weight: 500;">install.sh — flag suspicious -weight: 500;">npm -weight: 500;">install events
set -euo pipefail PKG_JSON="${1:-package.json}"
LOCK="${2:-package-lock.json}"
ALERTS=0 flag() { echo "ALERT: $1"; ALERTS=$((ALERTS + 1)); } # 1. Lockfile must exist and be up to date
[ -f "$LOCK" ] || flag "no lockfile found" # 2. Detect packages with postinstall scripts
node -e '
const lock = require(process.argv[1]);
const pkgs = lock.packages || {};
for (const [path, p] of Object.entries(pkgs)) { if (p.scripts && (p.scripts.postinstall || p.scripts.preinstall || p.scripts.-weight: 500;">install)) { console.log("HOOK:" + path); }
}
' "$LOCK" | while read line; do flag "$line"
done # 3. Recently published versions are suspicious
-weight: 500;">npm outdated --json --all 2>/dev/null \ | node -e '
let buf=""; process.stdin.on("data",d=>buf+=d);
process.stdin.on("end",()=>{ if(!buf) return; const o = JSON.parse(buf); for (const [name, info] of Object.entries(o)) { if (info.latest === info.wanted) continue; console.log("UPDATE:" + name + ":" + info.latest); }
});' # 4. Block -weight: 500;">install if any alert tripped without sign-off
if [ "$ALERTS" -gt 0 ] && [ -z "${ALLOW_RISKY:-}" ]; then echo "Aborting. Set ALLOW_RISKY=1 after manual review." exit 1
fi
#!/usr/bin/env bash
# scan--weight: 500;">install.sh — flag suspicious -weight: 500;">npm -weight: 500;">install events
set -euo pipefail PKG_JSON="${1:-package.json}"
LOCK="${2:-package-lock.json}"
ALERTS=0 flag() { echo "ALERT: $1"; ALERTS=$((ALERTS + 1)); } # 1. Lockfile must exist and be up to date
[ -f "$LOCK" ] || flag "no lockfile found" # 2. Detect packages with postinstall scripts
node -e '
const lock = require(process.argv[1]);
const pkgs = lock.packages || {};
for (const [path, p] of Object.entries(pkgs)) { if (p.scripts && (p.scripts.postinstall || p.scripts.preinstall || p.scripts.-weight: 500;">install)) { console.log("HOOK:" + path); }
}
' "$LOCK" | while read line; do flag "$line"
done # 3. Recently published versions are suspicious
-weight: 500;">npm outdated --json --all 2>/dev/null \ | node -e '
let buf=""; process.stdin.on("data",d=>buf+=d);
process.stdin.on("end",()=>{ if(!buf) return; const o = JSON.parse(buf); for (const [name, info] of Object.entries(o)) { if (info.latest === info.wanted) continue; console.log("UPDATE:" + name + ":" + info.latest); }
});' # 4. Block -weight: 500;">install if any alert tripped without sign-off
if [ "$ALERTS" -gt 0 ] && [ -z "${ALLOW_RISKY:-}" ]; then echo "Aborting. Set ALLOW_RISKY=1 after manual review." exit 1
fi
#!/usr/bin/env bash
# scan--weight: 500;">install.sh — flag suspicious -weight: 500;">npm -weight: 500;">install events
set -euo pipefail PKG_JSON="${1:-package.json}"
LOCK="${2:-package-lock.json}"
ALERTS=0 flag() { echo "ALERT: $1"; ALERTS=$((ALERTS + 1)); } # 1. Lockfile must exist and be up to date
[ -f "$LOCK" ] || flag "no lockfile found" # 2. Detect packages with postinstall scripts
node -e '
const lock = require(process.argv[1]);
const pkgs = lock.packages || {};
for (const [path, p] of Object.entries(pkgs)) { if (p.scripts && (p.scripts.postinstall || p.scripts.preinstall || p.scripts.-weight: 500;">install)) { console.log("HOOK:" + path); }
}
' "$LOCK" | while read line; do flag "$line"
done # 3. Recently published versions are suspicious
-weight: 500;">npm outdated --json --all 2>/dev/null \ | node -e '
let buf=""; process.stdin.on("data",d=>buf+=d);
process.stdin.on("end",()=>{ if(!buf) return; const o = JSON.parse(buf); for (const [name, info] of Object.entries(o)) { if (info.latest === info.wanted) continue; console.log("UPDATE:" + name + ":" + info.latest); }
});' # 4. Block -weight: 500;">install if any alert tripped without sign-off
if [ "$ALERTS" -gt 0 ] && [ -z "${ALLOW_RISKY:-}" ]; then echo "Aborting. Set ALLOW_RISKY=1 after manual review." exit 1
fi - Book: AI Agents Pocket Guide
- Also by me: Database Playbook
- My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools
- Me: xgabriel.com | GitHub - Quarantine new versions of critical packages until a 24-hour soak window passes.
- Block packages with a postinstall hook unless explicitly allowlisted.
- Audit who is pulling what. - Switch your CI from -weight: 500;">npm -weight: 500;">install to -weight: 500;">npm ci. Audit any failures. They are signal, not noise.
- Stand up a registry mirror or turn on the one your enterprise license already includes. Configure a soak window for new versions of the top 50 packages your fleet depends on.
- Wire the script above (or your equivalent) into the build, gated by an environment variable so engineers can override after manual review.