purifai 2.0.3 → 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 -383
- package/benchmark/results/v3.json +2767 -0
- package/dist/index.cjs +14 -475
- package/dist/index.d.cts +2 -189
- package/dist/index.d.ts +2 -189
- package/dist/index.js +14 -443
- 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 -42
package/dist/index.d.cts
CHANGED
|
@@ -1,189 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* `sanitize()` removes markup; it does not preserve safe HTML. Use `escape()`,
|
|
5
|
-
* `escapeAttribute()`, or `escapeUrl()` when the destination context is known.
|
|
6
|
-
*
|
|
7
|
-
* @version 2.0.3
|
|
8
|
-
* @license MIT
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Purifai Configuration Options
|
|
12
|
-
*/
|
|
13
|
-
export interface PurifaiOptions {
|
|
14
|
-
/** Maximum input length (default: 1MB) */
|
|
15
|
-
maxLength?: number;
|
|
16
|
-
/** Subset of the built-in safe URL protocols (default: http, https, mailto) */
|
|
17
|
-
allowedProtocols?: string[];
|
|
18
|
-
/** @deprecated Retained for source compatibility; strip-to-text is always used. */
|
|
19
|
-
aggressiveMode?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Purifai Sanitization Result
|
|
23
|
-
*/
|
|
24
|
-
export interface PurifaiResult {
|
|
25
|
-
/** Sanitized content */
|
|
26
|
-
content: string;
|
|
27
|
-
/** Advisory: whether a known dangerous pattern 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
|
-
* Convert HTML-like input to inert plain text using a bounded forward scanner.
|
|
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 apart from control characters: this is the correct choice when the
|
|
54
|
-
* input is plain text rather than markup and exact text fidelity matters.
|
|
55
|
-
*/
|
|
56
|
-
declare function escape(input: unknown): string;
|
|
57
|
-
/**
|
|
58
|
-
* Escape text for insertion into an HTML attribute value.
|
|
59
|
-
*
|
|
60
|
-
* Stricter than `escape()`: every character outside `[a-zA-Z0-9]` is
|
|
61
|
-
* hex-encoded, which stays safe even in an unquoted attribute — the case that
|
|
62
|
-
* breaks naive escaping, since a bare space or backtick can end the value and
|
|
63
|
-
* start a new attribute such as `onerror=`.
|
|
64
|
-
*/
|
|
65
|
-
declare function escapeAttribute(input: unknown): string;
|
|
66
|
-
/**
|
|
67
|
-
* Escape and validate a value used as a URL.
|
|
68
|
-
*
|
|
69
|
-
* Returns '' when the protocol is not in the caller-selected subset of the
|
|
70
|
-
* built-in safe protocols. Script-bearing schemes and protocol-relative URLs
|
|
71
|
-
* cannot be enabled through options.
|
|
72
|
-
*/
|
|
73
|
-
declare function escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
74
|
-
/**
|
|
75
|
-
* Purifai - bounded strip-to-text sanitizer
|
|
76
|
-
*
|
|
77
|
-
* Converts HTML-like input to plain text and exposes separate contextual
|
|
78
|
-
* encoders for HTML text, attributes, and URLs.
|
|
79
|
-
*
|
|
80
|
-
* Every method delegates to a module-level function and reads no instance or
|
|
81
|
-
* class state, so `Purifai.sanitize` and the standalone `sanitize` export are
|
|
82
|
-
* interchangeable and neither depends on its call-site receiver.
|
|
83
|
-
*/
|
|
84
|
-
export declare class Purifai {
|
|
85
|
-
/**
|
|
86
|
-
* Convert HTML-like input to plain text
|
|
87
|
-
*
|
|
88
|
-
* @param input - Content to sanitize (string, object, or any type)
|
|
89
|
-
* @param options - Optional configuration
|
|
90
|
-
* @returns Plain-text string; render it through normal text interpolation
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* import { Purifai } from 'purifai';
|
|
95
|
-
*
|
|
96
|
-
* const clean = Purifai.sanitize('<script>alert("xss")</script>Hello World');
|
|
97
|
-
* console.log(clean); // "Hello World"
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
static sanitize(input: unknown, options?: PurifaiOptions): string;
|
|
101
|
-
/**
|
|
102
|
-
* Sanitize input and return detailed analysis
|
|
103
|
-
*
|
|
104
|
-
* @param input - Content to sanitize
|
|
105
|
-
* @param options - Optional configuration
|
|
106
|
-
* @returns Detailed sanitization result with threat analysis
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* const result = Purifai.analyze('<script>alert("xss")</script>Hello');
|
|
111
|
-
* console.log(result.content); // "Hello"
|
|
112
|
-
* console.log(result.hadThreats); // true
|
|
113
|
-
* console.log(result.threatLevel); // "critical"
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
static analyze(input: unknown, options?: PurifaiOptions): PurifaiResult;
|
|
117
|
-
/**
|
|
118
|
-
* Check if input contains dangerous patterns
|
|
119
|
-
*
|
|
120
|
-
* @param input - Content to check
|
|
121
|
-
* @returns true if dangerous content detected
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const isDangerous = Purifai.isDangerous('<script>alert("xss")</script>');
|
|
126
|
-
* console.log(isDangerous); // true
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
static isDangerous(input: string): boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Batch sanitize multiple inputs for optimal performance
|
|
132
|
-
*
|
|
133
|
-
* @param inputs - Array of inputs to sanitize
|
|
134
|
-
* @param options - Optional configuration
|
|
135
|
-
* @returns Array of sanitized strings
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* const cleaned = Purifai.sanitizeBatch([
|
|
140
|
-
* '<script>alert("xss")</script>Hello',
|
|
141
|
-
* '<img src=x onerror=alert(1)>World'
|
|
142
|
-
* ]);
|
|
143
|
-
* console.log(cleaned); // ["Hello", "World"]
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
static sanitizeBatch(inputs: unknown[], options?: PurifaiOptions): string[];
|
|
147
|
-
/**
|
|
148
|
-
* Escape text for an HTML body context (lossless — nothing is removed)
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* Purifai.escape('if (a<b && c>d)'); // "if (a<b && c>d)"
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
static escape(input: unknown): string;
|
|
156
|
-
/**
|
|
157
|
-
* Escape text for an HTML attribute value, safe even when unquoted
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* `<div title="${Purifai.escapeAttribute(userInput)}">`
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
static escapeAttribute(input: unknown): string;
|
|
165
|
-
/**
|
|
166
|
-
* Escape a URL, returning '' if its protocol is not allowed
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* Purifai.escapeUrl('javascript:alert(1)'); // ""
|
|
171
|
-
* Purifai.escapeUrl('https://example.com'); // escaped, safe for href
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
static escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
175
|
-
/**
|
|
176
|
-
* Get version information
|
|
177
|
-
*/
|
|
178
|
-
static getVersion(): string;
|
|
179
|
-
/**
|
|
180
|
-
* Get performance and security statistics
|
|
181
|
-
*/
|
|
182
|
-
static getStats(): {
|
|
183
|
-
version: string;
|
|
184
|
-
securityLevel: string;
|
|
185
|
-
performance: string;
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
export { sanitize, analyze, isDangerous, sanitizeBatch, escape, escapeAttribute, escapeUrl };
|
|
189
|
-
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,189 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* `sanitize()` removes markup; it does not preserve safe HTML. Use `escape()`,
|
|
5
|
-
* `escapeAttribute()`, or `escapeUrl()` when the destination context is known.
|
|
6
|
-
*
|
|
7
|
-
* @version 2.0.3
|
|
8
|
-
* @license MIT
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Purifai Configuration Options
|
|
12
|
-
*/
|
|
13
|
-
export interface PurifaiOptions {
|
|
14
|
-
/** Maximum input length (default: 1MB) */
|
|
15
|
-
maxLength?: number;
|
|
16
|
-
/** Subset of the built-in safe URL protocols (default: http, https, mailto) */
|
|
17
|
-
allowedProtocols?: string[];
|
|
18
|
-
/** @deprecated Retained for source compatibility; strip-to-text is always used. */
|
|
19
|
-
aggressiveMode?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Purifai Sanitization Result
|
|
23
|
-
*/
|
|
24
|
-
export interface PurifaiResult {
|
|
25
|
-
/** Sanitized content */
|
|
26
|
-
content: string;
|
|
27
|
-
/** Advisory: whether a known dangerous pattern 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
|
-
* Convert HTML-like input to inert plain text using a bounded forward scanner.
|
|
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 apart from control characters: this is the correct choice when the
|
|
54
|
-
* input is plain text rather than markup and exact text fidelity matters.
|
|
55
|
-
*/
|
|
56
|
-
declare function escape(input: unknown): string;
|
|
57
|
-
/**
|
|
58
|
-
* Escape text for insertion into an HTML attribute value.
|
|
59
|
-
*
|
|
60
|
-
* Stricter than `escape()`: every character outside `[a-zA-Z0-9]` is
|
|
61
|
-
* hex-encoded, which stays safe even in an unquoted attribute — the case that
|
|
62
|
-
* breaks naive escaping, since a bare space or backtick can end the value and
|
|
63
|
-
* start a new attribute such as `onerror=`.
|
|
64
|
-
*/
|
|
65
|
-
declare function escapeAttribute(input: unknown): string;
|
|
66
|
-
/**
|
|
67
|
-
* Escape and validate a value used as a URL.
|
|
68
|
-
*
|
|
69
|
-
* Returns '' when the protocol is not in the caller-selected subset of the
|
|
70
|
-
* built-in safe protocols. Script-bearing schemes and protocol-relative URLs
|
|
71
|
-
* cannot be enabled through options.
|
|
72
|
-
*/
|
|
73
|
-
declare function escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
74
|
-
/**
|
|
75
|
-
* Purifai - bounded strip-to-text sanitizer
|
|
76
|
-
*
|
|
77
|
-
* Converts HTML-like input to plain text and exposes separate contextual
|
|
78
|
-
* encoders for HTML text, attributes, and URLs.
|
|
79
|
-
*
|
|
80
|
-
* Every method delegates to a module-level function and reads no instance or
|
|
81
|
-
* class state, so `Purifai.sanitize` and the standalone `sanitize` export are
|
|
82
|
-
* interchangeable and neither depends on its call-site receiver.
|
|
83
|
-
*/
|
|
84
|
-
export declare class Purifai {
|
|
85
|
-
/**
|
|
86
|
-
* Convert HTML-like input to plain text
|
|
87
|
-
*
|
|
88
|
-
* @param input - Content to sanitize (string, object, or any type)
|
|
89
|
-
* @param options - Optional configuration
|
|
90
|
-
* @returns Plain-text string; render it through normal text interpolation
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* import { Purifai } from 'purifai';
|
|
95
|
-
*
|
|
96
|
-
* const clean = Purifai.sanitize('<script>alert("xss")</script>Hello World');
|
|
97
|
-
* console.log(clean); // "Hello World"
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
static sanitize(input: unknown, options?: PurifaiOptions): string;
|
|
101
|
-
/**
|
|
102
|
-
* Sanitize input and return detailed analysis
|
|
103
|
-
*
|
|
104
|
-
* @param input - Content to sanitize
|
|
105
|
-
* @param options - Optional configuration
|
|
106
|
-
* @returns Detailed sanitization result with threat analysis
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* const result = Purifai.analyze('<script>alert("xss")</script>Hello');
|
|
111
|
-
* console.log(result.content); // "Hello"
|
|
112
|
-
* console.log(result.hadThreats); // true
|
|
113
|
-
* console.log(result.threatLevel); // "critical"
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
static analyze(input: unknown, options?: PurifaiOptions): PurifaiResult;
|
|
117
|
-
/**
|
|
118
|
-
* Check if input contains dangerous patterns
|
|
119
|
-
*
|
|
120
|
-
* @param input - Content to check
|
|
121
|
-
* @returns true if dangerous content detected
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const isDangerous = Purifai.isDangerous('<script>alert("xss")</script>');
|
|
126
|
-
* console.log(isDangerous); // true
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
static isDangerous(input: string): boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Batch sanitize multiple inputs for optimal performance
|
|
132
|
-
*
|
|
133
|
-
* @param inputs - Array of inputs to sanitize
|
|
134
|
-
* @param options - Optional configuration
|
|
135
|
-
* @returns Array of sanitized strings
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* const cleaned = Purifai.sanitizeBatch([
|
|
140
|
-
* '<script>alert("xss")</script>Hello',
|
|
141
|
-
* '<img src=x onerror=alert(1)>World'
|
|
142
|
-
* ]);
|
|
143
|
-
* console.log(cleaned); // ["Hello", "World"]
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
static sanitizeBatch(inputs: unknown[], options?: PurifaiOptions): string[];
|
|
147
|
-
/**
|
|
148
|
-
* Escape text for an HTML body context (lossless — nothing is removed)
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* Purifai.escape('if (a<b && c>d)'); // "if (a<b && c>d)"
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
static escape(input: unknown): string;
|
|
156
|
-
/**
|
|
157
|
-
* Escape text for an HTML attribute value, safe even when unquoted
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* `<div title="${Purifai.escapeAttribute(userInput)}">`
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
static escapeAttribute(input: unknown): string;
|
|
165
|
-
/**
|
|
166
|
-
* Escape a URL, returning '' if its protocol is not allowed
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* Purifai.escapeUrl('javascript:alert(1)'); // ""
|
|
171
|
-
* Purifai.escapeUrl('https://example.com'); // escaped, safe for href
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
static escapeUrl(input: unknown, options?: PurifaiOptions): string;
|
|
175
|
-
/**
|
|
176
|
-
* Get version information
|
|
177
|
-
*/
|
|
178
|
-
static getVersion(): string;
|
|
179
|
-
/**
|
|
180
|
-
* Get performance and security statistics
|
|
181
|
-
*/
|
|
182
|
-
static getStats(): {
|
|
183
|
-
version: string;
|
|
184
|
-
securityLevel: string;
|
|
185
|
-
performance: string;
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
export { sanitize, analyze, isDangerous, sanitizeBatch, escape, escapeAttribute, escapeUrl };
|
|
189
|
-
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';
|