Skip to content

Commit 582e28c

Browse files
authored
feat(security): add pre-commit hooks for secret detection (#50)
* feat(security): add pre-commit hooks for secret detection - Add gitleaks for hardcoded secrets detection - Add detect-aws-credentials hook - Add .gitleaks.toml for custom rules (AI/LLM API keys) * fix(security): remove custom rules that override gitleaks defaults - Remove openai-api-key, openai-project-key, anthropic-api-key rules (conflict with more accurate default gitleaks rules) - Remove alibaba-cloud and huggingface rules (already in defaults) - Keep only dashscope-api-key (Qwen specific, not in defaults)
1 parent ea8db00 commit 582e28c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

.gitleaks.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Gitleaks configuration for OpenJudge
2+
# This file configures secret detection rules
3+
4+
title = "OpenJudge Gitleaks Config"
5+
6+
[extend]
7+
# Extend the default gitleaks config
8+
useDefault = true
9+
10+
# Allowed patterns (false positives)
11+
[allowlist]
12+
description = "Allowlist for false positives"
13+
14+
# Exclude test files that may contain dummy secrets
15+
paths = [
16+
'''site/.*''',
17+
'''docs/.*\.html''',
18+
]
19+
20+
# Exclude common false positive patterns
21+
regexes = [
22+
# Example API key placeholders
23+
'''sk-[A-Za-z0-9]{3}\.{3}[A-Za-z0-9]{3}''',
24+
# Placeholder patterns
25+
'''your[-_]?api[-_]?key''',
26+
'''<YOUR[-_]?API[-_]?KEY>''',
27+
'''REPLACE[-_]?WITH[-_]?YOUR[-_]?KEY''',
28+
# Example/dummy patterns
29+
'''example[-_]?key''',
30+
'''dummy[-_]?key''',
31+
'''test[-_]?key''',
32+
'''fake[-_]?key''',
33+
]
34+
35+
# Custom rule for Dashscope (Qwen) API keys (not in default gitleaks config)
36+
[[rules]]
37+
id = "dashscope-api-key"
38+
description = "Dashscope (Qwen) API Key"
39+
regex = '''(?i)(?:dashscope|qwen)[-_]?(?:api)?[-_]?key\s*[=:]\s*['"]?([a-zA-Z0-9-_]{20,})['"]?'''
40+
keywords = ["dashscope", "qwen"]

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
repos:
2+
# Detect secrets and prevent committing sensitive data
3+
- repo: https://github.com/gitleaks/gitleaks
4+
rev: v8.18.4
5+
hooks:
6+
- id: gitleaks
27
- repo: https://github.com/pre-commit/pre-commit-hooks
38
rev: v6.0.0
49
hooks:
@@ -8,6 +13,8 @@ repos:
813
- id: check-toml
914
- id: check-json
1015
- id: detect-private-key
16+
- id: detect-aws-credentials
17+
args: ['--allow-missing-credentials']
1118
- id: trailing-whitespace
1219
- repo: https://github.com/PyCQA/autoflake
1320
rev: v2.2.1

0 commit comments

Comments
 (0)