import { ValidationRule, ValidationContext, ValidationSeverity } from '../interfaces'; /** * Options for the NoJsonCallbacksRule */ export interface NoJsonCallbacksOptions { /** * Block JSON.stringify with replacer function argument. * Default: true */ blockStringifyReplacer?: boolean; /** * Block JSON.parse with reviver function argument. * Default: true */ blockParseReviver?: boolean; /** * Custom error message template. * Placeholders: {method} */ messageTemplate?: string; } /** * Rule that blocks JSON.stringify and JSON.parse with callback functions. * * This prevents information leakage attacks where a replacer/reviver function * is used to walk and enumerate properties of objects, potentially exposing * internal sandbox globals or sensitive data. * * **Attack Vector (Vector 960 - "Native Walker" Replacer Leak):** * ```javascript * const walker = (key, value) => { * keysFound.push(key); // Leaks property names * return value; * }; * JSON.stringify(this, walker); // Walks global scope * ``` * * **Blocked patterns:** * - `JSON.stringify(value, replacerFunction)` - replacer can enumerate properties * - `JSON.stringify(value, replacerFunction, space)` - same with space argument * - `JSON.parse(text, reviverFunction)` - reviver can intercept all values * * **Allowed patterns:** * - `JSON.stringify(value)` - no replacer, safe * - `JSON.stringify(value, null)` - null replacer, safe * - `JSON.stringify(value, null, 2)` - null replacer with space, safe * - `JSON.stringify(value, ['key1', 'key2'])` - array allowlist replacer, safe * - `JSON.parse(text)` - no reviver, safe * * @example * ```typescript * // Block all JSON callbacks (default) * new NoJsonCallbacksRule() * * // Block only stringify replacer * new NoJsonCallbacksRule({ blockParseReviver: false }) * * // Block only parse reviver * new NoJsonCallbacksRule({ blockStringifyReplacer: false }) * ``` */ export declare class NoJsonCallbacksRule implements ValidationRule { readonly name = "no-json-callbacks"; readonly description = "Blocks JSON.stringify/parse with callback functions to prevent property enumeration attacks"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = false; private readonly blockStringifyReplacer; private readonly blockParseReviver; private readonly messageTemplate; constructor(options?: NoJsonCallbacksOptions); validate(context: ValidationContext): void; private checkJsonCall; private checkStringifyReplacer; private checkParseReviver; private isJsonObject; private getMethodName; private isNullOrUndefined; private isFunctionOrPotentialFunction; private report; }