import { default as React } from 'react'; import { CSRFConfig, CSRFRequestInterceptor, CSRFToken, CSRFValidationResult, ValidatedCSRFToken } from './types'; /** * CSRF Protection Manager class * * Provides comprehensive CSRF protection including: * - Token generation and validation * - Double-submit cookie pattern implementation * - Origin/Referer header validation * - Automatic request interceptor for fetch/XHR * * @example * ```typescript * const csrf = CSRFProtection.getInstance(); * * // Get token for form submission * const token = csrf.getToken(); * * // Validate an incoming token * const result = csrf.validateToken(requestToken); * * // Create request interceptor * const interceptor = csrf.createRequestInterceptor(); * ``` */ declare class CSRFProtectionClass { private static instance; private config; private currentToken; private initialized; private constructor(); /** * Get singleton instance */ static getInstance(config?: CSRFConfig): CSRFProtectionClass; /** * Reset singleton instance (for testing) */ static resetInstance(): void; /** * Initialize CSRF protection * Generates initial token and sets up cookie if using double-submit pattern */ initialize(): void; /** * Cleanup resources */ cleanup(): void; /** * Generate a new CSRF token */ regenerateToken(): ValidatedCSRFToken; /** * Get the current CSRF token * Regenerates if expired */ getToken(): ValidatedCSRFToken; /** * Get the current token synchronously (may be stale) */ getTokenSync(): string; /** * Validate a CSRF token from a request */ validateToken(requestToken: string): CSRFValidationResult; /** * Validate double-submit cookie pattern */ validateDoubleSubmit(headerToken: string, cookieToken?: string): CSRFValidationResult; /** * Validate Origin/Referer header */ validateOrigin(origin: string | null, referer: string | null): CSRFValidationResult; /** * Create a request interceptor that adds CSRF token to requests */ createRequestInterceptor(): CSRFRequestInterceptor; /** * Create a fetch wrapper with CSRF protection * * Note: This method intentionally returns a raw fetch wrapper because: * 1. This IS the CSRF security layer that wraps fetch * 2. It provides a drop-in fetch replacement with CSRF token injection * 3. The apiClient uses this wrapper internally for CSRF protection * * For application API calls, prefer using apiClient which has CSRF built-in. * @see {@link @/lib/api/api-client} for the recommended API client */ createSecureFetch(): typeof fetch; /** * Get hidden input props for forms */ getFormInputProps(): { type: 'hidden'; name: string; value: string; }; /** * Get headers object with CSRF token */ getHeaders(): Promise>; /** * Get headers synchronously (may have stale token) */ getHeadersSync(): Record; /** * Get current configuration */ getConfig(): Readonly; /** * Update configuration */ updateConfig(updates: Partial): void; /** * Check if CSRF protection is initialized */ isInitialized(): boolean; /** * Get header name for CSRF token */ getHeaderName(): string; /** * Get field name for CSRF token in forms */ getFieldName(): string; /** * Check if a token is valid (not expired) */ private isTokenValid; /** * Load token from cookie (for double-submit pattern) */ private loadTokenFromCookie; /** * Set token cookie for double-submit pattern */ private setTokenCookie; } /** * CSRF Protection singleton instance */ export declare const CSRFProtection: CSRFProtectionClass; /** * Generate a one-time CSRF token * For scenarios where token rotation is required */ export declare function generateOneTimeToken(): CSRFToken; /** * Create a request init object with CSRF token */ export declare function createSecureRequestInit(method: string, body?: BodyInit | null, additionalHeaders?: Record): Promise; /** * Create a protected form action handler */ export declare function createProtectedFormHandler(action: (formData: FormData) => Promise): (event: React.FormEvent) => Promise; /** * Validate a request for CSRF protection * Comprehensive validation using configured mode */ export declare function validateRequest(request: { method: string; headers: Headers | Record; url: string; }): CSRFValidationResult; /** * Create CSRF hidden input element props */ export declare function createCSRFInputProps(): Promise<{ type: 'hidden'; name: string; value: string; }>; /** * Create meta tag props for CSRF token * Useful for JavaScript access to token */ export declare function createCSRFMetaProps(): Promise<{ name: string; content: string; }>; export type { CSRFProtectionClass }; export type { CSRFToken, CSRFConfig, CSRFValidationResult, CSRFRequestInterceptor, ValidatedCSRFToken, };