UNPKG

sanitize-request

Version:

A TypeScript library for safe display and sanitization to prevent XSS attacks.

41 lines (35 loc) 1.39 kB
import { Request, Response, NextFunction } from 'express'; interface SanitizationConfig { allowedTags?: string[]; allowedAttributes?: Record<string, string[]>; stripIgnoreTag?: boolean; stripIgnoreTagBody?: boolean; allowEmptyTags?: boolean; maxTagDepth?: number; maxStringLength?: number; } declare const SANITIZATION_CONFIGS: { readonly base: SanitizationConfig; readonly strict: SanitizationConfig; readonly liberal: SanitizationConfig; readonly blog: SanitizationConfig; readonly comment: SanitizationConfig; readonly email: SanitizationConfig; readonly admin: SanitizationConfig; }; type ConfigName = keyof typeof SANITIZATION_CONFIGS; interface SanitizeRequestOptions { config?: SanitizationConfig | ConfigName; onSanitized?: (metadata: any) => void; onError?: (error: Error, req: Request) => void; skipPaths?: string[]; logWarnings?: boolean; } declare const sanitizeRequest: (options?: SanitizeRequestOptions) => (req: Request, res: Response, next: NextFunction) => void; interface SanitizeStringsOptions { customSensitiveFields?: string[]; customSanitizer?: (value: string) => string; skipEmptyStrings?: boolean; } declare const sanitizeStrings: (options?: SanitizeStringsOptions) => (req: Request, res: Response, next: NextFunction) => void; export { sanitizeRequest, sanitizeStrings };