import { ValidationRule, ValidationContext, ValidationSeverity } from '../interfaces'; /** * Options for UnicodeSecurityRule */ export interface UnicodeSecurityOptions { /** Block zero-width characters (default: true) */ blockZeroWidth?: boolean; /** Block bidirectional control characters (default: true) */ blockBidi?: boolean; /** Block homoglyph characters in identifiers (default: true) */ blockHomoglyphs?: boolean; /** Block invisible/formatting characters (default: true) */ blockInvisible?: boolean; /** Allow specific Unicode characters (whitelist) */ allowedCharacters?: string[]; /** Check string literals for Unicode attacks (default: false) */ checkStringLiterals?: boolean; /** Check template literals for Unicode attacks (default: false) */ checkTemplateLiterals?: boolean; /** Check comments for Unicode attacks (default: true for bidi) */ checkComments?: boolean; } /** * Rule that detects and blocks Unicode-based attacks * * This rule protects against: * 1. **Trojan Source attacks** - Bidirectional text control characters * that can visually reorder code to hide malicious logic * 2. **Homoglyph attacks** - Characters that look like ASCII but are * different (e.g., Cyrillic 'а' vs Latin 'a') * 3. **Zero-width injection** - Invisible characters that can hide * in identifiers or strings * 4. **Invisible character attacks** - Formatting characters that * don't render but affect string comparisons * * @example * ```typescript * // Trojan Source attack - bidi override makes code look different * // Code with U+202E (RLO) visually reverses text direction * * // Homoglyph attack - Cyrillic U+0430 looks like Latin 'a' * // const \u0430dmin = true; // looks like "admin" but is different * * // Zero-width injection * // const x = "hello\u200Bworld"; // Invisible ZWSP in string * ``` */ export declare class UnicodeSecurityRule implements ValidationRule { readonly name = "unicode-security"; readonly description = "Detects Unicode-based security attacks (homoglyphs, bidi, zero-width)"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = true; private options; private allHomoglyphs; constructor(options?: UnicodeSecurityOptions); validate(context: ValidationContext): void; /** * Check source code for bidirectional control characters * These can appear in comments and are not visible in the AST */ private checkSourceForBidi; /** * Check a string for Unicode security issues */ private checkString; /** * Detect all Unicode violations in a string */ private detectViolations; /** * Convert a character position to line and column numbers */ private getLineAndColumn; } /** * Helper function to normalize a string by replacing homoglyphs with ASCII equivalents * Useful for comparison or logging purposes */ export declare function normalizeHomoglyphs(str: string): string; /** * Helper function to detect if a string contains any Unicode security issues * Returns true if the string is safe, false if it contains suspicious characters */ export declare function isUnicodeSafe(str: string): boolean;