git-cli-scanner 1.3.0 โ 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 +57 -3
- package/package.json +1 -1
- package/readme.md +56 -60
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
|
});
|
|
@@ -901,7 +955,7 @@ var import_child_process2 = require("child_process");
|
|
|
901
955
|
var fs3 = __toESM(require("fs"));
|
|
902
956
|
var path3 = __toESM(require("path"));
|
|
903
957
|
var program = new import_commander.Command();
|
|
904
|
-
program.name("git-cli-scanner").description("Interactive Git hooks vulnerability scanner").version("1.3.
|
|
958
|
+
program.name("git-cli-scanner").description("Interactive Git hooks vulnerability scanner").version("1.3.1");
|
|
905
959
|
program.command("init").description("Install pre-commit hook for automatic scanning").action(() => {
|
|
906
960
|
info("Setting up pre-commit hook...");
|
|
907
961
|
try {
|
|
@@ -1061,7 +1115,7 @@ program.command("scan-history").description("Scan Git commit history for exposed
|
|
|
1061
1115
|
const { printIssues: printIssues2 } = (init_logger(), __toCommonJS(logger_exports));
|
|
1062
1116
|
printIssues2(issues, options.showSol);
|
|
1063
1117
|
} else {
|
|
1064
|
-
spinner.
|
|
1118
|
+
spinner.stop("No vulnerabilities found in the scanned history!");
|
|
1065
1119
|
}
|
|
1066
1120
|
} catch (err) {
|
|
1067
1121
|
error(`History scan failed: ${err.message}`);
|
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,82 +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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
npx git-cli-scanner init
|
|
27
|
-
```
|
|
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`).
|
|
28
16
|
|
|
29
|
-
|
|
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-all [dir] --show-sol` | Scan a directory and show suggested fixes |
|
|
43
|
-
| `explore` | Launch interactive file explorer TUI |
|
|
44
|
-
|
|
45
|
-
### Enable automatic scanning
|
|
21
|
+
## Installation
|
|
46
22
|
|
|
47
23
|
```bash
|
|
48
|
-
|
|
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
|
|
24
|
+
# Install globally via NPM
|
|
25
|
+
npm install -g git-cli-scanner
|
|
54
26
|
|
|
55
|
-
|
|
56
|
-
npx git-cli-scanner
|
|
27
|
+
# Or use directly with npx (no install needed)
|
|
28
|
+
npx git-cli-scanner <command>
|
|
57
29
|
```
|
|
58
30
|
|
|
59
|
-
|
|
31
|
+
---
|
|
60
32
|
|
|
61
|
-
|
|
33
|
+
## ๐ Usage & Commands
|
|
62
34
|
|
|
63
|
-
|
|
64
|
-
npx git-cli-scanner scan
|
|
65
|
-
npx git-cli-scanner scan --show-sol
|
|
66
|
-
```
|
|
35
|
+
### Commands Overview
|
|
67
36
|
|
|
68
|
-
|
|
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` |
|
|
69
45
|
|
|
70
|
-
|
|
71
|
-
npx git-cli-scanner scan-all .
|
|
72
|
-
npx git-cli-scanner scan-all ./src
|
|
73
|
-
npx git-cli-scanner scan-all tests --show-sol
|
|
74
|
-
```
|
|
46
|
+
### 6. Interactive File Explorer (TUI)
|
|
75
47
|
|
|
76
|
-
|
|
48
|
+
Launch an interactive Terminal User Interface (TUI) to navigate your project directory and manually select files to scan.
|
|
77
49
|
|
|
78
50
|
```bash
|
|
79
|
-
|
|
51
|
+
git-cli-scanner explore
|
|
80
52
|
```
|
|
81
53
|
|
|
82
54
|
| Key | Action |
|
|
@@ -90,15 +62,39 @@ npx git-cli-scanner explore
|
|
|
90
62
|
|
|
91
63
|
## Severity Levels
|
|
92
64
|
|
|
65
|
+
The scanner categorizes findings into different severity levels:
|
|
66
|
+
|
|
93
67
|
| Indicator | Level | Color | Meaning |
|
|
94
68
|
|-----------|-------|-------|---------|
|
|
95
|
-
| `โ` | HIGH | Red | Hardcoded secrets that must be removed |
|
|
96
|
-
| `โ` | MEDIUM | Yellow | Risky files not in
|
|
97
|
-
| `โ` | 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). |
|
|
98
72
|
|
|
99
73
|
---
|
|
100
74
|
|
|
101
|
-
##
|
|
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:
|
|
102
98
|
|
|
103
99
|
```bash
|
|
104
100
|
npm test
|