Skip to content

Commit dd31532

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 are not blocked, and adds .env.precommit to the allowlist alongside .env.example and .env.test. The previous regex only blocked bare .env / .env.local at the repo root and would have let through .env.production etc. — now blocks anything that doesn't match the template allowlist at any depth. Adds **/.cache/ to .gitignore as a defensive ignore for stray writers.
1 parent d02e480 commit dd31532

2 files changed

Lines changed: 9 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(\.local)?$'; 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Thumbs.db
1919
.nvm
2020
.pnpmfile.cjs
2121
node_modules/
22+
# Defensive cache ignore — Node compile-cache, corepack, and other
23+
# tools occasionally drop scratch dirs into a project-local .cache/.
24+
# node_modules/.cache/ is the canonical home for tools we control.
25+
**/.cache/
2226
npm-debug.log*
2327
pnpm-debug.log*
2428
yarn-error.log*

0 commit comments

Comments
 (0)