A lightweight Python SAST CLI that uses Python AST analysis to prioritize security-sensitive code and Mistral AI for semantic vulnerability analysis.
- Python 3.11+
- A Mistral API key
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export MISTRAL_API_KEY="your-api-key"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-latestUseful options:
--format terminal|json--output report.json--model MODEL--timeout SECONDS--retries N--max-file-bytes N--max-chunk-lines N--verbose
scanner/file_scanner.pydiscovers.pyfiles, preserves line numbers, chunks large files, and creates AST context.scanner/prompt.pydefines the security-analysis instructions and JSON contract.scanner/mistral_client.pyisolates the Mistral HTTP integration.scanner/parser.pyvalidates model JSON and merges findings.scanner/reporter.pyrenders terminal or JSON reports.sast_ai.pyprovides the CLI.
The Mistral provider can be replaced by implementing the same analyze_code(code, filename) -> str interface.
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.
- 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.
examples/vulnerable.py contains representative SQL injection, shell command injection, unsafe deserialization, eval, debug mode, and hardcoded-secret examples.
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.