An open API service indexing awesome lists of open source software.

https://github.com/alexandre-leng/ai-security-code-validator

MVP of an Open-source AI code security scanner for LLM-generated code. Detect prompt injection, secrets, vulnerable dependencies, and OWASP risks in CI/CD and DevSecOps workflows.
https://github.com/alexandre-leng/ai-security-code-validator

ai-security application-security code-security devsecops llm-security owasp prompt-injection sarif sbom secure-coding semgrep supply-chain-security vulnerability-scanner

Last synced: 1 day ago
JSON representation

MVP of an Open-source AI code security scanner for LLM-generated code. Detect prompt injection, secrets, vulnerable dependencies, and OWASP risks in CI/CD and DevSecOps workflows.

Awesome Lists containing this project

README

          

# šŸ¤– AI Code Validator

> **AI Code Validator is an open-source AI code security scanner for LLM-generated code, AI-assisted development, and modern AppSec workflows.**
> Catch prompt injection, insecure code patterns, secrets, vulnerable dependencies, and OWASP risks before AI-written code reaches production.

šŸ” **1000+ security rules** for LLM-generated code
šŸ›”ļø **Prompt injection detection** — integrated with Whitney (transilienceai/whitney)
⚔ **Scan in seconds** — before the code reaches production
šŸ¤– **Two-Level Workflow** — auto-approve safe code, escalate risks

**Keywords:** AI code security, AI-generated code scanner, LLM security scanner, prompt injection detection, secure code review, SAST for AI code, DevSecOps, Semgrep security automation, software supply chain security

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-green.svg)](https://python.org)
[![Docker](https://img.shields.io/badge/Docker-Ready-blue.svg)](Dockerfile)

---

## 🚨 The Problem: AI Writes Insecure Code

**45% of code generated by LLMs contains OWASP Top 10 vulnerabilities.**
*(Veracode, 2025)*

You asked ChatGPT for a Python script. It gave you something with `os.system()` and a hardcoded API key.

You used Copilot for a login form. It suggested `eval()` on user input.

You prompted Claude for a data pipeline. It generated `pickle.loads()` on untrusted data.

**The issue:** Developers trust AI-generated code. They don't read every line. They don't review what Copilot autocomplete inserted between two valid lines.

**Result:** Vulnerabilities slip into production at machine speed.

---

## āœ… The Solution: Security Guardrails for AI-Generated Code

AI Code Validator is the first security scanner **designed specifically for code written by machines** — not humans.

We don't just find SQL injection. We find:

šŸ”“ **LLM-specific vulnerabilities**
• Prompt injection in AI apps
• Unsafe deserialization (pickle, yaml) that LLMs love to generate
• `eval()` / `exec()` patterns injected by autocomplete
• Hardcoded API keys generated by Copilot
• SQL queries built with f-strings (Copilot's favorite pattern)

🟠 **Traditional vulnerabilities** — 1000+ rules across 14 languages
• SQL injection, XSS, command injection
• Secrets leakage (AWS, GitHub, Stripe, OpenAI keys)
• Vulnerable dependencies (SCA with OSV real-time database)
• License compliance (GPL detection)

🟢 **Workflow that doesn't slow you down**
• **Level 0:** Auto-approve safe code (zero friction)
• **Level 1:** Escalate real risks to human review
• **Auto-fix:** Generate corrected code with one command

---

## ⚔ Quick Start

```bash
# Install
pip install -e .
pip install semgrep bandit

# Scan a file (instant)
python3 -m aicv.cli scan app.py

# Scan your Copilot-generated project
python3 -m aicv.cli scan my-ai-project/

# Two-level workflow (recommended for teams)
python3 -m aicv.cli level0 my-project/ # Auto-approve safe code
python3 -m aicv.cli level1 my-project/ # Review escalated risks

# Auto-fix everything fixable
python3 -m aicv.cli fix --file app.py

# Generate SBOM for compliance
python3 -m aicv.cli sbom --target . --format cyclonedx

# Check dependencies for known CVEs (OSV real-time)
python3 -m aicv.cli sca --target .

# Start API + dashboard
AICV_API_KEY="demo" python3 -m aicv.cli serve
# → http://localhost:5001/review.html
```

---

## How It Works

AI Code Validator combines multiple application security testing engines into a single workflow built for **AI-generated code, Copilot-assisted commits, CI/CD pipelines, and security review at scale**.

### 1. Parse the target

The scanner detects the project language, framework, and file types, then chooses the right analyzers for source code, dependencies, infrastructure-as-code, and AI-specific attack surfaces.

### 2. Run multi-engine analysis

It orchestrates several engines in parallel:

• **Semgrep rules** for code vulnerabilities, insecure patterns, API misuse, IaC issues, and framework-specific risks
• **Prompt injection detection** for LLM apps, RAG pipelines, agent workflows, and dangerous sink chains
• **Secrets detection** for API keys, tokens, and leaked credentials
• **SCA** against the live OSV database for vulnerable dependencies
• **SBOM and license analysis** for compliance, governance, and supply chain visibility

### 3. Correlate and score findings

Findings are normalized, deduplicated, scored by severity and confidence, and converted into a developer-friendly risk report with a global score and actionable remediation hints.

### 4. Route through the two-level workflow

Safe or low-risk findings can be auto-approved in **Level 0**, while high-confidence or critical issues are escalated to **Level 1** for human validation, making the workflow usable in real engineering teams instead of producing alert fatigue.

### 5. Export or integrate

Results can be consumed through the CLI, REST API, SARIF output, dashboard, GitHub PR comments, and editor integration, so teams can use AI Code Validator in local development, pre-commit checks, pull requests, or production release gates.

---

## šŸ”„ What Makes Us Different

### 1. Prompt Injection Detection

Detects **prompt injection vulnerabilities** in AI applications across 16+ source types:

```python
# AI Code Validator detects this:
openai.ChatCompletion.create(
messages=[{"role": "user", "content": user_input}] # šŸ”“ PROMPT INJECTION
)

# And this:
pickle.loads(ai_generated_data) # šŸ”“ UNSAFE DESERIALIZATION

# And this:
eval(llm_output) # šŸ”“ CODE INJECTION
```

### 2. Built for the Speed of AI

• **Scan in < 10 seconds** on a typical file
• **1000+ rules** covering all major vulnerability classes
• **14 languages** — Python, JS/TS, Java, Go, Rust, C/C++, PHP, Ruby, C#, Swift, Kotlin, Shell
• **Real-time SCA** — queries OSV database live (not static CVE lists)

### 3. Two-Level Security Workflow

**Level 0 — Automated (Zero Friction)**

```bash
python3 -m aicv.cli level0 my-project/
```

What happens:
• LOW/MEDIUM findings with high confidence → **Auto-approved**
• Known fixable patterns → **Auto-resolved**
• CRITICAL/HIGH findings → **Escalated to Level 1**

Output:
```
šŸ¤– Level 0 — Automated Security Scan

šŸ“Š Results:
Auto-approved: 12
Auto-resolved: 3
Escalated to Level 1: 5
```

**Level 1 — Human Review**

```bash
python3 -m aicv.cli level1 my-project/
```

Interactive session with security checklist per finding type:
```
šŸ‘¤ Level 1 — Human Security Review

[CRITICAL] app.py:15
Rule: python-sqli-format-string
Code: cursor.execute(f"SELECT * FROM users WHERE id = {user_id}")

šŸ“ Security Checklist:
1. Is the user input properly parameterized?
2. Are ORM methods used instead of raw SQL?

Decision [approve/reject/skip/quit]: reject
Notes: Confirmed SQLi, must use parameterized queries
```

### 4. VS Code Extension (Real-Time)

Scan while you code. Get instant highlights on AI-generated vulnerabilities directly in your editor.

Commands:
• `Ctrl+Shift+S` — Scan current file
• Status bar — Live vulnerability count
• Dashboard — Severity breakdown webview

### 5. Open Source, Self-Hosted, Air-Gap Ready

• **MIT License** — no vendor lock-in
• **Self-hosted** — your code never leaves your infrastructure
• **Air-gap compatible** — works offline (except SCA which needs OSV API)
• **SARIF export** — integrates with GitHub Advanced Security

---

## šŸ›”ļø Detection Engines (13)

**Semgrep** — 1000+ rules, 30+ categories (SQLi, XSS, injection, IaC, containers, CI/CD, AI/ML)

**Prompt Injection (Whitney)** — Semgrep rules for 16+ prompt injection source types (direct HTTP/CLI/Voice, indirect RAG/Web/File Upload, critical sinks: PAL chains, SQL chains, PythonREPL)

**Bandit** — Python AST analysis (hardcoded passwords, shell injection)

**Secrets Detector** — 14 patterns + validators (AWS, GitHub, Stripe, OpenAI keys)

**SCA (Software Composition Analysis)** — Real-time OSV database queries. 7 ecosystems: PyPI, npm, Maven, Go, Cargo, RubyGems, Packagist

**SBOM Generator** — CycloneDX 1.5 + SPDX 2.3 export

**License Scanner** — Copyleft, restrictive, unknown license detection

**SARIF Exporter** — GitHub/CodeQL integration standard

**Dead Code Detector** — Python AST (unused imports, functions, classes)

**Framework Rules** — Django, Flask, Express, Laravel, FastAPI specifics

**Language Checkers** — 14 languages with dedicated analyzers

**Scoring Engine** — 0-100 score + A-F grade

**Auto-Fix** — Regex + AST-based code correction

---

## šŸŒ Languages & Frameworks

**Languages:** Python, JavaScript, TypeScript, Java, Go, PHP, Ruby, C#, Rust, C, C++, Swift, Kotlin, Shell/Bash

**Infrastructure:** Dockerfile, Kubernetes YAML, Terraform, CloudFormation

**AI/ML Specific:** PyTorch, TensorFlow, OpenAI API, LangChain patterns

**Blockchain:** Solidity smart contracts

**Mobile:** Android (Kotlin/Java), iOS (Swift)

---

## šŸ“‹ CLI Commands

```
scan šŸ” Full security scan (all 12 engines)
level0 šŸ¤– Automated workflow — auto-approve safe code
level1 šŸ‘¤ Human review — security checklist per finding
fix šŸ”§ Auto-fix vulnerabilities
delta šŸ“Š Compare two scans (regression detection)
notify šŸ“¢ Slack / Discord / Email / Webhook alerts
pr šŸ™ Post results as GitHub PR comment
sbom šŸ“¦ Generate Software Bill of Materials
sca šŸ“¦ Dependency vulnerability scan (OSV real-time)
license šŸ“œ License compliance scan
sarif šŸ“Š SARIF export for GitHub/CodeQL
checklist šŸ“ Security checklists for reviewers
serve šŸš€ REST API + Web dashboard
version šŸ“Œ Show version
tools šŸ“¦ List available tools
```

---

## šŸš€ Deployment Options

### Docker (Production-Ready)
```bash
docker-compose up -d
# API: http://localhost:5001
# Dashboard: http://localhost:5001/review.html
```

Multi-stage Dockerfile with:
• Non-root user
• Read-only filesystem
• Health checks
• Nginx reverse proxy with rate limiting

### GitHub Actions
```yaml
# Auto-scan every PR
# Block merge if CRITICAL vulnerabilities found
```

### API Usage
```bash
curl -X POST http://localhost:5001/api/v1/scan \
-H "X-API-Key: demo" \
-H "Content-Type: application/json" \
-d '{"code": "import os\nos.system('id')", "language": "python"}'
```

---

## šŸ“Š Example Output

```
╔══════════════════════════════════╗
ā•‘ šŸ¤– AI CODE VALIDATOR v3.3 ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
šŸ“ app.py
šŸ“Š Score: 0/100 šŸ’€ Grade F
šŸ” 23 vuln(s) | C:12 H:7 M:0 L:1

šŸ”“ [CRITICAL] app.py:10
[semgrep] LLM output passed to os.system(). Extreme risk.

šŸ”“ [CRITICAL] app.py:13
[semgrep] Unsafe pickle.loads() on AI-generated data

🟠 [HIGH] app.py:7
[semgrep] LLM prompt constructed with dynamic input.
Risk of prompt injection.

šŸ”“ [CRITICAL] app.py:20
[secrets] šŸ”‘ Stripe Secret Key detected: sk_l…7890

āš™ļø Two-Level Workflow:
Level 0 (Auto): 0/23 handled
Level 1 (Human): 23 need review
```

---

## šŸ—ļø Architecture

```
aicv/
ā”œā”€ā”€ scanner.py # Multi-engine orchestrator (12 engines)
ā”œā”€ā”€ scoring.py # 0-100 + A-F scoring
ā”œā”€ā”€ secrets_detector.py # API key patterns + entropy analysis
ā”œā”€ā”€ sca_scanner.py # Real-time OSV dependency scanning
ā”œā”€ā”€ sbom_generator.py # CycloneDX + SPDX generation
ā”œā”€ā”€ sarif_exporter.py # SARIF v2.1.0 export
ā”œā”€ā”€ license_scanner.py # License compliance
ā”œā”€ā”€ workflow.py # Two-level security workflow
ā”œā”€ā”€ auto_fix.py # Code correction engine
ā”œā”€ā”€ report_exporter.py # JSON / MD / HTML export
ā”œā”€ā”€ notifier.py # Slack / Discord / Email / Webhook
ā”œā”€ā”€ github_pr.py # GitHub PR integration
ā”œā”€ā”€ checkers/ # 11 language-specific analyzers
│ ā”œā”€ā”€ rust_checker.py
│ ā”œā”€ā”€ cpp_checker.py
│ ā”œā”€ā”€ typescript_checker.py
│ ā”œā”€ā”€ swift_checker.py
│ ā”œā”€ā”€ kotlin_checker.py
│ └── shell_checker.py

api/ # REST API (Flask + Gunicorn)
static/ # Web dashboard (review.html)
rules/semgrep/ # 1000+ security rules (50+ files)
vscode-extension/ # VS Code extension (TypeScript)
```

---

## šŸ“ˆ What's New in v3.3

**1000+ Semgrep rules** — 50+ rule files across 15+ categories

**Real-time SCA** — OSV API integration (replaces static CVE lists)

**VS Code Extension** — Real-time scanning in your IDE

**Docker + SaaS MVP** — Multi-stage Dockerfile, docker-compose, nginx

**Community Infrastructure** — Issue templates, CI/CD, CoC, PR templates

**AI/ML Security Rules** — Prompt injection, unsafe pickle, LLM eval detection

---

## šŸ“š Documentation

• [Architecture](docs/ARCHITECTURE.md) — System design & data flow
• [API Reference](docs/API.md) — Complete REST API documentation
• [Workflow Guide](docs/WORKFLOW.md) — Two-level security workflow
• [Contributing](docs/CONTRIBUTING.md) — Code standards & PR process
• [Security](docs/SECURITY.md) — Supported versions & disclosure policy
• [Strategy](docs/STRATEGY.md) — Competitive analysis & roadmap

---

## GitHub SEO Suggestions

If you want the repository to be easier to discover on GitHub search, the best lift usually comes from the **About description**, **topics**, and the first 20 lines of the README.

**Suggested GitHub description**

`Open-source AI code security scanner for LLM-generated code. Detect prompt injection, secrets, vulnerable dependencies, and OWASP risks in CI/CD and DevSecOps workflows.`

**Suggested GitHub topics**

`ai-security`, `llm-security`, `application-security`, `code-security`, `secure-coding`, `prompt-injection`, `sast`, `semgrep`, `devsecops`, `owasp`, `supply-chain-security`, `sbom`, `sarif`, `vulnerability-scanner`, `github-actions`

**Suggested website**

Use the repository URL for now, or a future landing page such as `https://www.formalibre.org` with a dedicated product section for AI Code Validator.

---

## šŸ“„ License

MIT

---

## šŸ™ Acknowledgments

This project includes or was inspired by the following open-source projects:

- **[transilienceai/whitney](https://github.com/transilienceai/whitney)** (Apache 2.0) — Prompt injection detection rules covering 16+ source types
- **[Shiboof/Code-Vulnerability-Scanner](https://github.com/Shiboof/Code-Vulnerability-Scanner)** (MIT) — Security scoring system, language detection patterns
- **[duriantaco/skylos](https://github.com/duriantaco/skylos)** (Apache 2.0) — Dead code detection patterns, framework-aware rules

See [LICENSE](LICENSE) for full third-party attribution details.

---

**[⭐ Star on GitHub](https://github.com/alexandre-leng/ai-code-validator)**
**[šŸ› Report Issue](https://github.com/alexandre-leng/ai-code-validator/issues)**
**[🌐 formalibre.org](https://www.formalibre.org)**