-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgitleaks.sh
More file actions
executable file
·59 lines (50 loc) · 1.89 KB
/
gitleaks.sh
File metadata and controls
executable file
·59 lines (50 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Gitleaks security scan script
# This script performs security scanning to detect potential secrets in code
set -e
echo "🔍 Running Gitleaks security scan..."
# Check if gitleaks is installed
if ! command -v gitleaks &> /dev/null; then
echo "⚠️ Gitleaks not found. Installing..."
# Install gitleaks based on OS
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
if command -v brew &> /dev/null; then
brew install gitleaks
else
echo "❌ Homebrew not found. Please install gitleaks manually:"
echo " Visit: https://github.com/gitleaks/gitleaks#installation"
exit 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
echo "Please install gitleaks manually for Linux:"
echo " Visit: https://github.com/gitleaks/gitleaks#installation"
exit 1
else
echo "❌ Unsupported OS. Please install gitleaks manually:"
echo " Visit: https://github.com/gitleaks/gitleaks#installation"
exit 1
fi
fi
# Run gitleaks scan on staged files
echo "Scanning staged files for secrets..."
# Create a temporary config file if it doesn't exist
GITLEAKS_CONFIG=""
if [ -f ".gitleaks.toml" ]; then
GITLEAKS_CONFIG="--config=.gitleaks.toml"
fi
# Scan staged files
if ! git diff --cached | gitleaks stdin --verbose --exit-code 1; then
echo ""
echo "❌ Gitleaks found potential secrets in your staged files!"
echo " Please review and remove any sensitive information before committing."
echo " You can use 'git diff --cached' to see your staged changes."
echo ""
echo " If this is a false positive, you can:"
echo " 1. Add the file/pattern to .gitleaks.toml allowlist"
echo " 2. Or skip this check with: git commit --no-verify"
echo ""
exit 1
fi
echo "✅ Gitleaks scan completed successfully - no secrets detected!"