// =============================================================================
// Security Pattern Detection Policy
// =============================================================================
// Blocks command injection, path traversal, and SQL injection attacks using
// regex-based pattern detection from Shield's security detectors.
//
// Context keys used (normalized by projection layer):
// - command_injection_detected: Bool - Command injection pattern found
// - command_injection_score: Long (0-100) - Detection confidence
// - path_traversal_detected: Bool - Path traversal pattern found
// - path_traversal_severity: String - Severity level (critical/high/medium/low)
// - sql_injection_detected: Bool - SQL injection pattern found
// - sql_injection_score: Long (0-100) - Detection confidence
//
// Category: security
// Namespace: Guardrails
// =============================================================================

@id("security-block-command-injection")
@name("Block command injection")
@description("Forbids requests containing command injection patterns such as reverse shells, privilege escalation, or destructive commands")
@severity("critical")
@tags("command-injection,security")
forbid (
    principal,
    action in [Guardrails::Action::"process_prompt", Guardrails::Action::"call_tool"],
    resource
) when {
    context has command_injection_detected && context.command_injection_detected == true
};

@id("security-block-path-traversal")
@name("Block high-severity path traversal")
@description("Forbids requests containing path traversal patterns targeting sensitive system files or using deep directory traversal")
@severity("high")
@tags("path-traversal,security")
forbid (
    principal,
    action in [Guardrails::Action::"process_prompt", Guardrails::Action::"call_tool", Guardrails::Action::"read_file", Guardrails::Action::"write_file"],
    resource
) when {
    context has path_traversal_detected && context.path_traversal_detected == true &&
    context has path_traversal_severity &&
    (context.path_traversal_severity == "critical" || context.path_traversal_severity == "high")
};

@id("security-block-sql-injection")
@name("Block high-confidence SQL injection")
@description("Forbids requests with SQL injection confidence above 75% (tautologies, UNION-based, destructive queries)")
@severity("high")
@tags("sql-injection,security")
forbid (
    principal,
    action in [Guardrails::Action::"process_prompt", Guardrails::Action::"call_tool"],
    resource
) when {
    context has sql_injection_detected && context.sql_injection_detected == true &&
    context has sql_injection_score && context.sql_injection_score >= 75
};
