import { ValidationRule, ValidationContext, ValidationSeverity } from '../interfaces'; /** * Options for ResourceExhaustionRule */ export interface ResourceExhaustionOptions { /** Maximum allowed BigInt exponent (default: 10000) */ maxBigIntExponent?: number; /** Maximum allowed array size literal (default: 1000000) */ maxArraySize?: number; /** Maximum allowed array size for .fill() operations (default: 100000) - lower because fill() immediately allocates */ maxArrayFillSize?: number; /** Maximum allowed string repeat count (default: 100000) */ maxStringRepeat?: number; /** Block constructor property access patterns (default: true) */ blockConstructorAccess?: boolean; /** Block BigInt exponentiation entirely (default: false, only blocks large exponents) */ blockBigIntExponentiation?: boolean; /** * Allow dynamic (computed) array size for .fill() operations (default: false) * * When true, Array(dynamicSize).fill() is allowed because runtime memory * patching will enforce the limit. Only enable this when memoryLimit is * configured at runtime. * * When false (default), only literal sizes are allowed for .fill() to * prevent memory exhaustion in environments without runtime protection. */ allowDynamicArrayFill?: boolean; } /** * Rule that detects patterns that could cause CPU or memory exhaustion * * Catches patterns like: * - BigInt exponentiation with large exponents: 2n ** 1000000n * - Large array allocations: new Array(10000000) * - String repeat with large counts: 'x'.repeat(10000000) * - Constructor property access chains (sandbox escape vector) * - String concatenation building 'constructor' (obfuscation attempt) * * These patterns can bypass VM timeout because they execute in native code. */ export declare class ResourceExhaustionRule implements ValidationRule { private options; readonly name = "resource-exhaustion"; readonly description = "Detects patterns that could cause CPU or memory exhaustion"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = true; constructor(options?: ResourceExhaustionOptions); validate(context: ValidationContext): void; /** * Check if a binary expression looks like suspicious string concatenation */ private isSuspiciousStringConcat; /** * Try to evaluate a string concatenation expression * Returns the result if it's a simple string concat, or null if too complex */ private evaluateStringConcat; private getLocation; }