Skip to content

Commit cc733bf

Browse files
committed
chore: add security scanning and enforce no-npx rule
- Add ecc-agentshield as pinned devDep for Claude Code config scanning - Add `pnpm run security` script (agentshield + zizmor) - Add /security-scan command for Claude - Add npx/dlx/yarn-dlx check to pre-commit hook - Add NEVER npx/dlx rule to CLAUDE.md ABSOLUTE RULES - Remove dead .husky/security-checks.sh (duplicate of .git-hooks/pre-commit)
1 parent c403600 commit cc733bf

File tree

7 files changed

+252
-125
lines changed

7 files changed

+252
-125
lines changed

.claude/commands/security-scan.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Run a security scan of the project via `pnpm run security`, or manually:
2+
3+
## 1. Claude Code configuration security
4+
5+
Run `pnpm exec agentshield scan` to check `.claude/` for:
6+
- Hardcoded secrets in CLAUDE.md and settings
7+
- Overly permissive tool allow lists (e.g. `Bash(*)`)
8+
- Prompt injection patterns in agent definitions
9+
- Command injection risks in hooks
10+
- Risky MCP server configurations
11+
12+
## 2. GitHub Actions workflow security
13+
14+
Run `zizmor .github/` to scan all workflows for:
15+
- Unpinned actions (should use full SHA, not tags)
16+
- Secrets used outside `env:` blocks
17+
- Injection risks from untrusted inputs
18+
- Overly permissive permissions
19+
20+
If zizmor is not installed, skip with a message. Install via `brew install zizmor` or see https://docs.zizmor.sh/installation/.
21+
22+
Report all findings with severity levels. Fix CRITICAL and HIGH findings immediately.

.git-hooks/pre-commit

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ for file in $STAGED_FILES; do
112112
fi
113113
done
114114

115+
# Check for npx/dlx usage (use pnpm exec or pnpm run instead).
116+
printf "Checking for npx/dlx usage...\n"
117+
for file in $STAGED_FILES; do
118+
if [ -f "$file" ]; then
119+
# Skip node_modules, lockfiles, and this hook itself.
120+
if echo "$file" | grep -qE 'node_modules/|pnpm-lock\.yaml|\.git-hooks/'; then
121+
continue
122+
fi
123+
124+
if grep -nE '\bnpx\b|\bpnpm dlx\b|\byarn dlx\b' "$file" 2>/dev/null | grep -v '# zizmor:' | grep -q .; then
125+
printf "${RED}✗ ERROR: npx/dlx usage found in: $file${NC}\n"
126+
grep -nE '\bnpx\b|\bpnpm dlx\b|\byarn dlx\b' "$file" | grep -v '# zizmor:' | head -3
127+
printf "Use 'pnpm exec <package>' or 'pnpm run <script>' instead.\n"
128+
ERRORS=$((ERRORS + 1))
129+
fi
130+
fi
131+
done
132+
115133
if [ $ERRORS -gt 0 ]; then
116134
printf "\n"
117135
printf "${RED}✗ Security check failed with $ERRORS error(s).${NC}\n"

.husky/security-checks.sh

Lines changed: 0 additions & 125 deletions
This file was deleted.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
- Always prefer editing existing files
7070
- Forbidden to create docs unless requested
7171
- Required to do exactly what was asked
72+
- 🚨 **NEVER use `npx`, `pnpm dlx`, or `yarn dlx`** — use `pnpm exec <package>` for devDep binaries, or `pnpm run <script>` for package.json scripts. If a tool is needed, add it as a pinned devDependency first.
7273

7374
## ROLE
7475

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"package-npm-publish": "node scripts/npm/publish-npm-packages.mjs",
4141
"perf": "node scripts/perf.mjs",
4242
"precommit": "pnpm run check --staged",
43+
"security": "agentshield scan && { command -v zizmor >/dev/null && zizmor .github/ || echo 'zizmor not installed — skipping workflow scan'; }",
4344
"prepare": "husky && pnpm run build",
4445
"prepublishOnly": "echo 'ERROR: Use GitHub Actions workflow for publishing' && exit 1",
4546
"publish": "node scripts/publish.mjs",
@@ -91,6 +92,7 @@
9192
"del-cli": "catalog:",
9293
"dev-null-cli": "catalog:",
9394
"didyoumean2": "catalog:",
95+
"ecc-agentshield": "catalog:",
9496
"esbuild": "catalog:",
9597
"eta": "catalog:",
9698
"fast-glob": "catalog:",

0 commit comments

Comments
 (0)