ailock
Version:
AI-Proof File Guard - Protect sensitive files from accidental AI modifications
96 lines • 2.66 kB
TypeScript
/**
* Secure error handling that prevents information disclosure
* and implements fail-safe security mechanisms
*/
export declare enum ErrorSeverity {
LOW = "low",
MEDIUM = "medium",
HIGH = "high",
CRITICAL = "critical"
}
export declare enum ErrorCategory {
SECURITY = "security",
VALIDATION = "validation",
FILESYSTEM = "filesystem",
PERMISSION = "permission",
CONFIGURATION = "configuration",
NETWORK = "network",
UNKNOWN = "unknown"
}
export interface SecureError {
message: string;
category: ErrorCategory;
severity: ErrorSeverity;
code: string;
timestamp: Date;
context?: Record<string, any>;
originalError?: Error;
shouldFailSafe: boolean;
}
export interface ErrorHandlerOptions {
failSafe: boolean;
logErrors: boolean;
sanitizeMessages: boolean;
includeStackTrace: boolean;
maxContextSize: number;
}
/**
* Secure error handler that prevents information disclosure
* and implements fail-safe mechanisms
*/
export declare class SecureErrorHandler {
private readonly options;
private readonly sanitizer;
private readonly recovery;
private readonly errorMessages;
constructor(options?: Partial<ErrorHandlerOptions>);
/**
* Handles an error with security-conscious processing
*/
handle(error: Error | unknown, context?: Record<string, any>): SecureError;
/**
* Handles an error and throws a sanitized version
*/
handleAndThrow(error: Error | unknown, context?: Record<string, any>): never;
/**
* Determines if an operation should fail safe based on error type
*/
shouldFailSafe(error: Error | unknown): boolean;
/**
* Creates a secure error from any error type
*/
private createSecureError;
/**
* Categorizes an error and determines its properties
*/
private categorizeError;
/**
* Sanitizes error messages to prevent information disclosure
*/
private sanitizeMessage;
/**
* Sanitizes and limits context information
*/
private sanitizeContext;
/**
* Checks if a key contains sensitive information
*/
private isSensitiveKey;
/**
* Sanitizes a value recursively with circular reference detection
*/
private sanitizeValue;
/**
* Logs error securely
*/
private logError;
/**
* Creates a recovery action based on error type
*/
createRecoveryAction(error: SecureError): (() => Promise<void>) | null;
/**
* Formats error for user display
*/
formatForUser(error: SecureError): string;
}
//# sourceMappingURL=ErrorHandler.d.ts.map