@bquery/bquery 1.2.0 → 1.4.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 +127 -27
- package/dist/batch-x7b2eZST.js +13 -0
- package/dist/batch-x7b2eZST.js.map +1 -0
- package/dist/component/component.d.ts +69 -0
- package/dist/component/component.d.ts.map +1 -0
- package/dist/component/html.d.ts +35 -0
- package/dist/component/html.d.ts.map +1 -0
- package/dist/component/index.d.ts +3 -126
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/props.d.ts +18 -0
- package/dist/component/props.d.ts.map +1 -0
- package/dist/component/types.d.ts +77 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component.es.mjs +90 -59
- package/dist/component.es.mjs.map +1 -1
- package/dist/core/collection.d.ts +55 -3
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/dom.d.ts +6 -0
- package/dist/core/dom.d.ts.map +1 -0
- package/dist/core/element.d.ts +31 -4
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/utils/array.d.ts +74 -0
- package/dist/core/utils/array.d.ts.map +1 -0
- package/dist/core/utils/function.d.ts +87 -0
- package/dist/core/utils/function.d.ts.map +1 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/misc.d.ts +63 -0
- package/dist/core/utils/misc.d.ts.map +1 -0
- package/dist/core/utils/number.d.ts +65 -0
- package/dist/core/utils/number.d.ts.map +1 -0
- package/dist/core/utils/object.d.ts +133 -0
- package/dist/core/utils/object.d.ts.map +1 -0
- package/dist/core/utils/string.d.ts +80 -0
- package/dist/core/utils/string.d.ts.map +1 -0
- package/dist/core/utils/type-guards.d.ts +79 -0
- package/dist/core/utils/type-guards.d.ts.map +1 -0
- package/dist/core-BhpuvPhy.js +170 -0
- package/dist/core-BhpuvPhy.js.map +1 -0
- package/dist/core.es.mjs +495 -489
- package/dist/core.es.mjs.map +1 -1
- package/dist/full.d.ts +2 -2
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +87 -64
- package/dist/full.es.mjs.map +1 -1
- package/dist/full.iife.js +2 -2
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +2 -2
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +138 -68
- package/dist/index.es.mjs.map +1 -1
- package/dist/motion/animate.d.ts +25 -0
- package/dist/motion/animate.d.ts.map +1 -0
- package/dist/motion/easing.d.ts +30 -0
- package/dist/motion/easing.d.ts.map +1 -0
- package/dist/motion/flip.d.ts +55 -0
- package/dist/motion/flip.d.ts.map +1 -0
- package/dist/motion/index.d.ts +11 -138
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/keyframes.d.ts +21 -0
- package/dist/motion/keyframes.d.ts.map +1 -0
- package/dist/motion/reduced-motion.d.ts +12 -0
- package/dist/motion/reduced-motion.d.ts.map +1 -0
- package/dist/motion/scroll.d.ts +15 -0
- package/dist/motion/scroll.d.ts.map +1 -0
- package/dist/motion/spring.d.ts +42 -0
- package/dist/motion/spring.d.ts.map +1 -0
- package/dist/motion/stagger.d.ts +22 -0
- package/dist/motion/stagger.d.ts.map +1 -0
- package/dist/motion/timeline.d.ts +21 -0
- package/dist/motion/timeline.d.ts.map +1 -0
- package/dist/motion/transition.d.ts +22 -0
- package/dist/motion/transition.d.ts.map +1 -0
- package/dist/motion/types.d.ts +182 -0
- package/dist/motion/types.d.ts.map +1 -0
- package/dist/motion.es.mjs +320 -61
- package/dist/motion.es.mjs.map +1 -1
- package/dist/persisted-DHoi3uEs.js +278 -0
- package/dist/persisted-DHoi3uEs.js.map +1 -0
- package/dist/platform/storage.d.ts.map +1 -1
- package/dist/platform.es.mjs +12 -7
- package/dist/platform.es.mjs.map +1 -1
- package/dist/reactive/batch.d.ts +13 -0
- package/dist/reactive/batch.d.ts.map +1 -0
- package/dist/reactive/computed.d.ts +50 -0
- package/dist/reactive/computed.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +72 -0
- package/dist/reactive/core.d.ts.map +1 -0
- package/dist/reactive/effect.d.ts +15 -0
- package/dist/reactive/effect.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +42 -0
- package/dist/reactive/internals.d.ts.map +1 -0
- package/dist/reactive/linked.d.ts +36 -0
- package/dist/reactive/linked.d.ts.map +1 -0
- package/dist/reactive/persisted.d.ts +14 -0
- package/dist/reactive/persisted.d.ts.map +1 -0
- package/dist/reactive/readonly.d.ts +26 -0
- package/dist/reactive/readonly.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +13 -312
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive/type-guards.d.ts +20 -0
- package/dist/reactive/type-guards.d.ts.map +1 -0
- package/dist/reactive/untrack.d.ts +29 -0
- package/dist/reactive/untrack.d.ts.map +1 -0
- package/dist/reactive/watch.d.ts +42 -0
- package/dist/reactive/watch.d.ts.map +1 -0
- package/dist/reactive.es.mjs +30 -163
- package/dist/reactive.es.mjs.map +1 -1
- package/dist/router/index.d.ts +6 -252
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/links.d.ts +44 -0
- package/dist/router/links.d.ts.map +1 -0
- package/dist/router/match.d.ts +20 -0
- package/dist/router/match.d.ts.map +1 -0
- package/dist/router/navigation.d.ts +45 -0
- package/dist/router/navigation.d.ts.map +1 -0
- package/dist/router/query.d.ts +16 -0
- package/dist/router/query.d.ts.map +1 -0
- package/dist/router/router.d.ts +34 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/state.d.ts +27 -0
- package/dist/router/state.d.ts.map +1 -0
- package/dist/router/types.d.ts +88 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/utils.d.ts +65 -0
- package/dist/router/utils.d.ts.map +1 -0
- package/dist/router.es.mjs +168 -132
- package/dist/router.es.mjs.map +1 -1
- package/dist/sanitize-Cxvxa-DX.js +283 -0
- package/dist/sanitize-Cxvxa-DX.js.map +1 -0
- package/dist/security/constants.d.ts +42 -0
- package/dist/security/constants.d.ts.map +1 -0
- package/dist/security/csp.d.ts +24 -0
- package/dist/security/csp.d.ts.map +1 -0
- package/dist/security/index.d.ts +4 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts +13 -0
- package/dist/security/sanitize-core.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +5 -57
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-types.d.ts +25 -0
- package/dist/security/trusted-types.d.ts.map +1 -0
- package/dist/security/types.d.ts +36 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security.es.mjs +50 -277
- package/dist/security.es.mjs.map +1 -1
- package/dist/store/create-store.d.ts +15 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/define-store.d.ts +28 -0
- package/dist/store/define-store.d.ts.map +1 -0
- package/dist/store/devtools.d.ts +22 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/index.d.ts +10 -286
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +28 -0
- package/dist/store/mapping.d.ts.map +1 -0
- package/dist/store/persisted.d.ts +13 -0
- package/dist/store/persisted.d.ts.map +1 -0
- package/dist/store/plugins.d.ts +13 -0
- package/dist/store/plugins.d.ts.map +1 -0
- package/dist/store/registry.d.ts +28 -0
- package/dist/store/registry.d.ts.map +1 -0
- package/dist/store/types.d.ts +71 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/utils.d.ts +28 -0
- package/dist/store/utils.d.ts.map +1 -0
- package/dist/store/watch.d.ts +23 -0
- package/dist/store/watch.d.ts.map +1 -0
- package/dist/store.es.mjs +22 -224
- package/dist/store.es.mjs.map +1 -1
- package/dist/type-guards-BdKlYYlS.js +32 -0
- package/dist/type-guards-BdKlYYlS.js.map +1 -0
- package/dist/untrack-DNnnqdlR.js +6 -0
- package/dist/untrack-DNnnqdlR.js.map +1 -0
- package/dist/view/directives/bind.d.ts +7 -0
- package/dist/view/directives/bind.d.ts.map +1 -0
- package/dist/view/directives/class.d.ts +8 -0
- package/dist/view/directives/class.d.ts.map +1 -0
- package/dist/view/directives/for.d.ts +23 -0
- package/dist/view/directives/for.d.ts.map +1 -0
- package/dist/view/directives/html.d.ts +7 -0
- package/dist/view/directives/html.d.ts.map +1 -0
- package/dist/view/directives/if.d.ts +7 -0
- package/dist/view/directives/if.d.ts.map +1 -0
- package/dist/view/directives/index.d.ts +12 -0
- package/dist/view/directives/index.d.ts.map +1 -0
- package/dist/view/directives/model.d.ts +7 -0
- package/dist/view/directives/model.d.ts.map +1 -0
- package/dist/view/directives/on.d.ts +7 -0
- package/dist/view/directives/on.d.ts.map +1 -0
- package/dist/view/directives/ref.d.ts +7 -0
- package/dist/view/directives/ref.d.ts.map +1 -0
- package/dist/view/directives/show.d.ts +7 -0
- package/dist/view/directives/show.d.ts.map +1 -0
- package/dist/view/directives/style.d.ts +7 -0
- package/dist/view/directives/style.d.ts.map +1 -0
- package/dist/view/directives/text.d.ts +7 -0
- package/dist/view/directives/text.d.ts.map +1 -0
- package/dist/view/evaluate.d.ts +43 -0
- package/dist/view/evaluate.d.ts.map +1 -0
- package/dist/view/index.d.ts +3 -93
- package/dist/view/index.d.ts.map +1 -1
- package/dist/view/mount.d.ts +69 -0
- package/dist/view/mount.d.ts.map +1 -0
- package/dist/view/process.d.ts +26 -0
- package/dist/view/process.d.ts.map +1 -0
- package/dist/view/types.d.ts +36 -0
- package/dist/view/types.d.ts.map +1 -0
- package/dist/view.es.mjs +358 -251
- package/dist/view.es.mjs.map +1 -1
- package/dist/watch-DXXv3iAI.js +58 -0
- package/dist/watch-DXXv3iAI.js.map +1 -0
- package/package.json +14 -14
- package/src/component/component.ts +289 -0
- package/src/component/html.ts +53 -0
- package/src/component/index.ts +40 -414
- package/src/component/props.ts +116 -0
- package/src/component/types.ts +85 -0
- package/src/core/collection.ts +181 -7
- package/src/core/dom.ts +38 -0
- package/src/core/element.ts +59 -25
- package/src/core/index.ts +48 -4
- package/src/core/utils/array.ts +102 -0
- package/src/core/utils/function.ts +151 -0
- package/src/core/utils/index.ts +83 -0
- package/src/core/utils/misc.ts +82 -0
- package/src/core/utils/number.ts +78 -0
- package/src/core/utils/object.ts +206 -0
- package/src/core/utils/string.ts +112 -0
- package/src/core/utils/type-guards.ts +112 -0
- package/src/full.ts +187 -150
- package/src/index.ts +36 -36
- package/src/motion/animate.ts +113 -0
- package/src/motion/easing.ts +40 -0
- package/src/motion/flip.ts +176 -0
- package/src/motion/index.ts +41 -358
- package/src/motion/keyframes.ts +46 -0
- package/src/motion/reduced-motion.ts +17 -0
- package/src/motion/scroll.ts +57 -0
- package/src/motion/spring.ts +150 -0
- package/src/motion/stagger.ts +43 -0
- package/src/motion/timeline.ts +246 -0
- package/src/motion/transition.ts +51 -0
- package/src/motion/types.ts +198 -0
- package/src/platform/storage.ts +215 -208
- package/src/reactive/batch.ts +22 -0
- package/src/reactive/computed.ts +92 -0
- package/src/reactive/core.ts +114 -0
- package/src/reactive/effect.ts +54 -0
- package/src/reactive/index.ts +23 -22
- package/src/reactive/internals.ts +122 -0
- package/src/reactive/linked.ts +56 -0
- package/src/reactive/persisted.ts +74 -0
- package/src/reactive/readonly.ts +35 -0
- package/src/reactive/signal.ts +20 -520
- package/src/reactive/type-guards.ts +22 -0
- package/src/reactive/untrack.ts +31 -0
- package/src/reactive/watch.ts +73 -0
- package/src/router/index.ts +41 -718
- package/src/router/links.ts +130 -0
- package/src/router/match.ts +106 -0
- package/src/router/navigation.ts +71 -0
- package/src/router/query.ts +35 -0
- package/src/router/router.ts +211 -0
- package/src/router/state.ts +46 -0
- package/src/router/types.ts +93 -0
- package/src/router/utils.ts +116 -0
- package/src/security/constants.ts +209 -0
- package/src/security/csp.ts +77 -0
- package/src/security/index.ts +4 -12
- package/src/security/sanitize-core.ts +364 -0
- package/src/security/sanitize.ts +66 -625
- package/src/security/trusted-types.ts +69 -0
- package/src/security/types.ts +40 -0
- package/src/store/create-store.ts +329 -0
- package/src/store/define-store.ts +48 -0
- package/src/store/devtools.ts +45 -0
- package/src/store/index.ts +22 -848
- package/src/store/mapping.ts +73 -0
- package/src/store/persisted.ts +61 -0
- package/src/store/plugins.ts +32 -0
- package/src/store/registry.ts +51 -0
- package/src/store/types.ts +94 -0
- package/src/store/utils.ts +141 -0
- package/src/store/watch.ts +52 -0
- package/src/view/directives/bind.ts +23 -0
- package/src/view/directives/class.ts +70 -0
- package/src/view/directives/for.ts +275 -0
- package/src/view/directives/html.ts +19 -0
- package/src/view/directives/if.ts +30 -0
- package/src/view/directives/index.ts +11 -0
- package/src/view/directives/model.ts +56 -0
- package/src/view/directives/on.ts +41 -0
- package/src/view/directives/ref.ts +41 -0
- package/src/view/directives/show.ts +26 -0
- package/src/view/directives/style.ts +47 -0
- package/src/view/directives/text.ts +15 -0
- package/src/view/evaluate.ts +290 -0
- package/src/view/index.ts +112 -1041
- package/src/view/mount.ts +200 -0
- package/src/view/process.ts +92 -0
- package/src/view/types.ts +44 -0
- package/dist/core/utils.d.ts +0 -313
- package/dist/core/utils.d.ts.map +0 -1
- package/src/core/utils.ts +0 -444
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
const P = "bquery-sanitizer", N = /* @__PURE__ */ new Set([
|
|
2
|
+
"a",
|
|
3
|
+
"abbr",
|
|
4
|
+
"address",
|
|
5
|
+
"article",
|
|
6
|
+
"aside",
|
|
7
|
+
"b",
|
|
8
|
+
"bdi",
|
|
9
|
+
"bdo",
|
|
10
|
+
"blockquote",
|
|
11
|
+
"br",
|
|
12
|
+
"button",
|
|
13
|
+
"caption",
|
|
14
|
+
"cite",
|
|
15
|
+
"code",
|
|
16
|
+
"col",
|
|
17
|
+
"colgroup",
|
|
18
|
+
"data",
|
|
19
|
+
"dd",
|
|
20
|
+
"del",
|
|
21
|
+
"details",
|
|
22
|
+
"dfn",
|
|
23
|
+
"div",
|
|
24
|
+
"dl",
|
|
25
|
+
"dt",
|
|
26
|
+
"em",
|
|
27
|
+
"figcaption",
|
|
28
|
+
"figure",
|
|
29
|
+
"footer",
|
|
30
|
+
"form",
|
|
31
|
+
"h1",
|
|
32
|
+
"h2",
|
|
33
|
+
"h3",
|
|
34
|
+
"h4",
|
|
35
|
+
"h5",
|
|
36
|
+
"h6",
|
|
37
|
+
"header",
|
|
38
|
+
"hgroup",
|
|
39
|
+
"hr",
|
|
40
|
+
"i",
|
|
41
|
+
"img",
|
|
42
|
+
"input",
|
|
43
|
+
"ins",
|
|
44
|
+
"kbd",
|
|
45
|
+
"label",
|
|
46
|
+
"legend",
|
|
47
|
+
"li",
|
|
48
|
+
"main",
|
|
49
|
+
"mark",
|
|
50
|
+
"nav",
|
|
51
|
+
"ol",
|
|
52
|
+
"optgroup",
|
|
53
|
+
"option",
|
|
54
|
+
"p",
|
|
55
|
+
"picture",
|
|
56
|
+
"pre",
|
|
57
|
+
"progress",
|
|
58
|
+
"q",
|
|
59
|
+
"rp",
|
|
60
|
+
"rt",
|
|
61
|
+
"ruby",
|
|
62
|
+
"s",
|
|
63
|
+
"samp",
|
|
64
|
+
"section",
|
|
65
|
+
"select",
|
|
66
|
+
"small",
|
|
67
|
+
"source",
|
|
68
|
+
"span",
|
|
69
|
+
"strong",
|
|
70
|
+
"sub",
|
|
71
|
+
"summary",
|
|
72
|
+
"sup",
|
|
73
|
+
"table",
|
|
74
|
+
"tbody",
|
|
75
|
+
"td",
|
|
76
|
+
"textarea",
|
|
77
|
+
"tfoot",
|
|
78
|
+
"th",
|
|
79
|
+
"thead",
|
|
80
|
+
"time",
|
|
81
|
+
"tr",
|
|
82
|
+
"u",
|
|
83
|
+
"ul",
|
|
84
|
+
"var",
|
|
85
|
+
"wbr"
|
|
86
|
+
]), A = /* @__PURE__ */ new Set([
|
|
87
|
+
"script",
|
|
88
|
+
"iframe",
|
|
89
|
+
"frame",
|
|
90
|
+
"frameset",
|
|
91
|
+
"object",
|
|
92
|
+
"embed",
|
|
93
|
+
"applet",
|
|
94
|
+
"link",
|
|
95
|
+
"meta",
|
|
96
|
+
"style",
|
|
97
|
+
"base",
|
|
98
|
+
"template",
|
|
99
|
+
"slot",
|
|
100
|
+
"math",
|
|
101
|
+
"svg",
|
|
102
|
+
"foreignobject",
|
|
103
|
+
"noscript"
|
|
104
|
+
]), D = /* @__PURE__ */ new Set([
|
|
105
|
+
// Global objects
|
|
106
|
+
"document",
|
|
107
|
+
"window",
|
|
108
|
+
"location",
|
|
109
|
+
"top",
|
|
110
|
+
"self",
|
|
111
|
+
"parent",
|
|
112
|
+
"frames",
|
|
113
|
+
"history",
|
|
114
|
+
"navigator",
|
|
115
|
+
"screen",
|
|
116
|
+
// Dangerous functions
|
|
117
|
+
"alert",
|
|
118
|
+
"confirm",
|
|
119
|
+
"prompt",
|
|
120
|
+
"eval",
|
|
121
|
+
"function",
|
|
122
|
+
// Document properties
|
|
123
|
+
"cookie",
|
|
124
|
+
"domain",
|
|
125
|
+
"referrer",
|
|
126
|
+
"body",
|
|
127
|
+
"head",
|
|
128
|
+
"forms",
|
|
129
|
+
"images",
|
|
130
|
+
"links",
|
|
131
|
+
"scripts",
|
|
132
|
+
// DOM traversal properties
|
|
133
|
+
"children",
|
|
134
|
+
"parentnode",
|
|
135
|
+
"firstchild",
|
|
136
|
+
"lastchild",
|
|
137
|
+
// Content manipulation
|
|
138
|
+
"innerhtml",
|
|
139
|
+
"outerhtml",
|
|
140
|
+
"textcontent"
|
|
141
|
+
]), F = /* @__PURE__ */ new Set([
|
|
142
|
+
"alt",
|
|
143
|
+
"class",
|
|
144
|
+
"dir",
|
|
145
|
+
"height",
|
|
146
|
+
"hidden",
|
|
147
|
+
"href",
|
|
148
|
+
"id",
|
|
149
|
+
"lang",
|
|
150
|
+
"loading",
|
|
151
|
+
"name",
|
|
152
|
+
"rel",
|
|
153
|
+
"role",
|
|
154
|
+
"src",
|
|
155
|
+
"srcset",
|
|
156
|
+
"tabindex",
|
|
157
|
+
"target",
|
|
158
|
+
"title",
|
|
159
|
+
"type",
|
|
160
|
+
"width",
|
|
161
|
+
"aria-*"
|
|
162
|
+
]), O = ["on", "formaction", "xlink:", "xmlns:"], R = ["javascript:", "data:", "vbscript:", "file:"], W = (t, e, r) => {
|
|
163
|
+
const s = t.toLowerCase();
|
|
164
|
+
for (const c of O)
|
|
165
|
+
if (s.startsWith(c)) return !1;
|
|
166
|
+
return r && s.startsWith("data-") || s.startsWith("aria-") ? !0 : e.has(s);
|
|
167
|
+
}, U = (t) => {
|
|
168
|
+
const e = t.toLowerCase().trim();
|
|
169
|
+
return !D.has(e);
|
|
170
|
+
}, _ = (t) => t.replace(/[\u0000-\u001F\u007F]+/g, "").replace(/[\u200B-\u200D\uFEFF\u2028\u2029]+/g, "").replace(/\\u[\da-fA-F]{4}/g, "").replace(/\s+/g, "").toLowerCase(), E = (t) => {
|
|
171
|
+
const e = _(t);
|
|
172
|
+
for (const r of R)
|
|
173
|
+
if (e.startsWith(r)) return !1;
|
|
174
|
+
return !0;
|
|
175
|
+
}, k = (t) => {
|
|
176
|
+
const e = t.split(",");
|
|
177
|
+
for (const r of e) {
|
|
178
|
+
const s = r.trim().split(/\s+/)[0];
|
|
179
|
+
if (s && !E(s)) return !1;
|
|
180
|
+
}
|
|
181
|
+
return !0;
|
|
182
|
+
}, H = (t) => {
|
|
183
|
+
try {
|
|
184
|
+
const e = t.trim();
|
|
185
|
+
if (e.startsWith("//"))
|
|
186
|
+
return !0;
|
|
187
|
+
const r = e.toLowerCase();
|
|
188
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(e) && !r.startsWith("http://") && !r.startsWith("https://") ? !0 : !r.startsWith("http://") && !r.startsWith("https://") ? !1 : typeof window > "u" || !window.location ? !0 : new URL(e, window.location.href).origin !== window.location.origin;
|
|
189
|
+
} catch {
|
|
190
|
+
return !0;
|
|
191
|
+
}
|
|
192
|
+
}, z = (t) => new DOMParser().parseFromString(t, "text/html"), S = (t) => {
|
|
193
|
+
const e = (typeof t == "string" ? t : String(t ?? "")).trim(), r = document.createDocumentFragment();
|
|
194
|
+
if (e.length === 0)
|
|
195
|
+
return r;
|
|
196
|
+
if (!(e.includes("<") || e.includes(">")))
|
|
197
|
+
return r.appendChild(document.createTextNode(e)), r;
|
|
198
|
+
const l = z(e).body;
|
|
199
|
+
if (!l)
|
|
200
|
+
return r;
|
|
201
|
+
for (; l.firstChild; )
|
|
202
|
+
r.appendChild(l.firstChild);
|
|
203
|
+
return r;
|
|
204
|
+
}, T = (t, e = {}) => {
|
|
205
|
+
const {
|
|
206
|
+
allowTags: r = [],
|
|
207
|
+
allowAttributes: s = [],
|
|
208
|
+
allowDataAttributes: c = !0,
|
|
209
|
+
stripAllTags: l = !1
|
|
210
|
+
} = e, y = new Set(
|
|
211
|
+
[...N, ...r.map((o) => o.toLowerCase())].filter(
|
|
212
|
+
(o) => !A.has(o)
|
|
213
|
+
)
|
|
214
|
+
), L = /* @__PURE__ */ new Set([
|
|
215
|
+
...F,
|
|
216
|
+
...s.map((o) => o.toLowerCase())
|
|
217
|
+
]), d = S(t);
|
|
218
|
+
if (l)
|
|
219
|
+
return d.textContent ?? "";
|
|
220
|
+
const p = document.createTreeWalker(d, NodeFilter.SHOW_ELEMENT), f = [];
|
|
221
|
+
for (; p.nextNode(); ) {
|
|
222
|
+
const o = p.currentNode, i = o.tagName.toLowerCase();
|
|
223
|
+
if (A.has(i)) {
|
|
224
|
+
f.push(o);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (!y.has(i)) {
|
|
228
|
+
f.push(o);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const u = [];
|
|
232
|
+
for (const n of Array.from(o.attributes)) {
|
|
233
|
+
const a = n.name.toLowerCase();
|
|
234
|
+
if (!W(a, L, c)) {
|
|
235
|
+
u.push(n.name);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if ((a === "id" || a === "name") && !U(n.value)) {
|
|
239
|
+
u.push(n.name);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if ((a === "href" || a === "src" || a === "action") && !E(n.value)) {
|
|
243
|
+
u.push(n.name);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
a === "srcset" && !k(n.value) && u.push(n.name);
|
|
247
|
+
}
|
|
248
|
+
for (const n of u)
|
|
249
|
+
o.removeAttribute(n);
|
|
250
|
+
if (i === "a") {
|
|
251
|
+
const n = o.getAttribute("href"), C = o.getAttribute("target")?.toLowerCase() === "_blank", v = n && H(n);
|
|
252
|
+
if (C || v) {
|
|
253
|
+
const b = o.getAttribute("rel"), m = new Set(b ? b.split(/\s+/).filter(Boolean) : []);
|
|
254
|
+
m.add("noopener"), m.add("noreferrer"), o.setAttribute("rel", Array.from(m).join(" "));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
for (const o of f)
|
|
259
|
+
o.remove();
|
|
260
|
+
const h = (o) => {
|
|
261
|
+
const i = document.createElement("div");
|
|
262
|
+
return i.appendChild(o.cloneNode(!0)), i.innerHTML;
|
|
263
|
+
}, g = h(d), x = S(g), w = h(x);
|
|
264
|
+
return g !== w ? d.textContent ?? "" : w;
|
|
265
|
+
}, j = (t, e = {}) => T(t, e), G = (t) => {
|
|
266
|
+
const e = {
|
|
267
|
+
"&": "&",
|
|
268
|
+
"<": "<",
|
|
269
|
+
">": ">",
|
|
270
|
+
'"': """,
|
|
271
|
+
"'": "'",
|
|
272
|
+
"`": "`"
|
|
273
|
+
};
|
|
274
|
+
return t.replace(/[&<>"'`]/g, (r) => e[r]);
|
|
275
|
+
}, I = (t) => T(t, { stripAllTags: !0 });
|
|
276
|
+
export {
|
|
277
|
+
P,
|
|
278
|
+
I as a,
|
|
279
|
+
T as b,
|
|
280
|
+
G as e,
|
|
281
|
+
j as s
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=sanitize-Cxvxa-DX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-Cxvxa-DX.js","sources":["../src/security/constants.ts","../src/security/sanitize-core.ts","../src/security/sanitize.ts"],"sourcesContent":["/**\n * Security constants and safe lists.\n *\n * @module bquery/security\n */\n\n/**\n * Trusted Types policy name.\n */\nexport const POLICY_NAME = 'bquery-sanitizer';\n\n/**\n * Default allowed HTML tags considered safe.\n */\nexport const DEFAULT_ALLOWED_TAGS = new Set([\n 'a',\n 'abbr',\n 'address',\n 'article',\n 'aside',\n 'b',\n 'bdi',\n 'bdo',\n 'blockquote',\n 'br',\n 'button',\n 'caption',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'data',\n 'dd',\n 'del',\n 'details',\n 'dfn',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hgroup',\n 'hr',\n 'i',\n 'img',\n 'input',\n 'ins',\n 'kbd',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'mark',\n 'nav',\n 'ol',\n 'optgroup',\n 'option',\n 'p',\n 'picture',\n 'pre',\n 'progress',\n 'q',\n 'rp',\n 'rt',\n 'ruby',\n 's',\n 'samp',\n 'section',\n 'select',\n 'small',\n 'source',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'u',\n 'ul',\n 'var',\n 'wbr',\n]);\n\n/**\n * Explicitly dangerous tags that should never be allowed.\n * These are checked even if somehow added to allowTags.\n */\nexport const DANGEROUS_TAGS = new Set([\n 'script',\n 'iframe',\n 'frame',\n 'frameset',\n 'object',\n 'embed',\n 'applet',\n 'link',\n 'meta',\n 'style',\n 'base',\n 'template',\n 'slot',\n 'math',\n 'svg',\n 'foreignobject',\n 'noscript',\n]);\n\n/**\n * Reserved IDs that could cause DOM clobbering attacks.\n * These are prevented to avoid overwriting global browser objects.\n */\nexport const RESERVED_IDS = new Set([\n // Global objects\n 'document',\n 'window',\n 'location',\n 'top',\n 'self',\n 'parent',\n 'frames',\n 'history',\n 'navigator',\n 'screen',\n // Dangerous functions\n 'alert',\n 'confirm',\n 'prompt',\n 'eval',\n 'function',\n // Document properties\n 'cookie',\n 'domain',\n 'referrer',\n 'body',\n 'head',\n 'forms',\n 'images',\n 'links',\n 'scripts',\n // DOM traversal properties\n 'children',\n 'parentnode',\n 'firstchild',\n 'lastchild',\n // Content manipulation\n 'innerhtml',\n 'outerhtml',\n 'textcontent',\n]);\n\n/**\n * Default allowed attributes considered safe.\n * Note: 'style' is excluded by default because inline CSS can be abused for:\n * - UI redressing attacks\n * - Data exfiltration via url() in CSS\n * - CSS injection vectors\n * If you need to allow inline styles, add 'style' to allowAttributes in your\n * sanitizeHtml options, but ensure you implement proper CSS value validation.\n */\nexport const DEFAULT_ALLOWED_ATTRIBUTES = new Set([\n 'alt',\n 'class',\n 'dir',\n 'height',\n 'hidden',\n 'href',\n 'id',\n 'lang',\n 'loading',\n 'name',\n 'rel',\n 'role',\n 'src',\n 'srcset',\n 'tabindex',\n 'target',\n 'title',\n 'type',\n 'width',\n 'aria-*',\n]);\n\n/**\n * Dangerous attribute prefixes to always remove.\n */\nexport const DANGEROUS_ATTR_PREFIXES = ['on', 'formaction', 'xlink:', 'xmlns:'];\n\n/**\n * Dangerous URL protocols to block.\n */\nexport const DANGEROUS_PROTOCOLS = ['javascript:', 'data:', 'vbscript:', 'file:'];\n","/**\r\n * Core HTML sanitization logic.\r\n *\r\n * @module bquery/security\r\n * @internal\r\n */\r\n\r\nimport {\r\n DANGEROUS_ATTR_PREFIXES,\r\n DANGEROUS_PROTOCOLS,\r\n DANGEROUS_TAGS,\r\n DEFAULT_ALLOWED_ATTRIBUTES,\r\n DEFAULT_ALLOWED_TAGS,\r\n RESERVED_IDS,\r\n} from './constants';\r\nimport type { SanitizeOptions } from './types';\r\n\r\n/**\r\n * Check if an attribute name is allowed.\r\n * @internal\r\n */\r\nconst isAllowedAttribute = (\r\n name: string,\r\n allowedSet: Set<string>,\r\n allowDataAttrs: boolean\r\n): boolean => {\r\n const lowerName = name.toLowerCase();\r\n\r\n // Check dangerous prefixes\r\n for (const prefix of DANGEROUS_ATTR_PREFIXES) {\r\n if (lowerName.startsWith(prefix)) return false;\r\n }\r\n\r\n // Check data attributes\r\n if (allowDataAttrs && lowerName.startsWith('data-')) return true;\r\n\r\n // Check aria attributes (allowed by default)\r\n if (lowerName.startsWith('aria-')) return true;\r\n\r\n // Check explicit allow list\r\n return allowedSet.has(lowerName);\r\n};\r\n\r\n/**\r\n * Check if an ID/name value could cause DOM clobbering.\r\n * @internal\r\n */\r\nconst isSafeIdOrName = (value: string): boolean => {\r\n const lowerValue = value.toLowerCase().trim();\r\n return !RESERVED_IDS.has(lowerValue);\r\n};\r\n\r\n/**\r\n * Normalize URL by removing control characters, whitespace, and Unicode tricks.\r\n * Enhanced to prevent various bypass techniques.\r\n * @internal\r\n */\r\nconst normalizeUrl = (value: string): string =>\r\n value\r\n // Remove null bytes and control characters\r\n .replace(/[\\u0000-\\u001F\\u007F]+/g, '')\r\n // Remove zero-width characters that could hide malicious content\r\n .replace(/[\\u200B-\\u200D\\uFEFF\\u2028\\u2029]+/g, '')\r\n // Remove escaped Unicode sequences\r\n .replace(/\\\\u[\\da-fA-F]{4}/g, '')\r\n // Remove whitespace\r\n .replace(/\\s+/g, '')\r\n // Normalize case\r\n .toLowerCase();\r\n\r\n/**\r\n * Check if a URL value is safe.\r\n * @internal\r\n */\r\nconst isSafeUrl = (value: string): boolean => {\r\n const normalized = normalizeUrl(value);\r\n for (const protocol of DANGEROUS_PROTOCOLS) {\r\n if (normalized.startsWith(protocol)) return false;\r\n }\r\n return true;\r\n};\r\n\r\n/**\r\n * Check if a srcset attribute value is safe.\r\n * srcset contains comma-separated entries of \"url [descriptor]\".\r\n * Each individual URL must be validated.\r\n * @internal\r\n */\r\nconst isSafeSrcset = (value: string): boolean => {\r\n const entries = value.split(',');\r\n for (const entry of entries) {\r\n const url = entry.trim().split(/\\s+/)[0];\r\n if (url && !isSafeUrl(url)) return false;\r\n }\r\n return true;\r\n};\r\n\r\n/**\r\n * Check if a URL is external (different origin).\r\n * @internal\r\n */\r\nconst isExternalUrl = (url: string): boolean => {\r\n try {\r\n // Normalize URL by trimming whitespace\r\n const trimmedUrl = url.trim();\r\n\r\n // Protocol-relative URLs (//example.com) are always external.\r\n // CRITICAL: This check must run before the relative-URL check below;\r\n // otherwise, a protocol-relative URL like \"//evil.com\" would be treated\r\n // as a non-http(s) relative URL and incorrectly classified as same-origin.\r\n // Handling them up front guarantees correct security classification.\r\n if (trimmedUrl.startsWith('//')) {\r\n return true;\r\n }\r\n\r\n // Normalize URL for case-insensitive protocol checks\r\n const lowerUrl = trimmedUrl.toLowerCase();\r\n\r\n // Check for non-http(s) protocols which are considered external/special\r\n // (mailto:, tel:, ftp:, etc.)\r\n const hasProtocol = /^[a-z][a-z0-9+.-]*:/i.test(trimmedUrl);\r\n if (hasProtocol && !lowerUrl.startsWith('http://') && !lowerUrl.startsWith('https://')) {\r\n // These are special protocols, not traditional \"external\" links\r\n // but we treat them as external for security consistency\r\n return true;\r\n }\r\n\r\n // Relative URLs are not external\r\n if (!lowerUrl.startsWith('http://') && !lowerUrl.startsWith('https://')) {\r\n return false;\r\n }\r\n\r\n // In non-browser environments (e.g., Node.js), treat all absolute URLs as external\r\n if (typeof window === 'undefined' || !window.location) {\r\n return true;\r\n }\r\n\r\n const urlObj = new URL(trimmedUrl, window.location.href);\r\n return urlObj.origin !== window.location.origin;\r\n } catch {\r\n // If URL parsing fails, treat as potentially external for safety\r\n return true;\r\n }\r\n};\r\n\r\n/**\r\n * Parse an HTML string into a Document using DOMParser.\r\n * This helper is intentionally separated to make the control-flow around HTML parsing\r\n * explicit for static analysis tools. It should ONLY be called when the input is\r\n * known to contain HTML syntax (angle brackets).\r\n *\r\n * DOMParser creates an inert document where scripts don't execute, making it safe\r\n * for parsing untrusted HTML that will subsequently be sanitized.\r\n *\r\n * @param htmlContent - A string that is known to contain HTML markup (has < or >)\r\n * @returns The parsed Document\r\n * @internal\r\n */\r\nconst parseHtmlDocument = (htmlContent: string): Document => {\r\n const parser = new DOMParser();\r\n // Parse as a full HTML document in an inert context; scripts won't execute\r\n return parser.parseFromString(htmlContent, 'text/html');\r\n};\r\n\r\n/**\r\n * Safely parse HTML string into a DocumentFragment using DOMParser.\r\n * DOMParser is preferred over innerHTML for security as it creates an inert document\r\n * where scripts don't execute and provides better static analysis recognition.\r\n *\r\n * This function includes input normalization to satisfy static analysis tools:\r\n * - Coerces input to string and trims whitespace\r\n * - For plain text (no HTML tags), creates a Text node directly without parsing\r\n * - Only invokes DOMParser for actual HTML-like content via parseHtmlDocument\r\n *\r\n * The separation between plain text handling and HTML parsing is intentional:\r\n * DOM text that contains no HTML syntax is never fed into an HTML parser,\r\n * preventing \"DOM text reinterpreted as HTML\" issues.\r\n *\r\n * @internal\r\n */\r\nconst parseHtmlSafely = (html: string): DocumentFragment => {\r\n // Step 1: Normalize input - coerce to string and trim\r\n // This defensive check handles edge cases even though TypeScript says it's a string\r\n const normalizedHtml = (typeof html === 'string' ? html : String(html ?? '')).trim();\r\n\r\n // Step 2: Create the fragment that will hold our result\r\n const fragment = document.createDocumentFragment();\r\n\r\n // Step 3: Early return for empty input\r\n if (normalizedHtml.length === 0) {\r\n return fragment;\r\n }\r\n\r\n // Step 4: If input contains no angle brackets, it's plain text - no HTML parsing needed.\r\n // Plain text is handled as a Text node, never passed to an HTML parser.\r\n // This explicitly prevents \"DOM text reinterpreted as HTML\" for purely textual inputs.\r\n const containsHtmlSyntax = normalizedHtml.includes('<') || normalizedHtml.includes('>');\r\n if (!containsHtmlSyntax) {\r\n fragment.appendChild(document.createTextNode(normalizedHtml));\r\n return fragment;\r\n }\r\n\r\n // Step 5: Input contains HTML syntax - parse it via the dedicated HTML parsing helper.\r\n // This separation makes the data-flow explicit: only strings with HTML syntax\r\n // are passed to DOMParser, satisfying static analysis requirements.\r\n const doc = parseHtmlDocument(normalizedHtml);\r\n\r\n // Move all children from the document body into the fragment.\r\n // This avoids interpolating untrusted HTML into an outer wrapper string.\r\n const body = doc.body;\r\n\r\n if (!body) {\r\n return fragment;\r\n }\r\n\r\n while (body.firstChild) {\r\n fragment.appendChild(body.firstChild);\r\n }\r\n\r\n return fragment;\r\n};\r\n\r\n/**\r\n * Core sanitization logic (without Trusted Types wrapper).\r\n * @internal\r\n */\r\nexport const sanitizeHtmlCore = (html: string, options: SanitizeOptions = {}): string => {\r\n const {\r\n allowTags = [],\r\n allowAttributes = [],\r\n allowDataAttributes = true,\r\n stripAllTags = false,\r\n } = options;\r\n\r\n // Build combined allow sets (excluding dangerous tags even if specified)\r\n const allowedTags = new Set(\r\n [...DEFAULT_ALLOWED_TAGS, ...allowTags.map((t) => t.toLowerCase())].filter(\r\n (tag) => !DANGEROUS_TAGS.has(tag)\r\n )\r\n );\r\n const allowedAttrs = new Set([\r\n ...DEFAULT_ALLOWED_ATTRIBUTES,\r\n ...allowAttributes.map((a) => a.toLowerCase()),\r\n ]);\r\n\r\n // Use DOMParser for safe HTML parsing (inert context, no script execution)\r\n const fragment = parseHtmlSafely(html);\r\n\r\n if (stripAllTags) {\r\n return fragment.textContent ?? '';\r\n }\r\n\r\n // Walk the DOM tree\r\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_ELEMENT);\r\n\r\n const toRemove: Element[] = [];\r\n\r\n while (walker.nextNode()) {\r\n const el = walker.currentNode as Element;\r\n const tagName = el.tagName.toLowerCase();\r\n\r\n // Remove explicitly dangerous tags even if in allow list\r\n if (DANGEROUS_TAGS.has(tagName)) {\r\n toRemove.push(el);\r\n continue;\r\n }\r\n\r\n // Remove disallowed tags entirely\r\n if (!allowedTags.has(tagName)) {\r\n toRemove.push(el);\r\n continue;\r\n }\r\n\r\n // Process attributes\r\n const attrsToRemove: string[] = [];\r\n for (const attr of Array.from(el.attributes)) {\r\n const attrName = attr.name.toLowerCase();\r\n\r\n // Check if attribute is allowed\r\n if (!isAllowedAttribute(attrName, allowedAttrs, allowDataAttributes)) {\r\n attrsToRemove.push(attr.name);\r\n continue;\r\n }\r\n\r\n // Check for DOM clobbering on id and name attributes\r\n if ((attrName === 'id' || attrName === 'name') && !isSafeIdOrName(attr.value)) {\r\n attrsToRemove.push(attr.name);\r\n continue;\r\n }\r\n\r\n // Validate URL attributes\r\n if (\r\n (attrName === 'href' || attrName === 'src' || attrName === 'action') &&\r\n !isSafeUrl(attr.value)\r\n ) {\r\n attrsToRemove.push(attr.name);\r\n continue;\r\n }\r\n\r\n // Validate srcset URLs individually\r\n if (attrName === 'srcset' && !isSafeSrcset(attr.value)) {\r\n attrsToRemove.push(attr.name);\r\n }\r\n }\r\n\r\n // Remove disallowed attributes\r\n for (const attrName of attrsToRemove) {\r\n el.removeAttribute(attrName);\r\n }\r\n\r\n // Add rel=\"noopener noreferrer\" to external links for security\r\n if (tagName === 'a') {\r\n const href = el.getAttribute('href');\r\n const target = el.getAttribute('target');\r\n const hasTargetBlank = target?.toLowerCase() === '_blank';\r\n const isExternal = href && isExternalUrl(href);\r\n\r\n // Add security attributes to links opening in new window or external links\r\n if (hasTargetBlank || isExternal) {\r\n const existingRel = el.getAttribute('rel');\r\n const relValues = new Set(existingRel ? existingRel.split(/\\s+/).filter(Boolean) : []);\r\n\r\n // Add noopener and noreferrer\r\n relValues.add('noopener');\r\n relValues.add('noreferrer');\r\n\r\n el.setAttribute('rel', Array.from(relValues).join(' '));\r\n }\r\n }\r\n }\r\n\r\n // Remove disallowed elements\r\n for (const el of toRemove) {\r\n el.remove();\r\n }\r\n\r\n // Serialize the sanitized fragment to HTML string.\r\n // We use a temporary container to get the innerHTML of the fragment.\r\n const serializeFragment = (frag: DocumentFragment): string => {\r\n const container = document.createElement('div');\r\n container.appendChild(frag.cloneNode(true));\r\n return container.innerHTML;\r\n };\r\n\r\n // Double-parse to prevent mutation XSS (mXSS).\r\n // Browsers may normalize HTML during serialization in ways that could create\r\n // new dangerous content when re-parsed. By re-parsing the sanitized output\r\n // and verifying stability, we ensure the final HTML is safe.\r\n const firstPass = serializeFragment(fragment);\r\n\r\n // Re-parse through DOMParser for mXSS detection.\r\n // Using DOMParser instead of innerHTML for security.\r\n const verifyFragment = parseHtmlSafely(firstPass);\r\n const secondPass = serializeFragment(verifyFragment);\r\n\r\n // Verify stability: if content mutates between parses, it indicates mXSS attempt\r\n if (firstPass !== secondPass) {\r\n // Content mutated during re-parse - potential mXSS detected.\r\n // Return safely escaped text content as fallback.\r\n return fragment.textContent ?? '';\r\n }\r\n\r\n return secondPass;\r\n};\r\n","/**\n * Security utilities for HTML sanitization.\n * All DOM writes are sanitized by default to prevent XSS attacks.\n *\n * @module bquery/security\n */\n\nimport { sanitizeHtmlCore } from './sanitize-core';\nimport type { SanitizeOptions } from './types';\nexport { generateNonce } from './csp';\nexport { isTrustedTypesSupported } from './trusted-types';\n\n/**\n * Sanitize HTML string, removing dangerous elements and attributes.\n * Uses Trusted Types when available for CSP compliance.\n *\n * @param html - The HTML string to sanitize\n * @param options - Sanitization options\n * @returns Sanitized HTML string\n *\n * @example\n * ```ts\n * const safe = sanitizeHtml('<div onclick=\"alert(1)\">Hello</div>');\n * // Returns: '<div>Hello</div>'\n * ```\n */\nexport const sanitizeHtml = (html: string, options: SanitizeOptions = {}): string => {\n return sanitizeHtmlCore(html, options);\n};\n\n/**\n * Escape HTML entities to prevent XSS.\n * Use this for displaying user content as text.\n *\n * @param text - The text to escape\n * @returns Escaped HTML string\n *\n * @example\n * ```ts\n * escapeHtml('<script>alert(1)</script>');\n * // Returns: '<script>alert(1)</script>'\n * ```\n */\nexport const escapeHtml = (text: string): string => {\n const escapeMap: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n };\n return text.replace(/[&<>\"'`]/g, (char) => escapeMap[char]);\n};\n\n/**\n * Strip all HTML tags and return plain text.\n *\n * @param html - The HTML string to strip\n * @returns Plain text content\n */\nexport const stripTags = (html: string): string => {\n return sanitizeHtmlCore(html, { stripAllTags: true });\n};\n\nexport type { SanitizeOptions } from './types';\n"],"names":["POLICY_NAME","DEFAULT_ALLOWED_TAGS","DANGEROUS_TAGS","RESERVED_IDS","DEFAULT_ALLOWED_ATTRIBUTES","DANGEROUS_ATTR_PREFIXES","DANGEROUS_PROTOCOLS","isAllowedAttribute","name","allowedSet","allowDataAttrs","lowerName","prefix","isSafeIdOrName","value","lowerValue","normalizeUrl","isSafeUrl","normalized","protocol","isSafeSrcset","entries","entry","url","isExternalUrl","trimmedUrl","lowerUrl","parseHtmlDocument","htmlContent","parseHtmlSafely","html","normalizedHtml","fragment","body","sanitizeHtmlCore","options","allowTags","allowAttributes","allowDataAttributes","stripAllTags","allowedTags","t","tag","allowedAttrs","a","walker","toRemove","el","tagName","attrsToRemove","attr","attrName","href","hasTargetBlank","isExternal","existingRel","relValues","serializeFragment","frag","container","firstPass","verifyFragment","secondPass","sanitizeHtml","escapeHtml","text","escapeMap","char","stripTags"],"mappings":"AASO,MAAMA,IAAc,oBAKdC,wBAA2B,IAAI;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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6
|
+
/**
|
|
7
|
+
* Trusted Types policy name.
|
|
8
|
+
*/
|
|
9
|
+
export declare const POLICY_NAME = "bquery-sanitizer";
|
|
10
|
+
/**
|
|
11
|
+
* Default allowed HTML tags considered safe.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_ALLOWED_TAGS: Set<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Explicitly dangerous tags that should never be allowed.
|
|
16
|
+
* These are checked even if somehow added to allowTags.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DANGEROUS_TAGS: Set<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Reserved IDs that could cause DOM clobbering attacks.
|
|
21
|
+
* These are prevented to avoid overwriting global browser objects.
|
|
22
|
+
*/
|
|
23
|
+
export declare const RESERVED_IDS: Set<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Default allowed attributes considered safe.
|
|
26
|
+
* Note: 'style' is excluded by default because inline CSS can be abused for:
|
|
27
|
+
* - UI redressing attacks
|
|
28
|
+
* - Data exfiltration via url() in CSS
|
|
29
|
+
* - CSS injection vectors
|
|
30
|
+
* If you need to allow inline styles, add 'style' to allowAttributes in your
|
|
31
|
+
* sanitizeHtml options, but ensure you implement proper CSS value validation.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_ALLOWED_ATTRIBUTES: Set<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Dangerous attribute prefixes to always remove.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DANGEROUS_ATTR_PREFIXES: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Dangerous URL protocols to block.
|
|
40
|
+
*/
|
|
41
|
+
export declare const DANGEROUS_PROTOCOLS: string[];
|
|
42
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/security/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,oBAAoB,aAqF/B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc,aAkBzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,YAAY,aAqCvB,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,aAqBrC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,uBAAuB,UAA2C,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,mBAAmB,UAAiD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Security Policy helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/security
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generate a nonce for inline scripts/styles.
|
|
8
|
+
* Use with Content-Security-Policy nonce directives.
|
|
9
|
+
*
|
|
10
|
+
* @param length - Nonce length in bytes (default: 16, max: 1024)
|
|
11
|
+
* @returns Cryptographically random nonce string
|
|
12
|
+
* @throws {Error} If crypto.getRandomValues or btoa are not available
|
|
13
|
+
* @throws {RangeError} If length is invalid (negative, non-integer, or exceeds maximum)
|
|
14
|
+
*/
|
|
15
|
+
export declare const generateNonce: (length?: number) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a CSP header is present with specific directive.
|
|
18
|
+
* Useful for feature detection and fallback strategies.
|
|
19
|
+
*
|
|
20
|
+
* @param directive - The CSP directive to check (e.g., 'script-src')
|
|
21
|
+
* @returns True if the directive appears to be enforced
|
|
22
|
+
*/
|
|
23
|
+
export declare const hasCSPDirective: (directive: string) => boolean;
|
|
24
|
+
//# sourceMappingURL=csp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../../src/security/csp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,SAAQ,MAAW,KAAG,MAiCnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,KAAG,OAanD,CAAC"}
|
package/dist/security/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module bquery/security
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
6
|
+
export { generateNonce, hasCSPDirective } from './csp';
|
|
7
|
+
export { escapeHtml, sanitizeHtml as sanitize, sanitizeHtml, stripTags } from './sanitize';
|
|
8
|
+
export { createTrustedHtml, getTrustedTypesPolicy, isTrustedTypesSupported } from './trusted-types';
|
|
9
|
+
export type { SanitizeOptions } from './types';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,YAAY,IAAI,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACpG,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core HTML sanitization logic.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/security
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
import type { SanitizeOptions } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Core sanitization logic (without Trusted Types wrapper).
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare const sanitizeHtmlCore: (html: string, options?: SanitizeOptions) => string;
|
|
13
|
+
//# sourceMappingURL=sanitize-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-core.d.ts","sourceRoot":"","sources":["../../src/security/sanitize-core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA+M/C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,UAAS,eAAoB,KAAG,MAyI9E,CAAC"}
|
|
@@ -1,40 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Security utilities for HTML sanitization
|
|
2
|
+
* Security utilities for HTML sanitization.
|
|
3
3
|
* All DOM writes are sanitized by default to prevent XSS attacks.
|
|
4
4
|
*
|
|
5
5
|
* @module bquery/security
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export interface SanitizeOptions {
|
|
11
|
-
/** Allow these additional tags (default: none) */
|
|
12
|
-
allowTags?: string[];
|
|
13
|
-
/** Allow these additional attributes (default: none) */
|
|
14
|
-
allowAttributes?: string[];
|
|
15
|
-
/** Allow data-* attributes (default: true) */
|
|
16
|
-
allowDataAttributes?: boolean;
|
|
17
|
-
/** Strip all tags and return plain text (default: false) */
|
|
18
|
-
stripAllTags?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/** Trusted Types policy interface */
|
|
21
|
-
interface TrustedTypePolicy {
|
|
22
|
-
createHTML: (input: string) => TrustedHTML;
|
|
23
|
-
}
|
|
24
|
-
/** Trusted HTML type placeholder for environments without Trusted Types */
|
|
25
|
-
interface TrustedHTML {
|
|
26
|
-
toString(): string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Check if Trusted Types API is available.
|
|
30
|
-
* @returns True if Trusted Types are supported
|
|
31
|
-
*/
|
|
32
|
-
export declare const isTrustedTypesSupported: () => boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Get or create the bQuery Trusted Types policy.
|
|
35
|
-
* @returns The Trusted Types policy or null if unsupported
|
|
36
|
-
*/
|
|
37
|
-
export declare const getTrustedTypesPolicy: () => TrustedTypePolicy | null;
|
|
7
|
+
import type { SanitizeOptions } from './types';
|
|
8
|
+
export { generateNonce } from './csp';
|
|
9
|
+
export { isTrustedTypesSupported } from './trusted-types';
|
|
38
10
|
/**
|
|
39
11
|
* Sanitize HTML string, removing dangerous elements and attributes.
|
|
40
12
|
* Uses Trusted Types when available for CSP compliance.
|
|
@@ -50,14 +22,6 @@ export declare const getTrustedTypesPolicy: () => TrustedTypePolicy | null;
|
|
|
50
22
|
* ```
|
|
51
23
|
*/
|
|
52
24
|
export declare const sanitizeHtml: (html: string, options?: SanitizeOptions) => string;
|
|
53
|
-
/**
|
|
54
|
-
* Create a Trusted HTML value for use with Trusted Types-enabled sites.
|
|
55
|
-
* Falls back to regular string when Trusted Types are unavailable.
|
|
56
|
-
*
|
|
57
|
-
* @param html - The HTML string to wrap
|
|
58
|
-
* @returns Trusted HTML value or sanitized string
|
|
59
|
-
*/
|
|
60
|
-
export declare const createTrustedHtml: (html: string) => TrustedHTML | string;
|
|
61
25
|
/**
|
|
62
26
|
* Escape HTML entities to prevent XSS.
|
|
63
27
|
* Use this for displaying user content as text.
|
|
@@ -79,21 +43,5 @@ export declare const escapeHtml: (text: string) => string;
|
|
|
79
43
|
* @returns Plain text content
|
|
80
44
|
*/
|
|
81
45
|
export declare const stripTags: (html: string) => string;
|
|
82
|
-
|
|
83
|
-
* Generate a nonce for inline scripts/styles.
|
|
84
|
-
* Use with Content-Security-Policy nonce directives.
|
|
85
|
-
*
|
|
86
|
-
* @param length - Nonce length (default: 16)
|
|
87
|
-
* @returns Cryptographically random nonce string
|
|
88
|
-
*/
|
|
89
|
-
export declare const generateNonce: (length?: number) => string;
|
|
90
|
-
/**
|
|
91
|
-
* Check if a CSP header is present with specific directive.
|
|
92
|
-
* Useful for feature detection and fallback strategies.
|
|
93
|
-
*
|
|
94
|
-
* @param directive - The CSP directive to check (e.g., 'script-src')
|
|
95
|
-
* @returns True if the directive appears to be enforced
|
|
96
|
-
*/
|
|
97
|
-
export declare const hasCSPDirective: (directive: string) => boolean;
|
|
98
|
-
export {};
|
|
46
|
+
export type { SanitizeOptions } from './types';
|
|
99
47
|
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/security/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/security/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,UAAS,eAAoB,KAAG,MAE1E,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,MAUzC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAExC,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trusted Types helpers for CSP compatibility.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/security
|
|
5
|
+
*/
|
|
6
|
+
import type { TrustedHTML, TrustedTypePolicy } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Check if Trusted Types API is available.
|
|
9
|
+
* @returns True if Trusted Types are supported
|
|
10
|
+
*/
|
|
11
|
+
export declare const isTrustedTypesSupported: () => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get or create the bQuery Trusted Types policy.
|
|
14
|
+
* @returns The Trusted Types policy or null if unsupported
|
|
15
|
+
*/
|
|
16
|
+
export declare const getTrustedTypesPolicy: () => TrustedTypePolicy | null;
|
|
17
|
+
/**
|
|
18
|
+
* Create a Trusted HTML value for use with Trusted Types-enabled sites.
|
|
19
|
+
* Falls back to regular string when Trusted Types are unavailable.
|
|
20
|
+
*
|
|
21
|
+
* @param html - The HTML string to wrap
|
|
22
|
+
* @returns Trusted HTML value or sanitized string
|
|
23
|
+
*/
|
|
24
|
+
export declare const createTrustedHtml: (html: string) => TrustedHTML | string;
|
|
25
|
+
//# sourceMappingURL=trusted-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-types.d.ts","sourceRoot":"","sources":["../../src/security/trusted-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAsB,MAAM,SAAS,CAAC;AAQlF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAO,OAK1C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAO,iBAAiB,GAAG,IAsB5D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,WAAW,GAAG,MAM9D,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security types for sanitization, CSP compatibility, and Trusted Types.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/security
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Sanitizer configuration options.
|
|
8
|
+
*/
|
|
9
|
+
export interface SanitizeOptions {
|
|
10
|
+
/** Allow these additional tags (default: none) */
|
|
11
|
+
allowTags?: string[];
|
|
12
|
+
/** Allow these additional attributes (default: none) */
|
|
13
|
+
allowAttributes?: string[];
|
|
14
|
+
/** Allow data-* attributes (default: true) */
|
|
15
|
+
allowDataAttributes?: boolean;
|
|
16
|
+
/** Strip all tags and return plain text (default: false) */
|
|
17
|
+
stripAllTags?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Window interface extended with Trusted Types */
|
|
20
|
+
export interface TrustedTypesWindow extends Window {
|
|
21
|
+
trustedTypes?: {
|
|
22
|
+
createPolicy: (name: string, rules: {
|
|
23
|
+
createHTML?: (input: string) => string;
|
|
24
|
+
}) => TrustedTypePolicy;
|
|
25
|
+
isHTML?: (value: unknown) => boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Trusted Types policy interface */
|
|
29
|
+
export interface TrustedTypePolicy {
|
|
30
|
+
createHTML: (input: string) => TrustedHTML;
|
|
31
|
+
}
|
|
32
|
+
/** Trusted HTML type placeholder for environments without Trusted Types */
|
|
33
|
+
export interface TrustedHTML {
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/security/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,8CAA8C;IAC9C,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,mDAAmD;AACnD,MAAM,WAAW,kBAAmB,SAAQ,MAAM;IAChD,YAAY,CAAC,EAAE;QACb,YAAY,EAAE,CACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE;YAAE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;SAAE,KAC9C,iBAAiB,CAAC;QACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;KACtC,CAAC;CACH;AAED,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;CAC5C;AAED,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IAC1B,QAAQ,IAAI,MAAM,CAAC;CACpB"}
|