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

export const mcpRules: SecurityRule[] = [
  {
    id: 'SEC-MCP-001',
    name: 'Hardcoded MCP Secrets',
    category: 'mcp',
    severity: 'error',
    confidence: 'medium',
    patterns: [/(?:API_KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL)\s*["']?\s*:\s*["'][^"']{8,}["']/i],
    fileGlob: '**/.mcp.json',
    message: 'Hardcoded secret detected in MCP server configuration',
    remediation: 'Use environment variable references instead of inline secrets in .mcp.json',
    references: ['CWE-798'],
  },
  {
    id: 'SEC-MCP-002',
    name: 'Shell Injection in MCP Args',
    category: 'mcp',
    severity: 'error',
    confidence: 'medium',
    patterns: [/\$\(/, /`[^`]+`/],
    fileGlob: '**/.mcp.json',
    message: 'Shell metacharacters detected in MCP server arguments',
    remediation: 'Use literal argument values; avoid shell interpolation in MCP args',
    references: ['CWE-78'],
  },
  {
    id: 'SEC-MCP-003',
    name: 'Network Exposure',
    category: 'mcp',
    severity: 'warning',
    confidence: 'high',
    patterns: [/0\.0\.0\.0/, /["']\*["']\s*:\s*\d/, /host["']?\s*:\s*["']\*["']/i],
    fileGlob: '**/.mcp.json',
    message: 'MCP server binding to all network interfaces (0.0.0.0 or wildcard *)',
    remediation: 'Bind to 127.0.0.1 or localhost to restrict access to local machine',
    references: ['CWE-668'],
  },
  {
    id: 'SEC-MCP-004',
    name: 'Typosquatting Vector',
    category: 'mcp',
    severity: 'warning',
    confidence: 'medium',
    patterns: [/\bnpx\s+(?:-y|--yes)\b/],
    fileGlob: '**/.mcp.json',
    message: 'npx -y auto-installs packages without confirmation, enabling typosquatting',
    remediation: 'Pin exact package versions or install packages explicitly before use',
    references: ['CWE-427'],
  },
  {
    id: 'SEC-MCP-005',
    name: 'Unencrypted Transport',
    category: 'mcp',
    severity: 'warning',
    confidence: 'medium',
    patterns: [/http:\/\/(?!localhost\b|127\.0\.0\.1\b)/],
    fileGlob: '**/.mcp.json',
    message: 'Unencrypted HTTP transport detected for MCP server connection',
    remediation: 'Use https:// for all non-localhost MCP server connections',
    references: ['CWE-319'],
  },
];
