repo-security-scanner 0.1.0__tar.gz
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.
- repo_security_scanner-0.1.0/LICENSE +21 -0
- repo_security_scanner-0.1.0/PKG-INFO +475 -0
- repo_security_scanner-0.1.0/README.md +454 -0
- repo_security_scanner-0.1.0/main.py +138 -0
- repo_security_scanner-0.1.0/pyproject.toml +37 -0
- repo_security_scanner-0.1.0/repo_scanner/__init__.py +5 -0
- repo_security_scanner-0.1.0/repo_scanner/cli/__init__.py +3 -0
- repo_security_scanner-0.1.0/repo_scanner/cli/arguments.py +45 -0
- repo_security_scanner-0.1.0/repo_scanner/config.py +117 -0
- repo_security_scanner-0.1.0/repo_scanner/models/__init__.py +3 -0
- repo_security_scanner-0.1.0/repo_scanner/models/scan_result.py +87 -0
- repo_security_scanner-0.1.0/repo_scanner/report/__init__.py +4 -0
- repo_security_scanner-0.1.0/repo_scanner/report/exporters.py +39 -0
- repo_security_scanner-0.1.0/repo_scanner/report/formatter.py +153 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/__init__.py +7 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/core.py +178 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/dependency_checker.py +160 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/dockerfile_scanner.py +75 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/entropy_calculator.py +44 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/file_analyzer.py +128 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/pattern_matcher.py +109 -0
- repo_security_scanner-0.1.0/repo_scanner/scanner/secret_detector.py +37 -0
- repo_security_scanner-0.1.0/repo_scanner/utils/__init__.py +4 -0
- repo_security_scanner-0.1.0/repo_scanner/utils/file_utils.py +91 -0
- repo_security_scanner-0.1.0/repo_scanner/utils/git_utils.py +23 -0
- repo_security_scanner-0.1.0/repo_security_scanner.egg-info/PKG-INFO +475 -0
- repo_security_scanner-0.1.0/repo_security_scanner.egg-info/SOURCES.txt +37 -0
- repo_security_scanner-0.1.0/repo_security_scanner.egg-info/dependency_links.txt +1 -0
- repo_security_scanner-0.1.0/repo_security_scanner.egg-info/entry_points.txt +2 -0
- repo_security_scanner-0.1.0/repo_security_scanner.egg-info/requires.txt +2 -0
- repo_security_scanner-0.1.0/repo_security_scanner.egg-info/top_level.txt +2 -0
- repo_security_scanner-0.1.0/setup.cfg +4 -0
- repo_security_scanner-0.1.0/tests/test_dependency_checker.py +73 -0
- repo_security_scanner-0.1.0/tests/test_dockerfile_scanner.py +72 -0
- repo_security_scanner-0.1.0/tests/test_entropy_calculator.py +25 -0
- repo_security_scanner-0.1.0/tests/test_file_utils.py +55 -0
- repo_security_scanner-0.1.0/tests/test_pattern_matcher.py +49 -0
- repo_security_scanner-0.1.0/tests/test_scoring.py +60 -0
- repo_security_scanner-0.1.0/tests/test_secret_detector.py +48 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MR-UNKNOWN8014
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: repo-security-scanner
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pre-clone security scanner for Git repositories: malicious code, secrets, vulnerable dependencies, and Dockerfile issues
|
|
5
|
+
Author: MR-UNKNOWN8014
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MR-UNKNOWN8014/repo-security-scanner
|
|
8
|
+
Project-URL: Issues, https://github.com/MR-UNKNOWN8014/repo-security-scanner/issues
|
|
9
|
+
Keywords: security,scanner,malware,secrets,supply-chain,sast,dockerfile
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: colorama>=0.4.6
|
|
19
|
+
Requires-Dist: tqdm>=4.64.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Repository Security Scanner
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+

|
|
26
|
+

|
|
27
|
+

|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
> A Python-based security tool that analyzes Git repositories for malicious code, backdoors, obfuscation, and suspicious patterns before you clone them. It provides risk scoring and actionable recommendations.
|
|
31
|
+
|
|
32
|
+
The scanner performs static analysis on repository files, detecting:
|
|
33
|
+
- Crypto miner patterns
|
|
34
|
+
- Backdoor signatures
|
|
35
|
+
- Data exfiltration code
|
|
36
|
+
- Obfuscation techniques
|
|
37
|
+
- Dangerous function calls
|
|
38
|
+
- Vulnerable dependencies
|
|
39
|
+
- High-entropy (encrypted/obfuscated) files
|
|
40
|
+
- Hardcoded secrets and API keys
|
|
41
|
+
- Insecure Dockerfile patterns
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Why?
|
|
46
|
+
|
|
47
|
+
Cloning a repo to audit it is already too late — `postinstall` scripts,
|
|
48
|
+
Makefiles, and CI configs run before you ever open the code. This tool
|
|
49
|
+
scans **before** `git clone` completes, so you know what you're pulling
|
|
50
|
+
in before it can touch your machine.
|
|
51
|
+
|
|
52
|
+
Built because existing tools (gitleaks, trufflehog) focus on *secrets*,
|
|
53
|
+
and SAST tools (semgrep, bandit) focus on *your* code. Neither answers
|
|
54
|
+
the question: "is this random GitHub repo safe to run?"
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Clone the repository
|
|
62
|
+
git clone https://github.com/MR-UNKNOWN8014/repo-security-scanner.git
|
|
63
|
+
cd repo-security-scanner
|
|
64
|
+
|
|
65
|
+
# Install dependencies
|
|
66
|
+
./setup.sh # Linux/macOS
|
|
67
|
+
setup.bat # Windows
|
|
68
|
+
|
|
69
|
+
# Scan a repository
|
|
70
|
+
python run_scanner.py https://github.com/user/repo.git
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
## 1. Installation:
|
|
76
|
+
|
|
77
|
+
**Needs Python 3.8 or Higher to work.**
|
|
78
|
+
|
|
79
|
+
### 1.2 Linux / macOS
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Linux/Mac
|
|
83
|
+
chmod +x setup.sh
|
|
84
|
+
|
|
85
|
+
# Windows
|
|
86
|
+
./setup.sh
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**The installer will**:
|
|
90
|
+
- Verify Python version
|
|
91
|
+
- Install all required dependencies
|
|
92
|
+
- Create the run script
|
|
93
|
+
|
|
94
|
+
>[!TIP]
|
|
95
|
+
>If Python is not in your PATH, the installer will prompt you to install Python 3.8+ from [python.org](https://python.org/).
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### 1.3 Manual Installation
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Create virtual environment (optional)
|
|
102
|
+
python -m venv venv
|
|
103
|
+
|
|
104
|
+
# Linux/Mac
|
|
105
|
+
source venv/bin/activate
|
|
106
|
+
|
|
107
|
+
# Windows
|
|
108
|
+
venv\Scripts\activate
|
|
109
|
+
|
|
110
|
+
# Install dependencies
|
|
111
|
+
pip install -r requirements.txt
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 1.4 Install as a Package
|
|
115
|
+
|
|
116
|
+
The project also ships a `pyproject.toml`, so it can be installed as an editable package instead of running the scripts directly:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
pip install -e .
|
|
120
|
+
|
|
121
|
+
# now available as a command anywhere in the venv
|
|
122
|
+
repo-scanner https://github.com/user/repo.git
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
----
|
|
126
|
+
## 2. Usage
|
|
127
|
+
|
|
128
|
+
### 2.1 Basic Commands
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Scan remote repository
|
|
132
|
+
python run_scanner.py https://github.com/user/repo.git
|
|
133
|
+
|
|
134
|
+
# Scan local repository
|
|
135
|
+
python run_scanner.py /path/to/local/repo
|
|
136
|
+
|
|
137
|
+
# Quick scan (limited files)
|
|
138
|
+
python run_scanner.py https://github.com/user/repo.git --mode quick
|
|
139
|
+
|
|
140
|
+
# Thorough scan with detailed output
|
|
141
|
+
python run_scanner.py https://github.com/user/repo.git --mode thorough --detailed
|
|
142
|
+
|
|
143
|
+
# Export report to JSON
|
|
144
|
+
python run_scanner.py https://github.com/user/repo.git --output report.json
|
|
145
|
+
|
|
146
|
+
# Check every pinned dependency against OSV.dev's live vulnerability database
|
|
147
|
+
python run_scanner.py https://github.com/user/repo.git --check-vulns
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 2.2 Command Line Arguments
|
|
151
|
+
|
|
152
|
+
| Option | Short | Description | Default |
|
|
153
|
+
| ----------------- | ----- | ------------------------------------------------------------------------------- | -------- |
|
|
154
|
+
| `--mode` | `-m` | Scan mode: quick, balanced, thorough, smart (detail below on types) | balanced |
|
|
155
|
+
| `--output` | `-o` | Export report to JSON or CSV file | None |
|
|
156
|
+
| `--verbose` | `-v` | Display detailed scan progress | False |
|
|
157
|
+
| `--detailed` | `-d` | Show detailed breakdown in report | False |
|
|
158
|
+
| `--format` | - | Report format: simple, multi, categories, detailed, all (detail below on types) | all |
|
|
159
|
+
| `--keep-repo` | - | Keep cloned repository after scanning | False |
|
|
160
|
+
| `--auto-decision` | - | Automatically decide based on risk score | False |
|
|
161
|
+
| `--check-vulns` | - | Query OSV.dev for live known vulnerabilities in every pinned dependency (sends dependency names/versions to a third-party service) | False |
|
|
162
|
+
|
|
163
|
+
### 2.3 Scan Modes
|
|
164
|
+
|
|
165
|
+
| Mode | Description | Files Scanned |
|
|
166
|
+
| ------------ | ----------------------------------- | ---------------------------------------------------------------------------- |
|
|
167
|
+
| **Quick** | Fast scanning with size limits | Files < 1MB, max 10,000 |
|
|
168
|
+
| **Balanced** | Moderate coverage with good speed | All valid files |
|
|
169
|
+
| **Thorough** | Complete scanning | All files without limits (will take some time if too many files or big size) |
|
|
170
|
+
| **Smart** | Prioritizes executable/script files | Scripts, binaries, executables |
|
|
171
|
+
|
|
172
|
+
>[!TIP]
|
|
173
|
+
>Use `--mode quick` for CI/CD pipelines and `--mode thorough` for security audits.
|
|
174
|
+
|
|
175
|
+
### 2.4 Ignoring Known False Positives
|
|
176
|
+
|
|
177
|
+
Drop a `.reposecurityignore` file in the root of the repository being scanned to skip specific files or paths, one glob pattern per line:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
# skip test fixtures with fake credentials
|
|
181
|
+
tests/fixtures/*
|
|
182
|
+
*.sample.env
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Lines starting with `#` and blank lines are ignored. Patterns match against both the file's path relative to the repo root and its filename.
|
|
186
|
+
|
|
187
|
+
----
|
|
188
|
+
## 3. Report Formats
|
|
189
|
+
|
|
190
|
+
The scanner supports four report formats, plus an "all" option that displays them sequentially.
|
|
191
|
+
|
|
192
|
+
### 3.1 Simple Format
|
|
193
|
+
|
|
194
|
+
Single percentage score with status bar and risk level.
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
============================================================
|
|
198
|
+
REPOSITORY: awesome-project
|
|
199
|
+
RISK SCORE: 23.5% [████████░░░░░░░░░░░░] LOW RISK
|
|
200
|
+
============================================================
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 3.2 Multi-Factor Format
|
|
204
|
+
|
|
205
|
+
Breaks down risk into four categories with individual scores.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
============================================================
|
|
209
|
+
REPOSITORY: awesome-project
|
|
210
|
+
|
|
211
|
+
MULTI-FACTOR ANALYSIS
|
|
212
|
+
Code Quality: 76.3% [██████████░░░░░░]
|
|
213
|
+
Security: 76.5% [██████████░░░░░░]
|
|
214
|
+
Obfuscation: 16.5% [██░░░░░░░░░░░░░░]
|
|
215
|
+
Malicious: 11.8% [█░░░░░░░░░░░░░░░]
|
|
216
|
+
|
|
217
|
+
OVERALL: 23.5% LOW RISK
|
|
218
|
+
============================================================
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 3.3 Categories Format
|
|
222
|
+
|
|
223
|
+
Displays risk category with file breakdown and recommendation.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
============================================================
|
|
227
|
+
REPOSITORY: awesome-project
|
|
228
|
+
|
|
229
|
+
[LOW] RISK
|
|
230
|
+
|
|
231
|
+
Risk Level: [LOW]
|
|
232
|
+
Score: 23.5%
|
|
233
|
+
Findings: 12 issues found
|
|
234
|
+
Files: 0 high, 3 medium, 9 low
|
|
235
|
+
Recommendation: REVIEW BEFORE CLONING
|
|
236
|
+
============================================================
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 3.4 Detailed Format
|
|
240
|
+
|
|
241
|
+
Complete report including all findings and statistics.
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
============================================================
|
|
245
|
+
REPOSITORY: awesome-project
|
|
246
|
+
|
|
247
|
+
[LOW] RISK
|
|
248
|
+
|
|
249
|
+
Risk Level: [LOW]
|
|
250
|
+
Score: 23.5%
|
|
251
|
+
Findings: 12 issues found
|
|
252
|
+
Files: 0 high, 3 medium, 9 low
|
|
253
|
+
Recommendation: REVIEW BEFORE CLONING
|
|
254
|
+
============================================================
|
|
255
|
+
|
|
256
|
+
FILE BREAKDOWN:
|
|
257
|
+
Safe: 45
|
|
258
|
+
Low Risk: 9
|
|
259
|
+
Medium Risk: 3
|
|
260
|
+
High Risk: 0
|
|
261
|
+
|
|
262
|
+
STATISTICS:
|
|
263
|
+
Total Files: 57
|
|
264
|
+
Scan Duration: 4.32s
|
|
265
|
+
Findings Found: 12
|
|
266
|
+
|
|
267
|
+
TOP FINDINGS:
|
|
268
|
+
1. [MEDIUM] encoding: Multiple base64 strings: 8
|
|
269
|
+
2. [MEDIUM] vulnerable_dependency: NPM package 'lodash': Prototype pollution vulnerabilities
|
|
270
|
+
3. [LOW] dangerous_function: Dangerous function: eval
|
|
271
|
+
4. [LOW] network: Network activity: HTTP request
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## 4. Risk Scoring
|
|
277
|
+
|
|
278
|
+
### 4.1 Risk Levels
|
|
279
|
+
|
|
280
|
+
|Score|Level|Recommendation|
|
|
281
|
+
|---|---|---|
|
|
282
|
+
|0-9|SAFE|Safe to clone|
|
|
283
|
+
|10-24|LOW RISK|Review before cloning|
|
|
284
|
+
|25-49|MEDIUM RISK|Exercise caution|
|
|
285
|
+
|50-74|HIGH RISK|Avoid cloning|
|
|
286
|
+
|75-100|CRITICAL|Do not clone|
|
|
287
|
+
|
|
288
|
+
### 4.2 Scoring Factors
|
|
289
|
+
|
|
290
|
+
|Factor|Maximum Points|Description|
|
|
291
|
+
|---|---|---|
|
|
292
|
+
|Malicious Patterns|100|Crypto miners, backdoors, exfiltration|
|
|
293
|
+
|Dangerous Functions|100|eval, exec, system, subprocess|
|
|
294
|
+
|Entropy Analysis|20|High entropy indicates encryption/obfuscation|
|
|
295
|
+
|Base64 Encoding|10|Large base64 strings may contain payloads|
|
|
296
|
+
|File Size|10|Large files may contain hidden payloads|
|
|
297
|
+
|Vulnerable Dependencies|15 per package (20 if confirmed via `--check-vulns`)|Known vulnerable packages|
|
|
298
|
+
|Secret Detection|80 per secret|Hardcoded API keys, tokens, passwords, private keys|
|
|
299
|
+
|Dockerfile Issues|3-20 per finding|Unpinned images, root user, curl-pipe-bash, hardcoded secrets|
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 5. Detection Capabilities
|
|
304
|
+
|
|
305
|
+
### 5.1 Malicious Pattern Categories
|
|
306
|
+
|
|
307
|
+
|Category|Example Patterns|
|
|
308
|
+
|---|---|
|
|
309
|
+
|Crypto Miners|cryptonight, stratum, xmrig, mining, cpuminer|
|
|
310
|
+
|Backdoors|socket.bind, socket.connect, base64.b64decode|
|
|
311
|
+
|Data Exfiltration|requests.post, discord webhook, smtplib, telegram|
|
|
312
|
+
|Obfuscation|base64, zlib, exec(decode), String.fromCharCode|
|
|
313
|
+
|Shell Commands|subprocess, os.system, popen, eval|
|
|
314
|
+
|Network Activity|socket, requests, urllib, websocket, ftp|
|
|
315
|
+
|File Operations|os.remove, shutil.rmtree, file.write, os.chmod|
|
|
316
|
+
|
|
317
|
+
### 5.2 Language-Specific Detection
|
|
318
|
+
|
|
319
|
+
|Language|Detected Functions|
|
|
320
|
+
|---|---|
|
|
321
|
+
|Python|exec, eval, compile, **import**, os.system, subprocess.call, subprocess.Popen, os.popen|
|
|
322
|
+
|JavaScript|eval, Function, setTimeout, setInterval, document.write, innerHTML|
|
|
323
|
+
|Bash|exec, eval, source, export, alias|
|
|
324
|
+
|PHP|eval, system, exec, passthru, shell_exec, assert|
|
|
325
|
+
|Ruby|eval, exec, system, ``, IO.popen, Open3|
|
|
326
|
+
|Go|os/exec, syscall, reflect, unsafe|
|
|
327
|
+
|Rust|std::process, std::fs, unsafe, std::mem|
|
|
328
|
+
|Java|Runtime.exec, ProcessBuilder, System.load, Class.forName|
|
|
329
|
+
|
|
330
|
+
### 5.3 Vulnerable Dependency Detection
|
|
331
|
+
|
|
332
|
+
Offline (default): checks pinned versions of the packages below against a known-bad floor. A package is only flagged if the pinned version is actually below the fixed version; unpinned or unparseable version specs are skipped rather than guessed at.
|
|
333
|
+
|
|
334
|
+
| Package Manager | Checked Packages |
|
|
335
|
+
| --------------- | ------------------------------------------------- |
|
|
336
|
+
| npm | crypto-js, node-fetch, axios, lodash, request |
|
|
337
|
+
| pip | requests, urllib3, paramiko, cryptography, pyyaml |
|
|
338
|
+
|
|
339
|
+
Online (`--check-vulns`): additionally queries the [OSV.dev](https://osv.dev/) API for every pinned dependency in `requirements.txt`/`package.json`, not just the packages above, against its live vulnerability database. Off by default since it sends dependency names and versions to a third-party service.
|
|
340
|
+
|
|
341
|
+
### 5.4 Secret Detection
|
|
342
|
+
|
|
343
|
+
Scans every text file for hardcoded credentials: AWS/GitHub/GitLab/Slack/Google/Stripe/Twilio/SendGrid keys, private key blocks, JWTs, and generic `api_key`/`secret`/`token`/`password` assignments. Matches are reported with a file and line number but the value itself is redacted (`AKIA************WXYZ`), never printed in full. Known placeholder values (`EXAMPLE`, `changeme`, `<your_key_here>`, etc.) are filtered out so docs and templates don't trip it. Any confirmed secret pushes that file's risk score into the CRITICAL range on its own.
|
|
344
|
+
|
|
345
|
+
Add real fixtures containing fake secrets you need to keep to `.reposecurityignore` (see 2.4) to suppress them.
|
|
346
|
+
|
|
347
|
+
### 5.5 Dockerfile Scanning
|
|
348
|
+
|
|
349
|
+
Any `Dockerfile`, `Dockerfile.*`, or `*.dockerfile` is additionally checked for:
|
|
350
|
+
|
|
351
|
+
| Check | What it catches |
|
|
352
|
+
|---|---|
|
|
353
|
+
| Unpinned base image | `FROM image:latest` or no tag at all |
|
|
354
|
+
| Root user | No `USER` instruction, or an explicit `USER root` |
|
|
355
|
+
| ADD vs COPY | `ADD` used for a local file instead of `COPY` (ADD's extra behavior is only needed for URLs/archives) |
|
|
356
|
+
| Pipe to shell | `curl \| bash`, `wget \| sh`, etc. |
|
|
357
|
+
| Insecure TLS | `curl -k`, `--no-check-certificate` |
|
|
358
|
+
| Hardcoded secret | `ENV`/`ARG` setting a `PASSWORD`/`SECRET`/`TOKEN`/`API_KEY` directly |
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## 6. Project Structure
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
repo-security-scanner/
|
|
366
|
+
├── setup.sh # Linux/macOS installer
|
|
367
|
+
├── setup.bat # Windows installer
|
|
368
|
+
├── requirements.txt # Python dependencies
|
|
369
|
+
├── pyproject.toml # Packaging (pip install -e .)
|
|
370
|
+
├── README.md # Documentation
|
|
371
|
+
├── LICENSE # MIT License
|
|
372
|
+
├── .gitignore # Git ignore file
|
|
373
|
+
├── run_scanner.py # Entry point
|
|
374
|
+
├── main.py # CLI entry point (main())
|
|
375
|
+
│
|
|
376
|
+
├── .github/
|
|
377
|
+
│ └── workflows/
|
|
378
|
+
│ └── tests.yml # CI: runs the test suite on push/PR
|
|
379
|
+
│
|
|
380
|
+
├── tests/ # Unit tests (unittest)
|
|
381
|
+
│ ├── test_entropy_calculator.py
|
|
382
|
+
│ ├── test_pattern_matcher.py
|
|
383
|
+
│ ├── test_dependency_checker.py
|
|
384
|
+
│ ├── test_file_utils.py
|
|
385
|
+
│ ├── test_scoring.py
|
|
386
|
+
│ ├── test_secret_detector.py
|
|
387
|
+
│ └── test_dockerfile_scanner.py
|
|
388
|
+
│
|
|
389
|
+
└── repo_scanner/ # Main package
|
|
390
|
+
├── __init__.py
|
|
391
|
+
├── config.py # Configuration and constants
|
|
392
|
+
├── cli/ # Command-line interface
|
|
393
|
+
│ ├── __init__.py
|
|
394
|
+
│ └── arguments.py # Argument parsing
|
|
395
|
+
│
|
|
396
|
+
├── scanner/ # Core scanning modules
|
|
397
|
+
│ ├── __init__.py
|
|
398
|
+
│ ├── core.py # Scanner orchestrator
|
|
399
|
+
│ ├── file_analyzer.py # Individual file analysis
|
|
400
|
+
│ ├── pattern_matcher.py # Pattern detection engine
|
|
401
|
+
│ ├── dependency_checker.py # Dependency scanning (offline + OSV.dev)
|
|
402
|
+
│ ├── entropy_calculator.py # Entropy analysis
|
|
403
|
+
│ ├── secret_detector.py # Credential/API key/token detection
|
|
404
|
+
│ └── dockerfile_scanner.py # Dockerfile security linting
|
|
405
|
+
│
|
|
406
|
+
├── report/ # Report generation
|
|
407
|
+
│ ├── __init__.py
|
|
408
|
+
│ ├── formatter.py # Output formatting
|
|
409
|
+
│ └── exporters.py # JSON/CSV export
|
|
410
|
+
│
|
|
411
|
+
├── models/ # Data models
|
|
412
|
+
│ ├── __init__.py
|
|
413
|
+
│ └── scan_result.py # Result data structures
|
|
414
|
+
│
|
|
415
|
+
└── utils/ # Utility functions
|
|
416
|
+
├── __init__.py
|
|
417
|
+
├── file_utils.py # File operations, .reposecurityignore
|
|
418
|
+
└── git_utils.py # Git operations
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 7. Troubleshooting
|
|
424
|
+
|
|
425
|
+
|Problem|Check|Solution|
|
|
426
|
+
|---|---|---|
|
|
427
|
+
|Python not found|Python installed?|Install Python 3.8+ from [python.org](https://python.org/)|
|
|
428
|
+
|ModuleNotFoundError|Dependencies installed?|Run `pip install -r requirements.txt`|
|
|
429
|
+
|Git clone failed|Git installed?|Install Git from [git-scm.com](https://git-scm.com/)|
|
|
430
|
+
|Permission denied|File permissions?|`chmod +x setup.sh` (Linux/macOS)|
|
|
431
|
+
|Scan takes too long|Large repository?|Use `--mode quick` or `--mode smart`|
|
|
432
|
+
|Report not generated|Output path valid?|Check write permissions for output directory|
|
|
433
|
+
|High entropy warnings|False positives?|Review the file manually, may be legitimate. Add it to `.reposecurityignore` to suppress it going forward|
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## 8. Future Enhancements
|
|
438
|
+
|
|
439
|
+
- [x] Secret detection - API keys, passwords, tokens, credentials
|
|
440
|
+
- [x] Dockerfile scanning - insecure base images, root user, secrets in ENV/ARG, curl-pipe-bash
|
|
441
|
+
- [ ] Git history analysis - scan commit history for secrets and keys
|
|
442
|
+
- [ ] License checker - detect incompatible or restrictive licenses
|
|
443
|
+
- [ ] Binary signature analysis - verify binaries from trusted sources
|
|
444
|
+
- [ ] Database of known malicious repositories
|
|
445
|
+
- [ ] Package registry scanning (PyPI, npm, RubyGems)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
-----
|
|
449
|
+
|
|
450
|
+
## 9. Contributing and Bugs
|
|
451
|
+
|
|
452
|
+
### 9.1 Pull Request Process
|
|
453
|
+
|
|
454
|
+
1. Fork the repository
|
|
455
|
+
2. Create a feature branch: `git checkout -b feature/AmazingFeature`
|
|
456
|
+
3. Run the test suite locally: `python -m unittest discover -s tests -v`
|
|
457
|
+
4. Commit your changes: `git commit -m 'Add some AmazingFeature'`
|
|
458
|
+
5. Push to the branch: `git push origin feature/AmazingFeature`
|
|
459
|
+
6. Submit a Pull Request
|
|
460
|
+
|
|
461
|
+
> [!note]
|
|
462
|
+
> All pull requests must pass the CI checks (.github/workflows/tests.yml, run on Python 3.8 and 3.12) and maintain 100% compatibility with Python 3.8+.
|
|
463
|
+
|
|
464
|
+
### 9.2 Reporting Issues
|
|
465
|
+
|
|
466
|
+
When reporting issues on GitHub, include:
|
|
467
|
+
|
|
468
|
+
- Description of the issue
|
|
469
|
+
- Steps to reproduce
|
|
470
|
+
- Expected behavior
|
|
471
|
+
- Actual behavior
|
|
472
|
+
- Environment (OS, Python version)
|
|
473
|
+
- Logs or screenshots (if applicable)
|
|
474
|
+
|
|
475
|
+
This all so I can work on those bugs and make the tool better.
|