/** * Input Protection System - Guards against remote attacks on chat input * * Protects against: * 1. Remote stdin injection attacks * 2. Automated paste attacks (superhuman typing speed) * 3. Escape sequence injection via clipboard * 4. Buffer overflow attempts (massive pastes) * 5. Control character injection * 6. Unicode-based attacks (homoglyphs, RTL override) * 7. Timing-based attacks (burst injection) * * @module inputProtection */ import { EventEmitter } from 'events'; /** Input validation result */ export interface InputValidation { allowed: boolean; sanitized: string; blocked: boolean; reason?: string; attackType?: InputAttackType; riskScore: number; } /** Types of input attacks */ export type InputAttackType = 'automated_injection' | 'escape_injection' | 'control_injection' | 'overflow_attempt' | 'unicode_attack' | 'timing_burst' | 'remote_paste' | 'stdin_hijack'; /** Input protection configuration */ export interface InputProtectionConfig { /** Maximum characters per second (human ~12 CPS, paste unlimited) */ maxCharactersPerSecond?: number; /** Maximum paste size in characters */ maxPasteSize?: number; /** Maximum total buffer size */ maxBufferSize?: number; /** Enable timing-based attack detection */ detectTimingAttacks?: boolean; /** Minimum interval between keystrokes in ms (human ~50ms+) */ minKeystrokeInterval?: number; /** Maximum burst size before suspicion */ maxBurstSize?: number; /** Enable strict mode (blocks suspicious input instead of sanitizing) */ strictMode?: boolean; /** Verbose logging */ verbose?: boolean; /** Callback on attack detection */ onAttackDetected?: (type: InputAttackType, details: string) => void; } /** * Input Protection System */ export declare class InputProtection extends EventEmitter { private config; private inputTimings; private lastKeystroke; private burstCounter; private suspicionScore; private blockedAttacks; private sanitizedInputs; private isInPasteMode; private pasteStartTime; private readonly dangerousEscapes; private readonly dangerousControls; private readonly unicodeAttacks; constructor(config?: InputProtectionConfig); /** * Validate and sanitize input before it enters the chat buffer */ validateInput(input: string, isPaste?: boolean): InputValidation; /** * Enter paste mode (more lenient validation) */ enterPasteMode(): void; /** * Exit paste mode */ exitPasteMode(): void; /** * Check if currently in paste mode */ isPasting(): boolean; /** * Validate a complete prompt before submission */ validatePromptSubmission(prompt: string): InputValidation; /** * Reset protection state (e.g., after idle period) */ reset(): void; /** * Get protection statistics */ getStats(): { blockedAttacks: number; sanitizedInputs: number; currentSuspicion: number; currentCPS: number; }; private checkEscapeSequences; private checkControlCharacters; private checkUnicodeAttacks; private cleanOldTimings; private getRecentCharCount; private calculateCPS; private log; } /** * Initialize global input protection (singleton) */ export declare function initializeInputProtection(config?: InputProtectionConfig): InputProtection; /** * Get input protection instance */ export declare function getInputProtection(): InputProtection | null; /** * Quick validate function for input */ export declare function validateChatInput(input: string, isPaste?: boolean): InputValidation; /** * Validate final prompt before submission */ export declare function validatePromptSubmit(prompt: string): InputValidation; //# sourceMappingURL=inputProtection.d.ts.map