/** * Security Pattern Library * Single source of truth for all regex patterns used in security analysis * * Extracted from SecurityResponseAnalyzer.ts (Issue #53) * Consolidates 16 pattern collections, eliminates duplicates */ /** * Patterns to detect HTTP error responses (4xx/5xx) * Used by: isHttpErrorResponse(), analyzeComputedMathResult() */ export declare const HTTP_ERROR_PATTERNS: { /** Full pattern: status code + context (e.g., "404 not found") */ readonly statusWithContext: RegExp; /** Simple pattern: status code at start (e.g., "404: ...") */ readonly statusAtStart: RegExp; /** Short "not found" responses */ readonly notFound: RegExp; /** JSON status field pattern */ readonly jsonStatus: RegExp; }; /** * Patterns for MCP protocol validation errors * These indicate proper input rejection (SAFE behavior) * Used by: isMCPValidationError() */ export declare const VALIDATION_ERROR_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Issue #146: Error context patterns indicating operation failure * Used to detect when payload appears in error message (likely false positive) * These patterns indicate the server rejected/failed the operation */ export declare const ERROR_CONTEXT_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Issue #146: Success context patterns indicating operation completion * Used to confirm operation actually executed (high confidence vulnerability) * These patterns indicate the server processed and returned results */ export declare const SUCCESS_CONTEXT_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Issue #146: Check if payload appears in error context (likely false positive) * @param responseText The full response text from the tool * @param payload The payload that was sent to the tool * @returns true if payload is reflected in an error context */ export declare function isPayloadInErrorContext(responseText: string, payload: string): boolean; /** * Issue #201: Check if payload is partially echoed in response * Handles truncation and path prepending common in error messages * * False positives occur when servers echo payloads in error messages like: * "File not found: /path/to/" * * The evidence regex matches the echoed payload, not actual exploitation. * This function detects partial echoes that the simple includes() check misses. * * @param responseText The full response text from the tool * @param payload The payload that was sent to the tool * @param minPrefixLength Minimum prefix length to check (default: 30) * @returns true if payload or significant portion is echoed in response */ export declare function isPayloadPartiallyEchoed(responseText: string, payload: string, minPrefixLength?: number): boolean; /** * Issue #146: Check if response indicates successful operation (high confidence) * @param responseText The full response text from the tool * @returns true if response indicates operation succeeded */ export declare function hasSuccessContext(responseText: string): boolean; /** * Issue #146: Check if response indicates failed operation (error context) * @param responseText The full response text from the tool * @returns true if response indicates operation failed */ export declare function hasErrorContext(responseText: string): boolean; /** * Patterns indicating actual code/command execution * Used by: hasExecutionEvidence() */ export declare const EXECUTION_INDICATORS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Patterns for detecting execution artifacts in response * Used by: detectExecutionArtifacts() */ export declare const EXECUTION_ARTIFACT_PATTERNS: { /** Always indicates execution */ readonly alwaysExecution: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** Context-sensitive - only count if no echoed payload */ readonly contextSensitive: readonly [RegExp, RegExp, RegExp]; }; /** * Structured LLM injection marker with name metadata * Used by OutputInjectionAnalyzer for detailed reporting (Issue #191) */ export interface LLMInjectionMarker { pattern: RegExp; name: string; category: "xml_instruction" | "chat_format" | "template_injection" | "instruction_override"; } /** * Patterns for detecting LLM prompt injection markers in tool output * These indicate potential indirect prompt injection (output injection) * Used by: hasLLMInjectionMarkers(), OutputInjectionAnalyzer * * When tool output contains these markers, it may flow to the orchestrating * LLM and influence its behavior - a security concern for MCP integrations. * * Consolidated from OutputInjectionAnalyzer.ts (Issue #191) - single source of truth */ export declare const LLM_INJECTION_MARKERS_WITH_METADATA: LLMInjectionMarker[]; /** * Legacy array of just patterns (for backward compatibility) * @deprecated Use LLM_INJECTION_MARKERS_WITH_METADATA for new code */ export declare const LLM_INJECTION_MARKERS: RegExp[]; /** * Patterns for detecting output injection vulnerability metadata * Tools that self-report vulnerability status */ export declare const OUTPUT_INJECTION_METADATA: { /** Tool reports it includes raw/unsanitized content */ readonly rawContentIncluded: readonly [RegExp, RegExp, RegExp]; /** Tool reports vulnerability in output handling */ readonly vulnerableOutput: readonly [RegExp, RegExp, RegExp, RegExp]; }; /** * Patterns for connection/server errors * Used by: isConnectionError(), isConnectionErrorFromException() */ export declare const CONNECTION_ERROR_PATTERNS: { /** Unambiguous connection errors */ readonly unambiguous: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** Only apply when response starts with MCP error prefix */ readonly contextual: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** MCP error prefix pattern */ readonly mcpPrefix: RegExp; }; /** * Patterns for error classification * Used by: classifyError(), classifyErrorFromException() */ export declare const ERROR_CLASSIFICATION_PATTERNS: { readonly connection: RegExp; readonly server: RegExp; readonly protocol: RegExp; }; /** * Transient error patterns that are worth retrying. * These indicate temporary network/server issues that may resolve. * Used by: isTransientError(), isTransientErrorFromException() * * @see https://github.com/triepod-ai/inspector-assessment/issues/157 */ export declare const TRANSIENT_ERROR_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Permanent error patterns that should NOT be retried. * These indicate issues that will not resolve with retry. * Used by: isTransientError() to short-circuit retry logic * * @see https://github.com/triepod-ai/inspector-assessment/issues/157 */ export declare const PERMANENT_ERROR_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Check if error text indicates a transient error worth retrying. * @param text Error message or response text * @returns true if error is transient and should be retried */ export declare function isTransientErrorPattern(text: string): boolean; /** * Issue #175: AppleScript syntax error patterns to exclude from XXE detection * * AppleScript errors can trigger false positives when: * 1. The tool returns an AppleScript syntax error (e.g., -2750 duplicate parameter) * 2. The XXE payload is echoed back in the error message * 3. XXE evidence patterns match "parameter" + "entity" combination * * These patterns detect AppleScript-specific errors by: * - Error code ranges (-27xx, -25xx are AppleScript domain) * - AppleScript-specific syntax error messages * - Common AppleScript error patterns */ export declare const APPLESCRIPT_SYNTAX_ERROR_PATTERNS: RegExp[]; /** * Check if error text indicates an AppleScript syntax error (Issue #175) * @param text Error message or response text * @returns true if error is an AppleScript syntax error */ export declare function isAppleScriptSyntaxError(text: string): boolean; /** * Issue #177: AppleScript injection SUCCESS patterns * * These patterns indicate that the injection payload SUCCESSFULLY escaped * the string context and reached the AppleScript interpreter. Even if the * script then fails (e.g., Word not running), the injection point was reached, * proving the vulnerability exists. * * Key insight: Distinguish between: * - Syntax error FROM the payload itself (malformed input → safe, payload rejected) * - Runtime error AFTER payload executed (injection succeeded → vulnerable!) * * H1 #3480575 scenario: * Payload: " & do shell script "id" & " * Response shows: if "" & do shell script "id" & "" is not "" then * Error: -2710 (Word not running) * This is INJECTION SUCCESS - payload escaped into executable code context */ export declare const APPLESCRIPT_INJECTION_SUCCESS_PATTERNS: RegExp[]; /** * Runtime error codes that occur AFTER AppleScript interpretation begins * These indicate the injection reached the execution stage * * -2710: "Can't make class" - object creation failed (app not running, but injection succeeded) * -2753: "Can't get" - property access failed (but script was parsed and executed) * -1708: "Application isn't running" - target app not available (injection reached tell block) * -10810: "Application launch failed" - tried to launch app (injection executed) */ export declare const APPLESCRIPT_RUNTIME_ERROR_CODES: RegExp[]; /** * Check if response shows AppleScript injection SUCCESS (Issue #177) * This takes PRECEDENCE over syntax error detection for injection payloads. * * @param text Response text to analyze * @param payload Optional - the injection payload that was sent (for context) * @returns true if injection appears to have succeeded (vulnerability EXISTS) */ export declare function isAppleScriptInjectionSuccess(text: string, payload?: string): boolean; /** * Status patterns indicating safe response handling * Used by: isReflectionResponse() */ export declare const STATUS_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Reflection patterns indicating safe data handling * Used by: isReflectionResponse() */ export declare const REFLECTION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Fail-open authentication patterns (VULNERABLE) * Used by: analyzeAuthBypassResponse() */ export declare const AUTH_FAIL_OPEN_PATTERNS: readonly [{ readonly pattern: RegExp; readonly evidence: "auth_type: fail-open (CVE-2025-52882)"; }, { readonly pattern: RegExp; readonly evidence: "auth_status: bypassed"; }, { readonly pattern: RegExp; readonly evidence: "access granted despite failure"; }, { readonly pattern: RegExp; readonly evidence: "authentication skipped"; }, { readonly pattern: RegExp; readonly evidence: "fail-open pattern detected"; }, { readonly pattern: RegExp; readonly evidence: "auth bypassed"; }, { readonly pattern: RegExp; readonly evidence: "authentication bypassed"; }, { readonly pattern: RegExp; readonly evidence: "vulnerable flag with auth context"; }, { readonly pattern: RegExp; readonly evidence: "auth succeeded with null token"; }, { readonly pattern: RegExp; readonly evidence: "granted without valid token"; }, { readonly pattern: RegExp; readonly evidence: "action performed indicator"; }]; /** * Fail-closed authentication patterns (SAFE) * Used by: analyzeAuthBypassResponse() */ export declare const AUTH_FAIL_CLOSED_PATTERNS: readonly [{ readonly pattern: RegExp; readonly evidence: "auth_type: fail-closed (secure)"; }, { readonly pattern: RegExp; readonly evidence: "auth_status: denied"; }, { readonly pattern: RegExp; readonly evidence: "access denied"; }, { readonly pattern: RegExp; readonly evidence: "authentication failed"; }, { readonly pattern: RegExp; readonly evidence: "fail-closed pattern detected"; }, { readonly pattern: RegExp; readonly evidence: "status: blocked"; }, { readonly pattern: RegExp; readonly evidence: "invalid token rejection"; }, { readonly pattern: RegExp; readonly evidence: "token required"; }, { readonly pattern: RegExp; readonly evidence: "unauthorized response"; }, { readonly pattern: RegExp; readonly evidence: "denial reason provided"; }]; /** * Patterns indicating vulnerable shared state authorization * Detects cross-tool privilege escalation via shared mutable state * Used by: analyzeStateBasedAuthBypass() */ export declare const STATE_AUTH_VULNERABLE_PATTERNS: readonly [{ readonly pattern: RegExp; readonly evidence: "admin_mode enabled in response"; }, { readonly pattern: RegExp; readonly evidence: "Tool hints at cross-tool state dependency"; }, { readonly pattern: RegExp; readonly evidence: "Explicit cross-tool state dependency"; }, { readonly pattern: RegExp; readonly evidence: "Cross-tool privilege escalation detected"; }, { readonly pattern: RegExp; readonly evidence: "Elevated privileges granted"; }, { readonly pattern: RegExp; readonly evidence: "Admin mode activated (state modifier)"; }, { readonly pattern: RegExp; readonly evidence: "Response hints at config_modifier for admin_mode"; }, { readonly pattern: RegExp; readonly evidence: "Tool depends on config_modifier for authorization"; }]; /** * Patterns indicating safe independent authorization * Detects tools that use per-request authentication (secure) * Used by: analyzeStateBasedAuthBypass() */ export declare const STATE_AUTH_SAFE_PATTERNS: readonly [{ readonly pattern: RegExp; readonly evidence: "Tool explicitly states it doesn't use shared state"; }, { readonly pattern: RegExp; readonly evidence: "Tool requires independent per-request auth"; }, { readonly pattern: RegExp; readonly evidence: "Independent authorization required"; }, { readonly pattern: RegExp; readonly evidence: "Tool confirms it does not use shared state"; }, { readonly pattern: RegExp; readonly evidence: "Request stored for admin review (no auto-execution)"; }, { readonly pattern: RegExp; readonly evidence: "Per-request authentication enforced"; }]; /** * Response pattern structure for chain exploitation analysis */ export interface ChainResponsePattern { pattern: RegExp; weight: number; category: string; description: string; } /** * Patterns indicating vulnerable chain execution behavior * - Arbitrary tool invocation without allowlist * - Output injection via template substitution * - Recursive/circular chain execution * - Missing depth limits * - State poisoning between steps * * Used by: analyzeChainExploitation() */ export declare const CHAIN_EXPLOIT_VULNERABLE_PATTERNS: ChainResponsePattern[]; /** * Patterns indicating safe/hardened chain handling * - Tool allowlist validation * - No execution (validation only) * - Depth limits enforced * - Output injection blocked * * Used by: analyzeChainExploitation() */ /** * Threshold for confirming vulnerable chain execution behavior. * Value of 1.5 requires ~2 weighted pattern matches to confirm vulnerability. * * Derived from A/B testing against vulnerable-mcp/hardened-mcp testbed: * - vulnerable-mcp: typical scores 2.0-4.0 for vulnerable chains * - hardened-mcp: typical scores 0.0-0.8 for safe chains * * Setting at 1.5 provides margin against false positives while * maintaining detection of genuine vulnerabilities. */ export declare const CHAIN_VULNERABLE_THRESHOLD = 1.5; /** * Threshold for confirming safe/hardened chain behavior. * Value of 1.0 requires 1+ weighted safe pattern matches. * * Derived from A/B testing: * - hardened-mcp: typical scores 1.5-3.0 for safe chains * - vulnerable-mcp: typical scores 0.0-0.5 for safe patterns */ export declare const CHAIN_SAFE_THRESHOLD = 1; /** * Maps vulnerability categories to detection patterns. * Used by analyzeChainExploitation() for category classification. * * Extracted from inline patterns to maintain single source of truth. */ export declare const CHAIN_CATEGORY_PATTERNS: Record; /** * Detect vulnerability categories from response text. * Returns array of detected category names. */ export declare function detectVulnerabilityCategories(responseText: string): string[]; export declare const CHAIN_EXPLOIT_SAFE_PATTERNS: ChainResponsePattern[]; /** * Patterns indicating search result responses * Used by: isSearchResultResponse() */ export declare const SEARCH_RESULT_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Patterns indicating creation/modification responses * Used by: isCreationResponse() */ export declare const CREATION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Patterns for echoed injection payloads * Used by: containsEchoedInjectionPayload() */ export declare const ECHOED_PAYLOAD_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Fallback execution detection patterns * Used by: analyzeInjectionResponse() */ export declare const FALLBACK_EXECUTION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Text-based validation rejection patterns * Used by: isValidationRejection() */ export declare const TEXT_REJECTION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Result field rejection patterns (for JSON responses) * Used by: isValidationRejection() */ export declare const RESULT_REJECTION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Ambiguous validation pattern strings (for confidence calculation) * Used by: isValidationPattern() */ export declare const AMBIGUOUS_VALIDATION_PATTERNS: readonly ["type.*error", "invalid.*type", "error", "invalid", "failed", "negative.*not.*allowed", "must.*be.*positive", "invalid.*value", "overflow", "out.*of.*range"]; /** * Patterns for identifying structured data tools * Used by: isStructuredDataTool() */ export declare const DATA_TOOL_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Read-only tool name patterns * Used by: analyzeComputedMathResult() */ export declare const READ_ONLY_TOOL_NAME_PATTERN: RegExp; /** * Simple math expression pattern * Used by: isComputedMathResult(), analyzeComputedMathResult() */ export declare const SIMPLE_MATH_PATTERN: RegExp; /** * Computational language indicators * Used by: analyzeComputedMathResult() */ export declare const COMPUTATIONAL_INDICATORS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; /** * Common data field names that often contain numeric values * Used by: isCoincidentalNumericInStructuredData() */ export declare const STRUCTURED_DATA_FIELD_NAMES: readonly ["count", "total", "records", "page", "limit", "offset", "id", "status", "code", "version", "index", "size", "employees", "items", "results", "entries", "length", "pages", "rows", "columns", "width", "height", "timestamp", "duration", "amount", "price", "quantity"]; /** * Structured data indicators for confidence calculation * Used by: calculateConfidence() */ export declare const STRUCTURED_DATA_INDICATORS: { readonly fieldPatterns: RegExp; readonly bulletPattern: RegExp; readonly jsonPattern: RegExp; readonly numericMetadataPattern: RegExp; }; /** * Patterns for detecting secret/credential leakage in tool responses * Used by: checkSecretLeakage() */ export declare const SECRET_LEAKAGE_PATTERNS: { /** Well-known API key formats */ readonly apiKeys: readonly [RegExp, RegExp, RegExp, RegExp, RegExp]; /** Database connection strings with credentials */ readonly connectionStrings: readonly [RegExp]; /** Environment variable patterns with values */ readonly envVars: readonly [RegExp]; /** Partial key exposure patterns */ readonly partialKeys: readonly [RegExp]; /** Generic credential assignment patterns */ readonly credentialAssignment: readonly [RegExp]; }; /** * Patterns for detecting tool output injection vulnerabilities * Detects when user content is echoed unsanitized in tool output * Used by: analyzeOutputInjection() */ export declare const OUTPUT_INJECTION_PATTERNS: { /** LLM control patterns that should be sanitized */ readonly llmControl: readonly [RegExp, RegExp, RegExp, RegExp]; /** Canary markers for echo detection */ readonly canaryMarkers: readonly [RegExp]; }; /** * Patterns indicating scope violation in tool response * Detects when tools exceed their declared annotations at runtime * CWE-250: Execution with Unnecessary Privileges * CWE-269: Improper Privilege Management */ export declare const SCOPE_VIOLATION_PATTERNS: readonly [{ readonly pattern: RegExp; readonly evidence: "scope_violation: true (tool exceeded declared scope)"; }, { readonly pattern: RegExp; readonly evidence: "scope_escalation: true (privilege escalation via input)"; }, { readonly pattern: RegExp; readonly evidence: "actual_scope indicates privileged operation"; }, { readonly pattern: RegExp; readonly evidence: "privileged_data exposed in response"; }, { readonly pattern: RegExp; readonly evidence: "system_secrets leaked in response"; }, { readonly pattern: RegExp; readonly evidence: "Admin mode activated via keyword trigger"; }]; /** * Patterns indicating safe scope enforcement (hardened behavior) * Used to confirm tools properly reject privileged actions */ export declare const SCOPE_ENFORCED_PATTERNS: readonly [{ readonly pattern: RegExp; readonly evidence: "scope_enforced: true (safe)"; }, { readonly pattern: RegExp; readonly evidence: "Action blocked by allowlist"; }, { readonly pattern: RegExp; readonly evidence: "Allowlist enforcement"; }, { readonly pattern: RegExp; readonly evidence: "Explicit rejection: action not in allowlist"; }, { readonly pattern: RegExp; readonly evidence: "No escalation attempted (safe)"; }, { readonly pattern: RegExp; readonly evidence: "Allowlist defined and enforced"; }]; /** * Privileged actions that should be blocked by readOnlyHint=True tools */ export declare const PRIVILEGED_ACTIONS: readonly ["write", "write_file", "delete", "delete_data", "execute", "execute_command", "network", "network_request", "modify", "modify_config", "admin", "environment_access"]; /** * Escalation keywords that may trigger hidden privilege escalation */ export declare const ESCALATION_KEYWORDS: readonly ["admin", "sudo", "elevate", "root", "superuser", "privilege"]; /** * Check if response contains scope violation indicators (Issue #144) */ export declare function hasScopeViolation(text: string): boolean; /** * Check if response contains scope enforcement indicators (Issue #144) */ export declare function hasScopeEnforcement(text: string): boolean; /** * Check if any pattern in array matches text */ export declare function matchesAny(patterns: readonly RegExp[], text: string): boolean; /** * Check if HTTP error pattern matches */ export declare function isHttpError(text: string): boolean; /** * Check if response has MCP error prefix */ export declare function hasMcpErrorPrefix(text: string): boolean; /** * Check if text contains LLM injection markers (Issue #110, Challenge #8) * Detects XML-style tags, chat format markers, and instruction overrides */ export declare function hasLLMInjectionMarkers(text: string): boolean; /** * Check if response indicates output injection vulnerability (Issue #110, Challenge #8) * Detects tools that self-report including raw/unsanitized content */ export declare function hasOutputInjectionVulnerability(text: string): boolean; //# sourceMappingURL=SecurityPatternLibrary.d.ts.map