Skip to content

Commit 1253338

Browse files
authored
Merge pull request #26 from epcgrs/hook-sec
Add Gitleaks to project and security action
2 parents bdeb8c0 + 104e7fe commit 1253338

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

.github/workflows/security.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Security / Secrets Scan
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
gitleaks:
8+
name: Security Leaks
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
pull-requests: read
13+
steps:
14+
- name: Checkout (full history para varredura correta)
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Run Gitleaks
20+
uses: gitleaks/gitleaks-action@v2
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
with:
24+
args: --config .gitleaks.toml --redact --verbose

.gitleaks.toml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
title = "Local Gitleaks Config"
2+
3+
[extend]
4+
5+
[allowlist]
6+
description = "False positives permitidos"
7+
paths = [
8+
'''tests/.*''',
9+
'''\.secret-allowlist'''
10+
]
11+
regexes = [
12+
'''EXEMPLO_TOKEN_FAKE_123'''
13+
]
14+
15+
[[rules]]
16+
id = "generic-api-key"
17+
description = "Generic API Key"
18+
regex = '''(?i)(api[_-]?key|secret|token)['"\s:=]{0,10}[A-Za-z0-9_\-]{16,64}'''
19+
tags = ["apikey", "generic"]
20+
21+
[[rules]]
22+
id = "github-pat"
23+
description = "GitHub Personal Access Token"
24+
regex = '''ghp_[0-9A-Za-z]{36}'''
25+
tags = ["github", "token"]
26+
27+
[[rules]]
28+
id = "aws-access-key"
29+
description = "AWS Access Key ID"
30+
regex = '''AKIA[0-9A-Z]{16}'''
31+
tags = ["aws", "key"]
32+
33+
[[rules]]
34+
id = "aws-secret-key"
35+
description = "AWS Secret Key (heurística)"
36+
regex = '''(?i)aws(.{0,20})?(secret|key)['"\s:=]{0,10}([A-Za-z0-9/+=]{40})'''
37+
tags = ["aws", "key"]
38+
39+
[[rules]]
40+
id = "slack-token"
41+
description = "Slack Token"
42+
regex = '''xox[baprs]-[A-Za-z0-9-]{10,48}'''
43+
tags = ["slack", "token"]
44+
45+
[[rules]]
46+
id = "private-key"
47+
description = "Private Key Block"
48+
regex = '''-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----'''
49+
tags = ["key", "private"]
50+
51+
[[rules]]
52+
id = "jwt"
53+
description = "Provável JWT"
54+
regex = '''eyJ[A-Za-z0-9_\-]{10,}\.[A-Za-z0-9_\-]{10,}\.[A-Za-z0-9_\-]{10,}'''
55+
tags = ["jwt", "token"]
56+

.husky/pre-commit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
2+
HUSKY=0 ./.scripts/gitleaks protect --staged --config .gitleaks.toml --redact || {
3+
echo "❌ Segredos suspeitos."
4+
echo "🔒 Use './.scripts/gitleaks protect --staged --config .gitleaks.toml --redact' para verificar localmente."
5+
exit 1
6+
}
7+
18
npx lint-staged

.scripts/gitleaks

20.9 MB
Binary file not shown.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"build": "next build",
1919
"migration:create": "node-pg-migrate -m infra/migrations create",
2020
"migration:up": "node-pg-migrate -m infra/migrations --envPath .env.development up",
21+
"secrets:scan": "./.scripts/gitleaks detect --config .gitleaks.toml --no-git --redact --source .",
22+
"secrets:scan:git": "./.scripts/gitleaks detect --config .gitleaks.toml --redact --source .",
23+
"secrets:scan:staged": "git diff --cached --name-only | xargs -r ./.scripts/gitleaks protect --staged --config .gitleaks.toml --redact",
2124
"wait-for-postgres": "node infra/scripts/wait-for-postgres.js",
2225
"prepare": "husky",
2326
"commit": "cz"

0 commit comments

Comments
 (0)