/** * Error classes for the pre-scanner module. * These errors are thrown BEFORE AST parsing when security issues are detected. * * @module pre-scanner/errors */ import { AstGuardError } from '../errors'; /** * Error codes for pre-scanner issues. * These codes identify specific security concerns detected during pre-scanning. */ export declare const PRESCANNER_ERROR_CODES: { /** Input exceeds size limit */ readonly INPUT_TOO_LARGE: "PRESCANNER_INPUT_TOO_LARGE"; /** Line exceeds maximum length */ readonly LINE_TOO_LONG: "PRESCANNER_LINE_TOO_LONG"; /** Too many lines in input */ readonly TOO_MANY_LINES: "PRESCANNER_TOO_MANY_LINES"; /** Null byte detected (binary/attack indicator) */ readonly NULL_BYTE_DETECTED: "PRESCANNER_NULL_BYTE"; /** Bracket nesting exceeds limit */ readonly EXCESSIVE_NESTING: "PRESCANNER_NESTING_OVERFLOW"; /** Consecutive operators exceed limit */ readonly EXCESSIVE_OPERATORS: "PRESCANNER_OPERATOR_SPAM"; /** Regex literal detected (blocked in strict mode) */ readonly REGEX_BLOCKED: "PRESCANNER_REGEX_BLOCKED"; /** ReDoS vulnerability detected in regex */ readonly REGEX_REDOS_DETECTED: "PRESCANNER_REDOS"; /** Regex pattern too long */ readonly REGEX_TOO_LONG: "PRESCANNER_REGEX_TOO_LONG"; /** Too many regex literals */ readonly REGEX_COUNT_EXCEEDED: "PRESCANNER_REGEX_COUNT"; /** String literal too long */ readonly STRING_TOO_LONG: "PRESCANNER_STRING_TOO_LONG"; /** Total string content exceeds limit */ readonly STRING_TOTAL_EXCEEDED: "PRESCANNER_STRING_TOTAL"; /** BiDi/Trojan Source attack detected */ readonly BIDI_ATTACK: "PRESCANNER_BIDI_ATTACK"; /** Suspicious Unicode characters detected */ readonly UNICODE_SUSPICIOUS: "PRESCANNER_UNICODE_SUSPICIOUS"; /** Homograph attack detected */ readonly HOMOGRAPH_ATTACK: "PRESCANNER_HOMOGRAPH"; }; /** * Type for pre-scanner error codes */ export type PreScannerErrorCode = (typeof PRESCANNER_ERROR_CODES)[keyof typeof PRESCANNER_ERROR_CODES]; /** * Details provided with pre-scanner errors */ export interface PreScannerErrorDetails { /** Position in source where issue was found */ position?: number; /** Line number (1-indexed) */ line?: number; /** Column number (1-indexed) */ column?: number; /** Actual value that triggered the error */ actual?: number | string; /** The limit that was exceeded */ limit?: number; /** The pattern that was detected (for regex/unicode issues) */ pattern?: string; /** Additional context */ context?: string; } /** * Error thrown during pre-scanning when a security issue is detected. * This error is thrown BEFORE the AST parser runs, providing * defense-in-depth against parser-level attacks. * * @example * ```typescript * throw new PreScannerError( * 'Input size (150MB) exceeds maximum allowed (100MB)', * PRESCANNER_ERROR_CODES.INPUT_TOO_LARGE, * { actual: 157286400, limit: 104857600 } * ); * ``` */ export declare class PreScannerError extends AstGuardError { /** * The specific error code identifying the issue type */ readonly errorCode: PreScannerErrorCode; /** * Additional details about the error */ readonly details: PreScannerErrorDetails; constructor(message: string, errorCode: PreScannerErrorCode, details?: PreScannerErrorDetails); /** * Returns a structured representation of the error for logging/reporting */ toJSON(): Record; /** * Creates a formatted error message with location information */ formatWithLocation(): string; } /** * Error thrown when ReDoS vulnerability is detected in a regex pattern */ export declare class ReDoSError extends PreScannerError { /** * The vulnerability score (0-100, higher = more dangerous) */ readonly vulnerabilityScore: number; /** * The type of ReDoS pattern detected */ readonly patternType: string; constructor(message: string, details: PreScannerErrorDetails & { vulnerabilityScore: number; patternType: string; }); } /** * Error thrown when BiDi/Trojan Source attack is detected */ export declare class BiDiAttackError extends PreScannerError { /** * The type of BiDi attack detected */ readonly attackType: 'trojan_source' | 'invisible_chars' | 'direction_override'; constructor(message: string, attackType: 'trojan_source' | 'invisible_chars' | 'direction_override', details?: PreScannerErrorDetails); } /** * Factory functions for creating common pre-scanner errors */ export declare const PreScannerErrors: { readonly inputTooLarge: (actual: number, limit: number) => PreScannerError; readonly lineTooLong: (line: number, length: number, limit: number) => PreScannerError; readonly tooManyLines: (actual: number, limit: number) => PreScannerError; readonly nullByteDetected: (position: number) => PreScannerError; readonly excessiveNesting: (depth: number, limit: number, position: number) => PreScannerError; readonly regexBlocked: (pattern: string, position: number, line?: number) => PreScannerError; readonly regexTooLong: (length: number, limit: number, position: number) => PreScannerError; readonly regexCountExceeded: (count: number, limit: number) => PreScannerError; readonly redosDetected: (pattern: string, patternType: string, score: number, position: number) => ReDoSError; readonly bidiAttack: (attackType: "trojan_source" | "invisible_chars" | "direction_override", position: number, line?: number) => BiDiAttackError; };