Skip to content

Commit f7edf84

Browse files
committed
chore: harden .env allowlist in commit-msg hook + add **/.cache/ ignore
Switches the commit-msg .env check to basename-based matching so nested .env.test files (e.g., .env.precommit, packages/<pkg>/.env.test) are not blocked, and adds .env.precommit to the allowlist alongside .env.example and .env.test. Previous regex was anchored to the repo root and let through nested .env files entirely. Adds **/.cache/ to .gitignore as a defensive ignore for stray writers (Node compile-cache, corepack, pnpm RC). Tools we control already write to node_modules/.cache/ which is covered by **/node_modules.
1 parent 9d5f189 commit f7edf84

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

.git-hooks/commit-msg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ if [ -n "$COMMITTED_FILES" ]; then
2323
ERRORS=$((ERRORS + 1))
2424
fi
2525

26-
# Check for .env files.
27-
if echo "$file" | grep -qE '^\.env(\.[^/]+)?$' && ! echo "$file" | grep -qE '^\.env\.(example|test)$'; then
26+
# Check for .env files. Allow committed templates (.env.example,
27+
# .env.test, .env.precommit) at any depth — they're tooling
28+
# config, not secrets. Block bare .env / .env.local at any depth.
29+
base=$(basename "$file")
30+
if echo "$base" | grep -qE '^\.env(\.[^/]+)?$' && ! echo "$base" | grep -qE '^\.env\.(example|test|precommit)$'; then
2831
printf "${RED}✗ SECURITY: .env file in commit!${NC}\n"
2932
ERRORS=$((ERRORS + 1))
3033
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ desktop.ini
5959
# store scratch dirs — cleared by pnpm install automatically).
6060
node_modules
6161
**/node_modules
62+
# Defensive cache ignore — Node compile-cache, corepack, and other
63+
# tools occasionally drop scratch dirs into a project-local .cache/.
64+
**/.cache/
6265

6366
# Misc temporary/generated files
6467
Do

0 commit comments

Comments
 (0)