repowarden 4.10.0 → 4.10.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/lib/i18n/en.sh +8 -0
- package/hooks/lib/i18n/fr.sh +8 -0
- package/hooks/lib/secrets.sh +49 -0
- package/hooks/pre-commit +19 -2
- package/package.json +1 -1
package/hooks/lib/i18n/en.sh
CHANGED
|
@@ -132,6 +132,14 @@ _msg_en() {
|
|
|
132
132
|
hook.pre_commit.3) _M=" (disable for this repository: git config repowarden.skip protect-branch)" ;;
|
|
133
133
|
hook.pre_commit.4) _M="Secret detection (gitleaks)" ;;
|
|
134
134
|
hook.pre_commit.5) _M="Secret detected: commit refused." ;;
|
|
135
|
+
hook.secrets.where) _M=" %s:%s (%s)" ;;
|
|
136
|
+
hook.secrets.unreadable) _M=" (unreadable gitleaks report: run gitleaks git --pre-commit --staged --redact to see the leaks)" ;;
|
|
137
|
+
hook.secrets.todo) _M="What to do:" ;;
|
|
138
|
+
hook.secrets.todo_1) _M=" 1. Remove the value from the file (environment variable, ignored file), then commit again." ;;
|
|
139
|
+
hook.secrets.todo_2) _M=" 2. File that must never be versioned: add it to .gitignore, then git rm --cached <file>." ;;
|
|
140
|
+
hook.secrets.todo_3) _M=" 3. Key that may have leaked elsewhere (already pushed, shared): revoke it at its provider." ;;
|
|
141
|
+
hook.secrets.todo_4) _M=" False positive: add its fingerprint to .gitleaksignore:" ;;
|
|
142
|
+
hook.secrets.failed) _M="gitleaks failed (code %s): commit refused, secret detection not done." ;;
|
|
135
143
|
hook.pre_commit.6) _M="gitleaks not installed, secret detection skipped (install: %s)." ;;
|
|
136
144
|
hook.pre_commit.7) _M="Pre-commit OK" ;;
|
|
137
145
|
hook.commit_msg.1) _M="First line too long (%s > 72 characters)." ;;
|
package/hooks/lib/i18n/fr.sh
CHANGED
|
@@ -111,6 +111,14 @@ _msg_fr() {
|
|
|
111
111
|
hook.pre_commit.3) _M=" (désactiver pour ce dépôt : git config repowarden.skip protect-branch)" ;;
|
|
112
112
|
hook.pre_commit.4) _M="Détection de secrets (gitleaks)" ;;
|
|
113
113
|
hook.pre_commit.5) _M="Secret détecté : commit refusé." ;;
|
|
114
|
+
hook.secrets.where) _M=" %s:%s (%s)" ;;
|
|
115
|
+
hook.secrets.unreadable) _M=" (rapport de gitleaks illisible : relancer gitleaks git --pre-commit --staged --redact pour voir les fuites)" ;;
|
|
116
|
+
hook.secrets.todo) _M="Que faire :" ;;
|
|
117
|
+
hook.secrets.todo_1) _M=" 1. Retirer la valeur du fichier (variable d'environnement, fichier ignoré), puis recommencer le commit." ;;
|
|
118
|
+
hook.secrets.todo_2) _M=" 2. Fichier qui ne doit jamais être versionné : l'ajouter à .gitignore, puis git rm --cached <fichier>." ;;
|
|
119
|
+
hook.secrets.todo_3) _M=" 3. Clé qui a pu fuir ailleurs (déjà poussée, partagée) : la révoquer chez son fournisseur." ;;
|
|
120
|
+
hook.secrets.todo_4) _M=" Faux positif : ajouter son empreinte à .gitleaksignore :" ;;
|
|
121
|
+
hook.secrets.failed) _M="gitleaks en échec (code %s) : commit refusé, détection de secrets non faite." ;;
|
|
114
122
|
hook.pre_commit.6) _M="gitleaks absent, détection de secrets ignorée (installation : %s)." ;;
|
|
115
123
|
hook.pre_commit.7) _M="Pre-commit OK" ;;
|
|
116
124
|
hook.commit_msg.1) _M="Première ligne trop longue (%s > 72 caractères)." ;;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Secrets détectés par gitleaks (pre-commit) : où ils sont et que faire, sans
|
|
3
|
+
# jamais afficher la valeur. Chargé après common.sh. Compatible bash 3.2.
|
|
4
|
+
|
|
5
|
+
# Lit le rapport JSON de gitleaks $1 (un objet par fuite, un champ par ligne,
|
|
6
|
+
# format de --report-format json) : seuls File, StartLine, RuleID et
|
|
7
|
+
# Fingerprint sont lus, jamais Secret ni Match. Affiche « fichier:ligne
|
|
8
|
+
# (règle) » par fuite, puis la marche à suivre et les empreintes à mettre dans
|
|
9
|
+
# .gitleaksignore en cas de faux positif.
|
|
10
|
+
secrets_report() {
|
|
11
|
+
local fuites empreintes f l r e
|
|
12
|
+
# awk : déséchappe ce que le JSON de Go échappe dans un chemin (\" \\ et
|
|
13
|
+
# les codes \u0026, \u003c, \u003e de & < >) ; sortie « fichier<TAB>ligne<TAB>règle<TAB>empreinte »
|
|
14
|
+
fuites="$(awk '
|
|
15
|
+
function valeur(s) {
|
|
16
|
+
sub(/^[^:]*: */, "", s); sub(/,$/, "", s)
|
|
17
|
+
if (s ~ /^".*"$/) s = substr(s, 2, length(s) - 2)
|
|
18
|
+
gsub(/\\u0026/, "\\&", s); gsub(/\\u003c/, "<", s); gsub(/\\u003e/, ">", s)
|
|
19
|
+
gsub(/\\"/, "\"", s); gsub(/\\\\/, "\\", s)
|
|
20
|
+
return s
|
|
21
|
+
}
|
|
22
|
+
/^ *\{/ { f = ""; l = ""; r = ""; e = "" }
|
|
23
|
+
/^ *"File": / { f = valeur($0) }
|
|
24
|
+
/^ *"StartLine": / { l = valeur($0) }
|
|
25
|
+
/^ *"RuleID": / { r = valeur($0) }
|
|
26
|
+
/^ *"Fingerprint": / { e = valeur($0) }
|
|
27
|
+
/^ *\}/ { printf "%s\t%s\t%s\t%s\n", f, l, r, e }
|
|
28
|
+
' "$1" 2>/dev/null || true)"
|
|
29
|
+
if [ -z "$fuites" ]; then
|
|
30
|
+
# Rapport illisible (format changé) : le dire, sans rien deviner
|
|
31
|
+
echo_t hook.secrets.unreadable
|
|
32
|
+
else
|
|
33
|
+
empreintes=""
|
|
34
|
+
while IFS="$(printf '\t')" read -r f l r e; do
|
|
35
|
+
_tr hook.secrets.where "$f" "$l" "$r"
|
|
36
|
+
echo "$_T"
|
|
37
|
+
[ -z "$e" ] || empreintes="$empreintes $e"$'\n'
|
|
38
|
+
done <<<"$fuites"
|
|
39
|
+
fi
|
|
40
|
+
echo
|
|
41
|
+
echo_t hook.secrets.todo
|
|
42
|
+
echo_t hook.secrets.todo_1
|
|
43
|
+
echo_t hook.secrets.todo_2
|
|
44
|
+
echo_t hook.secrets.todo_3
|
|
45
|
+
if [ -n "${empreintes:-}" ]; then
|
|
46
|
+
echo_t hook.secrets.todo_4
|
|
47
|
+
printf '%s' "$empreintes"
|
|
48
|
+
fi
|
|
49
|
+
}
|
package/hooks/pre-commit
CHANGED
|
@@ -6,6 +6,7 @@ set -euo pipefail
|
|
|
6
6
|
source "$(dirname "$0")/lib/common.sh"
|
|
7
7
|
source "$(dirname "$0")/lib/lang.sh"
|
|
8
8
|
source "$(dirname "$0")/lib/safety.sh"
|
|
9
|
+
source "$(dirname "$0")/lib/secrets.sh"
|
|
9
10
|
exit_if_skipped
|
|
10
11
|
check_version
|
|
11
12
|
cd "$GIT_TOPLEVEL"
|
|
@@ -33,10 +34,26 @@ fi
|
|
|
33
34
|
if ! skipped secrets; then
|
|
34
35
|
if has gitleaks; then
|
|
35
36
|
step_t hook.pre_commit.4
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
# Journal de gitleaks tu (horodatage, couleurs à chaque commit) ; ses
|
|
38
|
+
# trouvailles lues dans un rapport JSON. Code 42 : fuite ; tout autre
|
|
39
|
+
# code non nul : gitleaks en échec (jamais présenté comme une fuite)
|
|
40
|
+
rapport="$(mktemp)"
|
|
41
|
+
journal="$(mktemp)"
|
|
42
|
+
code=0
|
|
43
|
+
gitleaks git --pre-commit --staged --redact --no-banner --log-level error \
|
|
44
|
+
--report-format json --report-path "$rapport" --exit-code 42 >/dev/null 2>"$journal" || code=$?
|
|
45
|
+
if [ "$code" -ne 0 ]; then
|
|
46
|
+
if [ "$code" -eq 42 ]; then
|
|
47
|
+
err_t hook.pre_commit.5 >&2
|
|
48
|
+
secrets_report "$rapport" >&2
|
|
49
|
+
else
|
|
50
|
+
err_t hook.secrets.failed "$code" >&2
|
|
51
|
+
cat "$journal" >&2
|
|
52
|
+
fi
|
|
53
|
+
rm -f "$rapport" "$journal"
|
|
38
54
|
exit 1
|
|
39
55
|
fi
|
|
56
|
+
rm -f "$rapport" "$journal"
|
|
40
57
|
else
|
|
41
58
|
# Installation adaptée au système (bash le connaît sans sous-processus)
|
|
42
59
|
case "${OSTYPE:-}" in
|
package/package.json
CHANGED