/** * Unicode security checks for the pre-scanner. * Detects BiDi attacks, invisible characters, and homograph attacks. * * @module pre-scanner/checks/unicode-check */ import type { PreScannerConfig } from '../config'; import type { ScanState } from '../scan-state'; /** * BiDi (Bidirectional) override characters used in Trojan Source attacks. * CVE-2021-42574: "Trojan Source: Invisible Vulnerabilities" * * These characters can be used to make code appear different than it actually executes. */ export declare const BIDI_OVERRIDE_CHARS: { readonly LRE: "‪"; readonly RLE: "‫"; readonly PDF: "‬"; readonly LRO: "‭"; readonly RLO: "‮"; readonly LRI: "⁦"; readonly RLI: "⁧"; readonly FSI: "⁨"; readonly PDI: "⁩"; }; /** * All BiDi control characters to check for */ export declare const ALL_BIDI_CHARS: ("‪" | "‫" | "‬" | "‭" | "‮" | "⁦" | "⁧" | "⁨" | "⁩")[]; /** * Regex pattern matching any BiDi override character */ export declare const BIDI_PATTERN: RegExp; /** * Invisible/zero-width characters that can be used in attacks */ export declare const INVISIBLE_CHARS: { readonly ZWSP: "​"; readonly ZWNJ: "‌"; readonly ZWJ: "‍"; readonly WORD_JOINER: "⁠"; readonly FEFF: ""; readonly SHY: "­"; readonly CGJ: "͏"; }; /** * All invisible characters to check for */ export declare const ALL_INVISIBLE_CHARS: ("​" | "‌" | "‍" | "⁠" | "" | "­" | "͏")[]; /** * Regex pattern matching invisible characters * Note: We allow ZWNJ and ZWJ in some contexts for legitimate use * Using unicode escapes for security-relevant invisible character detection */ export declare const INVISIBLE_PATTERN: RegExp; /** * Check for BiDi override characters (Trojan Source attacks). * * These characters can make code appear visually different from what executes. * For example, RLO (Right-to-Left Override) can make "abc" display as "cba" * while still executing as "abc". * * @param source - The source code to check * @param config - Pre-scanner configuration * @param state - Scan state for recording issues */ export declare function checkBidiPatterns(source: string, config: PreScannerConfig, state: ScanState): void; /** * Check for invisible/zero-width characters. * * These characters can be used to: * - Create visually identical but different identifiers * - Hide malicious code within seemingly normal code * - Bypass security checks that match on visible text * * @param source - The source code to check * @param config - Pre-scanner configuration * @param state - Scan state for recording issues */ export declare function checkInvisibleChars(source: string, config: PreScannerConfig, state: ScanState): void; /** * Check for homograph attacks using confusable characters. * This is a basic check for common confusables in identifiers. * * @param source - The source code to check * @param config - Pre-scanner configuration * @param state - Scan state for recording issues */ export declare function checkHomographs(source: string, config: PreScannerConfig, state: ScanState): void; /** * Perform all Unicode security checks. * * @param source - The source code to check * @param config - Pre-scanner configuration * @param state - Scan state for recording issues */ export declare function performUnicodeChecks(source: string, config: PreScannerConfig, state: ScanState): void;