Skip to main content

Agentic AI framework untuk audit keamanan kode Python berbasis OWASP Top 10 (2025).

Project description

owasp-audit-agent

Framework agentic AI untuk audit keamanan kode Python berbasis OWASP Top 10 (2025). Menganalisis kode sumber, mendeteksi kerentanan di 10 kategori OWASP, menghasilkan ringkasan eksekutif dari LLM, mencoba memperbaiki secara otomatis, lalu memverifikasi ulang.

Orkestrasi dibangun di atas LangGraph; deteksi memakai checker modular yang ditemukan secara otomatis sehingga menambah aturan baru tidak menyentuh kode inti.

Instalasi

pip install -e .            # library + CLI
pip install -e ".[ui]"      # + UI Streamlit
pip install -e ".[dev]"     # + pytest

Buat file .env berisi kredensial LLM:

GROQ_API_KEY=your_key_here

Pemakaian sebagai library

from agent import audit_code

result = audit_code(open("app.py").read(), "app.py")

for f in result["findings"]:
    print(f.severity.value, f.owasp_category.value, f.title, f.line_number)

print(result["summary"])

CLI

owasp-audit app.py               # audit satu file
owasp-audit app.py --json        # keluaran JSON
owasp-audit --list-checkers      # daftar checker terdaftar

UI (Streamlit)

streamlit run app.py

Konfigurasi

Perilaku audit diatur lewat file audit.toml di root project (opsional) dan/atau environment variable. Salin audit.example.toml menjadi audit.toml lalu sesuaikan:

[llm]
provider = "groq"
model = "llama-3.1-8b-instant"
temperature = 0.0

[audit]
escalation_threshold = 3      # eskalasi jika jumlah CRITICAL > nilai ini
max_fix_iterations = 2
auto_fix = true

[checkers]
enabled = []                  # kosong = semua; mis. ["A01","A05","A07"]
disabled = ["A09"]            # kode kategori yang dimatikan

Env var menimpa file (berguna untuk CI): OWASP_LLM_MODEL, OWASP_ESCALATION_THRESHOLD, OWASP_MAX_FIX_ITERATIONS, OWASP_AUTO_FIX, OWASP_ENABLED_CHECKERS, OWASP_DISABLED_CHECKERS, OWASP_CONFIG (path file config).

Dari kode, config bisa dimuat manual:

from agent import AuditConfig
cfg = AuditConfig.load()          # audit.toml + env
print(cfg.escalation_threshold, cfg.llm_model, cfg.is_checker_enabled("A05"))

Provider LLM

Provider dipilih lewat [llm] provider di audit.toml (atau env OWASP_LLM_PROVIDER). Built-in: groq (default, sudah termasuk), openai, anthropic, google, ollama. Paket integrasi di-import lazy — install hanya yang dipakai:

pip install -e ".[openai]"      # atau .[anthropic] / .[google] / .[ollama]
[llm]
provider = "openai"
model = "gpt-4o-mini"
# base_url = "http://localhost:11434"   # untuk Ollama / endpoint OpenAI-compatible

API key dibaca dari env sesuai provider (GROQ_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, dst). Menambah provider kustom:

from agent import register_provider

@register_provider("myllm")
def _build(config):
    from my_pkg import MyChat
    return MyChat(model=config.llm_model, temperature=config.llm_temperature)

Lalu set provider = "myllm" di config.

Kategori OWASP yang dicakup

Kode Kategori
A01 Broken Access Control
A02 Security Misconfiguration
A03 Software Supply Chain Failures
A04 Cryptographic Failures
A05 Injection
A06 Insecure Design
A07 Authentication Failures
A08 Software or Data Integrity Failures
A09 Security Logging and Alerting Failures
A10 Mishandling of Exceptional Conditions

Menulis checker baru

Buat subclass BaseChecker dan implementasi category, name, dan analyze():

# agent/tools/my_checker.py
from typing import List
from agent.base_checker import BaseChecker
from agent.models import Finding, OWASPCategory, SeverityLevel

class MyChecker(BaseChecker):
    @property
    def category(self) -> OWASPCategory:
        return OWASPCategory.A05

    @property
    def name(self) -> str:
        return "My Custom Checker"

    def analyze(self, code: str, filename: str) -> List[Finding]:
        findings = []
        # ... logika deteksi ...
        return findings

Cukup letakkan file di agent/tools/auto-discovery akan mendaftarkannya otomatis saat registry.discover() dipanggil. Tidak perlu mengubah graph.py maupun registry.py.

Plugin eksternal (paket terpisah)

Checker juga bisa didistribusikan sebagai paket pihak ketiga tanpa menyentuh repo ini. Deklarasikan entry point pada group owasp_audit_agent.checkers:

# pyproject.toml paket plugin kamu
[project.entry-points."owasp_audit_agent.checkers"]
my_checker = "my_package.my_module:MyChecker"

Setelah paket terpasang, registry.discover_entry_points() akan memuatnya otomatis.

Arsitektur

agent/
├── base_checker.py     # abstract BaseChecker (kontrak checker)
├── registry.py         # CheckerRegistry + auto-discovery + entry points
├── models.py           # Finding, OWASPCategory, SeverityLevel (Pydantic)
├── state.py            # AuditState (state LangGraph)
├── graph.py            # workflow LangGraph + audit_code()
├── rule_fixer.py       # perbaikan berbasis aturan
├── sarif_exporter.py   # ekspor hasil ke SARIF
├── dependency_scanner.py
├── history.py          # riwayat scan
├── report.py           # laporan PDF
├── cli.py              # command owasp-audit
└── tools/              # satu file per checker (auto-discovered)

Lisensi

MIT — lihat LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

owasp_audit_agent-0.1.0.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

owasp_audit_agent-0.1.0-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file owasp_audit_agent-0.1.0.tar.gz.

File metadata

  • Download URL: owasp_audit_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for owasp_audit_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 251d90cc93d3917e63b1ba6ee7b2c08a5d0b86cc91a6cde84148cbafc5709bfa
MD5 29560da04585a4e435fd5e55609f2c43
BLAKE2b-256 6e6c2acb42d4c670e5b999cf198211a562b54d7a0b0576926809a1949056d153

See more details on using hashes here.

File details

Details for the file owasp_audit_agent-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for owasp_audit_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b74397547538002e7db756c47cc2b6d0deceeaa448da5abe4b630167e1274e3
MD5 58b9c9f20cd10fe7564187cc828ab517
BLAKE2b-256 63777ca7b81ddbf2fee29d86314634306512194e2af0bed3ffb07946f5230728

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page