Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/dompurify/dompurify.d.ts
3294 views
1
// Type definitions for DOM Purify 3.0
2
// Project: https://github.com/cure53/DOMPurify
3
// Definitions by: Dave Taylor https://github.com/davetayls
4
// Samira Bazuzi <https://github.com/bazuzi>
5
// FlowCrypt <https://github.com/FlowCrypt>
6
// Exigerr <https://github.com/Exigerr>
7
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
8
// Nicholas Ellul <https://github.com/NicholasEllul>
9
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
// Minimum TypeScript Version: 4.5
11
12
export default DOMPurify;
13
14
declare const DOMPurify: createDOMPurifyI;
15
16
type WindowLike = Pick<
17
typeof globalThis,
18
| 'NodeFilter'
19
| 'Node'
20
| 'Element'
21
| 'HTMLTemplateElement'
22
| 'DocumentFragment'
23
| 'HTMLFormElement'
24
| 'DOMParser'
25
| 'NamedNodeMap'
26
>;
27
28
interface createDOMPurifyI extends DOMPurify.DOMPurifyI {
29
(window?: Window | WindowLike): DOMPurify.DOMPurifyI;
30
}
31
32
declare namespace DOMPurify {
33
interface DOMPurifyI {
34
sanitize(source: string | Node): string;
35
sanitize(source: string | Node, config: Config & { RETURN_TRUSTED_TYPE: true }): TrustedHTML;
36
sanitize(
37
source: string | Node,
38
config: Config & { RETURN_DOM_FRAGMENT?: false | undefined; RETURN_DOM?: false | undefined },
39
): string;
40
sanitize(source: string | Node, config: Config & { RETURN_DOM_FRAGMENT: true }): DocumentFragment;
41
sanitize(source: string | Node, config: Config & { RETURN_DOM: true }): HTMLElement;
42
sanitize(source: string | Node, config: Config): string | HTMLElement | DocumentFragment;
43
44
addHook(
45
hook: 'uponSanitizeElement',
46
cb: (currentNode: Element, data: SanitizeElementHookEvent, config: Config) => void,
47
): void;
48
addHook(
49
hook: 'uponSanitizeAttribute',
50
cb: (currentNode: Element, data: SanitizeAttributeHookEvent, config: Config) => void,
51
): void;
52
addHook(hook: HookName, cb: (currentNode: Element, data: HookEvent, config: Config) => void): void;
53
54
setConfig(cfg: Config): void;
55
clearConfig(): void;
56
isValidAttribute(tag: string, attr: string, value: string): boolean;
57
58
removeHook(entryPoint: HookName): void;
59
removeHooks(entryPoint: HookName): void;
60
removeAllHooks(): void;
61
62
version: string;
63
removed: any[];
64
isSupported: boolean;
65
}
66
67
interface Config {
68
ADD_ATTR?: string[] | undefined;
69
ADD_DATA_URI_TAGS?: string[] | undefined;
70
ADD_TAGS?: string[] | undefined;
71
ADD_URI_SAFE_ATTR?: string[] | undefined;
72
ALLOW_ARIA_ATTR?: boolean | undefined;
73
ALLOW_DATA_ATTR?: boolean | undefined;
74
ALLOW_UNKNOWN_PROTOCOLS?: boolean | undefined;
75
ALLOW_SELF_CLOSE_IN_ATTR?: boolean | undefined;
76
ALLOWED_ATTR?: string[] | undefined;
77
ALLOWED_TAGS?: string[] | undefined;
78
ALLOWED_NAMESPACES?: string[] | undefined;
79
ALLOWED_URI_REGEXP?: RegExp | undefined;
80
FORBID_ATTR?: string[] | undefined;
81
FORBID_CONTENTS?: string[] | undefined;
82
FORBID_TAGS?: string[] | undefined;
83
FORCE_BODY?: boolean | undefined;
84
IN_PLACE?: boolean | undefined;
85
KEEP_CONTENT?: boolean | undefined;
86
/**
87
* change the default namespace from HTML to something different
88
*/
89
NAMESPACE?: string | undefined;
90
PARSER_MEDIA_TYPE?: string | undefined;
91
RETURN_DOM_FRAGMENT?: boolean | undefined;
92
/**
93
* This defaults to `true` starting DOMPurify 2.2.0. Note that setting it to `false`
94
* might cause XSS from attacks hidden in closed shadowroots in case the browser
95
* supports Declarative Shadow: DOM https://web.dev/declarative-shadow-dom/
96
*/
97
RETURN_DOM_IMPORT?: boolean | undefined;
98
RETURN_DOM?: boolean | undefined;
99
RETURN_TRUSTED_TYPE?: boolean | undefined;
100
SAFE_FOR_TEMPLATES?: boolean | undefined;
101
SANITIZE_DOM?: boolean | undefined;
102
/** @default false */
103
SANITIZE_NAMED_PROPS?: boolean | undefined;
104
USE_PROFILES?:
105
| false
106
| {
107
mathMl?: boolean | undefined;
108
svg?: boolean | undefined;
109
svgFilters?: boolean | undefined;
110
html?: boolean | undefined;
111
}
112
| undefined;
113
WHOLE_DOCUMENT?: boolean | undefined;
114
CUSTOM_ELEMENT_HANDLING?: {
115
tagNameCheck?: RegExp | ((tagName: string) => boolean) | null | undefined;
116
attributeNameCheck?: RegExp | ((lcName: string) => boolean) | null | undefined;
117
allowCustomizedBuiltInElements?: boolean | undefined;
118
};
119
}
120
121
type HookName =
122
| 'beforeSanitizeElements'
123
| 'uponSanitizeElement'
124
| 'afterSanitizeElements'
125
| 'beforeSanitizeAttributes'
126
| 'uponSanitizeAttribute'
127
| 'afterSanitizeAttributes'
128
| 'beforeSanitizeShadowDOM'
129
| 'uponSanitizeShadowNode'
130
| 'afterSanitizeShadowDOM';
131
132
type HookEvent = SanitizeElementHookEvent | SanitizeAttributeHookEvent | null;
133
134
interface SanitizeElementHookEvent {
135
tagName: string;
136
allowedTags: { [key: string]: boolean };
137
}
138
139
interface SanitizeAttributeHookEvent {
140
attrName: string;
141
attrValue: string;
142
keepAttr: boolean;
143
allowedAttributes: { [key: string]: boolean };
144
forceKeepAttr?: boolean | undefined;
145
}
146
}
147
148