@deepmetier/xss 0.0.0-stage → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,219 @@
1
+ /**
2
+ * xss
3
+ *
4
+ * @author Zongmin Lei<leizongmin@gmail.com>
5
+ */
6
+
7
+ declare module "@deepmetier/xss" {
8
+ global {
9
+ function filterXSS(html: string, options?: IFilterXSSOptions): string;
10
+ function filterXSSWithResult(html: string, options?: IFilterXSSOptions): {
11
+ html: string;
12
+ removed: Array<
13
+ | { type: "tag"; tag: string; html: string; isClosing: boolean }
14
+ | { type: "attr"; tag: string; attr: string; value: string }
15
+ >;
16
+ };
17
+
18
+ namespace XSS {
19
+ export interface IFilterXSSOptions {
20
+ allowList?: IWhiteList;
21
+ whiteList?: IWhiteList;
22
+ onTag?: OnTagHandler;
23
+ onTagAttr?: OnTagAttrHandler;
24
+ onIgnoreTag?: OnTagHandler;
25
+ onIgnoreTagAttr?: OnTagAttrHandler;
26
+ safeAttrValue?: SafeAttrValueHandler;
27
+ escapeHtml?: EscapeHandler;
28
+ stripIgnoreTag?: boolean;
29
+ stripIgnoreTagBody?: boolean | string[];
30
+ allowCommentTag?: boolean;
31
+ stripBlankChar?: boolean;
32
+ singleQuotedAttributeValue?: boolean;
33
+ css?: {} | boolean;
34
+ }
35
+
36
+ interface IWhiteList extends Record<string, string[] | undefined> {
37
+ a?: string[];
38
+ abbr?: string[];
39
+ address?: string[];
40
+ area?: string[];
41
+ article?: string[];
42
+ aside?: string[];
43
+ audio?: string[];
44
+ b?: string[];
45
+ bdi?: string[];
46
+ bdo?: string[];
47
+ big?: string[];
48
+ blockquote?: string[];
49
+ br?: string[];
50
+ caption?: string[];
51
+ center?: string[];
52
+ cite?: string[];
53
+ code?: string[];
54
+ col?: string[];
55
+ colgroup?: string[];
56
+ dd?: string[];
57
+ del?: string[];
58
+ details?: string[];
59
+ div?: string[];
60
+ dl?: string[];
61
+ dt?: string[];
62
+ em?: string[];
63
+ figure?: string[];
64
+ figcaption?: string[];
65
+ font?: string[];
66
+ footer?: string[];
67
+ h1?: string[];
68
+ h2?: string[];
69
+ h3?: string[];
70
+ h4?: string[];
71
+ h5?: string[];
72
+ h6?: string[];
73
+ header?: string[];
74
+ hr?: string[];
75
+ i?: string[];
76
+ img?: string[];
77
+ ins?: string[];
78
+ li?: string[];
79
+ mark?: string[];
80
+ nav?: string[];
81
+ ol?: string[];
82
+ p?: string[];
83
+ pre?: string[];
84
+ s?: string[];
85
+ section?: string[];
86
+ small?: string[];
87
+ span?: string[];
88
+ sub?: string[];
89
+ sup?: string[];
90
+ strong?: string[];
91
+ strike?: string[];
92
+ summary?: string[];
93
+ table?: string[];
94
+ tbody?: string[];
95
+ td?: string[];
96
+ tfoot?: string[];
97
+ th?: string[];
98
+ thead?: string[];
99
+ tr?: string[];
100
+ tt?: string[];
101
+ u?: string[];
102
+ ul?: string[];
103
+ video?: string[];
104
+ }
105
+
106
+ type OnTagHandler = (
107
+ tag: string,
108
+ html: string,
109
+ options: {
110
+ sourcePosition?: number;
111
+ position?: number;
112
+ isClosing?: boolean;
113
+ isWhite?: boolean;
114
+ }
115
+ ) => string | void;
116
+
117
+ type OnTagAttrHandler = (
118
+ tag: string,
119
+ name: string,
120
+ value: string,
121
+ isWhiteAttr: boolean
122
+ ) => string | void;
123
+
124
+ type SafeAttrValueHandler = (
125
+ tag: string,
126
+ name: string,
127
+ value: string,
128
+ cssFilter: ICSSFilter
129
+ ) => string;
130
+
131
+ type EscapeHandler = (str: string) => string;
132
+
133
+ interface ICSSFilter {
134
+ process(value: string): string;
135
+ }
136
+ }
137
+ }
138
+ export interface IFilterXSSOptions extends XSS.IFilterXSSOptions {}
139
+
140
+ export interface IWhiteList extends XSS.IWhiteList {}
141
+
142
+ export type OnTagHandler = XSS.OnTagHandler;
143
+
144
+ export type OnTagAttrHandler = XSS.OnTagAttrHandler;
145
+
146
+ export type SafeAttrValueHandler = XSS.SafeAttrValueHandler;
147
+
148
+ export type EscapeHandler = XSS.EscapeHandler;
149
+
150
+ export interface ICSSFilter extends XSS.ICSSFilter {}
151
+
152
+ export function StripTagBody(
153
+ tags: string[],
154
+ next: () => void
155
+ ): {
156
+ onIgnoreTag(
157
+ tag: string,
158
+ html: string,
159
+ options: {
160
+ position: number;
161
+ isClosing: boolean;
162
+ }
163
+ ): string;
164
+ remove(html: string): string;
165
+ };
166
+
167
+ export class FilterXSS {
168
+ constructor(options?: IFilterXSSOptions);
169
+ process(html: string): string;
170
+ }
171
+
172
+ export function filterXSS(html: string, options?: IFilterXSSOptions): string;
173
+ export function filterXSSWithResult(html: string, options?: IFilterXSSOptions): {
174
+ html: string;
175
+ removed: Array<
176
+ | { type: "tag"; tag: string; html: string; isClosing: boolean }
177
+ | { type: "attr"; tag: string; attr: string; value: string }
178
+ >;
179
+ };
180
+ export function parseTag(
181
+ html: string,
182
+ onTag: (
183
+ sourcePosition: number,
184
+ position: number,
185
+ tag: string,
186
+ html: string,
187
+ isClosing: boolean
188
+ ) => string,
189
+ escapeHtml: EscapeHandler
190
+ ): string;
191
+ export function parseAttr(
192
+ html: string,
193
+ onAttr: (name: string, value: string) => string
194
+ ): string;
195
+ export const whiteList: IWhiteList;
196
+ export function getDefaultWhiteList(): IWhiteList;
197
+ export const onTag: OnTagHandler;
198
+ export const onIgnoreTag: OnTagHandler;
199
+ export const onTagAttr: OnTagAttrHandler;
200
+ export const onIgnoreTagAttr: OnTagAttrHandler;
201
+ export const safeAttrValue: SafeAttrValueHandler;
202
+ export const escapeHtml: EscapeHandler;
203
+ export const escapeQuote: EscapeHandler;
204
+ export const unescapeQuote: EscapeHandler;
205
+ export const escapeHtmlEntities: EscapeHandler;
206
+ export const escapeDangerHtml5Entities: EscapeHandler;
207
+ export const clearNonPrintableCharacter: EscapeHandler;
208
+ export const friendlyAttrValue: EscapeHandler;
209
+ export const escapeAttrValue: EscapeHandler;
210
+ export function onIgnoreTagStripAll(): string;
211
+ export const stripCommentTag: EscapeHandler;
212
+ export const stripBlankChar: EscapeHandler;
213
+ export const attributeWrapSign: string;
214
+ export const cssFilter: ICSSFilter;
215
+ export function getDefaultCSSWhiteList(): ICSSFilter;
216
+
217
+ const xss: (html: string, options?: IFilterXSSOptions) => string;
218
+ export default xss;
219
+ }