""" OWASP Top-10 (2021) + OWASP LLM Top-10 knowledge base. Used by the security agent as a structured reference during analysis. """ from __future__ import annotations from typing import Dict, List # ────────────────────────────────────────────── # OWASP LLM Top-10 (2025 edition) # ────────────────────────────────────────────── OWASP_LLM_TOP10: Dict[str, Dict] = { "LLM01": { "id": "LLM01", "name": "Prompt Injection", "description": ( "User-supplied input alters the intended behaviour of a model prompt. " "Direct injections override system prompts; indirect injections are embedded " "in external content the model processes." ), "examples": [ "Concatenating user input directly into a prompt string", "Trusting model output for routing/tool calls without sanitisation", "Allowing retrieval of attacker-controlled documents in RAG pipelines", ], "severity": "critical", "cwe": "CWE-74", "patterns": [ r"f['\"].*\{.*user.*\}", r"prompt\s*=\s*.*\+.*request", r"format\(.*user_input", r"\.format\(.*query", ], }, "LLM02": { "id": "LLM02", "name": "Insecure Output Handling", "description": ( "LLM-generated text is passed to downstream components (shell, SQL, browser) " "without validation or sanitisation." ), "examples": [ "Passing model response to eval()", "Executing model-generated SQL without parameterisation", "Rendering model HTML output without escaping", ], "severity": "critical", "cwe": "CWE-116", "patterns": [ r"(? Dict: """Return a vulnerability category dict by ID (e.g. 'LLM01', 'A03').""" return ALL_CATEGORIES.get(category_id.upper(), {}) def get_all_patterns() -> List[Dict]: """Return a flat list of all pattern dicts for scanning.""" results = [] for cat_id, cat in ALL_CATEGORIES.items(): for pattern in cat.get("patterns", []): results.append( { "pattern": pattern, "category_id": cat_id, "category_name": cat["name"], "severity": cat["severity"], "cwe": cat.get("cwe", ""), "description": cat["description"], } ) for vuln in ML_SPECIFIC_VULNS: for pattern in vuln.get("patterns", []): results.append( { "pattern": pattern, "category_id": vuln["id"], "category_name": vuln["name"], "severity": vuln["severity"], "cwe": vuln.get("cwe", ""), "description": vuln["description"], } ) return results