Skip to content

Commit b3e9224

Browse files
committed
updated script for rules-update on running updateAllscript
1 parent 46b6f15 commit b3e9224

3 files changed

Lines changed: 84 additions & 5 deletions

File tree

.gitleaks.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ paths = [
1616

1717
[[rules]]
1818
id = "ethereum-private-key"
19-
description = "Detected Ethereum/EVM private key (64 hex chars)"
20-
regex = '''(?:0x)?[a-fA-F0-9]{64}'''
21-
entropy = 4.0
19+
description = "Ethereum private key (exact 64 hex chars, standalone)"
20+
regex = '''(^|[^a-fA-F0-9])(0x)?[a-fA-F0-9]{64}([^a-fA-F0-9]|$)'''
2221
tags = ["crypto", "evm", "ethereum", "private-key"]
2322

2423
[[rules]]
2524
id = "bitcoin-wif-private-key"
2625
description = "Detected Bitcoin WIF private key"
27-
regex = '''[5KL][1-9A-HJ-NP-Za-km-z]{50,51}'''
26+
regex = '''\b[5KL][1-9A-HJ-NP-Za-km-z]{50,51}\b'''
2827
entropy = 3.5
2928
tags = ["crypto", "bitcoin", "private-key"]
3029

@@ -38,7 +37,7 @@ tags = ["crypto", "solana", "private-key"]
3837
[[rules]]
3938
id = "tezos-private-key"
4039
description = "Detected Tezos private key"
41-
regex = '''(edsk|spsk|p2sk)[1-9A-HJ-NP-Za-km-z]{50,100}'''
40+
regex = '''\b(edsk[1-9A-HJ-NP-Za-km-z]{50}|edsk[1-9A-HJ-NP-Za-km-z]{94}|spsk[1-9A-HJ-NP-Za-km-z]{50}|p2sk[1-9A-HJ-NP-Za-km-z]{50})\b'''
4241
entropy = 3.5
4342
keywords = ["edsk", "spsk", "p2sk"]
4443
tags = ["crypto", "tezos", "private-key"]

update-all-repos.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,47 @@ if (-not (Test-Path (Join-Path $TEMPLATE_HOOKS "pre-commit"))) {
3232
exit 1
3333
}
3434

35+
# Function to sync global gitleaks config from repository
36+
function Sync-GlobalConfig {
37+
$scriptDir = Split-Path -Parent $PSCommandPath
38+
$sourceConfig = Join-Path $scriptDir ".gitleaks.toml"
39+
$configDir = Join-Path $env:USERPROFILE ".config\gitleaks"
40+
$targetConfig = Join-Path $configDir "gitleaks.toml"
41+
42+
# Check if source config exists
43+
if (-not (Test-Path $sourceConfig)) {
44+
Write-Warn "Source config not found: $sourceConfig"
45+
Write-Host " Skipping config sync" -ForegroundColor Gray
46+
return $false
47+
}
48+
49+
# Create config directory if it doesn't exist
50+
try {
51+
New-Item -ItemType Directory -Path $configDir -Force -ErrorAction Stop | Out-Null
52+
} catch {
53+
Write-Fail "Failed to create config directory: $configDir"
54+
return $false
55+
}
56+
57+
# Copy the config file
58+
try {
59+
Copy-Item -Path $sourceConfig -Destination $targetConfig -Force -ErrorAction Stop
60+
Write-Ok "Synced global config: $targetConfig"
61+
return $true
62+
} catch {
63+
Write-Fail "Failed to sync config to: $targetConfig"
64+
return $false
65+
}
66+
}
67+
3568
$preCommitSrc = Join-Path $TEMPLATE_HOOKS "pre-commit"
3669
$commitMsgSrc = Join-Path $TEMPLATE_HOOKS "commit-msg"
3770

71+
# Sync global gitleaks config from repository
72+
Write-Step "Syncing global gitleaks configuration..."
73+
Sync-GlobalConfig | Out-Null
74+
Write-Host ""
75+
3876
# No path given = scan all local fixed drives (C:\, D:\, E:\, etc.)
3977
if ($TargetPaths.Count -eq 0) {
4078
# Use .Name (e.g. "C:") to avoid null .Root on some Windows setups

update-all-repos.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,43 @@ if [ ! -d "$TEMPLATE_DIR/hooks" ]; then
7070
exit 1
7171
fi
7272

73+
# Function to sync global gitleaks config from repository
74+
function sync_global_config {
75+
# Determine the script directory (where .gitleaks.toml should be)
76+
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77+
local source_config="$script_dir/.gitleaks.toml"
78+
79+
# Determine the target config directory (handle sudo case)
80+
local config_dir="$HOME/.config/gitleaks"
81+
if [ -n "$SUDO_USER" ]; then
82+
config_dir=$(eval echo ~$SUDO_USER)/.config/gitleaks
83+
fi
84+
local target_config="$config_dir/gitleaks.toml"
85+
86+
# Check if source config exists
87+
if [ ! -f "$source_config" ]; then
88+
echo -e "${WARNING}${NORMAL} Warning: Source config not found: $source_config"
89+
echo -e "${HIGHLIGHT}${NORMAL} Skipping config sync"
90+
return 1
91+
fi
92+
93+
# Create config directory if it doesn't exist
94+
mkdir -p "$config_dir" 2>/dev/null || {
95+
echo -e "${ERROR}${NORMAL} Failed to create config directory: $config_dir"
96+
return 1
97+
}
98+
99+
# Copy the config file
100+
if cp "$source_config" "$target_config" 2>/dev/null; then
101+
echo -e "${SUCCESS}${NORMAL} Synced global config: $target_config"
102+
return 0
103+
else
104+
echo -e "${ERROR}${NORMAL} Failed to sync config to: $target_config"
105+
return 1
106+
fi
107+
}
108+
109+
73110
# Function to check if gitleaks is already in a file
74111
function has_gitleaks {
75112
local file="$1"
@@ -473,6 +510,11 @@ if [ "$EUID" -eq 0 ]; then
473510
echo ""
474511
fi
475512

513+
# Sync global gitleaks config from repository
514+
echo -e "${HIGHLIGHT}Syncing global gitleaks configuration...${NORMAL}"
515+
sync_global_config
516+
echo ""
517+
476518
if [ "$#" -eq 0 ]; then
477519
# No arguments provided - use smart defaults
478520
echo -e "${HIGHLIGHT}No directory specified - using smart detection${NORMAL}\n"

0 commit comments

Comments
 (0)