@vulnzap/cli
Version:
Secure AI-generated code by intercepting vulnerabilities in real-time
500 lines (404 loc) โข 15.1 kB
Markdown
# VulnZap ๐
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org/)
[](https://www.typescriptlang.org/)
[](https://modelcontextprotocol.io/)
**The Missing Security Layer for AI-Generated Code**
VulnZap is a real-time vulnerability scanning tool that integrates seamlessly with AI-powered IDEs like Cursor, Cline, and Windsurf. It automatically intercepts package installation commands and scans for known vulnerabilities before they enter your codebase, ensuring your AI-generated code remains secure.
## ๐ Features
### Core Security Features
- **Real-time Vulnerability Scanning**: Automatically scans packages before installation
- **Multi-Ecosystem Support**: npm, pip, go, rust, maven, gradle, composer, nuget, pypi
- **MCP Protocol Integration**: Native support for Model Context Protocol
- **Smart Caching**: 5-day cache with automatic invalidation for performance
- **Offline Mode**: Local vulnerability database fallback when API is unavailable
### AI-Enhanced Features
- **Amplified Security Prompts**: Transform feature requests into security-hardened implementations
- **Smart Documentation**: Context-aware package documentation and security guidelines
- **Latest Toolset Recommendations**: Up-to-date package recommendations with security scoring
- **OWASP Top 10 Compliance**: Built-in security guidance following OWASP standards
### IDE Integrations
- **Cursor IDE**: Native MCP server integration
- **Cline (Claude Dev)**: Full compatibility with Claude-based development
- **Windsurf IDE**: Seamless integration with Codeium's AI IDE
- **Generic MCP Support**: Compatible with any MCP-enabled environment
## ๐ฆ Installation
### Prerequisites
- Node.js 16.0.0 or higher
- npm or yarn package manager
### Global Installation
```bash
npm install -g vulnzap
```
### From Source
```bash
git clone https://github.com/vulnzap/vulnzap.git
cd vulnzap
npm install
npm run build
npm link
```
## ๐ ๏ธ Quick Start
### 1. Setup API Key
```bash
# Configure your API key (get it from https://vulnzap.com/dashboard/api-keys)
vulnzap setup -k <your-api-key>
# Setup API key with IDE connection in one step
vulnzap setup -k <your-api-key> --ide cursor
vulnzap setup -k <your-api-key> --ide windsurf
vulnzap setup -k <your-api-key> --ide cline
```
### 2. Connect to Your IDE (if not done in step 1)
```bash
# Connect to Cursor IDE
vulnzap connect --ide cursor
# Connect to Windsurf IDE
vulnzap connect --ide windsurf
# Connect to Cline
vulnzap connect --ide cline
```
### 3. Start Scanning
Once connected, VulnZap automatically scans packages when your AI assistant tries to install them.
## ๐ง CLI Commands
### Setup & Configuration
```bash
# Setup API key
vulnzap setup -k <api-key>
# Setup API key and connect to IDE in one step
vulnzap setup -k <api-key> --ide <cursor|windsurf|cline>
# Check account information
vulnzap account
```
### Project Management
```bash
# Check server status
vulnzap status
# View help
vulnzap help
```
### Security Scanning
```bash
# Check individual package
vulnzap check <ecosystem:package@version>
vulnzap check npm:express@4.17.1
vulnzap check pip:requests@2.25.1
# Alternative syntax
vulnzap check <package> --ecosystem <eco> --version <ver>
vulnzap check express --ecosystem npm --version 4.17.1
# Batch scan current directory
vulnzap batch-scan [--ecosystem <ecosystem>] [--output <file>]
# Options
--cache, -C Use cached results
--ai, -A Use AI for vulnerability summaries
```
### IDE Integration
```bash
# Connect to IDE (sets up MCP configuration)
vulnzap connect [--ide cursor|cline|windsurf]
# Start MCP server manually (for debugging)
vulnzap secure [--ide <ide>] [--port <port>]
```
## ๐ MCP Tools Reference
VulnZap provides several Model Context Protocol tools that integrate with your AI assistant:
### 1. auto-vulnerability-scan
**Purpose**: Automatically scans packages before installation
**Usage**: Called automatically when AI suggests package installation
```json
{
"command": "npm install",
"ecosystem": "npm",
"packageName": "express",
"version": "4.17.1"
}
```
### 2. batch-scan
**Purpose**: Scans all packages in a directory
**Parameters**:
- `directory`: Full path to scan
- `ecosystem` (optional): Specific ecosystem filter
### 3. amplify-feature-prompt
**Purpose**: Enhances feature requests with security best practices
**Parameters**:
- `user_prompt`: The feature request
- `project_type`: web_app, api, cli, library, etc.
- `security_level`: high, medium, low
- `tech_stack`: Array of technologies
- `compliance_requirements`: GDPR, SOX, etc.
### 4. get_docs
**Purpose**: Retrieves security-focused documentation
**Parameters**:
- `package_name`: Package to document
- `skill_level`: beginner, intermediate, advanced
- `project_context`: Context for documentation
- `learning_goals`: Array of learning objectives
### 5. latest_toolset
**Purpose**: Recommends up-to-date, secure packages
**Parameters**:
- `user_prompt`: Project description
- `user_tools`: User's preferred tools
- `agent_tools`: AI's suggested tools
- `security_requirements`: Include security features
- `performance_requirements`: Include performance optimizations
## ๐ Project Structure
```
vulnzap/
โโโ src/
โ โโโ api/ # API integration layer
โ โ โโโ auth.ts # Authentication & OAuth
โ โ โโโ batchScan.ts # Batch scanning functionality
โ โ โโโ apis.ts # API utilities
โ โโโ config/ # Configuration management
โ โ โโโ config.ts # App configuration
โ โโโ services/ # Core services
โ โ โโโ cache.ts # Caching service
โ โโโ types/ # TypeScript definitions
โ โ โโโ response.ts # API response types
โ โโโ utils/ # Utility functions
โ โ โโโ packageExtractor.ts # Package file parsing
โ โ โโโ apiClient.ts # HTTP client wrapper
โ โ โโโ checks.ts # Project validation
โ โโโ cli.ts # Command-line interface
โ โโโ index.ts # MCP server implementation
โโโ tests/ # Test suite
โโโ dist/ # Compiled JavaScript
โโโ package.json # Project dependencies
โโโ tsconfig.json # TypeScript configuration
โโโ README.md # This file
```
## ๐ Security Features
### OWASP Top 10 Coverage
VulnZap automatically checks for and provides guidance on:
- **A01:2021 โ Broken Access Control**
- **A02:2021 โ Cryptographic Failures**
- **A03:2021 โ Injection**
- **A04:2021 โ Insecure Design**
- **A05:2021 โ Security Misconfiguration**
- **A06:2021 โ Vulnerable and Outdated Components**
- **A07:2021 โ Identification and Authentication Failures**
- **A08:2021 โ Software and Data Integrity Failures**
- **A09:2021 โ Security Logging and Monitoring Failures**
- **A10:2021 โ Server-Side Request Forgery (SSRF)**
### Vulnerability Data Sources
- **GitHub Security Advisory Database**
- **National Vulnerability Database (NVD)**
- **OSV Database**
- **Local vulnerability database**
### Security Best Practices
- Secure credential storage using system keychain
- Encrypted API communications
- Local caching with TTL expiration
- Offline mode for air-gapped environments
## ๐๏ธ Architecture
### MCP Server Architecture
```
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ AI Assistant โโโโโบโ MCP Server โโโโโบโ VulnZap API โ
โ (Cursor/etc) โ โ (Local) โ โ (Remote) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Local Cache โ
โ (5-day TTL) โ
โโโโโโโโโโโโโโโโโโโ
```
### Package Detection Flow
```
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Package Install โโโโโบโ Extraction โโโโโบโ Vulnerability โ
โ Command โ โ & Parsing โ โ Scanning โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Supported Files โ
โ โข package.json โ
โ โข requirements โ
โ โข go.mod โ
โ โข Cargo.toml โ
โ โข pom.xml โ
โ โข *.csproj โ
โ โข build.gradle โ
โ โข composer.json โ
โโโโโโโโโโโโโโโโโโโ
```
## ๐ง Configuration
### Environment Variables
```bash
# Required
VULNZAP_API_KEY=your_api_key_here
# Server configuration
VULNZAP_SERVER_URL=https://api.vulnzap.com # Override default server
```
### IDE Configuration Files
#### Cursor (.cursor/mcp.json)
```json
{
"mcpServers": {
"VulnZap": {
"command": "vulnzap",
"args": ["secure", "--ide", "cursor"],
"env": {
"VULNZAP_API_KEY": "your_api_key"
}
}
}
}
```
#### Windsurf (.codeium/windsurf/mcp_config.json)
```json
{
"mcpServers": {
"VulnZap": {
"command": "vulnzap",
"args": ["secure", "--ide", "windsurf"],
"env": {
"VULNZAP_API_KEY": "your_api_key"
}
}
}
}
```
## ๐งช Testing
```bash
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
```
## ๐ Performance
### Caching Strategy
- **Local Cache**: 5-day TTL for vulnerability data
- **Memory Cache**: In-memory caching for session data
- **Smart Invalidation**: Automatic cache refresh on stale data
### Response Times
- **Cached Results**: < 50ms
- **API Calls**: 200-500ms (depending on network)
- **Batch Scans**: ~100ms per package (parallelized)
### Resource Usage
- **Memory**: ~50MB base usage
- **Disk**: ~10MB cache directory
- **Network**: Minimal (only when cache misses)
## ๐ Development Workflow
### Building from Source
```bash
# Install dependencies
npm install
# Build TypeScript
npm run build
# Start development server with hot reload
npm run dev
# Start CLI in watch mode
npm run cli
```
### Contributing
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass: `npm test`
6. Commit your changes: `git commit -m 'Add amazing feature'`
7. Push to the branch: `git push origin feature/amazing-feature`
8. Open a Pull Request
## ๐ API Reference
### Core Functions
#### checkVulnerability(ecosystem, packageName, version, options)
Scans a single package for vulnerabilities.
```typescript
const result = await checkVulnerability('npm', 'express', '4.17.1', {
useCache: true,
useAi: false
});
```
#### checkBatch(packages)
Scans multiple packages in parallel.
```typescript
const results = await checkBatch([
{ packageName: 'express', ecosystem: 'npm', version: '4.17.1' },
{ packageName: 'requests', ecosystem: 'pip', version: '2.25.1' }
]);
```
#### extractPackagesFromDirectory(dirPath, ecosystem?)
Extracts package information from project files.
```typescript
const packages = extractPackagesFromDirectory('./my-project', 'npm');
```
## ๐ Ecosystem Support
| Ecosystem | File Types | Status |
|-----------|------------|---------|
| **npm** | package.json | โ
Full |
| **pip** | requirements.txt, setup.py | โ
Full |
| **go** | go.mod | โ
Full |
| **rust** | Cargo.toml | โ
Full |
| **maven** | pom.xml | โ
Full |
| **gradle** | build.gradle | โ
Full |
| **nuget** | *.csproj, packages.config | โ
Full |
| **composer** | composer.json | โ
Full |
## ๐ Troubleshooting
### Common Issues
#### "API key not configured"
```bash
# Solution: Set up your API key
vulnzap setup -k your_api_key_here
```
#### "VulnZap server is down"
```bash
# Check server status
vulnzap status
# VulnZap will automatically use local cache in offline mode
```
#### "No packages found to scan"
Make sure your project contains supported package files:
- `package.json` (npm)
- `requirements.txt` (pip)
- `go.mod` (go)
- `Cargo.toml` (rust)
- etc.
#### MCP Connection Issues
1. Verify IDE MCP configuration
2. Check that vulnzap is in your PATH
3. Restart your IDE after configuration changes
### Debug Mode
```bash
# Enable verbose logging
VULNZAP_DEBUG=true vulnzap secure --ide cursor
# Check MCP server logs
tail -f ~/.vulnzap/logs/mcp-server.log
```
## ๐ Support
- **Documentation**: [https://vulnzap.com/docs](https://vulnzap.com/docs)
- **Issues**: [GitHub Issues](https://github.com/vulnzap/vulnzap/issues)
- **Discussions**: [GitHub Discussions](https://github.com/vulnzap/vulnzap/discussions)
- **Email**: support@plawlabs.com
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- **Model Context Protocol**: For enabling seamless AI integration
- **OWASP**: For security best practices and vulnerability guidelines
- **Security Community**: For vulnerability data and research
- **Open Source Contributors**: For making this project possible
## ๐ฎ Roadmap
### Upcoming Features
- [ ] Real-time CI/CD pipeline integration
- [ ] IDE vulnerability highlighting
- [ ] Custom vulnerability rules
- [ ] SBOM generation and analysis
- [ ] Compliance reporting (SOC2, ISO 27001)
- [ ] Advanced threat modeling
- [ ] Container image scanning
- [ ] Infrastructure as Code scanning
### Planned Integrations
- [ ] VS Code extension
- [ ] JetBrains plugin
- [ ] GitHub Actions integration
- [ ] Jenkins plugin
- [ ] GitLab CI integration
**Made with โค๏ธ by the PlawLabs Team**
*Securing the future of AI-generated code, one package at a time.*