/** * Code Analyzer - AST-based Static Analysis * * Uses TypeScript compiler API to analyze code for security issues. * This is Phase 1 of the validation pipeline - catches obvious patterns * before semantic analysis. * * Key advantages over regex-based detection: * - Catches obfuscated patterns (obj["__proto__"], eval["call"]) * - Understands code structure, not just text * - Can't be bypassed with string concatenation tricks */ /** * Security violation found during analysis */ export interface SecurityViolation { type: 'prototype_pollution' | 'eval_usage' | 'require_import' | 'constructor_access' | 'process_access' | 'global_access' | 'fs_access' | 'child_process' | 'metaprogramming' | 'descriptor_manipulation' | 'dangerous_module'; location: { line: number; column: number; }; code: string; severity: 'critical' | 'high' | 'medium'; description: string; } /** * Security warning (not a blocker but worth noting) */ export interface SecurityWarning { type: string; location: { line: number; column: number; }; code: string; description: string; } /** * MCP call pattern detected in code */ export interface MCPCallPattern { namespace: string; method: string; location: { line: number; column: number; }; code: string; } /** * Result of code analysis */ export interface AnalysisResult { valid: boolean; violations: SecurityViolation[]; warnings: SecurityWarning[]; detectedPatterns: { mcpCalls: MCPCallPattern[]; networkRequests: string[]; dangerousConstructs: string[]; }; parseErrors: string[]; } /** * Code Analyzer using TypeScript AST */ export declare class CodeAnalyzer { /** * Analyze code for security issues * * @param code - TypeScript/JavaScript code to analyze * @returns Analysis result with violations and detected patterns */ analyze(code: string): AnalysisResult; /** * Get location info from a node */ private getLocation; /** * Get code snippet from a node */ private getCode; /** * Check for dangerous global identifiers */ private checkDangerousIdentifier; /** * Check for dangerous property access (obj.__proto__, obj.constructor) */ private checkDangerousPropertyAccess; /** * Check for dangerous element access (obj["__proto__"]) */ private checkDangerousElementAccess; /** * Check for dangerous function calls */ private checkDangerousCall; /** * Check for import/export statements and require calls */ private checkImportExport; /** * Detect MCP namespace.method() calls */ private checkMCPCalls; /** * Detect network-related calls (fetch, XMLHttpRequest, etc.) */ private checkNetworkCalls; } /** * Create a code analyzer instance */ export declare function createCodeAnalyzer(): CodeAnalyzer; //# sourceMappingURL=code-analyzer.d.ts.map