purifai 2.0.2 → 3.0.0
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.
- package/README.md +204 -368
- package/benchmark/results/v3.json +2767 -0
- package/dist/index.cjs +14 -406
- package/dist/index.d.cts +2 -191
- package/dist/index.d.ts +2 -191
- package/dist/index.js +14 -374
- package/dist/src/api.d.ts +7 -0
- package/dist/src/config.d.ts +18 -0
- package/dist/src/contracts.d.ts +40 -0
- package/dist/src/entities.d.ts +15 -0
- package/dist/src/formatter.d.ts +36 -0
- package/dist/src/generated/entities.d.ts +3 -0
- package/dist/src/policy.d.ts +15 -0
- package/dist/src/scanner.d.ts +71 -0
- package/dist/src/session.d.ts +27 -0
- package/docs/benchmarks/v3.md +92 -0
- package/docs/migration-v3.md +95 -0
- package/package.json +42 -38
package/dist/index.d.cts
CHANGED
|
@@ -1,191 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Advanced XSS protection with polyglot attack resistance.
|
|
5
|
-
* Blocks sophisticated obfuscation techniques that bypass other sanitizers.
|
|
6
|
-
*
|
|
7
|
-
* @version 2.0.2
|
|
8
|
-
* @license MIT
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Purifai Configuration Options
|
|
12
|
-
*/
|
|
13
|
-
export interface PurifaiOptions {
|
|
14
|
-
/** Maximum input length (default: 1MB) */
|
|
15
|
-
maxLength?: number;
|
|
16
|
-
/** Custom allowed protocols (default: ['http', 'https', 'mailto']) */
|
|
17
|
-
allowedProtocols?: string[];
|
|
18
|
-
/** Enable aggressive mode for maximum security (default: true) */
|
|
19
|
-
aggressiveMode?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Purifai Sanitization Result
|
|
23
|
-
*/
|
|
24
|
-
export interface PurifaiResult {
|
|
25
|
-
/** Sanitized content */
|
|
26
|
-
content: string;
|
|
27
|
-
/** Whether dangerous content was detected */
|
|
28
|
-
hadThreats: boolean;
|
|
29
|
-
/** Processing time in milliseconds */
|
|
30
|
-
processingTime: number;
|
|
31
|
-
/** Threat level: 'none' | 'low' | 'medium' | 'high' | 'critical' */
|
|
32
|
-
threatLevel: 'none' | 'low' | 'medium' | 'high' | 'critical';
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Check if input contains dangerous patterns
|
|
36
|
-
*/
|
|
37
|
-
declare function isDangerous(input: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Sanitize input with maximum security protection
|
|
40
|
-
*/
|
|
41
|
-
declare function sanitize(input: unknown, options?: PurifaiOptions): string;
|
|
42
|
-
/**
|
|
43
|
-
* Sanitize input and return detailed analysis
|
|
44
|
-
*/
|
|
45
|
-
declare function analyze(input: unknown, options?: PurifaiOptions): PurifaiResult;
|
|
46
|
-
/**
|
|
47
|
-
* Batch sanitize multiple inputs for optimal performance
|
|
48
|
-
*/
|
|
49
|
-
declare function sanitizeBatch(inputs: unknown[], options?: PurifaiOptions): string[];
|
|
50
|
-
/**
|
|
51
|
-
* Escape text for insertion into an HTML body context.
|
|
52
|
-
*
|
|
53
|
-
* Lossless and total: nothing is removed, so this is the correct choice when
|
|
54
|
-
* the input is plain text rather than markup. `sanitize()` cannot tell the two
|
|
55
|
-
* apart — `a<b && c>d` is a valid HTML start tag by the parsing spec, so
|
|
56
|
-
* `sanitize()` drops it while `escape()` preserves it verbatim.
|
|
57
|
-
*/
|
|
58
|
-
declare function escape(input: unknown): string;
|
|
59
|
-
/**
|
|
60
|
-
* Escape text for insertion into an HTML attribute value.
|
|
61
|
-
*
|
|
62
|
-
* Stricter than `escape()`: every character outside `[a-zA-Z0-9]` is
|
|
63
|
-
* hex-encoded, which stays safe even in an unquoted attribute — the case that
|
|
64
|
-
* breaks naive escaping, since a bare space or backtick can end the value and
|
|
65
|
-
* start a new attribute such as `onerror=`.
|
|
66
|
-
*/
|
|
67
|
-
declare function escapeAttribute(input: unknown): string;
|
|
68
|
-
/**
|
|
69
|
-
* Escape and validate a value used as a URL.
|
|
70
|
-
*
|
|
71
|
-
* Returns '' when the protocol is not in `allowedProtocols`, which is what
|
|
72
|
-
* stops `javascript:`, `data:` and friends from reaching an `href`. Relative
|
|
73
|
-
* URLs are allowed through, since they cannot carry a protocol.
|
|
74
|
-
*/
|
|
75
|
-
declare function escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
76
|
-
/**
|
|
77
|
-
* 🛡️ Purifai - Ultra-Secure HTML Sanitizer
|
|
78
|
-
*
|
|
79
|
-
* Advanced lightweight HTML sanitizer with superior XSS protection
|
|
80
|
-
* against known attack vectors including advanced polyglot attacks.
|
|
81
|
-
*
|
|
82
|
-
* Every method delegates to a module-level function and reads no instance or
|
|
83
|
-
* class state, so `Purifai.sanitize` and the standalone `sanitize` export are
|
|
84
|
-
* interchangeable and neither depends on its call-site receiver.
|
|
85
|
-
*/
|
|
86
|
-
export declare class Purifai {
|
|
87
|
-
/**
|
|
88
|
-
* Sanitize input with maximum security protection
|
|
89
|
-
*
|
|
90
|
-
* @param input - Content to sanitize (string, object, or any type)
|
|
91
|
-
* @param options - Optional configuration
|
|
92
|
-
* @returns Sanitized string safe for HTML output
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* import { Purifai } from 'purifai';
|
|
97
|
-
*
|
|
98
|
-
* const clean = Purifai.sanitize('<script>alert("xss")</script>Hello World');
|
|
99
|
-
* console.log(clean); // "Hello World"
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
static sanitize(input: unknown, options?: PurifaiOptions): string;
|
|
103
|
-
/**
|
|
104
|
-
* Sanitize input and return detailed analysis
|
|
105
|
-
*
|
|
106
|
-
* @param input - Content to sanitize
|
|
107
|
-
* @param options - Optional configuration
|
|
108
|
-
* @returns Detailed sanitization result with threat analysis
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* const result = Purifai.analyze('<script>alert("xss")</script>Hello');
|
|
113
|
-
* console.log(result.content); // "Hello"
|
|
114
|
-
* console.log(result.hadThreats); // true
|
|
115
|
-
* console.log(result.threatLevel); // "critical"
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
static analyze(input: unknown, options?: PurifaiOptions): PurifaiResult;
|
|
119
|
-
/**
|
|
120
|
-
* Check if input contains dangerous patterns
|
|
121
|
-
*
|
|
122
|
-
* @param input - Content to check
|
|
123
|
-
* @returns true if dangerous content detected
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const isDangerous = Purifai.isDangerous('<script>alert("xss")</script>');
|
|
128
|
-
* console.log(isDangerous); // true
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
static isDangerous(input: string): boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Batch sanitize multiple inputs for optimal performance
|
|
134
|
-
*
|
|
135
|
-
* @param inputs - Array of inputs to sanitize
|
|
136
|
-
* @param options - Optional configuration
|
|
137
|
-
* @returns Array of sanitized strings
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* const cleaned = Purifai.sanitizeBatch([
|
|
142
|
-
* '<script>alert("xss")</script>Hello',
|
|
143
|
-
* '<img src=x onerror=alert(1)>World'
|
|
144
|
-
* ]);
|
|
145
|
-
* console.log(cleaned); // ["Hello", "World"]
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
static sanitizeBatch(inputs: unknown[], options?: PurifaiOptions): string[];
|
|
149
|
-
/**
|
|
150
|
-
* Escape text for an HTML body context (lossless — nothing is removed)
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* Purifai.escape('if (a<b && c>d)'); // "if (a<b && c>d)"
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
static escape(input: unknown): string;
|
|
158
|
-
/**
|
|
159
|
-
* Escape text for an HTML attribute value, safe even when unquoted
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* `<div title="${Purifai.escapeAttribute(userInput)}">`
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
static escapeAttribute(input: unknown): string;
|
|
167
|
-
/**
|
|
168
|
-
* Escape a URL, returning '' if its protocol is not allowed
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* Purifai.escapeUrl('javascript:alert(1)'); // ""
|
|
173
|
-
* Purifai.escapeUrl('https://example.com'); // escaped, safe for href
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
static escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
177
|
-
/**
|
|
178
|
-
* Get version information
|
|
179
|
-
*/
|
|
180
|
-
static getVersion(): string;
|
|
181
|
-
/**
|
|
182
|
-
* Get performance and security statistics
|
|
183
|
-
*/
|
|
184
|
-
static getStats(): {
|
|
185
|
-
version: string;
|
|
186
|
-
securityLevel: string;
|
|
187
|
-
performance: string;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
export { sanitize, analyze, isDangerous, sanitizeBatch, escape, escapeAttribute, escapeUrl };
|
|
191
|
-
export default Purifai;
|
|
1
|
+
export { PurifaiLimitError, convert, createTextTransform, escapeHtmlText, toText, } from './src/api.js';
|
|
2
|
+
export type { ConversionLimits, ConversionReport, ConversionResult, ConvertOptions, ImageMode, LayoutMode, LimitKind, LinkMode, OverflowMode, PurifaiTextTransform, ToTextOptions, } from './src/api.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,191 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Advanced XSS protection with polyglot attack resistance.
|
|
5
|
-
* Blocks sophisticated obfuscation techniques that bypass other sanitizers.
|
|
6
|
-
*
|
|
7
|
-
* @version 2.0.2
|
|
8
|
-
* @license MIT
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Purifai Configuration Options
|
|
12
|
-
*/
|
|
13
|
-
export interface PurifaiOptions {
|
|
14
|
-
/** Maximum input length (default: 1MB) */
|
|
15
|
-
maxLength?: number;
|
|
16
|
-
/** Custom allowed protocols (default: ['http', 'https', 'mailto']) */
|
|
17
|
-
allowedProtocols?: string[];
|
|
18
|
-
/** Enable aggressive mode for maximum security (default: true) */
|
|
19
|
-
aggressiveMode?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Purifai Sanitization Result
|
|
23
|
-
*/
|
|
24
|
-
export interface PurifaiResult {
|
|
25
|
-
/** Sanitized content */
|
|
26
|
-
content: string;
|
|
27
|
-
/** Whether dangerous content was detected */
|
|
28
|
-
hadThreats: boolean;
|
|
29
|
-
/** Processing time in milliseconds */
|
|
30
|
-
processingTime: number;
|
|
31
|
-
/** Threat level: 'none' | 'low' | 'medium' | 'high' | 'critical' */
|
|
32
|
-
threatLevel: 'none' | 'low' | 'medium' | 'high' | 'critical';
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Check if input contains dangerous patterns
|
|
36
|
-
*/
|
|
37
|
-
declare function isDangerous(input: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Sanitize input with maximum security protection
|
|
40
|
-
*/
|
|
41
|
-
declare function sanitize(input: unknown, options?: PurifaiOptions): string;
|
|
42
|
-
/**
|
|
43
|
-
* Sanitize input and return detailed analysis
|
|
44
|
-
*/
|
|
45
|
-
declare function analyze(input: unknown, options?: PurifaiOptions): PurifaiResult;
|
|
46
|
-
/**
|
|
47
|
-
* Batch sanitize multiple inputs for optimal performance
|
|
48
|
-
*/
|
|
49
|
-
declare function sanitizeBatch(inputs: unknown[], options?: PurifaiOptions): string[];
|
|
50
|
-
/**
|
|
51
|
-
* Escape text for insertion into an HTML body context.
|
|
52
|
-
*
|
|
53
|
-
* Lossless and total: nothing is removed, so this is the correct choice when
|
|
54
|
-
* the input is plain text rather than markup. `sanitize()` cannot tell the two
|
|
55
|
-
* apart — `a<b && c>d` is a valid HTML start tag by the parsing spec, so
|
|
56
|
-
* `sanitize()` drops it while `escape()` preserves it verbatim.
|
|
57
|
-
*/
|
|
58
|
-
declare function escape(input: unknown): string;
|
|
59
|
-
/**
|
|
60
|
-
* Escape text for insertion into an HTML attribute value.
|
|
61
|
-
*
|
|
62
|
-
* Stricter than `escape()`: every character outside `[a-zA-Z0-9]` is
|
|
63
|
-
* hex-encoded, which stays safe even in an unquoted attribute — the case that
|
|
64
|
-
* breaks naive escaping, since a bare space or backtick can end the value and
|
|
65
|
-
* start a new attribute such as `onerror=`.
|
|
66
|
-
*/
|
|
67
|
-
declare function escapeAttribute(input: unknown): string;
|
|
68
|
-
/**
|
|
69
|
-
* Escape and validate a value used as a URL.
|
|
70
|
-
*
|
|
71
|
-
* Returns '' when the protocol is not in `allowedProtocols`, which is what
|
|
72
|
-
* stops `javascript:`, `data:` and friends from reaching an `href`. Relative
|
|
73
|
-
* URLs are allowed through, since they cannot carry a protocol.
|
|
74
|
-
*/
|
|
75
|
-
declare function escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
76
|
-
/**
|
|
77
|
-
* 🛡️ Purifai - Ultra-Secure HTML Sanitizer
|
|
78
|
-
*
|
|
79
|
-
* Advanced lightweight HTML sanitizer with superior XSS protection
|
|
80
|
-
* against known attack vectors including advanced polyglot attacks.
|
|
81
|
-
*
|
|
82
|
-
* Every method delegates to a module-level function and reads no instance or
|
|
83
|
-
* class state, so `Purifai.sanitize` and the standalone `sanitize` export are
|
|
84
|
-
* interchangeable and neither depends on its call-site receiver.
|
|
85
|
-
*/
|
|
86
|
-
export declare class Purifai {
|
|
87
|
-
/**
|
|
88
|
-
* Sanitize input with maximum security protection
|
|
89
|
-
*
|
|
90
|
-
* @param input - Content to sanitize (string, object, or any type)
|
|
91
|
-
* @param options - Optional configuration
|
|
92
|
-
* @returns Sanitized string safe for HTML output
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* import { Purifai } from 'purifai';
|
|
97
|
-
*
|
|
98
|
-
* const clean = Purifai.sanitize('<script>alert("xss")</script>Hello World');
|
|
99
|
-
* console.log(clean); // "Hello World"
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
static sanitize(input: unknown, options?: PurifaiOptions): string;
|
|
103
|
-
/**
|
|
104
|
-
* Sanitize input and return detailed analysis
|
|
105
|
-
*
|
|
106
|
-
* @param input - Content to sanitize
|
|
107
|
-
* @param options - Optional configuration
|
|
108
|
-
* @returns Detailed sanitization result with threat analysis
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* const result = Purifai.analyze('<script>alert("xss")</script>Hello');
|
|
113
|
-
* console.log(result.content); // "Hello"
|
|
114
|
-
* console.log(result.hadThreats); // true
|
|
115
|
-
* console.log(result.threatLevel); // "critical"
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
static analyze(input: unknown, options?: PurifaiOptions): PurifaiResult;
|
|
119
|
-
/**
|
|
120
|
-
* Check if input contains dangerous patterns
|
|
121
|
-
*
|
|
122
|
-
* @param input - Content to check
|
|
123
|
-
* @returns true if dangerous content detected
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const isDangerous = Purifai.isDangerous('<script>alert("xss")</script>');
|
|
128
|
-
* console.log(isDangerous); // true
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
static isDangerous(input: string): boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Batch sanitize multiple inputs for optimal performance
|
|
134
|
-
*
|
|
135
|
-
* @param inputs - Array of inputs to sanitize
|
|
136
|
-
* @param options - Optional configuration
|
|
137
|
-
* @returns Array of sanitized strings
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* const cleaned = Purifai.sanitizeBatch([
|
|
142
|
-
* '<script>alert("xss")</script>Hello',
|
|
143
|
-
* '<img src=x onerror=alert(1)>World'
|
|
144
|
-
* ]);
|
|
145
|
-
* console.log(cleaned); // ["Hello", "World"]
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
static sanitizeBatch(inputs: unknown[], options?: PurifaiOptions): string[];
|
|
149
|
-
/**
|
|
150
|
-
* Escape text for an HTML body context (lossless — nothing is removed)
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* Purifai.escape('if (a<b && c>d)'); // "if (a<b && c>d)"
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
static escape(input: unknown): string;
|
|
158
|
-
/**
|
|
159
|
-
* Escape text for an HTML attribute value, safe even when unquoted
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* `<div title="${Purifai.escapeAttribute(userInput)}">`
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
static escapeAttribute(input: unknown): string;
|
|
167
|
-
/**
|
|
168
|
-
* Escape a URL, returning '' if its protocol is not allowed
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* Purifai.escapeUrl('javascript:alert(1)'); // ""
|
|
173
|
-
* Purifai.escapeUrl('https://example.com'); // escaped, safe for href
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
static escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
177
|
-
/**
|
|
178
|
-
* Get version information
|
|
179
|
-
*/
|
|
180
|
-
static getVersion(): string;
|
|
181
|
-
/**
|
|
182
|
-
* Get performance and security statistics
|
|
183
|
-
*/
|
|
184
|
-
static getStats(): {
|
|
185
|
-
version: string;
|
|
186
|
-
securityLevel: string;
|
|
187
|
-
performance: string;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
export { sanitize, analyze, isDangerous, sanitizeBatch, escape, escapeAttribute, escapeUrl };
|
|
191
|
-
export default Purifai;
|
|
1
|
+
export { PurifaiLimitError, convert, createTextTransform, escapeHtmlText, toText, } from './src/api.js';
|
|
2
|
+
export type { ConversionLimits, ConversionReport, ConversionResult, ConvertOptions, ImageMode, LayoutMode, LimitKind, LinkMode, OverflowMode, PurifaiTextTransform, ToTextOptions, } from './src/api.js';
|