A security-focused AI DevOps tool that automatically scans pull requests for security vulnerabilities, secrets, and hardcoded credentials using AI-powered analysis. Built with Go, Docker, and modern AI APIs.
- AI-Powered Security Scanning: Uses advanced AI models to detect security issues in code changes
- Secret Detection: Identifies hardcoded passwords, API keys, tokens, and other sensitive data
- Vulnerability Analysis: Scans for common security vulnerabilities and anti-patterns
- Automated PR Reviews: Leaves detailed, actionable comments on GitHub pull requests
- Docker Integration: Containerized for easy deployment and scaling
- GitHub Actions: Seamless integration with CI/CD pipelines
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β GitHub PR βββββΆβ CodeGuardian βββββΆβ AI Analysis β
β β β (Go Service) β β (OpenAI/Claude)β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β PR Comments ββββββ Security Rules β β Vulnerability β
β (Automated) β β Engine β β Database β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Backend: Go (Gin framework)
- AI Integration: OpenAI GPT-4 / Anthropic Claude
- Containerization: Docker
- CI/CD: GitHub Actions
- Security: JWT authentication, rate limiting
- Monitoring: Structured logging, metrics
- Go 1.21+
- Docker and Docker Compose
- GitHub Personal Access Token
- OpenAI API Key (or Anthropic API Key)
-
Clone the repository
git clone https://github.com/your-org/codeguardian.git cd codeguardian -
Set up environment variables
cp env.example .env # Edit .env with your API keys and configuration -
Run with Docker (Recommended)
# Build and start the application make docker-run # Or with monitoring (Prometheus + Grafana) make docker-run-monitoring
-
Or run locally
# Install dependencies make install # Run the application make run
-
Run tests
# Run all tests make test # Run with coverage make coverage
-
Add secrets to your repository:
CODEGUARDIAN_API_KEY: Your CodeGuardian API keyGITHUB_TOKEN: GitHub Personal Access Token
-
Add the workflow file to
.github/workflows/codeguardian.yml -
Configure the service in your repository settings
For automatic scanning on pull requests:
- Go to your repository settings
- Navigate to Webhooks β Add webhook
- Set the payload URL to:
https://your-domain.com/api/v1/webhook/github - Set content type to:
application/json - Select events:
Pull requests - Add the webhook secret to your
.envfile
# Server Configuration
PORT=8080
ENVIRONMENT=development
LOG_LEVEL=info
# GitHub Configuration
GITHUB_TOKEN=your_github_token
GITHUB_WEBHOOK_SECRET=your_webhook_secret
# AI Configuration
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
AI_MODEL=gpt-4
AI_MAX_TOKENS=2000
AI_TEMPERATURE=0.1
# Security Configuration
JWT_SECRET=your_jwt_secret
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1m
# Scan Configuration
MAX_FILE_SIZE=1048576
SCAN_TIMEOUT=300
CONCURRENT_SCANS=5
CONFIDENCE_THRESHOLD=0.7The tool uses a configurable rules engine for security scanning. Edit config/config.yaml:
security_rules:
secrets:
- pattern: "password\\s*=\\s*['\"][^'\"]+['\"]"
severity: "high"
message: "Hardcoded password detected"
category: "secrets"
api_keys:
- pattern: "api_key\\s*=\\s*['\"][^'\"]+['\"]"
severity: "critical"
message: "API key found in code"
category: "api_keys"
vulnerabilities:
- pattern: "eval\\s*\\("
severity: "critical"
message: "Dangerous eval() usage detected"
category: "code_execution"
- pattern: "f\"SELECT.*\\{.*\\}\""
severity: "high"
message: "Potential SQL injection detected"
category: "sql_injection"- Hardcoded passwords and credentials
- API keys and tokens
- Database connection strings
- Private keys and certificates
- OAuth secrets
- SQL injection patterns
- XSS vulnerabilities
- Command injection
- Insecure deserialization
- Path traversal issues
- Insecure random number generation
- Weak encryption algorithms
- Missing input validation
- Unsafe file operations
- Context-aware security assessment
- False positive reduction
- Custom security rule suggestions
- Code improvement recommendations
## π CodeGuardian Security Scan Results
### β οΈ High Priority Issues Found
1. **Hardcoded API Key** (Line 45)
```python
api_key = "sk-1234567890abcdef"Risk: API key exposed in source code Recommendation: Use environment variables or secret management
- SQL Injection Risk (Line 78)
Risk: Potential SQL injection vulnerability Recommendation: Use parameterized queries
query = f"SELECT * FROM users WHERE id = {user_id}"
- Good use of HTTPS endpoints
- Proper input validation on user data
- Secure session management
## π§ API Endpoints
### Webhook Endpoint
POST /api/v1/webhook/github
Handles GitHub webhook events for pull request scanning.
### Manual Scan Endpoint
POST /api/v1/scan { "repository": "owner/repo", "pull_request": 123, "base_sha": "abc123", "head_sha": "def456" }
### Health Check
GET /health
### Metrics Endpoint
GET /metrics
Prometheus metrics for monitoring.
### Configuration Endpoint
GET /api/v1/config
Returns current configuration status.
## π§ͺ Testing
```bash
# Run all tests
make test
# Run unit tests
go test ./tests/unit/...
# Run integration tests
go test ./tests/integration/...
# Run with coverage
make coverage
# Run linting
make lint
# Format code
make fmt
The service exposes Prometheus metrics at /metrics:
codeguardian_scans_total: Total number of scans performedcodeguardian_issues_found: Number of security issues detectedcodeguardian_scan_duration: Scan duration in secondscodeguardian_ai_api_calls: Number of AI API calls madecodeguardian_github_webhooks: GitHub webhook events receivedcodeguardian_security_score: Security scores distribution
When running with monitoring, access Grafana at http://localhost:3000:
- Username:
admin - Password:
admin
The application uses structured logging with configurable levels:
debug: Detailed debugging informationinfo: General operational informationwarn: Warning messageserror: Error messages
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and ensure tests pass (
make test) - Format your code (
make fmt) - Run linting (
make lint) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone and setup
git clone https://github.com/your-org/codeguardian.git
cd codeguardian
# Install dependencies
make install
# Run tests
make test
# Start development server
make runThis project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for providing the GPT models
- GitHub for the excellent API
- The Go community for amazing tooling
- All contributors and security researchers
Made with β€οΈ for secure code