Mojo-Maniac/Cerberus-Backend
<div align="center"> <img src="https://img.shields.io/badge/Security-Co--Pilot-red?style=for-the-badge&logo=shield" alt="Security Co-Pilot" /> <img src="https://img.shields.io/badge/VS%20Code-Extension-blue?style=for-the-badge&logo=visual-studio-code" alt="VS Code Extension" /> <img src="https://img.shields.io/badge/Powered%20By-n8n%20%7C%20Gemini%20%7C%20Groq-green?style=for-the-badge" alt="AI Powered" /> </div>
π Cerberus
Cerberus is an AI-powered security co-pilot built as a VS Code extension. It doesn't just find vulnerabilities in your Python codeβit securely and automatically fixes them in real-time.
β¨ Features
- π‘οΈ Real-Time Security Scanning: Cerberus continuously monitors your Python files as you type. If you introduce a vulnerability (like an SQL injection or a command injection), it spots it instantly.
- π€ Autonomous AI Patching: Using state-of-the-art LLMs (Google Gemini 2.5 Flash & Groq Llama 3.3), Cerberus automatically rewrites the vulnerable snippet securely.
- π Multi-Pass Verification: Cerberus uses an autonomous agent loop to verify its own fixes. If the first fix isn't fully secure, it will re-audit and re-patch the code up to 3 times.
- β‘ In-Place Replacements: Fixes are applied directly in your VS Code editor without breaking your surrounding code or formatting.
- π Vulnerability Dashboard: A dedicated VS Code sidebar panel allows you to view detailed security reports for any scanned file and manually trigger fixes.
ποΈ Architecture
Cerberus operates on a two-part architecture: the lightweight client (VS Code) and the heavily automated AI backend (n8n).
1. The Client (VS Code Extension)
Built in TypeScript, the extension hooks into VS Code's onDidChangeTextDocument API.
- It debounces keystrokes and extracts context around modified code.
- It provides commands like
Cerberus: Scan for Vulnerabilities,Cerberus: Start Real-Time Scanning, andCerberus: Apply Fix. - It communicates securely via REST to the backend workflow.
2. The AI Backend (n8n & LLMs)
The true power of Cerberus lies in its n8n workflow backend (located in n8n/Workflow.json).
- Trigger: Webhook endpoints (
/webhook/scanand/webhook/patch-snippet). - SAST Scanner (Bandit): The code is first run through Bandit to identify exact Python security flaws (B105, B603, B608, etc.).
- Auditor Agent: An LLM agent parses the Bandit report and structures the vulnerabilities into actionable JSON.
- Syntax Fixer & Patcher Agents: The vulnerable code is passed to a high-speed LLM (Gemini 2.5 Flash-Lite) armed with strict security rules (e.g., parameterized queries, secure secrets modules).
- Verification Loop: The newly patched code is fed back into Bandit. If any vulnerabilities remain, the loop restarts. Once the code is clean (or max retries are hit), the final secure payload is returned to the extension.
π Getting Started
Prerequisites
- Visual Studio Code (v1.109.0+)
- Node.js (v22.x)
1. Install the Extension
You can install the .vsix package contained in this repository:
- Open VS Code.
- Go to the Extensions view (
Ctrl+Shift+X). - Click the
...menu -> Install from VSIX... - Select
cerberus-latest.vsix.
2. Configure the Backend
By default, the extension points to a remote n8n backend or local server. To connect your own instance:
- Open VS Code Settings (
Cmd/Ctrl + ,). - Search for
Cerberus: Backend Url. - Set it to your
n8nproduction URL (e.g.,https://n8n.yourdomain.com/webhook).
3. Local Development (Extension)
To develop the extension locally:
npm install
npm run watch
# Press F5 in VS Code to launch the Extension Development Hostπ Security Fix Patterns Supported
Cerberus is explicitly instructed to execute DevSecOps remediation using industry-standard fix patterns:
- SQL Injection: Migrates dynamic string concatenation to parameterized execution (
cursor.execute("SELECT...", (val,))). - Command Injection: Migrates
os.systemand unsafesubprocesscalls to secure, list-basedsubprocess.run(..., shell=False). - Hardcoded Credentials: Strips raw passwords and tokens, replacing them with
os.getenv('SECRET_NAME'). - Insecure Randomness: Replaces the standard
randommodule with the cryptographically securesecretsmodule.
π License
This project is licensed under the MIT License.
