isomorphic-dompurify 3.0.0-rc.1 → 3.0.0-rc.2
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 +19 -0
- package/dist/browser.d.mts +2 -1
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +4 -0
- package/dist/browser.mjs +3 -0
- package/dist/index.d.mts +10 -36
- package/dist/index.d.ts +10 -36
- package/dist/index.js +23 -10
- package/dist/index.mjs +22 -10
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ It was inspired by [Isomorphic Unfetch](https://github.com/developit/unfetch/tre
|
|
|
27
27
|
| `>=1.10.0` | `>=18` | Server |
|
|
28
28
|
| `>=2.27.0` | `>=20` | Server |
|
|
29
29
|
| `>=2.30.0` | `>=20.19.5` | Server |
|
|
30
|
+
| `>=3.0.0` | `^20.19.0 \|\| ^22.12.0 \|\| >=24.0.0` | Server |
|
|
30
31
|
|
|
31
32
|
## Installation
|
|
32
33
|
|
|
@@ -58,6 +59,24 @@ import { sanitize } from "isomorphic-dompurify";
|
|
|
58
59
|
const clean = sanitize(dirtyString);
|
|
59
60
|
```
|
|
60
61
|
|
|
62
|
+
## Memory Management (Server)
|
|
63
|
+
|
|
64
|
+
In long-running Node.js processes, the internal jsdom window accumulates DOM state across sanitization calls, which can cause progressive slowdown and memory growth. Use `clearWindow()` to periodically release these resources:
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import { sanitize, clearWindow } from "isomorphic-dompurify";
|
|
68
|
+
|
|
69
|
+
// Sanitize as usual
|
|
70
|
+
const clean = sanitize(dirtyString);
|
|
71
|
+
|
|
72
|
+
// Release jsdom resources when appropriate (e.g. after a request, after a batch)
|
|
73
|
+
clearWindow();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`clearWindow()` closes the current jsdom window and creates a fresh one. All import styles (default and named) continue to work after calling it.
|
|
77
|
+
|
|
78
|
+
> **Note:** Any hooks or config set via `addHook`/`setConfig` will need to be re-applied after calling `clearWindow()`. In the browser build, `clearWindow()` is a no-op.
|
|
79
|
+
|
|
61
80
|
## Web Worker Support
|
|
62
81
|
|
|
63
82
|
The `isomorphic-dompurify` library is [compatible with Web Workers](https://github.com/kkomelin/isomorphic-dompurify/pull/242),
|
package/dist/browser.d.mts
CHANGED
|
@@ -40,5 +40,6 @@ declare const clearConfig: () => void;
|
|
|
40
40
|
declare const isValidAttribute: (tag: string, attr: string, value: string) => boolean;
|
|
41
41
|
declare const version: string;
|
|
42
42
|
declare const removed: (dompurify.RemovedElement | dompurify.RemovedAttribute)[];
|
|
43
|
+
declare function clearWindow(): void;
|
|
43
44
|
|
|
44
|
-
export { addHook, clearConfig, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
|
45
|
+
export { addHook, clearConfig, clearWindow, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
package/dist/browser.d.ts
CHANGED
|
@@ -40,5 +40,6 @@ declare const clearConfig: () => void;
|
|
|
40
40
|
declare const isValidAttribute: (tag: string, attr: string, value: string) => boolean;
|
|
41
41
|
declare const version: string;
|
|
42
42
|
declare const removed: (dompurify.RemovedElement | dompurify.RemovedAttribute)[];
|
|
43
|
+
declare function clearWindow(): void;
|
|
43
44
|
|
|
44
|
-
export { addHook, clearConfig, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
|
45
|
+
export { addHook, clearConfig, clearWindow, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
package/dist/browser.js
CHANGED
|
@@ -32,6 +32,7 @@ var browser_exports = {};
|
|
|
32
32
|
__export(browser_exports, {
|
|
33
33
|
addHook: () => addHook,
|
|
34
34
|
clearConfig: () => clearConfig,
|
|
35
|
+
clearWindow: () => clearWindow,
|
|
35
36
|
default: () => browser_default,
|
|
36
37
|
isSupported: () => isSupported,
|
|
37
38
|
isValidAttribute: () => isValidAttribute,
|
|
@@ -57,10 +58,13 @@ var clearConfig = import_dompurify.default.clearConfig.bind(import_dompurify.def
|
|
|
57
58
|
var isValidAttribute = import_dompurify.default.isValidAttribute.bind(import_dompurify.default);
|
|
58
59
|
var version = import_dompurify.default.version;
|
|
59
60
|
var removed = import_dompurify.default.removed;
|
|
61
|
+
function clearWindow() {
|
|
62
|
+
}
|
|
60
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
64
|
0 && (module.exports = {
|
|
62
65
|
addHook,
|
|
63
66
|
clearConfig,
|
|
67
|
+
clearWindow,
|
|
64
68
|
isSupported,
|
|
65
69
|
isValidAttribute,
|
|
66
70
|
removeAllHooks,
|
package/dist/browser.mjs
CHANGED
|
@@ -12,9 +12,12 @@ var clearConfig = DOMPurify.clearConfig.bind(DOMPurify);
|
|
|
12
12
|
var isValidAttribute = DOMPurify.isValidAttribute.bind(DOMPurify);
|
|
13
13
|
var version = DOMPurify.version;
|
|
14
14
|
var removed = DOMPurify.removed;
|
|
15
|
+
function clearWindow() {
|
|
16
|
+
}
|
|
15
17
|
export {
|
|
16
18
|
addHook,
|
|
17
19
|
clearConfig,
|
|
20
|
+
clearWindow,
|
|
18
21
|
browser_default as default,
|
|
19
22
|
isSupported,
|
|
20
23
|
isValidAttribute,
|
package/dist/index.d.mts
CHANGED
|
@@ -1,45 +1,19 @@
|
|
|
1
|
-
import * as trusted_types_lib from 'trusted-types/lib';
|
|
2
1
|
import * as dompurify from 'dompurify';
|
|
3
2
|
import { DOMPurify as DOMPurify$1 } from 'dompurify';
|
|
4
3
|
|
|
5
4
|
declare const DOMPurify: DOMPurify$1;
|
|
6
5
|
|
|
7
|
-
declare const sanitize:
|
|
8
|
-
(dirty: string | Node, cfg: dompurify.Config & {
|
|
9
|
-
RETURN_TRUSTED_TYPE: true;
|
|
10
|
-
}): trusted_types_lib.TrustedHTML;
|
|
11
|
-
(dirty: Node, cfg: dompurify.Config & {
|
|
12
|
-
IN_PLACE: true;
|
|
13
|
-
}): Node;
|
|
14
|
-
(dirty: string | Node, cfg: dompurify.Config & {
|
|
15
|
-
RETURN_DOM: true;
|
|
16
|
-
}): Node;
|
|
17
|
-
(dirty: string | Node, cfg: dompurify.Config & {
|
|
18
|
-
RETURN_DOM_FRAGMENT: true;
|
|
19
|
-
}): DocumentFragment;
|
|
20
|
-
(dirty: string | Node, cfg?: dompurify.Config): string;
|
|
21
|
-
};
|
|
6
|
+
declare const sanitize: DOMPurify$1["sanitize"];
|
|
22
7
|
declare const isSupported: boolean;
|
|
23
|
-
declare const addHook:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare const removeHook: {
|
|
31
|
-
(entryPoint: "beforeSanitizeElements" | "afterSanitizeElements" | "uponSanitizeShadowNode", hookFunction?: dompurify.NodeHook): dompurify.NodeHook | undefined;
|
|
32
|
-
(entryPoint: "beforeSanitizeAttributes" | "afterSanitizeAttributes", hookFunction?: dompurify.ElementHook): dompurify.ElementHook | undefined;
|
|
33
|
-
(entryPoint: "beforeSanitizeShadowDOM" | "afterSanitizeShadowDOM", hookFunction?: dompurify.DocumentFragmentHook): dompurify.DocumentFragmentHook | undefined;
|
|
34
|
-
(entryPoint: "uponSanitizeElement", hookFunction?: dompurify.UponSanitizeElementHook): dompurify.UponSanitizeElementHook | undefined;
|
|
35
|
-
(entryPoint: "uponSanitizeAttribute", hookFunction?: dompurify.UponSanitizeAttributeHook): dompurify.UponSanitizeAttributeHook | undefined;
|
|
36
|
-
};
|
|
37
|
-
declare const removeHooks: (entryPoint: dompurify.HookName) => void;
|
|
38
|
-
declare const removeAllHooks: () => void;
|
|
39
|
-
declare const setConfig: (cfg?: dompurify.Config) => void;
|
|
40
|
-
declare const clearConfig: () => void;
|
|
41
|
-
declare const isValidAttribute: (tag: string, attr: string, value: string) => boolean;
|
|
8
|
+
declare const addHook: DOMPurify$1["addHook"];
|
|
9
|
+
declare const removeHook: DOMPurify$1["removeHook"];
|
|
10
|
+
declare const removeHooks: DOMPurify$1["removeHooks"];
|
|
11
|
+
declare const removeAllHooks: DOMPurify$1["removeAllHooks"];
|
|
12
|
+
declare const setConfig: DOMPurify$1["setConfig"];
|
|
13
|
+
declare const clearConfig: DOMPurify$1["clearConfig"];
|
|
14
|
+
declare const isValidAttribute: DOMPurify$1["isValidAttribute"];
|
|
42
15
|
declare const version: string;
|
|
43
16
|
declare const removed: (dompurify.RemovedElement | dompurify.RemovedAttribute)[];
|
|
17
|
+
declare function clearWindow(): void;
|
|
44
18
|
|
|
45
|
-
export { addHook, clearConfig, DOMPurify as default, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
|
19
|
+
export { addHook, clearConfig, clearWindow, DOMPurify as default, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,19 @@
|
|
|
1
|
-
import * as trusted_types_lib from 'trusted-types/lib';
|
|
2
1
|
import * as dompurify from 'dompurify';
|
|
3
2
|
import { DOMPurify as DOMPurify$1 } from 'dompurify';
|
|
4
3
|
|
|
5
4
|
declare const DOMPurify: DOMPurify$1;
|
|
6
5
|
|
|
7
|
-
declare const sanitize:
|
|
8
|
-
(dirty: string | Node, cfg: dompurify.Config & {
|
|
9
|
-
RETURN_TRUSTED_TYPE: true;
|
|
10
|
-
}): trusted_types_lib.TrustedHTML;
|
|
11
|
-
(dirty: Node, cfg: dompurify.Config & {
|
|
12
|
-
IN_PLACE: true;
|
|
13
|
-
}): Node;
|
|
14
|
-
(dirty: string | Node, cfg: dompurify.Config & {
|
|
15
|
-
RETURN_DOM: true;
|
|
16
|
-
}): Node;
|
|
17
|
-
(dirty: string | Node, cfg: dompurify.Config & {
|
|
18
|
-
RETURN_DOM_FRAGMENT: true;
|
|
19
|
-
}): DocumentFragment;
|
|
20
|
-
(dirty: string | Node, cfg?: dompurify.Config): string;
|
|
21
|
-
};
|
|
6
|
+
declare const sanitize: DOMPurify$1["sanitize"];
|
|
22
7
|
declare const isSupported: boolean;
|
|
23
|
-
declare const addHook:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare const removeHook: {
|
|
31
|
-
(entryPoint: "beforeSanitizeElements" | "afterSanitizeElements" | "uponSanitizeShadowNode", hookFunction?: dompurify.NodeHook): dompurify.NodeHook | undefined;
|
|
32
|
-
(entryPoint: "beforeSanitizeAttributes" | "afterSanitizeAttributes", hookFunction?: dompurify.ElementHook): dompurify.ElementHook | undefined;
|
|
33
|
-
(entryPoint: "beforeSanitizeShadowDOM" | "afterSanitizeShadowDOM", hookFunction?: dompurify.DocumentFragmentHook): dompurify.DocumentFragmentHook | undefined;
|
|
34
|
-
(entryPoint: "uponSanitizeElement", hookFunction?: dompurify.UponSanitizeElementHook): dompurify.UponSanitizeElementHook | undefined;
|
|
35
|
-
(entryPoint: "uponSanitizeAttribute", hookFunction?: dompurify.UponSanitizeAttributeHook): dompurify.UponSanitizeAttributeHook | undefined;
|
|
36
|
-
};
|
|
37
|
-
declare const removeHooks: (entryPoint: dompurify.HookName) => void;
|
|
38
|
-
declare const removeAllHooks: () => void;
|
|
39
|
-
declare const setConfig: (cfg?: dompurify.Config) => void;
|
|
40
|
-
declare const clearConfig: () => void;
|
|
41
|
-
declare const isValidAttribute: (tag: string, attr: string, value: string) => boolean;
|
|
8
|
+
declare const addHook: DOMPurify$1["addHook"];
|
|
9
|
+
declare const removeHook: DOMPurify$1["removeHook"];
|
|
10
|
+
declare const removeHooks: DOMPurify$1["removeHooks"];
|
|
11
|
+
declare const removeAllHooks: DOMPurify$1["removeAllHooks"];
|
|
12
|
+
declare const setConfig: DOMPurify$1["setConfig"];
|
|
13
|
+
declare const clearConfig: DOMPurify$1["clearConfig"];
|
|
14
|
+
declare const isValidAttribute: DOMPurify$1["isValidAttribute"];
|
|
42
15
|
declare const version: string;
|
|
43
16
|
declare const removed: (dompurify.RemovedElement | dompurify.RemovedAttribute)[];
|
|
17
|
+
declare function clearWindow(): void;
|
|
44
18
|
|
|
45
|
-
export { addHook, clearConfig, DOMPurify as default, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
|
19
|
+
export { addHook, clearConfig, clearWindow, DOMPurify as default, isSupported, isValidAttribute, removeAllHooks, removeHook, removeHooks, removed, sanitize, setConfig, version };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
addHook: () => addHook,
|
|
34
34
|
clearConfig: () => clearConfig,
|
|
35
|
+
clearWindow: () => clearWindow,
|
|
35
36
|
default: () => src_default,
|
|
36
37
|
isSupported: () => isSupported,
|
|
37
38
|
isValidAttribute: () => isValidAttribute,
|
|
@@ -46,24 +47,36 @@ __export(src_exports, {
|
|
|
46
47
|
module.exports = __toCommonJS(src_exports);
|
|
47
48
|
var import_dompurify = __toESM(require("dompurify"));
|
|
48
49
|
var import_jsdom = require("jsdom");
|
|
49
|
-
var
|
|
50
|
-
var
|
|
50
|
+
var window = new import_jsdom.JSDOM("<!DOCTYPE html>").window;
|
|
51
|
+
var purify = (0, import_dompurify.default)(window);
|
|
52
|
+
var DOMPurify = new Proxy({}, {
|
|
53
|
+
get(_, prop) {
|
|
54
|
+
const value = purify[prop];
|
|
55
|
+
return typeof value === "function" ? value.bind(purify) : value;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
51
58
|
var src_default = DOMPurify;
|
|
52
|
-
var sanitize =
|
|
59
|
+
var sanitize = ((dirty, config) => purify.sanitize(dirty, config));
|
|
53
60
|
var isSupported = DOMPurify.isSupported;
|
|
54
|
-
var addHook =
|
|
55
|
-
var removeHook =
|
|
56
|
-
var removeHooks =
|
|
57
|
-
var removeAllHooks =
|
|
58
|
-
var setConfig =
|
|
59
|
-
var clearConfig =
|
|
60
|
-
var isValidAttribute =
|
|
61
|
+
var addHook = ((entryPoint, hookFunction) => purify.addHook(entryPoint, hookFunction));
|
|
62
|
+
var removeHook = ((entryPoint) => purify.removeHook(entryPoint));
|
|
63
|
+
var removeHooks = ((entryPoint) => purify.removeHooks(entryPoint));
|
|
64
|
+
var removeAllHooks = (() => purify.removeAllHooks());
|
|
65
|
+
var setConfig = ((config) => purify.setConfig(config));
|
|
66
|
+
var clearConfig = (() => purify.clearConfig());
|
|
67
|
+
var isValidAttribute = ((tag, attr, value) => purify.isValidAttribute(tag, attr, value));
|
|
61
68
|
var version = DOMPurify.version;
|
|
62
69
|
var removed = DOMPurify.removed;
|
|
70
|
+
function clearWindow() {
|
|
71
|
+
window.close();
|
|
72
|
+
window = new import_jsdom.JSDOM("<!DOCTYPE html>").window;
|
|
73
|
+
purify = (0, import_dompurify.default)(window);
|
|
74
|
+
}
|
|
63
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
76
|
0 && (module.exports = {
|
|
65
77
|
addHook,
|
|
66
78
|
clearConfig,
|
|
79
|
+
clearWindow,
|
|
67
80
|
isSupported,
|
|
68
81
|
isValidAttribute,
|
|
69
82
|
removeAllHooks,
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import DOMPurifyFactory from "dompurify";
|
|
3
3
|
import { JSDOM } from "jsdom";
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var window = new JSDOM("<!DOCTYPE html>").window;
|
|
5
|
+
var purify = DOMPurifyFactory(window);
|
|
6
|
+
var DOMPurify = new Proxy({}, {
|
|
7
|
+
get(_, prop) {
|
|
8
|
+
const value = purify[prop];
|
|
9
|
+
return typeof value === "function" ? value.bind(purify) : value;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
var src_default = DOMPurify;
|
|
7
|
-
var sanitize =
|
|
13
|
+
var sanitize = ((dirty, config) => purify.sanitize(dirty, config));
|
|
8
14
|
var isSupported = DOMPurify.isSupported;
|
|
9
|
-
var addHook =
|
|
10
|
-
var removeHook =
|
|
11
|
-
var removeHooks =
|
|
12
|
-
var removeAllHooks =
|
|
13
|
-
var setConfig =
|
|
14
|
-
var clearConfig =
|
|
15
|
-
var isValidAttribute =
|
|
15
|
+
var addHook = ((entryPoint, hookFunction) => purify.addHook(entryPoint, hookFunction));
|
|
16
|
+
var removeHook = ((entryPoint) => purify.removeHook(entryPoint));
|
|
17
|
+
var removeHooks = ((entryPoint) => purify.removeHooks(entryPoint));
|
|
18
|
+
var removeAllHooks = (() => purify.removeAllHooks());
|
|
19
|
+
var setConfig = ((config) => purify.setConfig(config));
|
|
20
|
+
var clearConfig = (() => purify.clearConfig());
|
|
21
|
+
var isValidAttribute = ((tag, attr, value) => purify.isValidAttribute(tag, attr, value));
|
|
16
22
|
var version = DOMPurify.version;
|
|
17
23
|
var removed = DOMPurify.removed;
|
|
24
|
+
function clearWindow() {
|
|
25
|
+
window.close();
|
|
26
|
+
window = new JSDOM("<!DOCTYPE html>").window;
|
|
27
|
+
purify = DOMPurifyFactory(window);
|
|
28
|
+
}
|
|
18
29
|
export {
|
|
19
30
|
addHook,
|
|
20
31
|
clearConfig,
|
|
32
|
+
clearWindow,
|
|
21
33
|
src_default as default,
|
|
22
34
|
isSupported,
|
|
23
35
|
isValidAttribute,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isomorphic-dompurify",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.2",
|
|
4
4
|
"description": "Makes it possible to use DOMPurify on server and client in the same way.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"security",
|
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
"sanitize-html",
|
|
17
17
|
"sanitizer"
|
|
18
18
|
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsup",
|
|
21
|
-
"test": "vitest run"
|
|
22
|
-
},
|
|
23
19
|
"bugs": {
|
|
24
20
|
"url": "https://github.com/kkomelin/isomorphic-dompurify/issues"
|
|
25
21
|
},
|
|
@@ -70,8 +66,11 @@
|
|
|
70
66
|
"typescript": "^5.9.3",
|
|
71
67
|
"vitest": "^4.0.16"
|
|
72
68
|
},
|
|
73
|
-
"packageManager": "pnpm@10.28.2",
|
|
74
69
|
"engines": {
|
|
75
70
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsup",
|
|
74
|
+
"test": "NODE_OPTIONS='--expose-gc' vitest run"
|
|
76
75
|
}
|
|
77
|
-
}
|
|
76
|
+
}
|