@@ -190,7 +190,7 @@ jobs:
190190
191191 - name : Check for tracked .env files
192192 run : |
193- ENV_FILES=$(git ls-files | awk '/\ .env$/')
193+ ENV_FILES=$(git ls-files | awk '/(^|\/)\ .env($|\.)/ && !/\.(example|template|sample) $/')
194194
195195 if [ -n "$ENV_FILES" ]; then
196196 echo "::error::Found committed .env files. These files usually contain secrets and should not be tracked by git."
@@ -200,4 +200,23 @@ jobs:
200200 echo "And ensure they are listed in .gitignore before committing."
201201 exit 1
202202 fi
203- echo "No tracked .env files found."
203+
204+ TEMPLATE_FILES=$(git ls-files | awk '/(^|\/)\.env\.(example|template|sample)$/')
205+ if [ -n "$TEMPLATE_FILES" ]; then
206+ for file in $TEMPLATE_FILES; do
207+ # 1. Known high-entropy prefixes: eyJ (JWTs), sk_test_/sk_live_/whsec_ (Stripe), gh[pousr]_ (GitHub)
208+ SUSPICIOUS=$(grep -E '=(eyJ|sk_(test|live)_|whsec_|gh[pousr]_)' "$file" || true)
209+ # 2. Generic 32+ char alphanumerics, ignoring usual placeholder words
210+ GENERIC=$(grep -E '=[a-zA-Z0-9]{32,}' "$file" | grep -v -i -E '(your|example|dummy|mock|insert|here)' || true)
211+
212+ if [ -n "$SUSPICIOUS" ] || [ -n "$GENERIC" ]; then
213+ echo "::error::File $file contains what looks like actual key patterns."
214+ [ -n "$SUSPICIOUS" ] && echo "$SUSPICIOUS"
215+ [ -n "$GENERIC" ] && echo "$GENERIC"
216+ echo "Please ensure templates only contain empty values or placeholders (e.g., 'your_key_here')."
217+ exit 1
218+ fi
219+ done
220+ fi
221+
222+ echo "No tracked .env files found, and templates are clean."
0 commit comments