🔒 code-validator

Static security scanner purpose-built for AI-generated code

MIT License Python 3.9+ Offline AI Code

What is code-validator?

code-validator is a static security scanner purpose-built for code produced by AI assistants — Claude Code, ChatGPT, GitHub Copilot, Cursor. It detects the specific failure modes that LLMs disproportionately emit: hardcoded API keys in examples, allow_origins=["*"] with allow_credentials=True, string-concatenated SQL, and unpatched dependency CVEs.

Why this exists: AI-assisted PRs frequently land with subtle security defects that look correct at a glance. code-validator is the lightweight CI gate that catches these before they reach main — in under 1 second per file, fully offline, with zero data exfiltration.

Sub-second scans

<1s per file. --git-diff mode scans only changed files for CI.

🔒

100% Offline

No SaaS. No code leaves your machine. Only dep: pydantic.

🎯

AI-code tuned

11 detection rules targeting LLM-specific failure modes (SEC001–007, QUAL001, DEP001–003).

🧪

CI/CD ready

Exit code 1 on critical/high. GitHub Actions + GitLab CI examples included.

Quick Start

# 1. Clone
git clone https://github.com/TTMK7777/code-validator.git
cd code-validator

# 2. Install (only pydantic required)
pip install -r requirements.txt

# 3. Scan
python validator.py --git-diff
# Exits with code 1 if critical/high issues found — blocks CI

Generate an HTML report

python validator.py --path . --output report.html --format html

Pre-commit hook

# .git/hooks/pre-commit
#!/bin/sh
python validator.py --git-diff || exit 1

Detection Rules

RuleSeverityCategoryDetects
SEC001CriticalSecurityHardcoded API key
SEC002CriticalSecurityHardcoded password
SEC003CriticalSecurityHardcoded database credentials
SEC004CriticalSecurityCORS wildcard + credentials enabled
SEC005HighSecurityCORS wildcard origins (production risk)
SEC006HighSecuritySQL injection via string concatenation
SEC007MediumSecurityMissing FastAPI security headers
QUAL001LowQualityLine exceeds max length
DEP002HighDepsPython package with known CVE
DEP003VariableDepsNode.js package with known CVE

How code-validator Compares

ToolAI-code focusOfflineSpeedDeps
code-validator✅ Purpose-built✅ Yes<1s/file✅ pydantic only
Bandit❌ General Python✅ YesFastMultiple
Semgrep❌ Multi-lang patterns⚠️ HybridMediumHeavy
GitGuardian❌ Git secrets❌ SaaSSlow (API)SaaS
TruffleHog❌ Git secrets✅ YesSlowMultiple

Positioning: code-validator is the only tool in this list specifically tuned for the failure modes of AI-generated code (e.g., the CORS wildcard + credentials pattern LLMs disproportionately emit).

FAQ

Why a separate tool for AI-generated code? Can't I just use Bandit or Semgrep?

General-purpose linters were designed for human-written code. AI assistants exhibit specific failure modes — hardcoded example credentials, overly permissive CORS for demos, string-concat SQL because the model "remembered" pre-ORM patterns. code-validator's rule set is tuned for these patterns and weights severity accordingly.

Does code-validator send my code anywhere?

No. The scanner runs fully offline. The only optional network call is pip-audit for CVE lookups, and that contacts only the official PyPA advisory database — never your source code.

How is this different from running Bandit + TruffleHog + pip-audit separately?

code-validator unifies them into a single CI step with a coherent severity model and one report format (HTML / JSON / Markdown). With --git-diff mode, only files changed in the current PR are scanned, keeping CI fast.

Does it work with Claude Code, Cursor, GitHub Copilot output?

Yes. It scans the resulting source files regardless of which AI assistant generated them. The detection patterns target the output, not the tool.

What Python version do I need?

Python 3.9 or later.

Is there a pre-commit hook?

Yes. Use python validator.py --git-diff in a pre-commit hook — exit code 1 blocks the commit when critical/high issues are found.

Can I customize the detection rules?

Yes — see config/validator_config.json. You can disable rule categories, change line-length thresholds, and add exclude patterns.

About the Author

Built by Taimu Tsuji (辻大夢) — Founder of Tsuji Lab, Applied AI Architect specializing in multi-agent AI coordination and AI-assisted software development at scale.