git-cli-scanner 1.0.0 → 1.1.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.
Files changed (3) hide show
  1. package/dist/cli.js +42 -23
  2. package/package.json +11 -2
  3. package/readme.md +44 -64
package/dist/cli.js CHANGED
@@ -652,12 +652,6 @@ init_logger();
652
652
 
653
653
  // src/utils/prompts.ts
654
654
  var import_prompts = require("@inquirer/prompts");
655
- async function askToScan() {
656
- return await (0, import_prompts.confirm)({
657
- message: "Do you want to scan for vulnerabilities before committing?",
658
- default: true
659
- });
660
- }
661
655
  async function askToContinue() {
662
656
  return await (0, import_prompts.confirm)({
663
657
  message: "Vulnerabilities were found! Do you still want to continue with the commit?",
@@ -709,36 +703,61 @@ var Spinner = class {
709
703
  };
710
704
 
711
705
  // src/cli.ts
712
- var import_child_process2 = require("child_process");
713
706
  var fs3 = __toESM(require("fs"));
714
707
  var path3 = __toESM(require("path"));
715
708
  var program = new import_commander.Command();
716
- program.name("git-cli-scanner").description("Interactive Git hooks vulnerability scanner").version("1.0.0");
717
- program.command("init").description("Initialize husky and add the pre-commit hook automatically").action(() => {
718
- info("Setting up git hooks with husky...");
709
+ program.name("git-cli-scanner").description("Interactive Git hooks vulnerability scanner").version("1.1.0");
710
+ program.command("init").description("Install pre-commit hook for automatic scanning").action(() => {
711
+ info("Setting up pre-commit hook...");
719
712
  try {
720
- (0, import_child_process2.execSync)("npx husky init", { stdio: "inherit" });
721
- const hookPath = path3.join(process.cwd(), ".husky", "pre-commit");
722
- const hookContent = `
713
+ const gitDir = path3.join(process.cwd(), ".git");
714
+ if (!fs3.existsSync(gitDir)) {
715
+ error("Not a git repository. Run `git init` first.");
716
+ process.exit(1);
717
+ }
718
+ const hooksDir = path3.join(gitDir, "hooks");
719
+ if (!fs3.existsSync(hooksDir)) {
720
+ fs3.mkdirSync(hooksDir, { recursive: true });
721
+ }
722
+ const hookPath = path3.join(hooksDir, "pre-commit");
723
+ const hookContent = `#!/bin/sh
724
+ # git-cli-scanner pre-commit hook
723
725
  # exec < /dev/tty is required to allow interactive prompts in git hooks
724
726
  exec < /dev/tty
725
727
  npx git-cli-scanner scan
726
- `.trim();
727
- fs3.writeFileSync(hookPath, hookContent, "utf-8");
728
- success("Successfully installed pre-commit hook!");
729
- info("Next time you run `git commit`, the scanner will prompt you.");
728
+ `;
729
+ fs3.writeFileSync(hookPath, hookContent, { mode: 493 });
730
+ success("Pre-commit hook installed!");
731
+ info("Every `git commit` will now automatically scan your staged files.");
730
732
  } catch (err) {
731
733
  error(`Failed to initialize: ${err.message}`);
732
734
  }
733
735
  });
734
- program.command("scan").description("Interactive vulnerability scan for staged files").option("--show-sol", "Show solutions for vulnerabilities").action(async (options) => {
735
- info("GitHub CLI Scanner triggered by Git Hook.");
736
+ program.command("disable").description("Remove the pre-commit hook and disable automatic scanning").action(() => {
736
737
  try {
737
- const shouldScan = await askToScan();
738
- if (!shouldScan) {
739
- info("Skipping scan as requested. Proceeding with commit...");
740
- process.exit(0);
738
+ const gitHookPath = path3.join(process.cwd(), ".git", "hooks", "pre-commit");
739
+ const huskyHookPath = path3.join(process.cwd(), ".husky", "pre-commit");
740
+ let removed = false;
741
+ if (fs3.existsSync(gitHookPath)) {
742
+ fs3.unlinkSync(gitHookPath);
743
+ removed = true;
741
744
  }
745
+ if (fs3.existsSync(huskyHookPath)) {
746
+ fs3.unlinkSync(huskyHookPath);
747
+ removed = true;
748
+ }
749
+ if (removed) {
750
+ success("Pre-commit hook removed. Automatic scanning is now disabled.");
751
+ } else {
752
+ info("No pre-commit hook found. Nothing to disable.");
753
+ }
754
+ } catch (err) {
755
+ error(`Failed to disable: ${err.message}`);
756
+ }
757
+ });
758
+ program.command("scan").description("Interactive vulnerability scan for staged files").option("--show-sol", "Show solutions for vulnerabilities").action(async (options) => {
759
+ info("Git CLI Scanner running...");
760
+ try {
742
761
  const spinner = new Spinner([
743
762
  "Scanning staged files for vulnerabilities...",
744
763
  "Analyzing code patterns...",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-cli-scanner",
3
- "version": "1.0.0",
3
+ "version": "1.1.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": {
@@ -8,7 +8,16 @@
8
8
  "build": "tsup src/cli.ts --format cjs",
9
9
  "prepare": "husky"
10
10
  },
11
- "keywords": ["security", "scanner", "git", "secrets", "api-keys", "cli", "pre-commit", "vulnerability"],
11
+ "keywords": [
12
+ "security",
13
+ "scanner",
14
+ "git",
15
+ "secrets",
16
+ "api-keys",
17
+ "cli",
18
+ "pre-commit",
19
+ "vulnerability"
20
+ ],
12
21
  "author": "riskchips",
13
22
  "license": "ISC",
14
23
  "dependencies": {
package/readme.md CHANGED
@@ -1,110 +1,90 @@
1
1
  # Git CLI Scanner
2
2
 
3
- A powerful, interactive CLI tool that scans your codebase for hardcoded secrets, API keys, passwords, private keys, and other vulnerabilities before they ever reach your Git history.
3
+ A powerful CLI tool that scans your codebase for hardcoded secrets, API keys, passwords, and private keys before they reach your Git history.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Installation
8
8
 
9
9
  ```bash
10
+ # Install globally
10
11
  npm install -g git-cli-scanner
12
+
13
+ # Or use directly with npx (no install needed)
14
+ npx git-cli-scanner <command>
11
15
  ```
12
16
 
13
- ## Quick Start
17
+ ---
18
+
19
+ ## Setup
14
20
 
15
21
  ```bash
16
- # Set up the pre-commit hook (one-time)
17
- npx git-cli-scanner init
22
+ # Navigate to your project
23
+ cd your-project
18
24
 
19
- # Now every time you run `git commit`, the scanner will automatically prompt you.
25
+ # Initialize the pre-commit hook
26
+ npx git-cli-scanner init
20
27
  ```
21
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.
30
+
22
31
  ---
23
32
 
24
33
  ## Commands
25
34
 
26
- ### `init` Set up Git hooks
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 |
27
44
 
28
- Installs a Husky pre-commit hook that triggers the scanner automatically before every commit.
45
+ ### Enable automatic scanning
29
46
 
30
47
  ```bash
31
48
  npx git-cli-scanner init
32
49
  ```
33
50
 
34
- ### `scan` Scan staged files (Git hook mode)
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.
35
52
 
36
- Interactively scans only the files you have staged (`git add`) for vulnerabilities. This is what the pre-commit hook runs.
53
+ ### Disable automatic scanning
37
54
 
38
55
  ```bash
39
- npx git-cli-scanner scan
40
- npx git-cli-scanner scan --show-sol # Also show suggested fixes
56
+ npx git-cli-scanner disable
41
57
  ```
42
58
 
43
- ### `scan-all` Scan an entire directory
59
+ Removes the pre-commit hook. The scanner will no longer run automatically on `git commit`.
44
60
 
45
- Recursively walks through a directory and scans every file for vulnerabilities. Skips `.git`, `node_modules`, `dist`, and `build` directories automatically.
61
+ ### Scan staged files
46
62
 
47
63
  ```bash
48
- npx git-cli-scanner scan-all . # Scan current directory
49
- npx git-cli-scanner scan-all ./src # Scan only src/
50
- npx git-cli-scanner scan-all tests --show-sol # Scan tests/ with solutions
64
+ npx git-cli-scanner scan
65
+ npx git-cli-scanner scan --show-sol
51
66
  ```
52
67
 
53
- ### `explore` Interactive file explorer TUI
68
+ ### Scan an entire directory
69
+
70
+ ```bash
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
+ ```
54
75
 
55
- Launch a fully interactive Terminal UI to browse your project and scan files on the fly.
76
+ ### Interactive file explorer
56
77
 
57
78
  ```bash
58
79
  npx git-cli-scanner explore
59
80
  ```
60
81
 
61
- **Controls:**
62
82
  | Key | Action |
63
83
  |-----|--------|
64
- | `Up / Down` | Move cursor through files and folders |
65
- | `Right / Enter` | Open a folder or scan a file |
84
+ | `Up / Down` | Move through files and folders |
85
+ | `Right / Enter` | Open folder or scan file |
66
86
  | `Left` | Go back to parent directory |
67
- | `Ctrl+C` | Exit the explorer |
68
-
69
- ---
70
-
71
- ## Flags
72
-
73
- | Flag | Available On | Description |
74
- |------|-------------|-------------|
75
- | `--show-sol` | `scan`, `scan-all` | Show actionable fix suggestions for each vulnerability |
76
-
77
- ---
78
-
79
- ## What It Detects
80
-
81
- ### HIGH Severity (Red)
82
- - AWS Access Keys & Secret Keys
83
- - Google Cloud API Keys
84
- - Slack Tokens & Webhooks
85
- - GitHub Personal Access Tokens & OAuth Tokens
86
- - Stripe API Keys
87
- - SendGrid, Mailgun, and Twilio Tokens
88
- - RSA, OpenSSH, and PGP Private Keys
89
- - Generic API keys, passwords, and passphrases (any format like `api_key`, `api-key`, `API_KEY`, etc.)
90
-
91
- ### MEDIUM Severity (Yellow)
92
- - `.env` files not listed in `.gitignore`
93
- - Banned file types: `.pem`, `.key`, `.sqlite`, `.db`, `.log`, `.p12`, `.pfx`
94
- - `node_modules/` committed to the repo
95
-
96
- ### Dummy Detection (Dimmed)
97
- The scanner has a strict dummy detection engine that automatically identifies obvious test/example secrets (like `AKIAIOSFODNN7EXAMPLE` or values containing `test`, `dummy`, `sample`, etc.) and downgrades them so they don't block your workflow.
98
-
99
- ---
100
-
101
- ## Gitignore Awareness
102
-
103
- The scanner checks if banned files (like `.env`, `.sqlite`, `.pem`) are listed in your `.gitignore` or `.npmignore`. If they are, the issue is downgraded to a safe "IGNORED" status. If they are NOT, you get a loud warning:
104
-
105
- ```
106
- DANGER: .env is NOT in .gitignore or .npmignore!
107
- ```
87
+ | `Ctrl+C` | Exit |
108
88
 
109
89
  ---
110
90
 
@@ -113,8 +93,8 @@ DANGER: .env is NOT in .gitignore or .npmignore!
113
93
  | Indicator | Level | Color | Meaning |
114
94
  |-----------|-------|-------|---------|
115
95
  | `●` | HIGH | Red | Hardcoded secrets that must be removed |
116
- | `●` | MEDIUM | Yellow | Risky files that should be in .gitignore |
117
- | `○` | IGNORED (DUMMY) | Dim | Detected but identified as a test/example value |
96
+ | `●` | MEDIUM | Yellow | Risky files not in .gitignore |
97
+ | `○` | IGNORED | Dim | Test/example values (auto-detected) |
118
98
 
119
99
  ---
120
100