File size: 3,634 Bytes
41dde94
 
 
 
 
 
 
 
 
747f016
63703ca
41dde94
98b502b
168ae1c
98b502b
168ae1c
7646eac
168ae1c
7646eac
168ae1c
 
 
98b502b
 
 
 
 
 
168ae1c
98b502b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b18317
98b502b
 
 
 
 
2b18317
98b502b
 
 
2b18317
98b502b
 
 
 
 
 
 
 
7877b4e
 
98b502b
 
 
 
7877b4e
 
 
 
 
 
 
 
 
98b502b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168ae1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: AI Code Security Scanner
emoji: πŸ›‘οΈ
colorFrom: blue
colorTo: indigo
sdk: streamlit
sdk_version: 1.52.2
app_file: app.py
pinned: false
app_port: 8501
short_description: AI Python security scanner using CodeBERT and rules.
---
# AI Code Security Scanner: Real-time Vulnerability Detection

An advanced security orchestration tool that detects critical vulnerabilities (SQLi, XSS, Command Injection) using a **Hybrid Analysis Engine**: combining static rule-based heuristics with deep learning **CodeBERT** models.

[![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Space-yellow)](https://huggingface.co/spaces/mubi-613/ai-code-scanner-ui)

> **Live Demo:** [AI Security Scanner on Hugging Face](https://huggingface.co/spaces/mubi-613/ai-code-scanner-ui)

---

## Core Engineering Features
* **Hybrid Detection Engine:** Utilizes **AST (Abstract Syntax Tree)** parsing for rule-based detection and fine-tuned **CodeBERT** (Deep Learning) for semantic vulnerability pattern matching.
* **Automated Remediation:** Generates context-aware "Fix Suggestions" using AI to provide secure code alternatives for identified risks.
* **Security Dashboard:** Real-time visualization of security scores and vulnerability distribution across large codebases.
* **Batch Processing:** Optimized for high-throughput scanning of multiple Python files simultaneously using Python's `multiprocessing` capabilities.
* **REST API Architecture:** Built with a **FastAPI** backend, allowing for easy integration into existing CI/CD pipelines as a security gate.

##  Technical Stack
* **Deep Learning:** CodeBERT (Transformers), PyTorch
* **Analysis Engine:** Python AST, Custom Rule-based Heuristics
* **Backend/Frontend:** FastAPI, Streamlit
* **Deployment:** Docker, Hugging Face Spaces (Debian Linux)

##  Installation

1. **Clone the repository:**
   ```bash
   git clone [https://github.com/mubi0613/AI-Code-Security-Scanner.git](https://github.com/mubi0613/AI-Code-Security-Scanner.git)
   cd AI-Code-Security-Scanner

2. **Setup environment:**
   ```bash
   python -m venv venv

   # On Windows:
   .\venv\Scripts\activate
   # On Mac/Linux:
   source venv/bin/activate

3. **Install dependencies:**
   ```bash
   pip install -r requirements.txt

4. **Run the application:**
   ```bash
   streamlit run app.py`

##  Docker Deployment
* Build and run with Docker Compose
* docker-compose up --build

## Access at:
* Web UI: http://localhost:8501
* API Docs: http://localhost:8000/docs

##  Project Structure

AI-Code-Security-Scanner/
* β”œβ”€β”€ app.py                 # Main Streamlit Dashboard & UI Logic
* β”œβ”€β”€ api_backend.py         # FastAPI Server for REST API Access
* β”œβ”€β”€ combined_detector.py   # Hybrid Logic (Rules + CodeBERT Model)
* β”œβ”€β”€ rule_detector.py       # Static Analysis & AST-based Heuristics
* β”œβ”€β”€ fix_generator.py       # AI-powered Remediation Engine
* β”œβ”€β”€ saved_model/           # Fine-tuned CodeBERT Weights & Config
* β”œβ”€β”€ docker-compose.yml     # Container Orchestration for UI & API
* β”œβ”€β”€ requirements.txt       # Project Dependencies
* └── README.md              # Technical Documentation

## Architecture Diagram

```mermaid
graph LR
    subgraph "Frontend Layer"
        A[Streamlit UI] --> B[User Code Input]
    end

    subgraph "Analysis Engine"
        B --> C{Hybrid Scanner}
        C --> D[Static Rule Engine]
        C --> E[CodeBERT DL Model]
    end

    subgraph "Remediation & Reporting"
        D & E --> F[Vulnerability Report]
        F --> G[AI Fix Generator]
        G --> H[Final Security Report]
    end
```