/** * @fileoverview Vulnerability Detection Module - Utility Functions * @module rules/vulnerabilities/utils * * Utility functions for vulnerability detection including safe regex matching, * snippet extraction, taint analysis helpers, and code normalization. */ import { SupportedLanguage, PatternMatch, SourceLocation, RegexPattern, TaintSource, TaintSink, TaintSanitizer, ConfidenceLevel } from '../types'; /** * Execute regex with timeout protection (ReDoS prevention) * * @param code - Source code to match against * @param pattern - Regex pattern to match * @returns Array of pattern matches */ export declare function safeRegexMatch(code: string, pattern: RegexPattern): PatternMatch[]; /** * Execute regex match with promise-based timeout * * @param code - Source code to match against * @param pattern - Regex pattern to match * @param timeout - Timeout in milliseconds * @returns Promise of pattern matches */ export declare function safeRegexMatchAsync(code: string, pattern: RegexPattern, timeout?: number): Promise; /** * Get line number from character index (1-based) * * @param code - Source code * @param index - Character index * @returns Line number (1-based) */ export declare function getLineNumber(code: string, index: number): number; /** * Get column number from character index (0-based) * * @param code - Source code * @param index - Character index * @returns Column number (0-based) */ export declare function getColumnNumber(code: string, index: number): number; /** * Get character index from line and column * * @param code - Source code * @param line - Line number (1-based) * @param column - Column number (0-based) * @returns Character index */ export declare function getCharacterIndex(code: string, line: number, column: number): number; /** * Extract code snippet with context * * @param code - Full source code * @param location - Source location * @param contextLines - Number of context lines before/after * @returns Code snippet with context */ export declare function extractSnippet(code: string, location: SourceLocation, contextLines?: number): { snippet: string; highlightStart: number; highlightEnd: number; }; /** * Extract the specific line of code * * @param code - Full source code * @param lineNumber - Line number (1-based) * @returns The line content */ export declare function extractLine(code: string, lineNumber: number): string; /** * Format snippet for display with line numbers * * @param snippet - Code snippet * @param startLine - Starting line number * @returns Formatted snippet with line numbers */ export declare function formatSnippetWithLineNumbers(snippet: string, startLine: number): string; /** * Normalize code for consistent analysis * * @param code - Source code * @param language - Programming language * @returns Normalized code */ export declare function normalizeCode(code: string, language: SupportedLanguage): string; /** * Remove comments from code (approximate) * * @param code - Source code * @param language - Programming language * @returns Code without comments */ export declare function removeComments(code: string, language: SupportedLanguage): string; /** * Check if a string appears to be a SQL query * * @param text - Text to check * @returns True if text looks like SQL */ export declare function looksLikeSql(text: string): boolean; /** * Check if a string appears to be a shell command * * @param text - Text to check * @returns True if text looks like a shell command */ export declare function looksLikeCommand(text: string): boolean; /** * Check if a string appears to be HTML * * @param text - Text to check * @returns True if text looks like HTML */ export declare function looksLikeHtml(text: string): boolean; /** * Check if text contains user-controlled input indicators * * @param text - Text to check * @param language - Programming language * @returns True if text contains user input patterns */ export declare function containsUserInput(text: string, language: SupportedLanguage): boolean; /** * Find taint sources in code * * @param code - Source code * @param sources - Taint source definitions * @param language - Programming language * @returns Array of found sources with locations */ export declare function findTaintSources(code: string, sources: TaintSource[], language: SupportedLanguage): Array<{ source: TaintSource; location: SourceLocation; matchedText: string; }>; /** * Find taint sinks in code * * @param code - Source code * @param sinks - Taint sink definitions * @param language - Programming language * @returns Array of found sinks with locations */ export declare function findTaintSinks(code: string, sinks: TaintSink[], language: SupportedLanguage): Array<{ sink: TaintSink; location: SourceLocation; matchedText: string; }>; /** * Check if sanitization is present between source and sink * * @param code - Source code * @param sourceLocation - Source location * @param sinkLocation - Sink location * @param sanitizers - Sanitizer definitions * @returns Found sanitizers between source and sink */ export declare function findSanitizers(code: string, sourceLocation: SourceLocation, sinkLocation: SourceLocation, sanitizers: TaintSanitizer[]): TaintSanitizer[]; /** * Check if code location is inside a test file * * @param filePath - File path * @returns True if file is a test file */ export declare function isTestFile(filePath: string): boolean; /** * Check if code location is inside vendor/node_modules * * @param filePath - File path * @returns True if file is vendor code */ export declare function isVendorCode(filePath: string): boolean; /** * Detect the programming language from file extension * * @param filePath - File path * @returns Detected language or null */ export declare function detectLanguage(filePath: string): SupportedLanguage | null; /** * Calculate confidence based on multiple factors * * @param factors - Array of confidence factors (0-1) * @returns Combined confidence level */ export declare function calculateConfidence(factors: number[]): ConfidenceLevel; /** * Boost confidence when taint flow is confirmed * * @param baseConfidence - Base confidence level * @param hasTaintFlow - Whether taint flow was detected * @returns Adjusted confidence level */ export declare function adjustConfidenceForTaintFlow(baseConfidence: ConfidenceLevel, hasTaintFlow: boolean): ConfidenceLevel; /** * Generate unique finding ID * * @param ruleId - Rule ID * @param filePath - File path * @param line - Line number * @returns Unique finding ID */ export declare function generateFindingId(ruleId: string, filePath: string, line: number): string; //# sourceMappingURL=index.d.ts.map