wide-cli 0.5.1611261726 → 0.7.211126
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 +16 -1
- package/data/osv-bundle.json +1 -1
- package/data/rules.json +1 -1
- package/dist/agent/index.d.ts +25 -3
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +117 -18
- package/dist/agent/index.js.map +1 -1
- package/dist/completion.js +5 -5
- package/dist/completion.js.map +1 -1
- package/dist/config/index.d.ts +4 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +9 -2
- package/dist/config/index.js.map +1 -1
- package/dist/fix.d.ts +25 -0
- package/dist/fix.d.ts.map +1 -0
- package/dist/fix.js +197 -0
- package/dist/fix.js.map +1 -0
- package/dist/hook.d.ts +31 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +152 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.js +169 -6
- package/dist/index.js.map +1 -1
- package/dist/providers/antigravity.d.ts +46 -0
- package/dist/providers/antigravity.d.ts.map +1 -0
- package/dist/providers/antigravity.js +496 -0
- package/dist/providers/antigravity.js.map +1 -0
- package/dist/providers/claude-code.d.ts +60 -0
- package/dist/providers/claude-code.d.ts.map +1 -0
- package/dist/providers/claude-code.js +973 -0
- package/dist/providers/claude-code.js.map +1 -0
- package/dist/providers/codex.d.ts +52 -0
- package/dist/providers/codex.d.ts.map +1 -0
- package/dist/providers/codex.js +742 -0
- package/dist/providers/codex.js.map +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +33 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/repl/commands.d.ts.map +1 -1
- package/dist/repl/commands.js +53 -3
- package/dist/repl/commands.js.map +1 -1
- package/dist/repl/index.d.ts +3 -0
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +11 -6
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/setup.d.ts.map +1 -1
- package/dist/repl/setup.js +16 -4
- package/dist/repl/setup.js.map +1 -1
- package/dist/security/crawler.d.ts +90 -0
- package/dist/security/crawler.d.ts.map +1 -0
- package/dist/security/crawler.js +622 -0
- package/dist/security/crawler.js.map +1 -0
- package/dist/security/fuzzer.d.ts +1 -0
- package/dist/security/fuzzer.d.ts.map +1 -1
- package/dist/security/fuzzer.js +25 -1
- package/dist/security/fuzzer.js.map +1 -1
- package/dist/security/inspect/evasion-decode.d.ts +41 -0
- package/dist/security/inspect/evasion-decode.d.ts.map +1 -0
- package/dist/security/inspect/evasion-decode.js +316 -0
- package/dist/security/inspect/evasion-decode.js.map +1 -0
- package/dist/security/inspect/http-conformance.d.ts +51 -0
- package/dist/security/inspect/http-conformance.d.ts.map +1 -0
- package/dist/security/inspect/http-conformance.js +389 -0
- package/dist/security/inspect/http-conformance.js.map +1 -0
- package/dist/security/inspect/lexical-sqli.d.ts +7 -0
- package/dist/security/inspect/lexical-sqli.d.ts.map +1 -0
- package/dist/security/inspect/lexical-sqli.js +986 -0
- package/dist/security/inspect/lexical-sqli.js.map +1 -0
- package/dist/security/inspect/lexical-xss.d.ts +10 -0
- package/dist/security/inspect/lexical-xss.d.ts.map +1 -0
- package/dist/security/inspect/lexical-xss.js +654 -0
- package/dist/security/inspect/lexical-xss.js.map +1 -0
- package/dist/security/inspect/libinjection-tables.d.ts +6 -0
- package/dist/security/inspect/libinjection-tables.d.ts.map +1 -0
- package/dist/security/inspect/libinjection-tables.js +6 -0
- package/dist/security/inspect/libinjection-tables.js.map +1 -0
- package/dist/security/inspect/safe-pattern.d.ts +62 -0
- package/dist/security/inspect/safe-pattern.d.ts.map +1 -0
- package/dist/security/inspect/safe-pattern.js +640 -0
- package/dist/security/inspect/safe-pattern.js.map +1 -0
- package/dist/security/inspect/score-policy.d.ts +82 -0
- package/dist/security/inspect/score-policy.d.ts.map +1 -0
- package/dist/security/inspect/score-policy.js +241 -0
- package/dist/security/inspect/score-policy.js.map +1 -0
- package/dist/security/inspect.d.ts +7 -0
- package/dist/security/inspect.d.ts.map +1 -0
- package/dist/security/inspect.js +7 -0
- package/dist/security/inspect.js.map +1 -0
- package/dist/security/loader.d.ts.map +1 -1
- package/dist/security/loader.js +12 -2
- package/dist/security/loader.js.map +1 -1
- package/dist/security/payloads.d.ts.map +1 -1
- package/dist/security/payloads.js +19 -0
- package/dist/security/payloads.js.map +1 -1
- package/dist/security/scanner.d.ts +2 -0
- package/dist/security/scanner.d.ts.map +1 -1
- package/dist/security/scanner.js +31 -26
- package/dist/security/scanner.js.map +1 -1
- package/dist/security/secrets.d.ts +2 -2
- package/dist/security/secrets.d.ts.map +1 -1
- package/dist/security/secrets.js +3 -43
- package/dist/security/secrets.js.map +1 -1
- package/dist/security/taint.d.ts +2 -13
- package/dist/security/taint.d.ts.map +1 -1
- package/dist/security/taint.js +1 -516
- package/dist/security/taint.js.map +1 -1
- package/dist/tools/article.d.ts +18 -0
- package/dist/tools/article.d.ts.map +1 -0
- package/dist/tools/article.js +193 -0
- package/dist/tools/article.js.map +1 -0
- package/dist/tools/browser.d.ts +8 -2
- package/dist/tools/browser.d.ts.map +1 -1
- package/dist/tools/browser.js +76 -10
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/docx.d.ts +11 -0
- package/dist/tools/docx.d.ts.map +1 -0
- package/dist/tools/docx.js +149 -0
- package/dist/tools/docx.js.map +1 -0
- package/dist/tools/fs.d.ts +2 -0
- package/dist/tools/fs.d.ts.map +1 -1
- package/dist/tools/fs.js +96 -7
- package/dist/tools/fs.js.map +1 -1
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +125 -48
- package/dist/tools/http.js.map +1 -1
- package/dist/tools/index.d.ts +21 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +137 -14
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/resilience.d.ts +78 -0
- package/dist/tools/resilience.d.ts.map +1 -0
- package/dist/tools/resilience.js +211 -0
- package/dist/tools/resilience.js.map +1 -0
- package/dist/tools/security.d.ts +2 -0
- package/dist/tools/security.d.ts.map +1 -1
- package/dist/tools/security.js +79 -1
- package/dist/tools/security.js.map +1 -1
- package/dist/tools/types.d.ts +4 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/banner.js +2 -2
- package/dist/ui/banner.js.map +1 -1
- package/dist/vendor/wide-engine/index.d.ts +4 -0
- package/dist/vendor/wide-engine/index.d.ts.map +1 -0
- package/dist/vendor/wide-engine/index.js +3 -0
- package/dist/vendor/wide-engine/index.js.map +1 -0
- package/dist/vendor/wide-engine/secrets.d.ts +4 -0
- package/dist/vendor/wide-engine/secrets.d.ts.map +1 -0
- package/dist/vendor/wide-engine/secrets.js +48 -0
- package/dist/vendor/wide-engine/secrets.js.map +1 -0
- package/dist/vendor/wide-engine/taint.d.ts +5 -0
- package/dist/vendor/wide-engine/taint.d.ts.map +1 -0
- package/dist/vendor/wide-engine/taint.js +533 -0
- package/dist/vendor/wide-engine/taint.js.map +1 -0
- package/dist/vendor/wide-engine/types.d.ts +30 -0
- package/dist/vendor/wide-engine/types.d.ts.map +1 -0
- package/dist/vendor/wide-engine/types.js +2 -0
- package/dist/vendor/wide-engine/types.js.map +1 -0
- package/package.json +5 -3
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import { XSS_BLACK_ATTRS, XSS_BLACK_EVENTS, XSS_BLACK_TAGS } from "./libinjection-tables.js";
|
|
2
|
+
function isWhite(c) {
|
|
3
|
+
return c === 0 || c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0b || c === 0x0c || c === 0x0d;
|
|
4
|
+
}
|
|
5
|
+
function isAlpha(c) {
|
|
6
|
+
return (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a);
|
|
7
|
+
}
|
|
8
|
+
class Html5Tokenizer {
|
|
9
|
+
s;
|
|
10
|
+
pos = 0;
|
|
11
|
+
state;
|
|
12
|
+
isClose = false;
|
|
13
|
+
tokenType = "DATA_TEXT"; // wide-ignore wide/secret-assignment
|
|
14
|
+
tokenValue = Buffer.alloc(0);
|
|
15
|
+
constructor(buf, ctx) {
|
|
16
|
+
this.s = buf;
|
|
17
|
+
this.state =
|
|
18
|
+
ctx === "data"
|
|
19
|
+
? "data"
|
|
20
|
+
: ctx === "value_no_quote"
|
|
21
|
+
? "before_attribute_name"
|
|
22
|
+
: ctx === "value_single_quote"
|
|
23
|
+
? "attribute_value_single_quote"
|
|
24
|
+
: ctx === "value_double_quote"
|
|
25
|
+
? "attribute_value_double_quote"
|
|
26
|
+
: "attribute_value_back_quote";
|
|
27
|
+
}
|
|
28
|
+
emit(t, start, len) {
|
|
29
|
+
this.tokenType = t;
|
|
30
|
+
this.tokenValue = this.s.subarray(start, start + len);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
skipWhite() {
|
|
34
|
+
while (this.pos < this.s.length) {
|
|
35
|
+
const c = this.s[this.pos];
|
|
36
|
+
if (isWhite(c)) {
|
|
37
|
+
this.pos += 1;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return c;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
next() {
|
|
46
|
+
let budget = 8 * (this.s.length + 4);
|
|
47
|
+
while (budget > 0) {
|
|
48
|
+
budget -= 1;
|
|
49
|
+
if (this.state === "eof")
|
|
50
|
+
return false;
|
|
51
|
+
const step = this.stepState();
|
|
52
|
+
if (step !== null)
|
|
53
|
+
return step;
|
|
54
|
+
}
|
|
55
|
+
this.state = "eof";
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
stepState() {
|
|
59
|
+
const s = this.s;
|
|
60
|
+
switch (this.state) {
|
|
61
|
+
case "data": {
|
|
62
|
+
const idx = s.indexOf(0x3c, this.pos);
|
|
63
|
+
if (idx < 0) {
|
|
64
|
+
const start = this.pos;
|
|
65
|
+
const len = s.length - start;
|
|
66
|
+
this.state = "eof";
|
|
67
|
+
if (len === 0)
|
|
68
|
+
return false;
|
|
69
|
+
return this.emit("DATA_TEXT", start, len);
|
|
70
|
+
}
|
|
71
|
+
const start = this.pos;
|
|
72
|
+
const len = idx - start;
|
|
73
|
+
this.pos = idx + 1;
|
|
74
|
+
this.state = "tag_open";
|
|
75
|
+
if (len === 0)
|
|
76
|
+
return null;
|
|
77
|
+
return this.emit("DATA_TEXT", start, len);
|
|
78
|
+
}
|
|
79
|
+
case "tag_open": {
|
|
80
|
+
if (this.pos >= s.length)
|
|
81
|
+
return false;
|
|
82
|
+
const c = s[this.pos];
|
|
83
|
+
if (c === 0x21) {
|
|
84
|
+
this.pos += 1;
|
|
85
|
+
this.state = "markup_declaration_open";
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (c === 0x2f) {
|
|
89
|
+
this.pos += 1;
|
|
90
|
+
this.isClose = true;
|
|
91
|
+
this.state = "end_tag_open";
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (c === 0x3f) {
|
|
95
|
+
this.pos += 1;
|
|
96
|
+
this.state = "bogus_comment";
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (c === 0x25) {
|
|
100
|
+
this.pos += 1;
|
|
101
|
+
this.state = "bogus_comment2";
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (c === 0 || isAlpha(c)) {
|
|
105
|
+
this.state = "tag_name";
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (this.pos === 0) {
|
|
109
|
+
this.state = "data";
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
this.state = "data";
|
|
113
|
+
return this.emit("DATA_TEXT", this.pos - 1, 1);
|
|
114
|
+
}
|
|
115
|
+
case "end_tag_open": {
|
|
116
|
+
if (this.pos >= s.length)
|
|
117
|
+
return false;
|
|
118
|
+
const c = s[this.pos];
|
|
119
|
+
if (c === 0x3e) {
|
|
120
|
+
this.state = "data";
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
if (isAlpha(c)) {
|
|
124
|
+
this.state = "tag_name";
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
this.isClose = false;
|
|
128
|
+
this.state = "bogus_comment";
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
case "tag_name_close": {
|
|
132
|
+
this.isClose = false;
|
|
133
|
+
const start = this.pos;
|
|
134
|
+
this.pos += 1;
|
|
135
|
+
this.state = this.pos < s.length ? "data" : "eof";
|
|
136
|
+
return this.emit("TAG_NAME_CLOSE", start, 1);
|
|
137
|
+
}
|
|
138
|
+
case "tag_name": {
|
|
139
|
+
let p = this.pos;
|
|
140
|
+
while (p < s.length) {
|
|
141
|
+
const c = s[p];
|
|
142
|
+
if (c === 0) {
|
|
143
|
+
p += 1;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (isWhite(c)) {
|
|
147
|
+
const start = this.pos;
|
|
148
|
+
this.pos = p + 1;
|
|
149
|
+
this.state = "before_attribute_name";
|
|
150
|
+
return this.emit("TAG_NAME_OPEN", start, p - start);
|
|
151
|
+
}
|
|
152
|
+
if (c === 0x2f) {
|
|
153
|
+
const start = this.pos;
|
|
154
|
+
this.pos = p + 1;
|
|
155
|
+
this.state = "self_closing_start_tag";
|
|
156
|
+
return this.emit("TAG_NAME_OPEN", start, p - start);
|
|
157
|
+
}
|
|
158
|
+
if (c === 0x3e) {
|
|
159
|
+
const start = this.pos;
|
|
160
|
+
if (this.isClose) {
|
|
161
|
+
this.pos = p + 1;
|
|
162
|
+
this.isClose = false;
|
|
163
|
+
this.state = "data";
|
|
164
|
+
return this.emit("TAG_CLOSE", start, p - start);
|
|
165
|
+
}
|
|
166
|
+
this.pos = p;
|
|
167
|
+
this.state = "tag_name_close";
|
|
168
|
+
return this.emit("TAG_NAME_OPEN", start, p - start);
|
|
169
|
+
}
|
|
170
|
+
p += 1;
|
|
171
|
+
}
|
|
172
|
+
const start = this.pos;
|
|
173
|
+
this.state = "eof";
|
|
174
|
+
return this.emit("TAG_NAME_OPEN", start, s.length - start);
|
|
175
|
+
}
|
|
176
|
+
case "before_attribute_name": {
|
|
177
|
+
const c = this.skipWhite();
|
|
178
|
+
if (c === null)
|
|
179
|
+
return false;
|
|
180
|
+
if (c === 0x2f) {
|
|
181
|
+
this.pos += 1;
|
|
182
|
+
if (this.pos < s.length && s[this.pos] !== 0x3e)
|
|
183
|
+
return null;
|
|
184
|
+
this.state = "self_closing_start_tag";
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
if (c === 0x3e) {
|
|
188
|
+
const start = this.pos;
|
|
189
|
+
this.pos += 1;
|
|
190
|
+
this.state = "data";
|
|
191
|
+
return this.emit("TAG_NAME_CLOSE", start, 1);
|
|
192
|
+
}
|
|
193
|
+
this.state = "attribute_name";
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
case "attribute_name": {
|
|
197
|
+
let p = this.pos + 1;
|
|
198
|
+
while (p < s.length) {
|
|
199
|
+
const c = s[p];
|
|
200
|
+
let ns = null;
|
|
201
|
+
if (c === 0x2f)
|
|
202
|
+
ns = "self_closing_start_tag";
|
|
203
|
+
else if (c === 0x3d)
|
|
204
|
+
ns = "before_attribute_value";
|
|
205
|
+
else if (c === 0x3e)
|
|
206
|
+
ns = "tag_name_close";
|
|
207
|
+
else if (isWhite(c))
|
|
208
|
+
ns = "after_attribute_name";
|
|
209
|
+
if (ns !== null) {
|
|
210
|
+
const start = this.pos;
|
|
211
|
+
this.state = ns;
|
|
212
|
+
this.pos = c === 0x3e ? p : p + 1;
|
|
213
|
+
return this.emit("ATTR_NAME", start, p - start);
|
|
214
|
+
}
|
|
215
|
+
p += 1;
|
|
216
|
+
}
|
|
217
|
+
const start = this.pos;
|
|
218
|
+
this.state = "eof";
|
|
219
|
+
this.pos = s.length;
|
|
220
|
+
return this.emit("ATTR_NAME", start, s.length - start);
|
|
221
|
+
}
|
|
222
|
+
case "after_attribute_name": {
|
|
223
|
+
const c = this.skipWhite();
|
|
224
|
+
if (c === null)
|
|
225
|
+
return false;
|
|
226
|
+
if (c === 0x2f) {
|
|
227
|
+
this.pos += 1;
|
|
228
|
+
this.state = "self_closing_start_tag";
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
if (c === 0x3d) {
|
|
232
|
+
this.pos += 1;
|
|
233
|
+
this.state = "before_attribute_value";
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
if (c === 0x3e) {
|
|
237
|
+
this.state = "tag_name_close";
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
this.state = "attribute_name";
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
case "before_attribute_value": {
|
|
244
|
+
const c = this.skipWhite();
|
|
245
|
+
if (c === null) {
|
|
246
|
+
this.state = "eof";
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if (c === 0x22)
|
|
250
|
+
this.state = "attribute_value_double_quote";
|
|
251
|
+
else if (c === 0x27)
|
|
252
|
+
this.state = "attribute_value_single_quote";
|
|
253
|
+
else if (c === 0x60)
|
|
254
|
+
this.state = "attribute_value_back_quote";
|
|
255
|
+
else
|
|
256
|
+
this.state = "attribute_value_no_quote";
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
case "attribute_value_double_quote":
|
|
260
|
+
return this.attrValueQuote(0x22);
|
|
261
|
+
case "attribute_value_single_quote":
|
|
262
|
+
return this.attrValueQuote(0x27);
|
|
263
|
+
case "attribute_value_back_quote":
|
|
264
|
+
return this.attrValueQuote(0x60);
|
|
265
|
+
case "attribute_value_no_quote": {
|
|
266
|
+
let p = this.pos;
|
|
267
|
+
while (p < s.length) {
|
|
268
|
+
const c = s[p];
|
|
269
|
+
if (isWhite(c)) {
|
|
270
|
+
const start = this.pos;
|
|
271
|
+
this.pos = p + 1;
|
|
272
|
+
this.state = "before_attribute_name";
|
|
273
|
+
return this.emit("ATTR_VALUE", start, p - start);
|
|
274
|
+
}
|
|
275
|
+
if (c === 0x3e) {
|
|
276
|
+
const start = this.pos;
|
|
277
|
+
this.pos = p;
|
|
278
|
+
this.state = "tag_name_close";
|
|
279
|
+
return this.emit("ATTR_VALUE", start, p - start);
|
|
280
|
+
}
|
|
281
|
+
p += 1;
|
|
282
|
+
}
|
|
283
|
+
const start = this.pos;
|
|
284
|
+
this.state = "eof";
|
|
285
|
+
return this.emit("ATTR_VALUE", start, s.length - start);
|
|
286
|
+
}
|
|
287
|
+
case "after_attribute_value_quoted": {
|
|
288
|
+
if (this.pos >= s.length)
|
|
289
|
+
return false;
|
|
290
|
+
const c = s[this.pos];
|
|
291
|
+
if (isWhite(c)) {
|
|
292
|
+
this.pos += 1;
|
|
293
|
+
this.state = "before_attribute_name";
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
if (c === 0x2f) {
|
|
297
|
+
this.pos += 1;
|
|
298
|
+
this.state = "self_closing_start_tag";
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (c === 0x3e) {
|
|
302
|
+
const start = this.pos;
|
|
303
|
+
this.pos += 1;
|
|
304
|
+
this.state = "data";
|
|
305
|
+
return this.emit("TAG_NAME_CLOSE", start, 1);
|
|
306
|
+
}
|
|
307
|
+
this.state = "before_attribute_name";
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
case "self_closing_start_tag": {
|
|
311
|
+
if (this.pos >= s.length)
|
|
312
|
+
return false;
|
|
313
|
+
if (s[this.pos] === 0x3e) {
|
|
314
|
+
const start = Math.max(0, this.pos - 1);
|
|
315
|
+
this.state = "data";
|
|
316
|
+
this.pos += 1;
|
|
317
|
+
return this.emit("TAG_NAME_SELFCLOSE", start, 2);
|
|
318
|
+
}
|
|
319
|
+
this.state = "before_attribute_name";
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
case "bogus_comment": {
|
|
323
|
+
const start = this.pos;
|
|
324
|
+
const idx = s.indexOf(0x3e, this.pos);
|
|
325
|
+
if (idx >= 0) {
|
|
326
|
+
this.pos = idx + 1;
|
|
327
|
+
this.state = "data";
|
|
328
|
+
return this.emit("TAG_COMMENT", start, idx - start);
|
|
329
|
+
}
|
|
330
|
+
this.pos = s.length;
|
|
331
|
+
this.state = "eof";
|
|
332
|
+
return this.emit("TAG_COMMENT", start, s.length - start);
|
|
333
|
+
}
|
|
334
|
+
case "bogus_comment2": {
|
|
335
|
+
const start = this.pos;
|
|
336
|
+
let p = this.pos;
|
|
337
|
+
while (true) {
|
|
338
|
+
const idx = s.indexOf(0x25, p);
|
|
339
|
+
if (idx < 0 || idx + 1 >= s.length)
|
|
340
|
+
break;
|
|
341
|
+
if (s[idx + 1] !== 0x3e) {
|
|
342
|
+
p = idx + 1;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
this.pos = idx + 2;
|
|
346
|
+
this.state = "data";
|
|
347
|
+
return this.emit("TAG_COMMENT", start, idx - start);
|
|
348
|
+
}
|
|
349
|
+
this.pos = s.length;
|
|
350
|
+
this.state = "eof";
|
|
351
|
+
return this.emit("TAG_COMMENT", start, s.length - start);
|
|
352
|
+
}
|
|
353
|
+
case "markup_declaration_open": {
|
|
354
|
+
const rest = s.subarray(Math.min(this.pos, s.length));
|
|
355
|
+
if (rest.length >= 7 && rest.subarray(0, 7).toString("latin1").toUpperCase() === "DOCTYPE") {
|
|
356
|
+
this.state = "doctype";
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
if (rest.length >= 7 && rest.subarray(0, 7).toString("latin1") === "[CDATA[") {
|
|
360
|
+
this.pos += 7;
|
|
361
|
+
this.state = "cdata";
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
if (rest.length >= 2 && rest[0] === 0x2d && rest[1] === 0x2d) {
|
|
365
|
+
this.pos += 2;
|
|
366
|
+
this.state = "comment";
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
this.state = "bogus_comment";
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
case "comment": {
|
|
373
|
+
const start = this.pos;
|
|
374
|
+
let p = this.pos;
|
|
375
|
+
while (true) {
|
|
376
|
+
const idx = s.indexOf(0x2d, p);
|
|
377
|
+
if (idx < 0 || idx + 3 > s.length)
|
|
378
|
+
break;
|
|
379
|
+
let off = 1;
|
|
380
|
+
while (idx + off < s.length && s[idx + off] === 0)
|
|
381
|
+
off += 1;
|
|
382
|
+
if (idx + off >= s.length)
|
|
383
|
+
break;
|
|
384
|
+
const c1 = s[idx + off];
|
|
385
|
+
if (c1 !== 0x2d && c1 !== 0x21) {
|
|
386
|
+
p = idx + 1;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
off += 1;
|
|
390
|
+
if (idx + off >= s.length)
|
|
391
|
+
break;
|
|
392
|
+
if (s[idx + off] !== 0x3e) {
|
|
393
|
+
p = idx + 1;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
off += 1;
|
|
397
|
+
this.pos = idx + off;
|
|
398
|
+
this.state = "data";
|
|
399
|
+
return this.emit("TAG_COMMENT", start, idx - start);
|
|
400
|
+
}
|
|
401
|
+
this.state = "eof";
|
|
402
|
+
return this.emit("TAG_COMMENT", start, s.length - start);
|
|
403
|
+
}
|
|
404
|
+
case "cdata": {
|
|
405
|
+
const start = this.pos;
|
|
406
|
+
const idx = s.indexOf("]]>", this.pos, "latin1");
|
|
407
|
+
if (idx >= 0) {
|
|
408
|
+
this.pos = idx + 3;
|
|
409
|
+
this.state = "data";
|
|
410
|
+
return this.emit("TAG_COMMENT", start, idx - start);
|
|
411
|
+
}
|
|
412
|
+
this.state = "eof";
|
|
413
|
+
return this.emit("TAG_COMMENT", start, s.length - start);
|
|
414
|
+
}
|
|
415
|
+
case "doctype": {
|
|
416
|
+
const start = this.pos;
|
|
417
|
+
const idx = s.indexOf(0x3e, this.pos);
|
|
418
|
+
if (idx >= 0) {
|
|
419
|
+
this.pos = idx + 1;
|
|
420
|
+
this.state = "data";
|
|
421
|
+
return this.emit("DOCTYPE", start, idx - start);
|
|
422
|
+
}
|
|
423
|
+
this.state = "eof";
|
|
424
|
+
return this.emit("DOCTYPE", start, s.length - start);
|
|
425
|
+
}
|
|
426
|
+
default:
|
|
427
|
+
this.state = "eof";
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
attrValueQuote(q) {
|
|
432
|
+
if (this.pos > 0)
|
|
433
|
+
this.pos += 1;
|
|
434
|
+
const idx = this.s.indexOf(q, this.pos);
|
|
435
|
+
if (idx < 0) {
|
|
436
|
+
const start = this.pos;
|
|
437
|
+
this.state = "eof";
|
|
438
|
+
return this.emit("ATTR_VALUE", start, this.s.length - start);
|
|
439
|
+
}
|
|
440
|
+
const start = this.pos;
|
|
441
|
+
const len = idx - start;
|
|
442
|
+
this.state = "after_attribute_value_quoted";
|
|
443
|
+
this.pos += len + 1;
|
|
444
|
+
return this.emit("ATTR_VALUE", start, len);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function eqFoldSkippingNul(aUpper, b, n) {
|
|
448
|
+
let ai = 0;
|
|
449
|
+
let bi = 0;
|
|
450
|
+
let left = n;
|
|
451
|
+
while (left > 0) {
|
|
452
|
+
left -= 1;
|
|
453
|
+
if (bi >= b.length)
|
|
454
|
+
return false;
|
|
455
|
+
const raw = b[bi];
|
|
456
|
+
bi += 1;
|
|
457
|
+
if (raw === 0)
|
|
458
|
+
continue;
|
|
459
|
+
if (ai >= aUpper.length)
|
|
460
|
+
return false;
|
|
461
|
+
const up = raw >= 0x61 && raw <= 0x7a ? raw - 0x20 : raw;
|
|
462
|
+
if (aUpper.charCodeAt(ai) !== up)
|
|
463
|
+
return false;
|
|
464
|
+
ai += 1;
|
|
465
|
+
}
|
|
466
|
+
return ai === aUpper.length;
|
|
467
|
+
}
|
|
468
|
+
function startsWithFold(prefixUpper, buf) {
|
|
469
|
+
let ai = 0;
|
|
470
|
+
for (let i = 0; i < buf.length && ai < prefixUpper.length; i += 1) {
|
|
471
|
+
const raw = buf[i];
|
|
472
|
+
if (raw === 0)
|
|
473
|
+
continue;
|
|
474
|
+
const up = raw >= 0x61 && raw <= 0x7a ? raw - 0x20 : raw;
|
|
475
|
+
if (prefixUpper.charCodeAt(ai) !== up)
|
|
476
|
+
return false;
|
|
477
|
+
ai += 1;
|
|
478
|
+
}
|
|
479
|
+
return ai === prefixUpper.length;
|
|
480
|
+
}
|
|
481
|
+
function decodeCharAt(buf, off) {
|
|
482
|
+
if (off >= buf.length)
|
|
483
|
+
return { ch: -1, consumed: 0 };
|
|
484
|
+
if (buf[off] !== 0x26 || off + 2 >= buf.length)
|
|
485
|
+
return { ch: buf[off], consumed: 1 };
|
|
486
|
+
if (buf[off + 1] !== 0x23)
|
|
487
|
+
return { ch: 0x26, consumed: 1 };
|
|
488
|
+
const isHex = off + 3 < buf.length && (buf[off + 2] === 0x78 || buf[off + 2] === 0x58);
|
|
489
|
+
if (isHex) {
|
|
490
|
+
let val = 0;
|
|
491
|
+
let i = off + 3;
|
|
492
|
+
let digits = 0;
|
|
493
|
+
while (i < buf.length) {
|
|
494
|
+
const c = buf[i];
|
|
495
|
+
if (c === 0x3b)
|
|
496
|
+
return digits > 0 ? { ch: val, consumed: i - off + 1 } : { ch: 0x26, consumed: 1 };
|
|
497
|
+
let d = -1;
|
|
498
|
+
if (c >= 0x30 && c <= 0x39)
|
|
499
|
+
d = c - 0x30;
|
|
500
|
+
else if (c >= 0x61 && c <= 0x66)
|
|
501
|
+
d = c - 0x61 + 10;
|
|
502
|
+
else if (c >= 0x41 && c <= 0x46)
|
|
503
|
+
d = c - 0x41 + 10;
|
|
504
|
+
if (d < 0)
|
|
505
|
+
return digits > 0 ? { ch: val, consumed: i - off } : { ch: 0x26, consumed: 1 };
|
|
506
|
+
val = val * 16 + d;
|
|
507
|
+
digits += 1;
|
|
508
|
+
if (val > 0x1000ff)
|
|
509
|
+
return { ch: 0x26, consumed: 1 };
|
|
510
|
+
i += 1;
|
|
511
|
+
}
|
|
512
|
+
return digits > 0 ? { ch: val, consumed: i - off } : { ch: 0x26, consumed: 1 };
|
|
513
|
+
}
|
|
514
|
+
let val = 0;
|
|
515
|
+
let i = off + 2;
|
|
516
|
+
let digits = 0;
|
|
517
|
+
while (i < buf.length) {
|
|
518
|
+
const c = buf[i];
|
|
519
|
+
if (c === 0x3b)
|
|
520
|
+
return digits > 0 ? { ch: val, consumed: i - off + 1 } : { ch: 0x26, consumed: 1 };
|
|
521
|
+
if (c < 0x30 || c > 0x39)
|
|
522
|
+
return digits > 0 ? { ch: val, consumed: i - off } : { ch: 0x26, consumed: 1 };
|
|
523
|
+
val = val * 10 + (c - 0x30);
|
|
524
|
+
digits += 1;
|
|
525
|
+
if (val > 0x1000ff)
|
|
526
|
+
return { ch: 0x26, consumed: 1 };
|
|
527
|
+
i += 1;
|
|
528
|
+
}
|
|
529
|
+
return digits > 0 ? { ch: val, consumed: i - off } : { ch: 0x26, consumed: 1 };
|
|
530
|
+
}
|
|
531
|
+
function htmlEncodeStartsWith(upperPrefix, buf) {
|
|
532
|
+
let ai = 0;
|
|
533
|
+
let idx = 0;
|
|
534
|
+
let first = true;
|
|
535
|
+
while (idx < buf.length) {
|
|
536
|
+
if (ai === upperPrefix.length)
|
|
537
|
+
return true;
|
|
538
|
+
const dec = decodeCharAt(buf, idx);
|
|
539
|
+
idx += Math.max(dec.consumed, 1);
|
|
540
|
+
let cb = dec.ch;
|
|
541
|
+
if (first && cb <= 32)
|
|
542
|
+
continue;
|
|
543
|
+
first = false;
|
|
544
|
+
if (cb === 0 || cb === 10)
|
|
545
|
+
continue;
|
|
546
|
+
if (cb >= 0x61 && cb <= 0x7a)
|
|
547
|
+
cb -= 0x20;
|
|
548
|
+
if (upperPrefix.charCodeAt(ai) !== cb)
|
|
549
|
+
return false;
|
|
550
|
+
ai += 1;
|
|
551
|
+
}
|
|
552
|
+
return ai === upperPrefix.length;
|
|
553
|
+
}
|
|
554
|
+
export function isBlackTag(buf) {
|
|
555
|
+
if (buf.length < 3)
|
|
556
|
+
return false;
|
|
557
|
+
for (const tag of XSS_BLACK_TAGS) {
|
|
558
|
+
if (eqFoldSkippingNul(tag, buf, buf.length))
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
return startsWithFold("SVG", buf) || startsWithFold("XSL", buf);
|
|
562
|
+
}
|
|
563
|
+
export function blackAttrKind(buf) {
|
|
564
|
+
if (buf.length < 2)
|
|
565
|
+
return 0;
|
|
566
|
+
if (buf.length >= 5) {
|
|
567
|
+
const b0 = buf[0];
|
|
568
|
+
const b1 = buf[1];
|
|
569
|
+
if ((b0 === 0x6f || b0 === 0x4f) && (b1 === 0x6e || b1 === 0x4e)) {
|
|
570
|
+
const tail = buf.subarray(2);
|
|
571
|
+
for (const [name, kind] of XSS_BLACK_EVENTS) {
|
|
572
|
+
const n = Math.min(tail.length, name.length);
|
|
573
|
+
if (eqFoldSkippingNul(name, tail, n))
|
|
574
|
+
return kind;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (eqFoldSkippingNul("XMLNS", buf, 5) || eqFoldSkippingNul("XLINK", buf, 5))
|
|
578
|
+
return 1;
|
|
579
|
+
}
|
|
580
|
+
for (const [name, kind] of XSS_BLACK_ATTRS) {
|
|
581
|
+
if (eqFoldSkippingNul(name, buf, buf.length))
|
|
582
|
+
return kind;
|
|
583
|
+
}
|
|
584
|
+
return 0;
|
|
585
|
+
}
|
|
586
|
+
export function isBlackUrl(buf) {
|
|
587
|
+
let start = 0;
|
|
588
|
+
while (start < buf.length && (buf[start] <= 32 || buf[start] >= 127))
|
|
589
|
+
start += 1;
|
|
590
|
+
const trimmed = buf.subarray(start);
|
|
591
|
+
return (htmlEncodeStartsWith("DATA", trimmed) ||
|
|
592
|
+
htmlEncodeStartsWith("VIEW-SOURCE", trimmed) ||
|
|
593
|
+
htmlEncodeStartsWith("JAVA", trimmed) ||
|
|
594
|
+
htmlEncodeStartsWith("VBSCRIPT", trimmed));
|
|
595
|
+
}
|
|
596
|
+
export function detectXssInContext(input, ctx) {
|
|
597
|
+
const buf = typeof input === "string" ? Buffer.from(input, "latin1") : input;
|
|
598
|
+
const tok = new Html5Tokenizer(buf, ctx);
|
|
599
|
+
let attrKind = 0;
|
|
600
|
+
while (tok.next()) {
|
|
601
|
+
if (tok.tokenType !== "ATTR_VALUE")
|
|
602
|
+
attrKind = 0;
|
|
603
|
+
switch (tok.tokenType) {
|
|
604
|
+
case "DOCTYPE":
|
|
605
|
+
return true;
|
|
606
|
+
case "TAG_NAME_OPEN":
|
|
607
|
+
if (isBlackTag(tok.tokenValue))
|
|
608
|
+
return true;
|
|
609
|
+
break;
|
|
610
|
+
case "ATTR_NAME":
|
|
611
|
+
attrKind = blackAttrKind(tok.tokenValue);
|
|
612
|
+
break;
|
|
613
|
+
case "ATTR_VALUE":
|
|
614
|
+
if (attrKind === 1 || attrKind === 3)
|
|
615
|
+
return true;
|
|
616
|
+
if (attrKind === 2 && isBlackUrl(tok.tokenValue))
|
|
617
|
+
return true;
|
|
618
|
+
if (attrKind === 4 && blackAttrKind(tok.tokenValue) !== 0)
|
|
619
|
+
return true;
|
|
620
|
+
attrKind = 0;
|
|
621
|
+
break;
|
|
622
|
+
case "TAG_COMMENT": {
|
|
623
|
+
const v = tok.tokenValue;
|
|
624
|
+
if (v.includes(0x60))
|
|
625
|
+
return true;
|
|
626
|
+
if (v.length > 3) {
|
|
627
|
+
if (v[0] === 0x5b && (v[1] === 0x69 || v[1] === 0x49) && (v[2] === 0x66 || v[2] === 0x46))
|
|
628
|
+
return true;
|
|
629
|
+
if ((v[0] === 0x78 || v[0] === 0x58) && (v[1] === 0x6d || v[1] === 0x4d) && (v[2] === 0x6c || v[2] === 0x4c)) {
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (v.length > 5 && (eqFoldSkippingNul("IMPORT", v, 6) || eqFoldSkippingNul("ENTITY", v, 6)))
|
|
634
|
+
return true;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
default:
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
export function detectXss(input) {
|
|
644
|
+
const buf = typeof input === "string" ? Buffer.from(input, "latin1") : input;
|
|
645
|
+
if (buf.length === 0)
|
|
646
|
+
return { xss: false, context: null };
|
|
647
|
+
const contexts = ["data", "value_no_quote", "value_single_quote", "value_double_quote", "value_back_quote"];
|
|
648
|
+
for (const ctx of contexts) {
|
|
649
|
+
if (detectXssInContext(buf, ctx))
|
|
650
|
+
return { xss: true, context: ctx };
|
|
651
|
+
}
|
|
652
|
+
return { xss: false, context: null };
|
|
653
|
+
}
|
|
654
|
+
//# sourceMappingURL=lexical-xss.js.map
|