Skip to content
codefort-secPublic

About

Frontier AI security reasoning engine, LoRA fine-tuning & evaluation benchmarks for CodeFort PR defense

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

⚡ BARQ-AI // FRONTIER AI REASONING & DEFENSE ENGINE

Main CodeFort Monorepo Web Dashboard Copilot Studio FastAPI Docs

AI Model LoRA SFT Pytest OSV Evaluation Benchmark License

Barq-AI is the specialized AI security reasoning engine powering CodeFort. It unifies frontier LLM reasoning (Qwen 2.5 Coder 32B Instruct / Qwen3.8-Max MoE and Google Gemini) with real-time Google OSV telemetry grounding, deterministic AST static analysis, and autonomous in-memory patch verification to eradicate supply-chain poisoning, malicious pull requests, and CI/CD workflow injection attacks.


🏛️ Ecosystem Architecture: CodeFort vs. Barq-AI

CodeFort is engineered with a strict separation between defense platform orchestration and frontier AI reasoning:

Layer Repository Responsibilities Target Deployment
Platform Monorepo codefort-sec/codefort Web Dashboard, Chrome & Firefox Extension, GitHub App Webhooks, Checks API & Policy Orchestrator codefort-web.vercel.app
AI Engine & Benchmarks codefort-sec/barqai (This Repo) Model Weights (codefort-qwen-lora), LoRA Fine-Tuning Pipeline, 5D Benchmark Rig, OSV Datasets, & AI Inference Server codefort-lilac.vercel.app

🧠 Core Technical Pillars

1. Unified Multi-Provider MoE Architecture (Qwen + Gemini)

  • Built on a multi-provider fallback cascading from Google Gemini (gemini-3.8-flash / gemini-1.5-flash) to Qwen 2.5 Coder 32B Instruct via OpenRouter, backed by an instant 0ms deterministic engine.
  • Decouples complex multi-stage attack analysis (e.g. polyglot Buffer.from obfuscation + lifecycle droppers) from brittle single-model APIs.

2. Zero-Hallucination "Evidence-Grounded" Architecture ([EVIDENCE: ...])

  • Eliminates AI hallucinations by requiring every advisory claim to anchor directly to deterministic telemetry tags ([EVIDENCE: ...]).
  • Strict post-processing sanitizer (_validate_and_sanitize_evidence) cross-checks every referenced CVE/GHSA against the live Google OSV database, automatically stripping ungrounded IDs.

3. Cross-Engine Threat Correlation Layer

  • Synthesizes isolated engine signals (AST Static Analyzer, Levenshtein Typosquatting Intel, Workflow Linters) into compound attack vectors.
  • Automatically elevates PR risk to CRITICAL (100/100) when a suspicious lifecycle hook correlates with network socket creation or C2 dropper behavior.

4. GPU-Accelerated LoRA Fine-Tuning Trajectory

  • Base Model: Qwen/Qwen2.5-Coder-1.5B-Instruct
  • Adapter: models/codefort-qwen-lora/
  • Hardware: Dedicated NVIDIA GeForce RTX 4050 Laptop GPU (CUDA 12.4, NF4 4-bit double quantization, LoRA rank $r=16, \alpha=32$).
  • Curated Datasets:
    • Balanced SFT pairs from dataset.jsonl covering Command Injection (CWE-78), Path Traversal (CWE-22), SQLi (CWE-89), and Insecure Deserialization (CWE-502).
    • CISA Known Exploited Vulnerabilities (KEV) telemetry to ground advisory claims.
  • Results: Final step loss down to 0.1307, mean token accuracy 96.59%, and 100% anti-hallucination rate on adversarial prompt tests.

5. In-Memory PatchVerifier (0 Regressions)

  • Autonomous remediation engine synthesizes unified git diffs (clean_patch).
  • Every patch is tested in-memory against target source code to prove vulnerability eradication with 0 syntax corruption and 0 regressions.

📊 Standardized 5-Dimensional Security Benchmark

Run locally via python -m app.ai.eval_suite --compare:

Evaluation Metric Qwen 2.5 Coder 32B Google Gemini 1.5 Flash Deterministic Fail-Safe
1. Verdict Accuracy 100.0% (4/4) 100.0% (4/4) 100.0% (4/4)
2. Evidence Grounding Rate 100.0% 100.0% 100.0%
3. Remediation Viability 100.0% 100.0% 100.0%
4. Independent Patch Verify 100.0% (0 Regressions) 100.0% (0 Regressions) 100.0% (0 Regressions)
5. False Positive Resilience 100.0% 100.0% 100.0%
Zero-Hallucination Rate 100.0% 100.0% 100.0%
Average Scan Latency 0.17s 0.16s 0.15s
OSV 20-Case Benchmark 20/20 (100%) 20/20 (100%) 20/20 (100%)

🧪 Verified Attack & Defense Scenarios

Scenario Vector Detection Rule Verdict Risk Score Remediation
01_malicious_preinstall curl | bash C2 dropper in package.json npm.lifecycle.preinstall BLOCKED 100 / 100 Verified Clean Patch
02_typosquat_dependency Typosquatted package reqeusts dep.typosquat REVIEW 65 / 100 Upgrade to requests
03_unsafe_workflow_injection pull_request_target + write-all workflow.target.checkout BLOCKED 100 / 100 Least-Privilege Token
04_clean_feature_pr Benign AST math parser N/A (clean baseline) PASS 0 / 100 Clean Baseline (0 FP)

🚀 Quickstart & Local Execution

Prerequisites

  • Python $\ge 3.11$ (uv recommended)
  • Optional: CUDA-compatible GPU for local LoRA training / inference
# 1. Clone repository
git clone https://github.com/codefort-sec/barqai.git
cd barqai/services/api

# 2. Install dependencies
uv sync

# 3. Run Pytest Test Suite (82 tests)
uv run pytest -v

# 4. Run Multi-Model Comparative Benchmark
python -m app.ai.eval_suite --compare

# 5. Run LoRA Verification Test
python -m app.ai.test_lora_inference

# 6. Start Inference Backend API
uv run uvicorn app.main:app --reload --port 8000

📂 Repository Structure

barqai/
├── models/
│   └── codefort-qwen-lora/          # Fine-tuned Qwen 2.5 Coder adapter weights & Hugging Face model card
├── services/
│   └── api/
│       ├── app/
│       │   ├── ai/                  # LoRA training (train_lora.py), eval suite (eval_suite.py), dataset.jsonl
│       │   ├── api/v1/              # FastAPI endpoints (/barqai/chat, /scans, /remediation)
│       │   ├── services/engines/    # Barq-AI reasoning engine (barqai.py), patch verifier
│       │   └── schemas/             # Pydantic models for scans, findings, & analysis
│       ├── datasets/
│       │   ├── raw/                 # osv_data.json
│       │   ├── processed/           # vulnerabilities.json (OSV cache)
│       │   └── evaluation/          # barqai_test.jsonl (20-case OSV evaluation benchmark)
│       └── tests/                   # 82 automated pytest suites
├── fixtures/
│   └── scenarios/                   # Attack scenarios (01-04) for benchmark verification
└── vercel.json                      # Canonical 301 redirects to codefort-web.vercel.app

👥 Maintainers & License

About

Frontier AI security reasoning engine, LoRA fine-tuning & evaluation benchmarks for CodeFort PR defense

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages