import type { SecurityRule } from '../types';

export const agentConfigRules: SecurityRule[] = [
  {
    id: 'SEC-AGT-001',
    name: 'Hidden Unicode Characters',
    category: 'agent-config',
    severity: 'error',
    confidence: 'high',
    patterns: [/\u200B|\u200C|\u200D|\uFEFF|\u2060/],
    fileGlob: '**/CLAUDE.md,**/AGENTS.md,**/*.yaml',
    message: 'Hidden zero-width Unicode characters detected in agent configuration',
    remediation: 'Remove invisible Unicode characters; they may hide malicious instructions',
    references: ['CWE-116'],
  },
  {
    id: 'SEC-AGT-002',
    name: 'URL Execution Directives',
    category: 'agent-config',
    severity: 'warning',
    confidence: 'medium',
    patterns: [/\b(?:curl|wget)\s+\S+/i, /\bfetch\s*\(/i],
    fileGlob: '**/CLAUDE.md,**/AGENTS.md',
    message: 'URL execution directive found in agent configuration',
    remediation: 'Avoid instructing agents to download and execute remote content',
    references: ['CWE-94'],
  },
  {
    id: 'SEC-AGT-003',
    name: 'Wildcard Tool Permissions',
    category: 'agent-config',
    severity: 'warning',
    confidence: 'high',
    patterns: [/(?:Bash|Write|Edit)\s*\(\s*\*\s*\)/],
    fileGlob: '**/.claude/**,**/settings*.json',
    message: 'Wildcard tool permissions grant unrestricted access',
    remediation: 'Scope tool permissions to specific patterns instead of wildcards',
    references: ['CWE-250'],
  },
  {
    id: 'SEC-AGT-004',
    name: 'Auto-approve Patterns',
    category: 'agent-config',
    severity: 'warning',
    confidence: 'high',
    patterns: [/\bautoApprove\b/i, /\bauto_approve\b/i],
    fileGlob: '**/.claude/**,**/.mcp.json',
    message: 'Auto-approve configuration bypasses human review of tool calls',
    remediation:
      'Review auto-approved tools carefully; prefer explicit approval for destructive operations',
    references: ['CWE-862'],
  },
  {
    id: 'SEC-AGT-005',
    name: 'Prompt Injection Surface',
    category: 'agent-config',
    severity: 'warning',
    confidence: 'medium',
    patterns: [/\$\{[^}]*\}/, /\{\{[^}]*\}\}/],
    fileGlob: '**/skill.yaml',
    message: 'Template interpolation syntax in skill YAML may enable prompt injection',
    remediation: 'Avoid dynamic interpolation in skill descriptions; use static text',
    references: ['CWE-94'],
  },
  {
    id: 'SEC-AGT-006',
    name: 'Permission Bypass Flags',
    category: 'agent-config',
    severity: 'error',
    confidence: 'high',
    patterns: [/--dangerously-skip-permissions/, /--no-verify/],
    fileGlob: '**/CLAUDE.md,**/AGENTS.md,**/.claude/**',
    message: 'Permission bypass flag detected in agent configuration',
    remediation: 'Remove flags that bypass safety checks; they undermine enforcement',
    references: ['CWE-863'],
  },
  {
    id: 'SEC-AGT-007',
    name: 'Hook Injection Surface',
    category: 'agent-config',
    severity: 'error',
    confidence: 'low',
    patterns: [/\$\(/, /`[^`]+`/, /\s&&\s/, /\s\|\|\s/],
    fileGlob: '**/settings*.json,**/hooks.json',
    message: 'Shell metacharacters in hook commands may enable command injection',
    remediation:
      'Use simple, single-command hooks without shell operators; chain logic inside the script',
    references: ['CWE-78'],
  },
];
