import { SafeHtml } from '@angular/platform-browser'; import DOMPurify from 'dompurify'; import * as i0 from "@angular/core"; /** * Configuration options for HTML sanitization */ export interface SanitizerConfig { /** * Allowed HTML tags * @default DOMPurify defaults + common safe tags */ allowedTags?: string[]; /** * Allowed HTML attributes * @default DOMPurify defaults + common safe attributes */ allowedAttributes?: string[]; /** * Allow CSS styles * @default true */ allowStyles?: boolean; /** * Allow data attributes (data-*) * @default true */ allowDataAttributes?: boolean; /** * Custom DOMPurify configuration * @see https://github.com/cure53/DOMPurify#can-i-configure-dompurify */ customConfig?: DOMPurify.Config; } /** * Service xử lý XSS (Cross-Site Scripting) sử dụng DOMPurify * * Service này cung cấp các phương thức để sanitize HTML content, * loại bỏ các yếu tố nguy hiểm có thể gây XSS attack trong khi * vẫn giữ lại các HTML tags và styles hợp lệ. * * @example * ```typescript * const sanitizer = inject(SanitizerService); * const safeHtml = sanitizer.sanitize('

Safe content

'); * // Result: '

Safe content

' * ``` */ export declare class SanitizerService { private readonly domSanitizer; /** * Default configuration cho DOMPurify * Cho phép hầu hết HTML tags và styles an toàn */ private readonly defaultConfig; /** * Sanitize HTML content để loại bỏ XSS threats * * Method này sử dụng DOMPurify để clean HTML content, * loại bỏ các scripts, event handlers và các yếu tố nguy hiểm khác * trong khi vẫn giữ lại HTML structure và styles hợp lệ. * * @param html - HTML content cần sanitize * @param config - Optional configuration để customize sanitization * @returns Sanitized HTML string an toàn * * @example * ```typescript * // Basic usage * const safe = sanitizer.sanitize('

Text

'); * // Result: '

Text

' * * // With custom config * const safe = sanitizer.sanitize(html, { * allowedTags: ['p', 'span', 'strong'], * allowStyles: false * }); * ``` */ sanitize(html: string, config?: SanitizerConfig): string; /** * Sanitize HTML và trả về Angular SafeHtml * * Method này kết hợp DOMPurify sanitization với Angular's DomSanitizer * để tạo ra SafeHtml object có thể sử dụng trực tiếp với [innerHTML]. * * @param html - HTML content cần sanitize * @param config - Optional configuration * @returns Angular SafeHtml object * * @example * ```typescript * // In component * safeContent = sanitizer.sanitizeToSafeHtml(userHtml); * * // In template *
* ``` */ sanitizeToSafeHtml(html: string, config?: SanitizerConfig): SafeHtml; /** * Sanitize HTML với strict mode (chỉ cho phép text formatting cơ bản) * * Mode này chỉ cho phép các tags an toàn nhất như p, span, strong, em, br. * Không cho phép links, images, hoặc các elements phức tạp khác. * * @param html - HTML content cần sanitize * @returns Strictly sanitized HTML * * @example * ```typescript * const safe = sanitizer.sanitizeStrict('

Text

Link'); * // Result: '

Text

Link' * ``` */ sanitizeStrict(html: string): string; /** * Sanitize HTML cho rich text editor (cho phép nhiều features) * * Mode này cho phép hầu hết HTML tags và styles cần thiết cho * rich text editors như Quill, TinyMCE, CKEditor, etc. * * @param html - HTML content từ rich text editor * @returns Sanitized HTML với rich formatting * * @example * ```typescript * const safe = sanitizer.sanitizeRichText(editorContent); * ``` */ sanitizeRichText(html: string): string; /** * Strip tất cả HTML tags, chỉ giữ lại plain text * * Method này loại bỏ hoàn toàn tất cả HTML tags và chỉ giữ lại text content. * Hữu ích khi cần hiển thị user input dưới dạng plain text. * * @param html - HTML content * @returns Plain text without any HTML tags * * @example * ```typescript * const text = sanitizer.stripHtml('

Hello World

'); * // Result: 'Hello World' * ``` */ stripHtml(html: string): string; /** * Kiểm tra xem HTML content có chứa XSS threats không * * Method này so sánh HTML gốc với HTML đã sanitize để detect * xem có bất kỳ malicious content nào bị loại bỏ không. * * @param html - HTML content cần kiểm tra * @returns true nếu có XSS threats được detect, false nếu clean * * @example * ```typescript * const hasXSS = sanitizer.hasXSSThreats(''); * // Result: true * * const hasXSS = sanitizer.hasXSSThreats('

Safe content

'); * // Result: false * ``` */ hasXSSThreats(html: string): boolean; /** * Build DOMPurify config từ SanitizerConfig */ private buildConfig; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; }