|
1 | | -/// <reference types="trusted-types" /> |
2 | | -/*! @license DOMPurify 3.2.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.2/LICENSE */ |
| 1 | +/*! @license DOMPurify 3.3.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.0/LICENSE */ |
| 2 | + |
| 3 | +import { TrustedTypePolicy, TrustedHTML, TrustedTypesWindow } from 'trusted-types/lib'; |
3 | 4 |
|
4 | 5 | /** |
5 | 6 | * Configuration to control DOMPurify behavior. |
6 | 7 | */ |
7 | 8 | interface Config { |
8 | 9 | /** |
9 | 10 | * Extend the existing array of allowed attributes. |
| 11 | + * Can be an array of attribute names, or a function that receives |
| 12 | + * the attribute name and tag name to determine if the attribute is allowed. |
10 | 13 | */ |
11 | | - ADD_ATTR?: string[] | undefined; |
| 14 | + ADD_ATTR?: string[] | ((attributeName: string, tagName: string) => boolean) | undefined; |
12 | 15 | /** |
13 | 16 | * Extend the existing array of elements that can use Data URIs. |
14 | 17 | */ |
15 | 18 | ADD_DATA_URI_TAGS?: string[] | undefined; |
16 | 19 | /** |
17 | 20 | * Extend the existing array of allowed tags. |
| 21 | + * Can be an array of tag names, or a function that receives |
| 22 | + * the tag name to determine if the tag is allowed. |
18 | 23 | */ |
19 | | - ADD_TAGS?: string[] | undefined; |
| 24 | + ADD_TAGS?: string[] | ((tagName: string) => boolean) | undefined; |
20 | 25 | /** |
21 | 26 | * Extend the existing array of elements that are safe for URI-like values (be careful, XSS risk). |
22 | 27 | */ |
@@ -75,7 +80,7 @@ interface Config { |
75 | 80 | * Regular expression or function to match to allowed attributes. |
76 | 81 | * Default is null (disallow any attributes not on the allow list). |
77 | 82 | */ |
78 | | - attributeNameCheck?: RegExp | ((attributeName: string) => boolean) | null | undefined; |
| 83 | + attributeNameCheck?: RegExp | ((attributeName: string, tagName?: string) => boolean) | null | undefined; |
79 | 84 | /** |
80 | 85 | * Allow custom elements derived from built-ins if they pass `tagNameCheck`. Default is false. |
81 | 86 | */ |
@@ -329,44 +334,49 @@ interface DOMPurify { |
329 | 334 | addHook(entryPoint: 'uponSanitizeAttribute', hookFunction: UponSanitizeAttributeHook): void; |
330 | 335 | /** |
331 | 336 | * Remove a DOMPurify hook at a given entryPoint |
332 | | - * (pops it from the stack of hooks if more are present) |
| 337 | + * (pops it from the stack of hooks if hook not specified) |
333 | 338 | * |
334 | 339 | * @param entryPoint entry point for the hook to remove |
335 | | - * @returns removed(popped) hook |
| 340 | + * @param hookFunction optional specific hook to remove |
| 341 | + * @returns removed hook |
336 | 342 | */ |
337 | | - removeHook(entryPoint: BasicHookName): NodeHook | undefined; |
| 343 | + removeHook(entryPoint: BasicHookName, hookFunction?: NodeHook): NodeHook | undefined; |
338 | 344 | /** |
339 | 345 | * Remove a DOMPurify hook at a given entryPoint |
340 | | - * (pops it from the stack of hooks if more are present) |
| 346 | + * (pops it from the stack of hooks if hook not specified) |
341 | 347 | * |
342 | 348 | * @param entryPoint entry point for the hook to remove |
343 | | - * @returns removed(popped) hook |
| 349 | + * @param hookFunction optional specific hook to remove |
| 350 | + * @returns removed hook |
344 | 351 | */ |
345 | | - removeHook(entryPoint: ElementHookName): ElementHook | undefined; |
| 352 | + removeHook(entryPoint: ElementHookName, hookFunction?: ElementHook): ElementHook | undefined; |
346 | 353 | /** |
347 | 354 | * Remove a DOMPurify hook at a given entryPoint |
348 | | - * (pops it from the stack of hooks if more are present) |
| 355 | + * (pops it from the stack of hooks if hook not specified) |
349 | 356 | * |
350 | 357 | * @param entryPoint entry point for the hook to remove |
351 | | - * @returns removed(popped) hook |
| 358 | + * @param hookFunction optional specific hook to remove |
| 359 | + * @returns removed hook |
352 | 360 | */ |
353 | | - removeHook(entryPoint: DocumentFragmentHookName): DocumentFragmentHook | undefined; |
| 361 | + removeHook(entryPoint: DocumentFragmentHookName, hookFunction?: DocumentFragmentHook): DocumentFragmentHook | undefined; |
354 | 362 | /** |
355 | 363 | * Remove a DOMPurify hook at a given entryPoint |
356 | | - * (pops it from the stack of hooks if more are present) |
| 364 | + * (pops it from the stack of hooks if hook not specified) |
357 | 365 | * |
358 | 366 | * @param entryPoint entry point for the hook to remove |
359 | | - * @returns removed(popped) hook |
| 367 | + * @param hookFunction optional specific hook to remove |
| 368 | + * @returns removed hook |
360 | 369 | */ |
361 | | - removeHook(entryPoint: 'uponSanitizeElement'): UponSanitizeElementHook | undefined; |
| 370 | + removeHook(entryPoint: 'uponSanitizeElement', hookFunction?: UponSanitizeElementHook): UponSanitizeElementHook | undefined; |
362 | 371 | /** |
363 | 372 | * Remove a DOMPurify hook at a given entryPoint |
364 | | - * (pops it from the stack of hooks if more are present) |
| 373 | + * (pops it from the stack of hooks if hook not specified) |
365 | 374 | * |
366 | 375 | * @param entryPoint entry point for the hook to remove |
367 | | - * @returns removed(popped) hook |
| 376 | + * @param hookFunction optional specific hook to remove |
| 377 | + * @returns removed hook |
368 | 378 | */ |
369 | | - removeHook(entryPoint: 'uponSanitizeAttribute'): UponSanitizeAttributeHook | undefined; |
| 379 | + removeHook(entryPoint: 'uponSanitizeAttribute', hookFunction?: UponSanitizeAttributeHook): UponSanitizeAttributeHook | undefined; |
370 | 380 | /** |
371 | 381 | * Removes all DOMPurify hooks at a given entryPoint |
372 | 382 | * |
@@ -428,8 +438,7 @@ interface UponSanitizeAttributeHookEvent { |
428 | 438 | type WindowLike = Pick<typeof globalThis, 'DocumentFragment' | 'HTMLTemplateElement' | 'Node' | 'Element' | 'NodeFilter' | 'NamedNodeMap' | 'HTMLFormElement' | 'DOMParser'> & { |
429 | 439 | document?: Document; |
430 | 440 | MozNamedAttrMap?: typeof window.NamedNodeMap; |
431 | | - trustedTypes?: typeof window.trustedTypes; |
432 | | -}; |
| 441 | +} & Pick<TrustedTypesWindow, 'trustedTypes'>; |
433 | 442 |
|
434 | 443 | export { type Config, type DOMPurify, type DocumentFragmentHook, type ElementHook, type HookName, type NodeHook, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike }; |
435 | 444 |
|
|
0 commit comments