import { type DOMPurify } from "dompurify"; export type SanitizerLike = Pick; /*********************************************** * ALLOWED_TAGS * * Base allowlist of HTML tag names for DOMPurify. * * Intent: * - Represent a broad but finite subset of “safe-ish” * HTML5 elements that are expected in typical UI * markup (text, lists, tables, basic form controls). * - Anything not in this list must be explicitly added * via `ADD_TAGS` in `sanitize_external`, or it will * be stripped by DOMPurify. * * Notes: * - All entries are lowercase to match DOMPurify’s * internal normalization. * - High-risk or complex tags (e.g. , media, * scripting, embedding) are excluded and handled * separately via `FORBID_TAGS_HARD`. ***********************************************/ export declare const ALLOWED_TAGS: string[]; /*********************************************** * ALLOWED_ATTR * * Base allowlist of HTML attributes for DOMPurify. * * Coverage: * - Core identity / semantics: * id, class, title, role, data-* * - Accessibility: * aria-label, aria-hidden, aria-expanded, * aria-controls * - Links and images: * href, src, srcset, sizes, alt, target, rel * - Performance hints: * loading, decoding * * Behavior: * - Attributes not in this list are removed unless * DOMPurify is configured to allow them via * additional options. * - `data-*` is handled via `ALLOW_DATA_ATTR: true` * in the sanitizer options, not by literal listing * of every possible data-foo. ***********************************************/ export declare const ALLOWED_ATTR: string[]; /*********************************************** * FORBID_TAGS_HARD * * Set of tag names that are *always* rejected by the * sanitizer, even if: * - they appear in the HTML, * - they are added to `ADD_TAGS`, or * - they slip into default DOMPurify allowlists. * * Includes: * - Active / executable content: * script, style * - Embedding / navigation primitives: * iframe, object, embed, link, meta, base, form * - Complex rendering surfaces: * svg, math, video, audio * * Rationale: * - These tags either: * - can execute code, * - change document-level behavior (base/meta), * - or open a large security / complexity surface * (SVG, MathML, media). * - If you ever need a *safe subset* of these (e.g. * SVG icons), introduce a dedicated, tightly * constrained pipeline instead of weakening this set. ***********************************************/ export declare const FORBID_TAGS_HARD: Set; /*********************************************** * ALLOWED_URI_REGEX * * URI scheme allowlist used for URL-bearing attributes * (href, src, srcset, etc.). * * Allowed schemes: * - http: * - https: * - mailto: * - tel: * - data:image/ (images only, not arbitrary data:) * * Security: * - Rejects javascript:, vbscript:, and other * scriptable / dangerous schemes by default. * - Used both: * - directly in `set_attrs_safe`, and * - indirectly via DOMPurify’s ALLOWED_URI_REGEXP. ***********************************************/ export declare const ALLOWED_URI_REGEX: RegExp; /*********************************************** * sanitize_external * * One-shot sanitization for *external / untrusted* HTML * using DOMPurify, augmented with: * - discovery-driven tag allowlists, * - hard tag forbids, * - strict attribute and URL enforcement, * - and minimal attribute hygiene for links. * * Tag policy: * - Base allowlist: `ALLOWED_TAGS`. * - Per-call additions: `ADD_TAGS = buildAddTags(html)`, * derived from the actual tag usage in the HTML. * - Hard blocklist: `FORBID_TAGS_HARD`, which overrides * any other allow lists and is always enforced. * * Attribute policy: * - `ALLOWED_ATTR` defines the base attribute allowlist. * - Syntactic `hson:*` candidates found in the source are added only so the * canonical metadata registry can validate them after sanitization. * - `FORBID_ATTR: ["style", "srcdoc"]` forbids inline * styles and srcdoc frames outright. * - `ALLOW_DATA_ATTR: true` allows all `data-*` attributes. * - A DOMPurify `uponSanitizeAttribute` hook: * - Drops `style` and `srcdoc` even if seen. * - Validates URL-bearing attributes (`href`, `src`, * `xlink:href`, `poster`) against `ALLOWED_URI_REGEX`. * - For `srcset`, rejects the whole attribute if *any* * candidate URL is unsafe. * - Enforces `rel="noopener noreferrer"` on links with * `target="_blank"` for tab-hijack protection. * * Behavior: * - Returns a new HTML string that has been: * - parsed by DOMPurify, * - stripped of disallowed tags/attributes/URLs, * - normalized according to the above policies. * * Notes: * - Hard-forbidden elements (e.g. `