/** * The sanitization policy, shared by both sanitizer backends. * * There are two parsers — the DOM one in `sanitize-dom.ts` and the DOM-free * one in `sanitize-string.ts` — but there must only ever be one set of rules * about what is safe. Every predicate a backend needs lives here, so a policy * change cannot land in one backend and miss the other. * * @module bquery/security * @internal */ import type { SanitizeOptions } from './types.js'; /** The resolved allow lists for one `sanitizeHtml()` call. */ export interface SanitizePolicy { allowedTags: Set; allowedAttrs: Set; allowDataAttributes: boolean; stripAllTags: boolean; } /** * Resolve caller options into allow sets. Dangerous tags are filtered out even * when explicitly allowed, so `allowTags: ['script']` cannot open a hole. * @internal */ export declare const resolvePolicy: (options?: SanitizeOptions) => SanitizePolicy; /** Whether an element may appear in the output at all. @internal */ export declare const isAllowedTag: (tagName: string, policy: SanitizePolicy) => boolean; /** * Check if an attribute name is allowed. * @internal */ export declare const isAllowedAttribute: (name: string, allowedSet: Set, allowDataAttrs: boolean) => boolean; /** * An attribute name safe to serialize into a tag. Deliberately stricter than * what the HTML spec tolerates: anything outside this shape is dropped rather * than emitted, so the output cannot depend on a consumer's error recovery. * * Shared by every serializer — the string sanitizer backend and the SSR * renderer — because an emitter that trusts its parser to have rejected a * hostile name inherits that parser's blind spots. `src/ssr/html-parser.ts` * stops an attribute name at whitespace, `=`, `>` and `/`, but not at a quote, * so a name can carry one. Validating at the point of emission means no such * gap can reach output. * @internal */ export declare const VALID_ATTRIBUTE_NAME: RegExp; /** * Whether an attribute name is safe to serialize into a tag. * @internal */ export declare const isValidAttributeName: (name: string) => boolean; /** * A tag name safe to serialize. Covers HTML elements and custom elements, * and nothing that could close or open a tag on its own. * @internal */ export declare const VALID_TAG_NAME: RegExp; /** * Whether a tag name is safe to serialize. * @internal */ export declare const isValidTagName: (tag: string) => boolean; /** * Whether an element's text content is dropped during text extraction. * * `stripTags()` and `stripAllTags` answer "what does this markup say", and a * `` hands the caller * attacker-authored source under the name of prose, which then flows into a * log line, a search index or a ``. * * The rule lives here rather than in either backend because the two used to * disagree on it: the DOM one returned `textContent` (script source included) * and the DOM-free one suppressed the subtree, so `stripTags()` produced * different output on the server and in the browser for the same well-formed * input — under the default `'auto'` backend, in the same app. * @internal */ export declare const suppressesTextContent: (tagName: string) => boolean; /** * Escape HTML entities so text is inert when assigned to an HTML sink. * @internal */ export declare const escapeHtmlText: (text: string) => string; /** * Check if an ID/name value could cause DOM clobbering. * @internal */ export declare const isSafeIdOrName: (value: string) => boolean; /** * Check if a URL value is safe. * @internal */ export declare const isSafeUrl: (value: string) => boolean; /** * Check if a srcset attribute value is safe. * srcset contains comma-separated entries of "url [descriptor]". * Each individual URL must be validated. * @internal */ export declare const isSafeSrcset: (value: string) => boolean; /** Attributes whose value is a single URL. @internal */ export declare const URL_ATTRIBUTES: Set<string>; /** * Check if a URL is external (different origin). * @internal */ export declare const isExternalUrl: (url: string) => boolean; /** * The `rel` value an `<a>` should carry, or null to leave it alone. * * External links and `target="_blank"` links get `noopener noreferrer`, which * closes the reverse-tabnabbing hole. Existing `rel` tokens are preserved. * @internal */ export declare const relForAnchor: (href: string | null, target: string | null, existingRel: string | null) => string | null; /** * Decide whether one attribute survives, given the element's policy and the * ids already emitted in this fragment. * * Duplicate ids are dropped because two elements sharing an id turn * `document.getElementById`/named access into a clobberable HTMLCollection * (the classic `<a id=x><a id=x name=y>` vector). The first occurrence wins. * @internal */ export declare const isAttributeAllowed: (name: string, value: string, policy: SanitizePolicy, seenIds: Set<string>) => boolean; //# sourceMappingURL=sanitize-policy.d.ts.map