api-key-guard 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-key-guard",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A comprehensive tool to detect, prevent, and manage API key leaks in your codebase with AI-powered README generation",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -28,4 +28,4 @@
28
28
  "engines": {
29
29
  "node": ">=14.0.0"
30
30
  }
31
- }
31
+ }
@@ -97,7 +97,7 @@ async function generateWithGemini(apiKey, projectContext) {
97
97
 
98
98
  try {
99
99
  const response = await axios.post(
100
- `https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${apiKey}`,
100
+ `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${apiKey}`,
101
101
  {
102
102
  contents: [{
103
103
  parts: [{
package/TESTING.md DELETED
@@ -1,111 +0,0 @@
1
- # Testing the API Key Guard CLI
2
-
3
- ## Demo Instructions
4
-
5
- This guide helps you test the API Key Guard CLI tool with the AI-powered README generator.
6
-
7
- ### Step 1: Install Dependencies
8
- ```bash
9
- cd api-key-guard
10
- npm install
11
- ```
12
-
13
- ### Step 2: Test Basic Commands
14
-
15
- #### Test the help system:
16
- ```bash
17
- node bin/cli.js --help
18
- node bin/cli.js readme --help
19
- node bin/cli.js scan --help
20
- ```
21
-
22
- #### Test the scanner:
23
- ```bash
24
- node bin/cli.js scan
25
- node bin/cli.js scan --verbose
26
- ```
27
-
28
- ### Step 3: Test API Key Detection
29
- Create a test file with fake API keys:
30
- ```javascript
31
- // test-keys.js
32
- const config = {
33
- api_key: "sk-1234567890abcdef1234567890abcdef12345678",
34
- aws_key: "AKIA1234567890ABCDEF",
35
- github_token: "ghp_abcdefghijklmnopqrstuvwxyz1234567890"
36
- };
37
- ```
38
-
39
- Then scan:
40
- ```bash
41
- node bin/cli.js scan --verbose
42
- ```
43
-
44
- ### Step 4: Test README Generator
45
-
46
- #### Without API key (should show error):
47
- ```bash
48
- node bin/cli.js readme --output test-readme.md
49
- ```
50
-
51
- #### With API key (requires real Gemini API key):
52
- 1. Get API key from [Google AI Studio](https://makersuite.google.com/app/apikey)
53
- 2. Set environment variable:
54
- ```bash
55
- # Windows PowerShell
56
- $env:GEMINI_API_KEY = "your_actual_api_key"
57
-
58
- # Then run
59
- node bin/cli.js readme --force --output ai-generated-readme.md
60
- ```
61
-
62
- ### Step 5: Test Git Hooks
63
- ```bash
64
- # Initialize git (if not already done)
65
- git init
66
-
67
- # Install hooks
68
- node bin/cli.js setup-hooks
69
-
70
- # Test the hook by trying to commit a file with API keys
71
- echo 'const key = "AKIA1234567890ABCDEF";' > bad-file.js
72
- git add bad-file.js
73
- git commit -m "test commit" # Should be blocked
74
- ```
75
-
76
- ## Expected Outputs
77
-
78
- ### Successful README Generation
79
- When you have a valid API key, you should see:
80
- ```
81
- 🤖 Generating README with AI...
82
- 📝 Analyzing project structure...
83
- 🚀 Generating README with Gemini AI...
84
- 💾 Writing README.md...
85
- ✅ Successfully generated README.md!
86
- ```
87
-
88
- ### API Key Detection
89
- When scanning files with API keys:
90
- ```
91
- 🔍 Scanning for API key leaks...
92
- 🚨 Found X potential API key leak(s):
93
- 📄 filename.js:line_number
94
- Pattern: detected_pattern
95
- ⚠️ Please review these findings and secure any exposed API keys!
96
- ```
97
-
98
- ### Error Handling
99
- Without API key:
100
- ```
101
- Error generating README: GEMINI_API_KEY environment variable is required. Please set your Gemini API key.
102
- ```
103
-
104
- ## Cleanup After Testing
105
- ```bash
106
- # Remove test files
107
- rm test-keys.js bad-file.js ai-generated-readme.md
108
-
109
- # Remove git hooks if needed
110
- rm .git/hooks/pre-commit
111
- ```
package/USAGE.md DELETED
@@ -1,126 +0,0 @@
1
- # API Key Guard - Usage Guide
2
-
3
- ## Quick Setup
4
-
5
- 1. **Install the package:**
6
- ```bash
7
- npm install -g api-key-guard
8
- ```
9
-
10
- 2. **Get a Gemini API key:**
11
- - Visit [Google AI Studio](https://makersuite.google.com/app/apikey)
12
- - Create a new API key
13
- - Copy the API key
14
-
15
- 3. **Set up environment variable:**
16
- ```bash
17
- # Windows (PowerShell)
18
- $env:GEMINI_API_KEY = "your_gemini_api_key_here"
19
-
20
- # Windows (Command Prompt)
21
- set GEMINI_API_KEY=your_gemini_api_key_here
22
-
23
- # macOS/Linux
24
- export GEMINI_API_KEY=your_gemini_api_key_here
25
- ```
26
-
27
- ## Using the AI-Powered README Generator
28
-
29
- ### Basic Usage
30
- ```bash
31
- # Generate README.md with AI
32
- api-key-guard readme
33
- ```
34
-
35
- ### With Options
36
- ```bash
37
- # Force overwrite existing README.md
38
- api-key-guard readme --force
39
-
40
- # Output to a different file
41
- api-key-guard readme --output DOCUMENTATION.md
42
-
43
- # Combine options
44
- api-key-guard readme --force --output NEW_README.md
45
- ```
46
-
47
- ### What the AI Generates
48
- The README generator creates a comprehensive README.md that includes:
49
-
50
- - **Project title and description**
51
- - **Problem statement** explaining API key leak issues
52
- - **Features list** showcasing all capabilities
53
- - **Installation instructions** for npm
54
- - **CLI usage examples** for all commands
55
- - **Git hooks setup guide**
56
- - **Configuration options**
57
- - **Security best practices**
58
- - **Contributing guidelines**
59
- - **License information**
60
-
61
- ## Other Commands
62
-
63
- ### Scan for API Key Leaks
64
- ```bash
65
- # Scan current directory
66
- api-key-guard scan
67
-
68
- # Scan specific path
69
- api-key-guard scan --path ./src
70
-
71
- # Verbose output
72
- api-key-guard scan --verbose
73
- ```
74
-
75
- ### Setup Git Hooks
76
- ```bash
77
- # Install pre-commit hook
78
- api-key-guard setup-hooks
79
- ```
80
-
81
- ## Error Handling
82
-
83
- The tool provides clear error messages for common issues:
84
-
85
- - **Missing API key**: Clear instructions on how to set GEMINI_API_KEY
86
- - **Network issues**: Helpful network troubleshooting information
87
- - **Invalid API responses**: Detailed API error messages
88
- - **File permissions**: Clear permission error messages
89
-
90
- ## Security Features
91
-
92
- - **No API key storage**: API keys are read from environment variables only
93
- - **Pattern-based detection**: Uses regex patterns to detect various API key formats
94
- - **Configurable ignore patterns**: Respects .gitignore-style patterns
95
- - **Git hook integration**: Prevents commits with detected API keys
96
-
97
- ## Supported API Key Formats
98
-
99
- The scanner detects these common API key patterns:
100
- - Generic API keys (`api_key`, `secret_key`, `access_token`)
101
- - AWS Access Keys (`AKIA...`)
102
- - GitHub Personal Access Tokens (`ghp_...`)
103
- - Google API Keys (`AIza...`)
104
- - Bearer tokens
105
- - Custom patterns (configurable)
106
-
107
- ## Configuration
108
-
109
- Create a `api-key-guard.config.json` file to customize:
110
-
111
- ```json
112
- {
113
- "ignorePatterns": [
114
- "node_modules",
115
- ".git",
116
- "dist",
117
- "*.log"
118
- ],
119
- "customPatterns": [
120
- {
121
- "name": "Custom API Key",
122
- "pattern": "custom_[0-9a-f]{32}"
123
- }
124
- ]
125
- }
126
- ```
@@ -1,49 +0,0 @@
1
- {
2
- "apiKeyPatterns": [
3
- {
4
- "name": "Generic API Key",
5
- "pattern": "(?i)api[_-]?key[\\s]*[=:][\\s]*['\"]?([a-z0-9]{20,})",
6
- "description": "Generic API key pattern"
7
- },
8
- {
9
- "name": "Generic Secret Key",
10
- "pattern": "(?i)secret[_-]?key[\\s]*[=:][\\s]*['\"]?([a-z0-9]{20,})",
11
- "description": "Generic secret key pattern"
12
- },
13
- {
14
- "name": "Access Token",
15
- "pattern": "(?i)access[_-]?token[\\s]*[=:][\\s]*['\"]?([a-z0-9]{20,})",
16
- "description": "Generic access token pattern"
17
- },
18
- {
19
- "name": "AWS Access Key ID",
20
- "pattern": "AKIA[0-9A-Z]{16}",
21
- "description": "AWS Access Key ID"
22
- },
23
- {
24
- "name": "GitHub Token",
25
- "pattern": "ghp_[0-9a-zA-Z]{36}",
26
- "description": "GitHub personal access token"
27
- },
28
- {
29
- "name": "Google API Key",
30
- "pattern": "AIza[0-9A-Za-z\\-_]{35}",
31
- "description": "Google API key"
32
- }
33
- ],
34
- "ignorePatterns": [
35
- "node_modules",
36
- ".git",
37
- "dist",
38
- "build",
39
- "*.log",
40
- "*.min.js",
41
- "package-lock.json",
42
- ".env.example"
43
- ],
44
- "fileExtensions": [
45
- ".js", ".ts", ".jsx", ".tsx", ".json", ".md", ".txt", ".yml", ".yaml",
46
- ".xml", ".html", ".css", ".scss", ".sass", ".less", ".env", ".config",
47
- ".py", ".java", ".php", ".rb", ".go", ".rs", ".cpp", ".c", ".h"
48
- ]
49
- }