Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI-SAST

A lightweight Python SAST CLI that uses Python AST analysis to prioritize security-sensitive code and Mistral AI for semantic vulnerability analysis.

Requirements

  • Python 3.11+
  • A Mistral API key

Installation

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export MISTRAL_API_KEY="your-api-key"

Usage

python sast_ai.py scan app.py
python sast_ai.py scan ./src
python sast_ai.py scan ./src --format json --output report.json
python sast_ai.py scan app.py --model mistral-large-latest

Useful options:

  • --format terminal|json
  • --output report.json
  • --model MODEL
  • --timeout SECONDS
  • --retries N
  • --max-file-bytes N
  • --max-chunk-lines N
  • --verbose

Architecture

  1. scanner/file_scanner.py discovers .py files, preserves line numbers, chunks large files, and creates AST context.
  2. scanner/prompt.py defines the security-analysis instructions and JSON contract.
  3. scanner/mistral_client.py isolates the Mistral HTTP integration.
  4. scanner/parser.py validates model JSON and merges findings.
  5. scanner/reporter.py renders terminal or JSON reports.
  6. sast_ai.py provides the CLI.

The Mistral provider can be replaced by implementing the same analyze_code(code, filename) -> str interface.

Security model

The AST pass is a supporting signal, not the final detector. It identifies imports, sources, suspicious sinks, functions, classes, and calls. Mistral receives that context plus source code and decides whether the data flow is security-relevant.

For large files, the scanner sends overlapping line chunks. Each line is prefixed with its original source line number so findings can map back to the file.

Limitations of this MVP

  • Cross-file data flow is not implemented.
  • The scanner does not execute the target application.
  • Authentication/authorization analysis is limited to the supplied source context.
  • Large projects can produce many Mistral API calls.
  • A model can miss vulnerabilities or produce incorrect conclusions, so results should be reviewed before use in a security gate.
  • Files are decoded as UTF-8 with replacement for malformed bytes.
  • The API response must satisfy the strict finding schema; malformed responses fail the scan rather than being silently accepted.

Example

examples/vulnerable.py contains representative SQL injection, shell command injection, unsafe deserialization, eval, debug mode, and hardcoded-secret examples.

Disclaimer

This repository is provided for educational and research purposes only.

AI-generated results may be incomplete, inaccurate, or incorrect. The results should not be considered proof that a system is vulnerable or secure.

Use this project at your own risk. The author is not responsible for any damage, data loss, security incident, service interruption, or other consequences resulting from the use of this project, its code, or its results.

Always validate findings using appropriate security tools and your organization's security procedures before taking action in a production environment.

About

SAST with AI

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages