5f306d7edc
--no-warn-script-location: bandit scripts go to /tmp/.local/bin which is not on PATH, but we invoke via 'python -m bandit' so this is harmless. PIP_DISABLE_PIP_VERSION_CHECK=1: silence the version upgrade notice. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
940 B
Bash
Executable File
36 lines
940 B
Bash
Executable File
#!/bin/sh
|
|
# Security pre-commit hook — runs checks inside Docker, no host installs required.
|
|
# Install: git config core.hooksPath .githooks
|
|
|
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
|
|
|
# Collect staged files on the host and pass them into the container as arguments
|
|
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
|
|
|
|
if [ -z "$STAGED" ]; then
|
|
echo "[pre-commit] no staged files — skipping security check."
|
|
exit 0
|
|
fi
|
|
|
|
echo "[pre-commit] running security checks..."
|
|
|
|
# Pass staged file list via environment variable
|
|
docker run --rm \
|
|
-v "$REPO_ROOT":/repo \
|
|
-w /repo \
|
|
-e STAGED_FILES="$STAGED" \
|
|
-u 1001:1001 \
|
|
-e HOME=/tmp \
|
|
-e PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
|
python:3.12-slim \
|
|
sh -c "pip install --quiet --user --no-warn-script-location bandit && python scripts/security_check.py"
|
|
|
|
EXIT_CODE=$?
|
|
|
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
echo "[pre-commit] commit blocked by security check."
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|