/**
 * OWASP LLM Top 10 Compliance Framework
 *
 * Maps security findings to OWASP Top 10 for Large Language Model Applications (2025).
 * This framework addresses AI-specific security risks in LLM-powered applications.
 *
 * @see https://owasp.org/www-project-top-10-for-large-language-model-applications/
 * @module compliance/frameworks/owasp-llm
 */
/**
 * OWASP LLM Top 10 Controls (2025 version)
 *
 * Each control maps to one of the OWASP LLM Top 10 risks with
 * associated finding categories from agent scanners.
 */
export const OWASP_LLM_CONTROLS = [
    // LLM01: Prompt Injection
    {
        id: "LLM01",
        framework: "OWASP-LLM",
        category: "Input Validation",
        title: "Prompt Injection",
        description: "Prompt injection occurs when an attacker manipulates a large language model (LLM) through crafted inputs, causing the LLM to unknowingly execute the attacker's intentions. This can be done directly by 'jailbreaking' the system prompt or indirectly through manipulated external inputs, potentially leading to data exfiltration, social engineering, and other issues.",
        keywords: [
            "prompt injection",
            "jailbreak",
            "instruction override",
            "system prompt",
            "indirect injection",
            "context manipulation",
        ],
        findingCategories: [
            "prompt-injection",
            "injection",
            "insecure-plugin",
        ],
        cweIds: ["CWE-94", "CWE-77", "CWE-74"],
        severityThreshold: "high",
    },
    // LLM02: Insecure Output Handling
    {
        id: "LLM02",
        framework: "OWASP-LLM",
        category: "Output Validation",
        title: "Insecure Output Handling",
        description: "Insecure Output Handling refers specifically to insufficient validation, sanitization, and handling of the outputs generated by large language models before they are passed downstream to other components and systems. Since LLM-generated content can be controlled by prompt input, this behavior is similar to providing users indirect access to additional functionality.",
        keywords: [
            "output validation",
            "output sanitization",
            "downstream injection",
            "xss",
            "sql injection",
            "command injection",
        ],
        findingCategories: [
            "insecure-output",
            "xss",
            "sql-injection",
            "command-injection",
            "code-injection",
        ],
        cweIds: ["CWE-79", "CWE-89", "CWE-78", "CWE-94", "CWE-116"],
        severityThreshold: "high",
    },
    // LLM03: Training Data Poisoning
    {
        id: "LLM03",
        framework: "OWASP-LLM",
        category: "Data Integrity",
        title: "Training Data Poisoning",
        description: "The starting point of any machine learning approach is training data. In terms of large language models, this is 'pre-training'. Poisoning refers to manipulation of pre-training data or data involved in fine-tuning or embedding to introduce vulnerabilities, backdoors or biases that could compromise the model's security, effectiveness or ethical behavior.",
        keywords: [
            "training data",
            "data poisoning",
            "fine-tuning",
            "backdoor",
            "bias injection",
            "model manipulation",
        ],
        findingCategories: [
            "training-data-poisoning",
            "integrity-failure",
            "supply-chain-vuln",
        ],
        cweIds: ["CWE-1035", "CWE-829", "CWE-494"],
        severityThreshold: "high",
    },
    // LLM04: Model Denial of Service
    {
        id: "LLM04",
        framework: "OWASP-LLM",
        category: "Availability",
        title: "Model Denial of Service",
        description: "An attacker interacts with an LLM in a method that consumes an exceptionally high amount of resources, which results in a decline in the quality of service for them and other users, as well as potentially incurring high resource costs. The model may become unresponsive or significantly slow, impacting legitimate users.",
        keywords: [
            "denial of service",
            "resource exhaustion",
            "token flooding",
            "context overflow",
            "recursive prompts",
            "rate limiting",
        ],
        findingCategories: [
            "model-denial-of-service",
            "resource-exhaustion",
        ],
        cweIds: ["CWE-400", "CWE-770", "CWE-789"],
        severityThreshold: "medium",
    },
    // LLM05: Supply Chain Vulnerabilities
    {
        id: "LLM05",
        framework: "OWASP-LLM",
        category: "Supply Chain",
        title: "Supply Chain Vulnerabilities",
        description: "The supply chain in LLMs can be vulnerable, impacting the integrity of training data, ML models, and deployment platforms. These vulnerabilities can lead to biased outcomes, security breaches, or system failures. Risks include outdated components, vulnerable pre-trained models, poisoned fine-tuning datasets, and insecure plugin stores.",
        keywords: [
            "supply chain",
            "dependency",
            "third-party",
            "plugin",
            "model hub",
            "package vulnerability",
            "typosquatting",
        ],
        findingCategories: [
            "supply-chain-vuln",
            "dependency-vuln",
            "vulnerable-component",
            "insecure-plugin",
        ],
        cweIds: ["CWE-1035", "CWE-829", "CWE-494", "CWE-937"],
        severityThreshold: "high",
    },
    // LLM06: Sensitive Information Disclosure
    {
        id: "LLM06",
        framework: "OWASP-LLM",
        category: "Data Protection",
        title: "Sensitive Information Disclosure",
        description: "LLM applications have the potential to reveal sensitive information, proprietary algorithms, or other confidential details through their output. This can result in unauthorized access to sensitive data, intellectual property, privacy violations, and other security breaches. Consumers of LLM applications should be aware of how to safely interact with LLMs.",
        keywords: [
            "sensitive data",
            "data leakage",
            "pii exposure",
            "confidential information",
            "system prompt extraction",
            "model memorization",
        ],
        findingCategories: [
            "sensitive-disclosure",
            "pii-exposure",
            "hardcoded-secret",
            "exfil-path",
        ],
        cweIds: ["CWE-200", "CWE-359", "CWE-532", "CWE-538"],
        severityThreshold: "high",
    },
    // LLM07: Insecure Plugin Design
    {
        id: "LLM07",
        framework: "OWASP-LLM",
        category: "Plugin Security",
        title: "Insecure Plugin Design",
        description: "LLM plugins are extensions that, when enabled, are called automatically by the model during user interactions. They are driven by the model, and there is no application control over the execution. Plugins can process inputs from untrusted sources with insufficient validation, increasing the risk of data exfiltration, remote code execution, and privilege escalation.",
        keywords: [
            "plugin",
            "tool",
            "extension",
            "mcp",
            "function calling",
            "tool execution",
            "sandbox escape",
        ],
        findingCategories: [
            "insecure-plugin",
            "excessive-agency",
            "missing-sandbox",
            "manifest-drift",
            "tool-drift",
        ],
        cweIds: ["CWE-20", "CWE-918", "CWE-78", "CWE-250"],
        severityThreshold: "high",
    },
    // LLM08: Excessive Agency
    {
        id: "LLM08",
        framework: "OWASP-LLM",
        category: "Access Control",
        title: "Excessive Agency",
        description: "An LLM-based system is often granted a degree of agency by its developer – the ability to interface with other systems and undertake actions in response to a prompt. Excessive Agency is the vulnerability that enables damaging actions to be performed in response to unexpected/ambiguous outputs from an LLM. This could be due to excessive functionality, permissions, or autonomy granted to the LLM.",
        keywords: [
            "excessive permissions",
            "over-privileged",
            "autonomy",
            "destructive actions",
            "uncontrolled execution",
            "permission minimization",
        ],
        findingCategories: [
            "excessive-agency",
            "overscoped-permission",
            "credential-overscoped",
            "broken-access-control",
        ],
        cweIds: ["CWE-269", "CWE-250", "CWE-266", "CWE-732"],
        severityThreshold: "high",
    },
    // LLM09: Overreliance
    {
        id: "LLM09",
        framework: "OWASP-LLM",
        category: "Operational Risk",
        title: "Overreliance",
        description: "Overreliance occurs when systems or people depend on LLMs for decision-making or content generation without sufficient oversight. LLMs can produce authoritative-sounding but incorrect or inappropriate content, leading to misinformation, security vulnerabilities, or legal issues if outputs are not validated by human reviewers.",
        keywords: [
            "overreliance",
            "hallucination",
            "misinformation",
            "human oversight",
            "validation",
            "autonomous decision",
        ],
        findingCategories: [
            "overreliance",
            "consensus-manipulation",
        ],
        cweIds: ["CWE-807", "CWE-352"],
        severityThreshold: "medium",
    },
    // LLM10: Model Theft
    {
        id: "LLM10",
        framework: "OWASP-LLM",
        category: "Intellectual Property",
        title: "Model Theft",
        description: "Model theft involves unauthorized access, copying, or exfiltration of proprietary LLM models. This can lead to economic losses, erosion of competitive advantage, and unauthorized access to sensitive information contained in the model. Risks include model extraction through API abuse, side-channel attacks, and insider threats.",
        keywords: [
            "model theft",
            "model extraction",
            "intellectual property",
            "model weights",
            "api abuse",
            "side-channel",
        ],
        findingCategories: [
            "model-theft",
            "auth-bypass",
            "broken-access-control",
        ],
        cweIds: ["CWE-284", "CWE-200", "CWE-863"],
        severityThreshold: "critical",
    },
];
/**
 * Cross-mapping to SOC 2 controls for integrated compliance
 */
export const OWASP_LLM_TO_SOC2_MAPPING = {
    LLM01: ["CC6.6", "CC6.8", "PI1.2"], // Prompt Injection → Security Boundaries, Malicious Software, Input Controls
    LLM02: ["CC6.8", "PI1.1", "PI1.2"], // Insecure Output → Malicious Software, Processing Accuracy, Input Controls
    LLM03: ["CC9.2", "C1.1"], // Training Data Poisoning → Vendor Risk, Confidentiality
    LLM04: ["A1.1"], // Model DoS → Capacity Management
    LLM05: ["CC9.1", "CC9.2"], // Supply Chain → Risk Management, Vendor Risk
    LLM06: ["C1.1", "C1.2", "CC6.7"], // Sensitive Disclosure → Confidentiality, Transmission Protection
    LLM07: ["CC6.6", "CC6.8", "CC8.1"], // Insecure Plugin → Security Boundaries, Change Management
    LLM08: ["CC6.1", "CC6.3"], // Excessive Agency → Access Control, Access Removal
    LLM09: ["CC7.3", "CC7.4"], // Overreliance → Security Event Analysis, Response
    LLM10: ["CC6.1", "C1.1"], // Model Theft → Access Control, Confidentiality
};
/**
 * Cross-mapping to ISO 27001 controls
 */
export const OWASP_LLM_TO_ISO27001_MAPPING = {
    LLM01: ["A.14.2.5", "A.14.1.2"], // Input validation, Application security
    LLM02: ["A.14.2.5", "A.14.1.3"], // Input validation, Application security
    LLM03: ["A.15.2.1", "A.14.2.7"], // Supplier service monitoring, Outsourced development
    LLM04: ["A.17.2.1", "A.12.1.3"], // Availability, Capacity management
    LLM05: ["A.15.1.1", "A.15.2.1"], // Supplier relationships
    LLM06: ["A.18.1.4", "A.8.2.3"], // Privacy, Data handling
    LLM07: ["A.14.2.1", "A.14.2.5"], // Development policy, Input validation
    LLM08: ["A.9.2.3", "A.9.4.1"], // Access management
    LLM09: ["A.12.4.1", "A.16.1.1"], // Logging, Incident management
    LLM10: ["A.9.1.1", "A.18.1.2"], // Access control, IP protection
};
/**
 * Get all OWASP LLM Top 10 controls
 */
export function getOWASPLLMControls() {
    return OWASP_LLM_CONTROLS;
}
/**
 * Get OWASP LLM control by ID (LLM01-LLM10)
 */
export function getOWASPLLMControlById(id) {
    return OWASP_LLM_CONTROLS.find((c) => c.id === id);
}
/**
 * Get OWASP LLM controls by category
 */
export function getOWASPLLMControlsByCategory(category) {
    return OWASP_LLM_CONTROLS.filter((c) => c.category === category);
}
/**
 * Get all OWASP LLM categories
 */
export function getOWASPLLMCategories() {
    return [...new Set(OWASP_LLM_CONTROLS.map((c) => c.category))];
}
/**
 * Get cross-mapping to SOC 2 for a specific LLM control
 */
export function getSOC2MappingForLLMControl(llmControlId) {
    return OWASP_LLM_TO_SOC2_MAPPING[llmControlId] || [];
}
/**
 * Get cross-mapping to ISO 27001 for a specific LLM control
 */
export function getISO27001MappingForLLMControl(llmControlId) {
    return OWASP_LLM_TO_ISO27001_MAPPING[llmControlId] || [];
}
/**
 * Generate remediation guidance for a specific LLM control
 */
export function getRemediationGuidance(controlId) {
    const guidance = {
        LLM01: [
            "Implement strict input validation on all user-provided prompts",
            "Use prompt injection detection classifiers",
            "Enforce privilege separation between system prompts and user inputs",
            "Apply output filtering to detect instruction override attempts",
            "Use sandboxed execution environments for LLM tools",
        ],
        LLM02: [
            "Encode and sanitize all LLM outputs before use in downstream systems",
            "Apply context-aware output validation (SQL, HTML, command shells)",
            "Implement parameterized queries for database operations",
            "Use Content Security Policy for web outputs",
            "Log and monitor output patterns for anomalies",
        ],
        LLM03: [
            "Verify training data provenance and integrity",
            "Implement data validation pipelines with anomaly detection",
            "Use secure fine-tuning environments with access controls",
            "Maintain data lineage and audit trails",
            "Apply differential privacy where appropriate",
        ],
        LLM04: [
            "Implement rate limiting on API endpoints",
            "Set token limits and context window bounds",
            "Use request queuing with timeout thresholds",
            "Monitor resource consumption patterns",
            "Implement circuit breakers for cascading failures",
        ],
        LLM05: [
            "Audit and verify all model dependencies",
            "Use signed and verified model artifacts",
            "Scan plugins/tools for vulnerabilities",
            "Maintain SBOM for AI components",
            "Implement continuous monitoring for supply chain risks",
        ],
        LLM06: [
            "Implement output filtering for sensitive patterns (PII, secrets)",
            "Apply data classification and access controls",
            "Use differential privacy for training data protection",
            "Implement guardrails against system prompt disclosure",
            "Log and audit data access patterns",
        ],
        LLM07: [
            "Validate all plugin inputs with strict schemas",
            "Apply least-privilege principles to tool permissions",
            "Use sandboxing for plugin execution",
            "Implement plugin allowlisting and code signing",
            "Monitor plugin behavior for anomalies",
        ],
        LLM08: [
            "Apply principle of least privilege to LLM capabilities",
            "Require human approval for destructive actions",
            "Implement action rate limiting and spending caps",
            "Use explicit scope declarations for tools",
            "Monitor and alert on unusual action patterns",
        ],
        LLM09: [
            "Implement human-in-the-loop for critical decisions",
            "Display confidence scores and uncertainty indicators",
            "Require verification for high-stakes outputs",
            "Educate users on LLM limitations",
            "Implement multi-agent verification for important outputs",
        ],
        LLM10: [
            "Implement strong API authentication and rate limiting",
            "Use query obfuscation and response fuzzing",
            "Monitor for model extraction patterns",
            "Apply access controls to model artifacts",
            "Use watermarking for model output attribution",
        ],
    };
    return guidance[controlId] || ["Implement controls appropriate to the specific risk"];
}
//# sourceMappingURL=owasp-llm.js.map