Skip to main content

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

Project description

   _____ _               _    __  __       _
  / ____| |             | |  |  \/  |     | |
 | |    | |__   ___  ___| | _| \  / | __ _| |_ ___
 | |    | '_ \ / _ \/ __| |/ / |\/| |/ _` | __/ _ \
 | |____| | | |  __/ (__|   <| |  | | (_| | ||  __/
  \_____|_| |_|\___|\___|_|\_\_|  |_|\__,_|\__\___|

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

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.

pip install checkmate-ai
checkmate scan your_code.py

CheckMate Scanner in Terminal

๐Ÿ“Œ Project Background

CheckMate was originally developed for a hackathon competition focused on human-in-the-loop anomaly detection. While we didn't win, we believe in the value of this tool and are continuing development as an open-source side project. Our goal is to build a practical, privacy-focused security scanner that helps developers catch vulnerabilities in AI-generated code.

๐ŸŽฏ 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

โœจ Core Features

CheckMate delivers on all essential security scanning capabilities:

Feature Implementation
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

๐ŸŽจ 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/farhann-saleem/checkmate-ai
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.3.tar.gz (18.6 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.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: checkmate_ai-1.0.3.tar.gz
  • Upload date:
  • Size: 18.6 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.3.tar.gz
Algorithm Hash digest
SHA256 38a0a0d91f83b337aa69499c9779c3192bd456545900caf3fe815e7b1cf3ae54
MD5 f458c20579d68a1625d901eed0973943
BLAKE2b-256 c2a5d916ab2ef77d01ab843a21ab8d35a885e334134232992afea4602a220bc8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: checkmate_ai-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b9d8e8f6cb1e0543994f2080b3de9d006fccad9a82586d55e40bd6d9a43bef24
MD5 0032170ee4ee69b5239c55d10890d380
BLAKE2b-256 52ef72eea50f30fd28431d746ba28ef60cad1e5bf66b06351ca4bb35d56188a7

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