/** * Sanitization Detector * * Detects sanitization libraries and practices from tool metadata/descriptions. * Used to reduce false positives when tools have proper input sanitization in place. * * @see Issue #56: Improve security analysis granularity */ import { Tool } from "@modelcontextprotocol/sdk/types.js"; import { SanitizationCategory } from "../../config/sanitizationPatterns.js"; /** * Result of sanitization detection analysis */ export interface SanitizationDetectionResult { /** Whether any sanitization was detected */ detected: boolean; /** Specific libraries detected by name */ libraries: string[]; /** Categories of sanitization detected */ categories: SanitizationCategory[]; /** Generic sanitization keywords found */ genericPatterns: string[]; /** Total confidence adjustment (0-50 capped) */ totalConfidenceAdjustment: number; /** Evidence strings for what was detected */ evidence: string[]; } /** * Result of input reflection analysis */ export interface ReflectionAnalysis { /** Whether the input was reflected in the response */ reflected: boolean; /** Type of reflection detected */ reflectionType: "exact" | "partial" | "transformed" | "none"; /** Specific parts that were matched (for partial reflection) */ partialMatches: string[]; /** Confidence reduction based on reflection analysis */ confidenceReduction: number; } /** * Detects sanitization patterns in tool descriptions, metadata, and responses. * Uses pattern matching to identify known security libraries and generic * sanitization practices. */ export declare class SanitizationDetector { /** * Detect sanitization from tool description and metadata * * @param tool - MCP Tool object with name, description, and inputSchema * @returns Detection result with libraries, categories, and confidence adjustment */ detect(tool: Tool): SanitizationDetectionResult; /** * Detect sanitization from arbitrary text (e.g., prompt descriptions) * * @param text - Text content to analyze * @returns Detection result */ detectFromText(text: string): SanitizationDetectionResult; /** * Detect sanitization indicators in tool response content * * @param responseText - Response text from tool execution * @returns Detection result focusing on response-time evidence */ detectInResponse(responseText: string): SanitizationDetectionResult; /** * Merge multiple detection results into one * * @param results - Array of detection results to merge * @returns Combined result with deduplicated values */ mergeResults(...results: SanitizationDetectionResult[]): SanitizationDetectionResult; /** * Analyze whether input payload was reflected in the response * * @param payload - Original payload that was sent * @param responseText - Response text to check for reflection * @returns Reflection analysis with type and confidence reduction */ detectInputReflection(payload: string, responseText: string): ReflectionAnalysis; /** * Extract all analyzable text from a tool definition */ private extractToolText; /** * Recursively extract text from JSON schema */ private extractSchemaText; /** * Analyze text for sanitization patterns */ private analyzeText; /** * Check if text matches a library pattern */ private matchesLibrary; /** * Check if a generic keyword match is part of an already-detected library name */ private isPartOfLibraryMatch; /** * Calculate total confidence adjustment from detection results */ private calculateTotalAdjustment; /** * Extract key parts of a payload for partial matching * * Extracts significant portions that would indicate reflection: * - Command keywords (SELECT, DROP, rm, etc.) * - Injection markers (', ", --, etc.) * - Common payload strings */ private extractKeyPayloadParts; /** * Check if payload appears in transformed form (encoded/escaped) */ private checkTransformedReflection; /** * Create an empty detection result */ private createEmptyResult; } //# sourceMappingURL=SanitizationDetector.d.ts.map