๐ง AI in CybersecurityJune 7, 2026โ
Tests passing
AI Code Vulnerability Scanner
This tool scans Python codebases for common security vulnerabilities using a pre-trained AI model fine-tuned on secure coding patterns. It identifies issues like hardcoded secrets, insecure function usage, and potential injection vulnerabilities, providing specific remediation suggestions.
What It Does
- AI-powered detection of security vulnerabilities in Python code.
- Provides precise recommendations for fixing identified issues.
- Scans entire codebases or individual files.
- Outputs a detailed, human-readable report.
Installation
1. Clone the repository:
git clone https://github.com/your-repo/ai_code_vuln_scanner.git
cd ai_code_vuln_scanner2. Install dependencies:
pip install -r requirements.txtUsage
Scanning file: /path/to/file.py
File: /path/to/file.py
Vulnerabilities
Line Issue Suggestion
---- ------------------------ -----------------------------------
1 Hardcoded secret Use environment variables instead.
5 Insecure function usage Use a secure alternative.Source Code
import os
import argparse
from transformers import pipeline
from tqdm import tqdm
from rich.console import Console
from rich.table import Table
def scan_file(file_path, ai_model):
"""
Scans a single Python file for vulnerabilities using the AI model.
Args:
file_path (str): Path to the Python file.
ai_model: Pre-trained AI model for vulnerability detection.
Returns:
list: List of detected vulnerabilities with line numbers and suggestions.
"""
vulnerabilities = []
try:
with open(file_path, 'r') as file:
code = file.read()
results = ai_model(code)
for result in results:
vulnerabilities.append({
'line': result['line'],
'issue': result['issue'],
'suggestion': result['suggestion']
})
except Exception as e:
vulnerabilities.append({
'line': None,
'issue': f"Error reading file: {e}",
'suggestion': "Ensure the file is accessible and properly formatted."
})
return vulnerabilities
def scan_directory(directory_path, ai_model):
"""
Scans all Python files in a directory for vulnerabilities using the AI model.
Args:
directory_path (str): Path to the directory.
ai_model: Pre-trained AI model for vulnerability detection.
Returns:
dict: Dictionary with file paths as keys and vulnerability lists as values.
"""
results = {}
for root, _, files in os.walk(directory_path):
for file in files:
if file.endswith('.py'):
file_path = os.path.join(root, file)
results[file_path] = scan_file(file_path, ai_model)
return results
def main():
parser = argparse.ArgumentParser(description="AI Code Vulnerability Scanner")
parser.add_argument('--path', type=str, required=True, help="Path to a Python file or directory to scan.")
args = parser.parse_args()
console = Console()
ai_model = pipeline('text-classification', model='secure-coding/vuln-scanner')
if os.path.isfile(args.path):
console.print(f"[bold green]Scanning file:[/bold green] {args.path}")
vulnerabilities = scan_file(args.path, ai_model)
display_results({args.path: vulnerabilities}, console)
elif os.path.isdir(args.path):
console.print(f"[bold green]Scanning directory:[/bold green] {args.path}")
results = scan_directory(args.path, ai_model)
display_results(results, console)
else:
console.print(f"[bold red]Error:[/bold red] The path {args.path} does not exist.")
def display_results(results, console):
"""
Displays the scan results in a human-readable format.
Args:
results (dict): Dictionary of scan results.
console (Console): Rich console for output.
"""
for file_path, vulnerabilities in results.items():
console.print(f"\n[bold blue]File:[/bold blue] {file_path}")
if not vulnerabilities:
console.print("[green]No vulnerabilities found![/green]")
else:
table = Table(title="Vulnerabilities")
table.add_column("Line", justify="center")
table.add_column("Issue", justify="left")
table.add_column("Suggestion", justify="left")
for vuln in vulnerabilities:
table.add_row(
str(vuln['line']) if vuln['line'] else "N/A",
vuln['issue'],
vuln['suggestion']
)
console.print(table)
if __name__ == "__main__":
main()Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- ai_code_vuln_scanner
- Category
- AI in Cybersecurity
- Generated
- June 7, 2026
- Tests
- Passing โ
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-06-07/ai_code_vuln_scanner cd generated_tools/2026-06-07/ai_code_vuln_scanner pip install -r requirements.txt 2>/dev/null || true python ai_code_vuln_scanner.py