Skip to main content

AI Code Security Scanner with Human-in-the-Loop Feedback

Project description

โ™ž CheckMate - AI Code Security Scanner with Human-in-the-Loop Feedback

PyPI version Python 3.11+ License: MIT

Human-in-the-loop anomaly detection for AI-generated code. A professional CLI tool that scans code for security vulnerabilities, enables human review, and learns from feedback to improve detection accuracy.

๐ŸŽฏ The Problem

AI-generated code is powerful but risky:

  • โŒ Hardcoded secrets (API keys, passwords)
  • โŒ Code execution vulnerabilities (eval, exec, pickle)
  • โŒ SQL injection patterns
  • โŒ No built-in security checks

CheckMate solves this with automated detection + human judgment.


๐Ÿš€ What Makes CheckMate Different

Human-in-the-Loop Learning

Scan โ†’ Review Flags โ†’ Mark as Valid/False Positive โ†’ System Learns โ†’ Better Scans
  • ๐Ÿ“Š Before/After Metrics - See precision improve in real-time
  • โœ… Human Feedback Loop - Mark false positives, build whitelist
  • ๐ŸŽฏ 31 Detection Rules - Across secrets, code execution, SQL injection
  • ๐Ÿ’พ Persistent Learning - Whitelist saves automatically
  • ๐ŸŒ Multi-Language - Python & JavaScript support

โšก Quick Start

1. Install (30 seconds)

pip install checkmate-ai

2. Start Dashboard (in Terminal 1)

checkmate dashboard

Browser opens automatically to http://localhost:3000 showing "Waiting for scan..."

3. Run Scanner (in Terminal 2)

checkmate scan demo.py

The dashboard updates automatically showing detected flags.

4. Review & Provide Feedback

  • See code with syntax highlighting
  • Read security explanations
  • Click "Mark as Safe" to whitelist patterns
  • View suggested fixes

5. Rescan & Watch Improvement

checkmate scan demo.py

Metrics page shows precision improvement (e.g., 62% โ†’ 84%)


๐Ÿ“‹ All CLI Commands

Command Purpose
checkmate dashboard Start web UI + backend server
checkmate scan <file> Scan single file
checkmate scan file1.py file2.js Scan multiple files
checkmate scan . Scan all .py and .js in current directory
checkmate whitelist View current whitelist
checkmate reset Clear all data (fresh start)
checkmate version Show version info

๐Ÿ† Hackathon Scoring Alignment (100 Points)

CheckMate scores on all 6 evaluation categories:

Category Evidence
Problem Definition AI code security + human review = clear, valuable problem
Anomaly Detection 31 rules across 3 categories (secrets, code exec, SQL injection)
Human-in-Loop Users mark valid/false positive โ†’ whitelist updates โ†’ system learns
Before/After Improvement Metrics page shows precision improvement (tracked over time)
Explainability Each flag shows: explanation, severity, suggested fix, line number
Presentation Professional CLI, web dashboard, polished UX
TOTAL **Production-ready, ship-worthy

๐ŸŽจ Dashboard Features

Results Page (/)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ CheckMate - Security Scan Results       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ File: demo.py                           โ”‚
โ”‚ Total Flags: 5                          โ”‚
โ”‚                                         โ”‚
โ”‚ [CRITICAL] Hardcoded API Key (Line 15) โ”‚
โ”‚ sk-1234567890abcdef                     โ”‚
โ”‚ Use: os.environ.get('OPENAI_API_KEY')   โ”‚
โ”‚ [Mark as Safe] [Copy Fix]               โ”‚
โ”‚                                         โ”‚
โ”‚ [DANGER] eval() Usage (Line 28)         โ”‚
โ”‚ eval("user_input")                      โ”‚
โ”‚ Use: ast.literal_eval() instead         โ”‚
โ”‚ [Mark as Safe] [Copy Fix]               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Metrics Page (/metrics)

  • Precision Trend - Line chart showing improvement over time
  • Stat Cards - Total scans, total flags, precision %, improvement %
  • Before/After Card - Visual improvement comparison
  • Per-Rule Breakdown - Accuracy by detection rule

๐Ÿ” Detection Rules (31 Total)

Category 1: Secrets (10 rules) ๐Ÿ”ด CRITICAL

  • OpenAI API keys (sk-...)
  • AWS Access Keys (AKIA...)
  • Hardcoded passwords
  • Private tokens, JWT secrets
  • Firebase API keys
  • Stripe API keys
  • GitHub tokens
  • And more...

Category 2: Code Execution (14 rules) ๐ŸŸ  DANGER

  • eval() usage
  • exec() usage
  • pickle.loads() deserialization
  • subprocess with shell=True
  • os.system() calls
  • Dynamic imports
  • And more...

Category 3: SQL Injection (7 rules) ๐ŸŸก HIGH RISK

  • F-string SQL queries
  • String concatenation in queries
  • Variable interpolation in SQL
  • And more...

๐Ÿ“Š How the Feedback Loop Works

Step 1: Initial Scan

checkmate scan code.py
# Detects: 5 flags
# Metrics: 3 valid, 2 false positives
# Precision: 60%

Step 2: Human Review

  • Dashboard shows each flag
  • User reads explanation: "eval() can execute arbitrary code"
  • User decides: "This is a false positive (test code)"
  • Clicks: "Mark as Safe"

Step 3: Whitelist Update

  • Backend saves to whitelist.json
  • Pattern added: eval("test_value")
  • Next scan will skip this pattern

Step 4: Rescan & Improvement

checkmate scan code.py
# Detects: 4 flags (1 skipped via whitelist)
# Metrics: 3 valid, 1 false positive (whitelisted)
# Precision: 75% (improved!)

Step 5: Persistent Learning

  • Precision tracked over time
  • Metrics page shows trend: 60% โ†’ 75% โ†’ 84%
  • Team learns what their codebase's real risks are

๐Ÿ—๏ธ Architecture

Tech Stack

  • CLI: Python 3.11+ with Click framework
  • Detection: Regex-based (31 rules, no ML)
  • Backend: FastAPI (lightweight API)
  • Dashboard: Next.js 14 + React 18 + TypeScript
  • UI Components: shadcn/ui + Tailwind CSS
  • Data: SQLite database + JSON files

Data Flow

Terminal (User)
    โ†“
[checkmate scan file.py]
    โ†“
CLI Scanner (runs detectors)
    โ†“
FastAPI Backend (saves to DB)
    โ†“
Browser (Next.js Dashboard)
    โ†“
User Reviews & Marks Safe/False Positive
    โ†“
Backend Updates Whitelist + Metrics
    โ†“
Next Scan Reads Whitelist (skips patterns)
    โ†“
Precision Improves โœ…

๐Ÿ“ฆ Installation & Setup

For detailed setup instructions, see SETUP.md

Quick Install

# From PyPI (recommended)
pip install checkmate-ai
checkmate dashboard

# From source
git clone https://github.com/yourusername/checkmate
cd checkmate
pip install -e .
checkmate dashboard

๐ŸŽฌ Demo Walkthrough

  1. Open Terminal 1

    checkmate dashboard
    

    Browser shows: "Waiting for scan..."

  2. Open Terminal 2

    checkmate scan samples/vulnerable_1.py
    
  3. See Results (browser auto-refreshes)

    • 5 flags detected
    • Severity badges, code snippets, suggestions
  4. Provide Feedback

    • Click "Mark as Safe" on false positive
    • Watch whitelist update in real-time
  5. Rescan

    checkmate scan samples/vulnerable_1.py
    
    • Flag count decreased
    • Metrics page shows precision improved
  6. View Metrics

    • Navigate to /metrics
    • See precision trend chart
    • Before: 60% | After: 84%

๐Ÿ“ Project Structure

checkmate/
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ SETUP.md                  # Installation guide
โ”œโ”€โ”€ setup.py                  # PyPI packaging
โ”œโ”€โ”€ pyproject.toml            # Modern Python standard
โ”‚
โ”œโ”€โ”€ checkmate/                # Main package
โ”‚   โ”œโ”€โ”€ cli.py                # CLI entry point
โ”‚   โ”œโ”€โ”€ scanner.py            # Detection engine
โ”‚   โ””โ”€โ”€ detectors/            # 31 detection rules
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py               # FastAPI server
โ”‚   โ”œโ”€โ”€ database.py           # SQLite operations
โ”‚   โ”œโ”€โ”€ models.py             # Data models
โ”‚   โ””โ”€โ”€ routes/               # API endpoints
โ”‚
โ”œโ”€โ”€ dashboard/                # Next.js web UI
โ”‚   โ”œโ”€โ”€ app/                  # Pages (/, /metrics)
โ”‚   โ””โ”€โ”€ components/           # UI components
โ”‚
โ”œโ”€โ”€ data/                     # JSON storage
โ”‚   โ”œโ”€โ”€ scan_results.json
โ”‚   โ”œโ”€โ”€ whitelist.json
โ”‚   โ”œโ”€โ”€ feedback.json
โ”‚   โ””โ”€โ”€ metrics.json
โ”‚
โ””โ”€โ”€ samples/                  # Example vulnerable files
    โ”œโ”€โ”€ vulnerable_1.py
    โ”œโ”€โ”€ vulnerable_2.py
    โ””โ”€โ”€ vulnerable_3.js

๐Ÿ”— Links


Running the Demo

# Terminal 1
checkmate dashboard

# Terminal 2 (wait 3 seconds)
checkmate scan samples/vulnerable_1.py

# Browser shows results automatically
# Mark a false positive as safe
# Rescan to see improvement

Time needed: 2 minutes total


๐Ÿค Contributing

Found a bug? Have a rule idea? Open a GitHub issue or PR!


๐Ÿ“„ License

MIT License - See LICENSE file for details


๐Ÿ’ก Future Enhancements

  • Machine learning for adaptive rules
  • More language support (Go, Java, Rust)
  • Integration with CI/CD pipelines
  • API for programmatic scanning
  • Rule customization UI

CheckMate - Making AI-generated code safer, one scan at a time.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

checkmate_ai-1.0.2.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

checkmate_ai-1.0.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file checkmate_ai-1.0.2.tar.gz.

File metadata

  • Download URL: checkmate_ai-1.0.2.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for checkmate_ai-1.0.2.tar.gz
Algorithm Hash digest
SHA256 64db0f2dd99bc108fdb7caf5f937ea36f5f21142b3d5439da8fcf5b4a07d2fd7
MD5 d9c3e3a668f9edd56a2ef3ddbcedfb95
BLAKE2b-256 db2d590415acd0a70b2f018be95f917ebfa8198f93dafbb8faa9b330926524a7

See more details on using hashes here.

File details

Details for the file checkmate_ai-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: checkmate_ai-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for checkmate_ai-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ae9cfa2cb663e15fe56cd976f49872301966ad8fa62a7142c0501a2ceba194cc
MD5 64839bb1d8e5c57d9faac7354302eb38
BLAKE2b-256 fcf4727b0dc9266fc6b646291e954a76eb5fca329493efd2571a5d8bb7fd37f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page