Skip to content

Commit 971eaf9

Browse files
committed
fix: prevent shell injection in pre-push hook environment loading
- Replace unsafe export $(grep -v '^#' .env.local | xargs) pattern - Use dotenvx for secure environment variable parsing without shell evaluation - Prevents execution of malicious commands in .env.local values - Uses existing @dotenvx/dotenvx dependency already in project - Maintains same functionality while eliminating injection vulnerability
1 parent c6a02bb commit 971eaf9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

.husky/pre-push

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ fi
1818

1919
$pnpm_cmd run check-types
2020

21-
# Load .env.local if it exists
21+
# Use dotenvx to securely load .env.local and run commands that depend on it
2222
if [ -f ".env.local" ]; then
23-
export $(grep -v '^#' .env.local | xargs)
24-
fi
25-
26-
# Run tests if RUN_TESTS_ON_PUSH is set to true
27-
if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then
28-
$pnpm_cmd run test
23+
# Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx
24+
if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then
25+
npx dotenvx run -f .env.local -- $pnpm_cmd run test
26+
fi
27+
else
28+
# Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment
29+
if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then
30+
$pnpm_cmd run test
31+
fi
2932
fi
3033

3134
# Check for new changesets.

0 commit comments

Comments
 (0)