/** * HeuristicAnalyzer * * Advanced heuristic detection using three techniques from research (DMPI-PMHFE, 2026): * * 1. SYNONYM EXPANSION — Expand injection keywords to catch paraphrased attacks * Instead of matching "ignore" only, match {ignore, disregard, overlook, neglect, skip, bypass, omit...} * * 2. STRUCTURAL PATTERN ANALYSIS — Detect instruction-like sentence structures * Imperative commands, Q&A injection (many-shot), repeated token attacks * * 3. STATISTICAL FEATURES — Score inputs based on statistical properties * Instruction word density, special character ratio, command-to-question ratio * * These techniques are zero-dependency, pure string analysis — no ML required. * Research shows they add +10-15pp detection over keyword-only regex. */ export interface HeuristicAnalyzerConfig { /** Enable synonym expansion (default: true) */ synonymExpansion?: boolean; /** Enable structural pattern analysis (default: true) */ structuralAnalysis?: boolean; /** Enable statistical feature scoring (default: true) */ statisticalScoring?: boolean; /** Risk threshold for blocking (0-1, default: 0.6) */ riskThreshold?: number; /** Q&A pair threshold for many-shot detection (default: 3) */ manyShotThreshold?: number; /** Repeated token threshold (default: 3) */ repeatedTokenThreshold?: number; } export interface HeuristicResult { allowed: boolean; reason?: string; riskScore: number; features: HeuristicFeatures; violations: string[]; } export interface HeuristicFeatures { is_ignore: boolean; is_urgent: boolean; is_incentive: boolean; is_covert: boolean; is_format_manipulation: boolean; is_hypothetical: boolean; is_systemic: boolean; is_immoral: boolean; synonym_categories_matched: number; is_shot_attack: boolean; is_repeated_token: boolean; is_imperative: boolean; is_role_assignment: boolean; structural_score: number; instruction_word_density: number; special_char_ratio: number; uppercase_ratio: number; average_word_length: number; statistical_score: number; } export declare class HeuristicAnalyzer { private config; constructor(config?: HeuristicAnalyzerConfig); /** * Analyze input using all three heuristic techniques */ analyze(input: string, requestId?: string): HeuristicResult; /** * Technique 1: Synonym Expansion * Check if input tokens match expanded synonym sets for 8 attack categories */ private checkSynonyms; /** * Technique 2: Structural Pattern Analysis * Detect instruction-like sentence structures */ private checkStructure; /** * Technique 3: Statistical Feature Scoring * Score based on statistical properties of the input */ private scoreStatistics; }