#!/usr/bin/env python3 """AppSecBench vulnerability catalog. Each entry is an ORIGINAL archetype definition: the canonical CWE, the OWASP Top 10 (2021) and OWASP API Security (2023) mapping, the OWASP LLM Top 10 (2025) mapping where relevant, the high-level category, representative public references (OWASP/CWE/PortSwigger/OWASP ASVS — no copyrighted code), and a human-readable description template that the generator fills in per case. Nothing here is copied from an existing benchmark; the code snippets are authored from scratch in `generators.py`. """ from __future__ import annotations # Canonical list of supported dimensions (derived from the master prompt). LANGUAGES = [ "Python", "Java", "JavaScript", "TypeScript", "Go", "Rust", "PHP", "C#", "Kotlin", "Swift", "C", "C++", "Ruby", "Scala", ] FRAMEWORKS = [ "Flask", "FastAPI", "Django", "Spring Boot", "Express", "NestJS", "Next.js", "Laravel", "ASP.NET Core", "Gin", "Echo", "Fiber", "Android", "iOS", "Rails", "Angular", "Vue", ] DIFFICULTIES = ["Beginner", "Intermediate", "Advanced", "Expert", "Real-world enterprise"] # Frameworks are only relevant for vulnerabilities that live in a web/rpc layer. DIFFICULTIES_NO_FRAMEWORK = ["Beginner", "Intermediate", "Advanced", "Expert", "Real-world enterprise"] # (vulnerability_name, category, cwe, owasp2021, owasp_api2023, owasp_llm2025, refs, description) CATALOG = [ ("SQL Injection", "Injection", "CWE-89", "A03:2021", "API8:2023", "", ["https://owasp.org/www-community/attacks/SQL_Injection", "https://cwe.mitre.org/data/definitions/89.html", "https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html"], "Untrusted input is concatenated into a SQL query string, allowing an attacker to alter the query's structure and read or modify data."), ("Cross-Site Scripting", "Injection", "CWE-79", "A03:2021", "API8:2023", "", ["https://owasp.org/www-community/attacks/xss/", "https://cwe.mitre.org/data/definitions/79.html", "https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html"], "Untrusted input is reflected into an HTTP response without output encoding, letting an attacker execute JavaScript in the victim's browser."), ("Server-Side Request Forgery", "Injection", "CWE-918", "A10:2021", "API7:2023", "", ["https://owasp.org/www-community/attacks/Server_Side_Request_Forgery", "https://cwe.mitre.org/data/definitions/918.html"], "A server fetches a URL built from user input, letting an attacker reach internal services, cloud metadata endpoints, or ports not exposed publicly."), ("Command Injection", "Injection", "CWE-77", "A03:2021", "API8:2023", "", ["https://owasp.org/www-community/attacks/Command_Injection", "https://cwe.mitre.org/data/definitions/77.html"], "User input is passed to a shell command interpreter, letting an attacker execute arbitrary operating-system commands."), ("Path Traversal", "Injection", "CWE-22", "A01:2021", "API8:2023", "", ["https://owasp.org/www-community/attacks/Path_Traversal", "https://cwe.mitre.org/data/definitions/22.html"], "User-controlled file paths are joined to a base directory without canonicalization, allowing read or write outside the intended root."), ("XML External Entity", "Injection", "CWE-611", "A05:2021", "API8:2023", "", ["https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing", "https://cwe.mitre.org/data/definitions/611.html"], "An XML parser resolves external entities in attacker-supplied documents, enabling file disclosure, SSRF, or denial of service."), ("Insecure Direct Object Reference", "Broken Access Control", "CWE-639", "A01:2021", "API1:2023", "", ["https://owasp.org/www-community/attacks/Insecure_Direct_Object_Reference", "https://cwe.mitre.org/data/definitions/639.html"], "An endpoint exposes an object reference (id, filename, token) and trusts the caller to only access records they own, enabling horizontal privilege escalation."), ("Broken Access Control", "Broken Access Control", "CWE-285", "A01:2021", "API5:2023", "", ["https://owasp.org/Top10/A01_2021-Broken_Access_Control/", "https://cwe.mitre.org/data/definitions/285.html"], "Authorization checks are missing or can be bypassed, letting a user act on resources or functions outside their privilege level."), ("Broken Authentication", "Authentication", "CWE-287", "A07:2021", "API2:2023", "", ["https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/", "https://cwe.mitre.org/data/definitions/287.html"], "Authentication mechanisms are weak, spoofable, or bypassable, allowing an attacker to assume another user's identity."), ("Broken Authorization", "Authorization", "CWE-862", "A01:2021", "API5:2023", "", ["https://cwe.mitre.org/data/definitions/862.html", "https://owasp.org/Top10/A01_2021-Broken_Access_Control/"], "A function performs a sensitive action without verifying the caller is permitted to do so (missing authorization check)."), ("JWT Vulnerabilities", "Authentication", "CWE-345", "A07:2021", "API2:2023", "", ["https://cwe.mitre.org/data/definitions/345.html", "https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html"], "A JWT implementation accepts tokens with a weak or 'none' algorithm, skips signature verification, or trusts an attacker-controlled key/secret."), ("OAuth Vulnerabilities", "Authentication", "CWE-287", "A07:2021", "API2:2023", "", ["https://cwe.mitre.org/data/definitions/287.html", "https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/"], "An OAuth/OIDC flow is misimplemented (redirect_uri not validated, implicit flow, token leakage) allowing account takeover."), ("Session Management", "Authentication", "CWE-614", "A07:2021", "API2:2023", "", ["https://cwe.mitre.org/data/definitions/614.html", "https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html"], "Session identifiers are created, stored, or invalidated insecurely (predictable IDs, missing HttpOnly/Secure, no rotation on auth)."), ("Cross-Site Request Forgery", "Broken Access Control", "CWE-352", "A01:2021", "API8:2023", "", ["https://owasp.org/www-community/attacks/csrf", "https://cwe.mitre.org/data/definitions/352.html"], "A state-changing request lacks an unguessable token, letting a third-party site force the victim's browser to perform actions."), ("Insecure File Upload", "Injection", "CWE-434", "A03:2021", "API8:2023", "", ["https://owasp.org/www-community/vulnerabilities/Unrestricted_File_Upload", "https://cwe.mitre.org/data/definitions/434.html"], "Uploaded files are not validated for type, content, or location, enabling remote code execution or storage abuse."), ("Insecure Deserialization", "Injection", "CWE-502", "A08:2021", "API8:2023", "", ["https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection", "https://cwe.mitre.org/data/definitions/502.html"], "Untrusted data is deserialized by a native/object serializer, which can trigger code execution or logic abuse during reconstruction."), ("Open Redirect", "Injection", "CWE-601", "A01:2021", "API8:2023", "", ["https://cwe.mitre.org/data/definitions/601.html", "https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html"], "A redirect target is taken from user input without an allow-list, enabling phishing by bouncing victims through a trusted domain."), ("Race Condition", "Business Logic", "CWE-362", "A04:2021", "", "", ["https://cwe.mitre.org/data/definitions/362.html", "https://owasp.org/www-community/attacks/Thread_Safety_and_State_Problems"], "A check-then-act sequence is not atomic, letting concurrent requests pass the check before a shared state update lands (TOCTOU)."), ("Insecure Cryptography", "Cryptographic Failures", "CWE-327", "A02:2021", "", "", ["https://cwe.mitre.org/data/definitions/327.html", "https://owasp.org/Top10/A02_2021-Cryptographic_Failures/"], "Broken or deprecated primitives (MD5/SHA1, ECB, static IVs, weak RNG) are used to protect sensitive data."), ("Hardcoded Secrets", "Cryptographic Failures", "CWE-798", "A02:2021", "", "", ["https://cwe.mitre.org/data/definitions/798.html", "https://owasp.org/Top10/A02_2021-Cryptographic_Failures/"], "Credentials, API keys, or private keys are embedded in source code, exposing them to anyone with repository access."), ("Business Logic", "Business Logic", "CWE-840", "A04:2021", "API6:2023", "", ["https://cwe.mitre.org/data/definitions/840.html", "https://owasp.org/Top10/A04_2021-Insecure_Design/"], "The application enforces no invariant for a workflow (negative quantity, replayed coupon, price override), leading to abuse."), ("Missing Rate Limiting", "Security Misconfiguration", "CWE-307", "A07:2021", "API4:2023", "", ["https://cwe.mitre.org/data/definitions/307.html", "https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/"], "Authentication or sensitive endpoints lack throttling, enabling credential stuffing, brute force, or resource exhaustion."), ("Sensitive Data Logging", "Security Misconfiguration", "CWE-532", "A09:2021", "", "", ["https://cwe.mitre.org/data/definitions/532.html", "https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/"], "Credentials, tokens, or PII are written to logs in cleartext, widening the blast radius of a log compromise."), ("Header Injection", "Injection", "CWE-113", "A03:2021", "API8:2023", "", ["https://cwe.mitre.org/data/definitions/113.html", "https://owasp.org/www-community/attacks/HTTP_Response_Splitting"], "Unsanitized input is placed into response or request headers, allowing response splitting or header smuggling."), ("Prompt Injection", "AI Security", "CWE-1427", "A05:2021", "", "LLM01:2025", ["https://cwe.mitre.org/data/definitions/1427.html", "https://owasp.org/www-project-top-10-for-large-language-model-applications/"], "An LLM application merges untrusted content into its prompt, letting an attacker override instructions or exfiltrate data."), ("RAG Security", "AI Security", "CWE-1427", "A05:2021", "", "LLM02:2025", ["https://owasp.org/www-project-top-10-for-large-language-model-applications/", "https://cwe.mitre.org/data/definitions/1427.html"], "A retrieval-augmented generation pipeline ingests untrusted documents whose content steers the model or poisons the index."), ("MCP Security", "AI Security", "CWE-918", "A05:2021", "", "LLM06:2025", ["https://modelcontextprotocol.io/", "https://owasp.org/www-project-top-10-for-large-language-model-applications/"], "A Model Context Protocol server exposes tools/resources that an agent can invoke with overly broad permissions or unvalidated arguments."), ("AI Agent Security", "AI Security", "CWE-77", "A05:2021", "", "LLM06:2025", ["https://owasp.org/www-project-top-10-for-large-language-model-applications/", "https://cwe.mitre.org/data/definitions/77.html"], "An autonomous agent that can call tools or shells is tricked by external content into performing unsafe actions."), ("GraphQL Security", "API Security", "CWE-915", "A04:2021", "API4:2023", "", ["https://cwe.mitre.org/data/definitions/915.html", "https://owasp.org/Top10/A04_2021-Insecure_Design/"], "A GraphQL endpoint lacks query costing/introspection control or object-level authorization, enabling data exfiltration or DoS."), ("REST API Security", "API Security", "CWE-639", "A01:2021", "API1:2023", "", ["https://owasp.org/Top10/A01_2021-Broken_Access_Control/", "https://cwe.mitre.org/data/definitions/639.html"], "A REST API exposes objects by id without ownership checks or proper input validation, enabling IDOR or mass assignment."), ("gRPC Security", "API Security", "CWE-285", "A01:2021", "API5:2023", "", ["https://cwe.mitre.org/data/definitions/285.html", "https://owasp.org/Top10/A01_2021-Broken_Access_Control/"], "A gRPC service does not enforce per-method authorization or input validation, allowing unauthorized RPC calls."), ("Cloud Misconfiguration", "Security Misconfiguration", "CWE-1188", "A05:2021", "", "", ["https://cwe.mitre.org/data/definitions/1188.html", "https://owasp.org/Top10/A05_2021-Security_Misconfiguration/"], "A cloud resource (bucket, blob, policy, security group) is exposed publicly or grants excessive permission."), ("Kubernetes Security", "Security Misconfiguration", "CWE-250", "A05:2021", "", "", ["https://cwe.mitre.org/data/definitions/250.html", "https://owasp.org/Top10/A05_2021-Security_Misconfiguration/"], "A pod or cluster is over-privileged (privileged container, hostPath mount, wildcard RBAC) enabling node compromise."), ("Docker Security", "Security Misconfiguration", "CWE-250", "A05:2021", "", "", ["https://cwe.mitre.org/data/definitions/250.html", "https://owasp.org/Top10/A05_2021-Security_Misconfiguration/"], "A container image or runtime is configured insecurely (running as root, mounting the Docker socket, latest tag, secrets in env)."), ] # Build fast lookup CATALOG_BY_NAME = {} for _row in CATALOG: (_name, _cat, _cwe, _o21, _oapi, _ollm, _refs, _desc) = _row CATALOG_BY_NAME[_name] = { "category": _cat, "cwe": _cwe, "owasp": _o21, "owasp_api": _oapi, "owasp_llm": _ollm, "references": _refs, "description": _desc, } # Which (vuln, language) pairs make sense. We restrict infra/AI vulns to a # sensible subset so every record is realistic rather than contrived. INFRA_VULNS = {"Cloud Misconfiguration", "Kubernetes Security", "Docker Security"} AI_VULNS = {"Prompt Injection", "RAG Security", "MCP Security", "AI Agent Security"} API_VULNS = {"GraphQL Security", "REST API Security", "gRPC Security"} # Languages that trivially support a native web/rpc framework example. WEB_LANGS = {"Python", "Java", "JavaScript", "TypeScript", "Go", "PHP", "C#", "Kotlin", "Swift", "Ruby", "Scala"} # Framework applicability per language (kept realistic). LANG_FRAMEWORKS = { "Python": ["Flask", "FastAPI", "Django"], "Java": ["Spring Boot"], "JavaScript": ["Express", "Next.js", "Angular", "Vue"], "TypeScript": ["Express", "NestJS", "Next.js", "Angular", "Vue"], "Go": ["Gin", "Echo", "Fiber"], "PHP": ["Laravel"], "C#": ["ASP.NET Core"], "Kotlin": ["Android", "Spring Boot"], "Swift": ["iOS"], "Ruby": ["Rails"], "Scala": ["Spring Boot"], "Rust": ["None"], # no Rust framework in the required framework list "C": ["None"], "C++": ["None"], } def applicable_languages(vuln_name: str) -> list: if vuln_name in INFRA_VULNS: return ["YAML", "Dockerfile", "Bash"] if vuln_name == "Insecure Cryptography": return ["Python", "Java", "C", "C++", "Go", "JavaScript", "PHP"] if vuln_name == "Hardcoded Secrets": return LANGUAGES if vuln_name in AI_VULNS: return ["Python", "JavaScript", "TypeScript", "Ruby"] if vuln_name == "Race Condition": return ["Python", "Java", "Go", "JavaScript", "C", "C++", "PHP", "C#", "Ruby"] if vuln_name == "Insecure Deserialization": return ["Python", "Java", "PHP", "JavaScript", "C#", "Go", "Ruby"] if vuln_name in API_VULNS: return ["Python", "JavaScript", "TypeScript", "Go", "Java", "Ruby"] # Generic web/rpc injection & access-control classes. return [l for l in LANGUAGES if l in WEB_LANGS] def applicable_frameworks(vuln_name: str, language: str) -> list: if vuln_name in INFRA_VULNS or language in ("YAML", "Dockerfile", "Bash", "C", "C++"): return ["None"] return LANG_FRAMEWORKS.get(language, ["None"])