git-cli-scanner 1.3.1 โ 1.4.0
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/dist/cli.js +55 -1
- package/package.json +1 -1
- package/readme.md +56 -76
package/dist/cli.js
CHANGED
|
@@ -439,6 +439,58 @@ var init_envFiles = __esm({
|
|
|
439
439
|
}
|
|
440
440
|
});
|
|
441
441
|
|
|
442
|
+
// src/scans/infrastructure.ts
|
|
443
|
+
var rules5, infrastructureScanner;
|
|
444
|
+
var init_infrastructure = __esm({
|
|
445
|
+
"src/scans/infrastructure.ts"() {
|
|
446
|
+
"use strict";
|
|
447
|
+
rules5 = [
|
|
448
|
+
{
|
|
449
|
+
id: "docker-hub-token",
|
|
450
|
+
description: "Docker Hub Personal Access Token",
|
|
451
|
+
pattern: /dckr_pat_[a-zA-Z0-9_\-]{25,}/,
|
|
452
|
+
risk: "An attacker can push malicious images to your Docker registries, leading to a supply chain attack on your production containers.",
|
|
453
|
+
solution: "Revoke this token immediately in Docker Hub (Account Settings > Security > New Access Token) and replace it using CI/CD secrets."
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
id: "database-connection-string",
|
|
457
|
+
description: "Database Connection String with Credentials",
|
|
458
|
+
pattern: /(?:postgres|mysql|mongodb(?:\+srv)?|redis):\/\/[^:\/\s]+:[^@\/\s]+@[^:\/\s]+(?::\d+)?\//,
|
|
459
|
+
risk: "An attacker can directly connect to your database instance, allowing them to steal, modify, or delete all of your user data.",
|
|
460
|
+
solution: "Remove the hardcoded database URL and read it from an environment variable (e.g., process.env.DATABASE_URL) at runtime."
|
|
461
|
+
}
|
|
462
|
+
];
|
|
463
|
+
infrastructureScanner = {
|
|
464
|
+
id: "infrastructure",
|
|
465
|
+
scan(diff) {
|
|
466
|
+
const issues = [];
|
|
467
|
+
const lines = diff.content.split("\n");
|
|
468
|
+
let lineNumber = 1;
|
|
469
|
+
for (const line of lines) {
|
|
470
|
+
if (line.startsWith("+")) {
|
|
471
|
+
const cleanLine = line.substring(1);
|
|
472
|
+
for (const rule of rules5) {
|
|
473
|
+
if (rule.pattern.test(cleanLine)) {
|
|
474
|
+
issues.push({
|
|
475
|
+
type: rule.id,
|
|
476
|
+
file: diff.file,
|
|
477
|
+
line: lineNumber,
|
|
478
|
+
match: cleanLine.trim().substring(0, 50) + "...",
|
|
479
|
+
severity: "high",
|
|
480
|
+
solution: rule.solution,
|
|
481
|
+
risk: rule.risk
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
lineNumber++;
|
|
487
|
+
}
|
|
488
|
+
return issues;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
|
|
442
494
|
// src/scans/index.ts
|
|
443
495
|
var allScanners;
|
|
444
496
|
var init_scans = __esm({
|
|
@@ -449,12 +501,14 @@ var init_scans = __esm({
|
|
|
449
501
|
init_collaboration();
|
|
450
502
|
init_privateKeys();
|
|
451
503
|
init_envFiles();
|
|
504
|
+
init_infrastructure();
|
|
452
505
|
allScanners = [
|
|
453
506
|
apiKeyScanner,
|
|
454
507
|
cloudProviderScanner,
|
|
455
508
|
collaborationScanner,
|
|
456
509
|
privateKeyScanner,
|
|
457
|
-
envFileScanner
|
|
510
|
+
envFileScanner,
|
|
511
|
+
infrastructureScanner
|
|
458
512
|
];
|
|
459
513
|
}
|
|
460
514
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-cli-scanner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A powerful interactive CLI tool that scans your codebase for hardcoded secrets, API keys, passwords, and private keys before they reach your Git history.",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"scripts": {
|
package/readme.md
CHANGED
|
@@ -1,98 +1,54 @@
|
|
|
1
1
|
# Git CLI Scanner
|
|
2
2
|
|
|
3
|
-
A powerful CLI tool that scans your codebase for hardcoded secrets, API keys, passwords,
|
|
3
|
+
A powerful CLI tool that scans your codebase for hardcoded secrets, API keys, passwords, private keys, database credentials, and Docker infrastructure tokens before they reach your Git history.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# Install globally
|
|
11
|
-
npm install -g git-cli-scanner
|
|
12
|
-
|
|
13
|
-
# Or use directly with npx (no install needed)
|
|
14
|
-
npx git-cli-scanner <command>
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
7
|
+
## What Does It Scan For?
|
|
18
8
|
|
|
19
|
-
|
|
9
|
+
Git CLI Scanner uses regex heuristics and pattern matching to detect:
|
|
20
10
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
- **Cloud Provider Keys**: AWS Access/Secret Keys, Google Cloud API Keys.
|
|
12
|
+
- **Infrastructure & Databases**: Database Connection Strings (MongoDB, PostgreSQL, MySQL, Redis), Docker Hub Personal Access Tokens.
|
|
13
|
+
- **Collaboration Tools**: Slack Tokens, Slack Webhooks, GitHub PATs, OAuth Tokens, Discord Webhooks.
|
|
14
|
+
- **Private Keys**: RSA, DSA, EC, OpenSSH, PGP Private Keys.
|
|
15
|
+
- **Banned Files**: Accidental commits of `.env`, `.pem`, `.sqlite`, `.log` files (unless they are explicitly added to `.gitignore`).
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
npx git-cli-scanner init
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
After running `init`, every time you run `git commit`, the scanner will automatically scan your staged files and warn you if any vulnerabilities are found.
|
|
17
|
+
It features an intelligent **Ignore System** (Dummy Detection) that automatically downgrades the severity of fake, dummy, or test secrets commonly used in unit tests (e.g., `1234567890abcdef`, `dummy_token`).
|
|
30
18
|
|
|
31
19
|
---
|
|
32
20
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
| Command | Description |
|
|
36
|
-
|---------|-------------|
|
|
37
|
-
| `init` | Install the pre-commit hook for automatic scanning |
|
|
38
|
-
| `disable` | Remove the pre-commit hook and stop automatic scanning |
|
|
39
|
-
| `scan` | Manually scan staged files |
|
|
40
|
-
| `scan --show-sol` | Scan staged files and show suggested fixes |
|
|
41
|
-
| `scan-all [dir]` | Scan an entire directory recursively |
|
|
42
|
-
| `scan-history` | Scan Git commit history for leaked secrets |
|
|
43
|
-
| `explore` | Launch interactive file explorer TUI |
|
|
44
|
-
|
|
45
|
-
### Enable automatic scanning
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npx git-cli-scanner init
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Installs a pre-commit hook. After this, every `git commit` will automatically scan your staged files. If vulnerabilities are found, you choose to continue or abort.
|
|
52
|
-
|
|
53
|
-
### Disable automatic scanning
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
npx git-cli-scanner disable
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Removes the pre-commit hook. The scanner will no longer run automatically on `git commit`.
|
|
60
|
-
|
|
61
|
-
### Scan staged files
|
|
21
|
+
## Installation
|
|
62
22
|
|
|
63
23
|
```bash
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Scan an entire directory
|
|
24
|
+
# Install globally via NPM
|
|
25
|
+
npm install -g git-cli-scanner
|
|
69
26
|
|
|
70
|
-
|
|
71
|
-
npx git-cli-scanner
|
|
72
|
-
npx git-cli-scanner scan-all ./src
|
|
73
|
-
npx git-cli-scanner scan-all tests --show-sol
|
|
27
|
+
# Or use directly with npx (no install needed)
|
|
28
|
+
npx git-cli-scanner <command>
|
|
74
29
|
```
|
|
75
30
|
|
|
76
|
-
|
|
31
|
+
---
|
|
77
32
|
|
|
78
|
-
|
|
79
|
-
# Scan the very last commit (default)
|
|
80
|
-
npx git-cli-scanner scan-history
|
|
33
|
+
## ๐ Usage & Commands
|
|
81
34
|
|
|
82
|
-
|
|
83
|
-
npx git-cli-scanner scan-history --id <hash>
|
|
35
|
+
### Commands Overview
|
|
84
36
|
|
|
85
|
-
|
|
86
|
-
|
|
37
|
+
| Command | Description | Arguments & Flags | Example Usage |
|
|
38
|
+
|---------|-------------|-------------------|---------------|
|
|
39
|
+
| `init` | Installs the pre-commit hook to automatically scan files on `git commit`. | None | `npx git-cli-scanner init` |
|
|
40
|
+
| `disable` | Removes the pre-commit hook to stop automatic scanning. | None | `npx git-cli-scanner disable` |
|
|
41
|
+
| `scan` | Manually scans the currently staged files (files added via `git add`). | `--show-sol` (Shows suggested solutions) | `npx git-cli-scanner scan`<br>`npx git-cli-scanner scan --show-sol` |
|
|
42
|
+
| `scan-all` | Recursively scans an entire directory for secrets. | `<dir>` (The directory to scan)<br>`--show-sol` (Shows solutions) | `npx git-cli-scanner scan-all .`<br>`npx git-cli-scanner scan-all ./src --show-sol` |
|
|
43
|
+
| `scan-history`| Scans Git commit history for leaked secrets (Time Travel). | `--id <hash>` (Scan a specific commit)<br>`--since="<time>"` (Scan from a time)<br>`--all` (Scan entire history)<br>`--show-sol` (Shows solutions) | `npx git-cli-scanner scan-history`<br>`npx git-cli-scanner scan-history --id 3a4b5c6`<br>`npx git-cli-scanner scan-history --since="30 days ago"`<br>`npx git-cli-scanner scan-history --all` |
|
|
44
|
+
| `explore` | Launches an interactive Terminal User Interface (TUI) to navigate and scan files. | None | `npx git-cli-scanner explore` |
|
|
87
45
|
|
|
88
|
-
|
|
89
|
-
npx git-cli-scanner scan-history --all
|
|
90
|
-
```
|
|
46
|
+
### 6. Interactive File Explorer (TUI)
|
|
91
47
|
|
|
92
|
-
|
|
48
|
+
Launch an interactive Terminal User Interface (TUI) to navigate your project directory and manually select files to scan.
|
|
93
49
|
|
|
94
50
|
```bash
|
|
95
|
-
|
|
51
|
+
git-cli-scanner explore
|
|
96
52
|
```
|
|
97
53
|
|
|
98
54
|
| Key | Action |
|
|
@@ -106,15 +62,39 @@ npx git-cli-scanner explore
|
|
|
106
62
|
|
|
107
63
|
## Severity Levels
|
|
108
64
|
|
|
65
|
+
The scanner categorizes findings into different severity levels:
|
|
66
|
+
|
|
109
67
|
| Indicator | Level | Color | Meaning |
|
|
110
68
|
|-----------|-------|-------|---------|
|
|
111
|
-
| `โ` | HIGH | Red | Hardcoded secrets that must be removed |
|
|
112
|
-
| `โ` | MEDIUM | Yellow | Risky files not in
|
|
113
|
-
| `โ` | IGNORED | Dim | Test/example values (auto-detected) |
|
|
69
|
+
| `โ` | HIGH | Red | Hardcoded secrets that pose a critical risk and must be removed. |
|
|
70
|
+
| `โ` | MEDIUM | Yellow | Risky files or configurations not safely ignored in `.gitignore`. |
|
|
71
|
+
| `โ` | IGNORED | Dim | Test/example values (auto-detected dummy values that pose no risk). |
|
|
114
72
|
|
|
115
73
|
---
|
|
116
74
|
|
|
117
|
-
##
|
|
75
|
+
## Example Output
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
โ Found 2 vulnerabilities! (2 blockers)
|
|
79
|
+
|
|
80
|
+
Scan Results:
|
|
81
|
+
|
|
82
|
+
โ HIGH ยท aws-secret-key
|
|
83
|
+
File: src/config/aws.ts:12
|
|
84
|
+
Match: aws_secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEX...
|
|
85
|
+
Risk: Compromised AWS Secret Keys grant direct access to your entire cloud infrastructure.
|
|
86
|
+
|
|
87
|
+
โ HIGH ยท database-connection-string
|
|
88
|
+
File: src/db/connection.ts:5
|
|
89
|
+
Match: mongodb+srv://admin:supersecret123@cluster0.mongo...
|
|
90
|
+
Risk: An attacker can directly connect to your database instance, allowing them to steal user data.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Running Tests Locally
|
|
96
|
+
|
|
97
|
+
If you are contributing to the project, you can run the test suite using Vitest:
|
|
118
98
|
|
|
119
99
|
```bash
|
|
120
100
|
npm test
|