@onlyflows/servicenow-mcp 2.3.0-rc.2 → 2.3.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/CHANGELOG.md +171 -0
- package/README.md +28 -1
- package/dist/field-policy.d.ts +13 -3
- package/dist/field-policy.d.ts.map +1 -1
- package/dist/field-policy.js +316 -23
- package/dist/field-policy.js.map +1 -1
- package/dist/policy-card.d.ts.map +1 -1
- package/dist/policy-card.js +2 -0
- package/dist/policy-card.js.map +1 -1
- package/dist/risky-grants.d.ts +6 -2
- package/dist/risky-grants.d.ts.map +1 -1
- package/dist/risky-grants.js +57 -5
- package/dist/risky-grants.js.map +1 -1
- package/dist/tools/platform-view-contracts.d.ts +2 -2
- package/dist/tools/platform-view-evaluate.d.ts +214 -6
- package/dist/tools/platform-view-evaluate.d.ts.map +1 -1
- package/dist/tools/platform-view-evaluate.js +1337 -10
- package/dist/tools/platform-view-evaluate.js.map +1 -1
- package/dist/update-set-eval/engine.d.ts +29 -0
- package/dist/update-set-eval/engine.d.ts.map +1 -0
- package/dist/update-set-eval/engine.js +405 -0
- package/dist/update-set-eval/engine.js.map +1 -0
- package/dist/update-set-eval/prepare.d.ts +72 -0
- package/dist/update-set-eval/prepare.d.ts.map +1 -0
- package/dist/update-set-eval/prepare.js +216 -0
- package/dist/update-set-eval/prepare.js.map +1 -0
- package/dist/update-set-eval/rules.d.ts +126 -0
- package/dist/update-set-eval/rules.d.ts.map +1 -0
- package/dist/update-set-eval/rules.js +927 -0
- package/dist/update-set-eval/rules.js.map +1 -0
- package/dist/update-set-eval/script-scan.d.ts +65 -0
- package/dist/update-set-eval/script-scan.d.ts.map +1 -0
- package/dist/update-set-eval/script-scan.js +378 -0
- package/dist/update-set-eval/script-scan.js.map +1 -0
- package/dist/update-set-eval/secret-patterns.js +2 -2
- package/dist/update-set-eval/secret-patterns.js.map +1 -1
- package/dist/update-set-eval/types.d.ts +181 -0
- package/dist/update-set-eval/types.d.ts.map +1 -0
- package/dist/update-set-eval/types.js +20 -0
- package/dist/update-set-eval/types.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,927 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The evaluator's 32 rules.
|
|
4
|
+
*
|
|
5
|
+
* Row rules run once per prepared row, and set rules once per call. Every
|
|
6
|
+
* rule reads the shared preparation (the parsed records, tokenized scripts
|
|
7
|
+
* and secret matches) and never rescans payload text. Messages are fixed
|
|
8
|
+
* sentences with no instance text; SEC011's table is a separate field.
|
|
9
|
+
* SEC005 and SEC010 findings carry no field and no line.
|
|
10
|
+
*
|
|
11
|
+
* The rules are heuristics, and a clean result is not an approval. Known limits:
|
|
12
|
+
* - Script rules read only the script elements listed for each table (see
|
|
13
|
+
* `prepare.ts`). Script elsewhere is not examined: `g:evaluate` and other
|
|
14
|
+
* Jelly in UI pages and macros, `javascript:` default values, reference
|
|
15
|
+
* qualifiers and conditions, and Flow Designer inline scripts.
|
|
16
|
+
* - The tokenizer does not parse. Code inside a template literal's `${…}` is
|
|
17
|
+
* part of the literal; a regular expression is told from a division by the
|
|
18
|
+
* token before it, so `{} / eval(x) / 1` hides the call; PERF001 sees only
|
|
19
|
+
* braced loop bodies; PERF002 treats a variable as script-wide.
|
|
20
|
+
* - SEC004 sees `eval(`, `gs.eval(`, `new Function(`, the evaluator classes,
|
|
21
|
+
* unicode-escaped spellings of those names, and bracket access with a
|
|
22
|
+
* constant name (`gs['eval']`). It does not see computed names
|
|
23
|
+
* (`this['ev' + 'al']`) or aliases (`var e = eval; e(x)`).
|
|
24
|
+
* - SEC009 sees `setWorkflow` and `autoSysFields` called with `false`, `0`
|
|
25
|
+
* or `!1`; not with a variable or another falsy expression.
|
|
26
|
+
* - SEC005 scans the decoded text of every element of every record that is
|
|
27
|
+
* not on a credential table: script and non-script fields alike, comments
|
|
28
|
+
* and `${…}` included. It finds what `secret-patterns.ts` matches: a
|
|
29
|
+
* literal assigned to or passed with a credential-named key, credentials in
|
|
30
|
+
* URLs, headers and connection strings, private keys and vendor token
|
|
31
|
+
* shapes. It does not follow a secret through a variable, rebuild a
|
|
32
|
+
* concatenation that does not start with a literal, or decode base64.
|
|
33
|
+
*/
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.SET_RULES = exports.RESOLVED_PROBLEM_STATUS = exports.ROW_RULES = exports.RULE_MESSAGES = exports.RULE_IDS = exports.RULES_VERSION = void 0;
|
|
36
|
+
exports.ruleGroup = ruleGroup;
|
|
37
|
+
exports.callBefore = callBefore;
|
|
38
|
+
exports.duplicateNamesAcrossSets = duplicateNamesAcrossSets;
|
|
39
|
+
const script_scan_js_1 = require("./script-scan.js");
|
|
40
|
+
const prepare_js_1 = require("./prepare.js");
|
|
41
|
+
exports.RULES_VERSION = "1";
|
|
42
|
+
exports.RULE_IDS = Object.freeze([
|
|
43
|
+
"PERF001", "PERF002", "PERF003", "PERF004", "PERF005", "PERF006", "PERF007", "PERF008", "PERF009",
|
|
44
|
+
"SEC001", "SEC002", "SEC003", "SEC004", "SEC005", "SEC006", "SEC007", "SEC008", "SEC009", "SEC010", "SEC011",
|
|
45
|
+
"BP001", "BP002", "BP003", "BP004", "BP005", "BP006", "BP007", "BP008", "BP009", "BP010", "BP011", "BP012",
|
|
46
|
+
]);
|
|
47
|
+
function ruleGroup(id) {
|
|
48
|
+
return id.startsWith("PERF") ? "perf" : id.startsWith("SEC") ? "sec" : "bp";
|
|
49
|
+
}
|
|
50
|
+
/** Fixed messages. None holds instance text: SEC011's table goes in the finding's `table` field. */
|
|
51
|
+
exports.RULE_MESSAGES = Object.freeze({
|
|
52
|
+
PERF001: "A query runs inside a loop over query results (N+1 queries).",
|
|
53
|
+
PERF002: "A GlideRecord query runs with no filter or limit (full-table scan).",
|
|
54
|
+
PERF003: "getRowCount() counts rows by reading them; use GlideAggregate.",
|
|
55
|
+
PERF004: "A business rule runs on every query of its table.",
|
|
56
|
+
PERF004_QUERY: "A business rule runs on every query of its table and itself queries.",
|
|
57
|
+
PERF005: "A client script makes a synchronous server round trip.",
|
|
58
|
+
PERF006: "A business rule that is not async makes an outbound call the user waits on.",
|
|
59
|
+
PERF007: "A business rule calls current.update(), which writes twice and can recurse.",
|
|
60
|
+
PERF008: "A script sleeps or busy-waits, holding a worker.",
|
|
61
|
+
PERF009: "The set has more than 1,000 updates, which slows preview and commit.",
|
|
62
|
+
PERF009_HIGH: "The set has more than 5,000 updates, which slows preview and commit.",
|
|
63
|
+
PERF009_BATCH: "The batch has more than 1,000 updates, which slows preview and commit.",
|
|
64
|
+
PERF009_BATCH_HIGH: "The batch has more than 5,000 updates, which slows preview and commit.",
|
|
65
|
+
SEC001: "An access control rule changes.",
|
|
66
|
+
SEC001_HIGH: "An access control rule is deleted, always grants access, or has no role, condition or script.",
|
|
67
|
+
SEC002: "A role or role containment changes.",
|
|
68
|
+
SEC002_CRITICAL: "A role or role containment change involves an elevated role.",
|
|
69
|
+
SEC003: "A script include is callable from the browser.",
|
|
70
|
+
SEC003_HIGH: "A script include is callable from the browser and its isPublic() returns true.",
|
|
71
|
+
SEC004: "A script evaluates dynamic code.",
|
|
72
|
+
SEC005: "A script or value holds what looks like a credential literal.",
|
|
73
|
+
SEC006: "A system property changes.",
|
|
74
|
+
SEC006_HIGH: "A security-related or password-typed system property changes.",
|
|
75
|
+
SEC007: "A cross-scope access is allowed, or a script include is public across scopes.",
|
|
76
|
+
SEC008: "An unauthenticated entry point is added or changed.",
|
|
77
|
+
SEC009: "A script turns off business rules or system-field updates for its writes.",
|
|
78
|
+
SEC010: "The update carries credentials to the target instance.",
|
|
79
|
+
SEC011: "The update writes a data record, on a table that does not extend sys_metadata, which overwrites data on the target instance.",
|
|
80
|
+
BP001: "The set is the Default update set, which cannot be promoted.",
|
|
81
|
+
BP002: "The set's updates belong to more than one application, or to another application than the set.",
|
|
82
|
+
BP003: "The update deletes a record, which is hard to back out.",
|
|
83
|
+
BP004: "A preview problem is not resolved, so the commit is blocked.",
|
|
84
|
+
BP004_LOCAL: "Another open update set holds the same update; the last writer wins.",
|
|
85
|
+
BP005: "The update changes a baseline record, so upgrades will skip it.",
|
|
86
|
+
BP006: "The set has no description.",
|
|
87
|
+
BP007: "A batch member's state differs from its root's (partial promotion).",
|
|
88
|
+
BP008: "The same update is in more than one set of the batch; the result depends on order.",
|
|
89
|
+
BP009: "The set is empty.",
|
|
90
|
+
BP010: "A script holds a hard-coded sys_id, which differs between instances.",
|
|
91
|
+
BP011: "Server code logs with gs.log, gs.print or console.log.",
|
|
92
|
+
BP012: "The update is marked replace on upgrade.",
|
|
93
|
+
});
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
// Helpers
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
function at(script, token) {
|
|
98
|
+
const t = script.scan.tokens[token];
|
|
99
|
+
const out = {};
|
|
100
|
+
if ((0, prepare_js_1.isFieldName)(script.field))
|
|
101
|
+
out.field = script.field;
|
|
102
|
+
if (t !== undefined)
|
|
103
|
+
out.line = (0, script_scan_js_1.scriptLine)(script.scan, t.start);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function scriptsOf(row, side) {
|
|
107
|
+
return side === undefined ? row.scripts : row.scripts.filter((s) => s.side === side);
|
|
108
|
+
}
|
|
109
|
+
function mainRecord(row) {
|
|
110
|
+
return row.records[0];
|
|
111
|
+
}
|
|
112
|
+
function field(row, name) {
|
|
113
|
+
return mainRecord(row)?.fields.get(name);
|
|
114
|
+
}
|
|
115
|
+
const isTrue = (value) => value?.trim().toLowerCase() === "true";
|
|
116
|
+
const isFalse = (value) => value?.trim().toLowerCase() === "false";
|
|
117
|
+
function isDelete(row) {
|
|
118
|
+
return (row.update.action ?? "").toUpperCase() === "DELETE" || (mainRecord(row)?.action ?? "").toUpperCase() === "DELETE";
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* True when token `k` is `new` followed by one of `classes` and `(`:
|
|
122
|
+
* `new GlideRecord(` or `new sn_ws.RESTMessageV2(`, where the class is the
|
|
123
|
+
* last name before `(`. It reads at most seven tokens.
|
|
124
|
+
*/
|
|
125
|
+
function isNewAt(scan, k, classes) {
|
|
126
|
+
const { tokens } = scan;
|
|
127
|
+
if (tokens[k]?.value !== "new" || tokens[k].kind !== script_scan_js_1.TokenKind.Identifier || k + 2 >= tokens.length)
|
|
128
|
+
return false;
|
|
129
|
+
let j = k + 1;
|
|
130
|
+
while (j + 2 < tokens.length && tokens[j + 1].value === "." && tokens[j + 2].kind === script_scan_js_1.TokenKind.Identifier && j < k + 7)
|
|
131
|
+
j += 2;
|
|
132
|
+
return tokens[j].kind === script_scan_js_1.TokenKind.Identifier && classes.has(tokens[j].value) && tokens[j + 1]?.value === "(";
|
|
133
|
+
}
|
|
134
|
+
/** The first token at or after `from` where `isNewAt` holds, or -1. */
|
|
135
|
+
function findNew(scan, classes, from = 0) {
|
|
136
|
+
for (let k = from; k < scan.tokens.length; k++)
|
|
137
|
+
if (isNewAt(scan, k, classes))
|
|
138
|
+
return k;
|
|
139
|
+
return -1;
|
|
140
|
+
}
|
|
141
|
+
const QUERY_CLASSES = new Set(["GlideRecord", "GlideRecordSecure", "GlideAggregate"]);
|
|
142
|
+
const RECORD_CLASSES = new Set(["GlideRecord", "GlideRecordSecure"]);
|
|
143
|
+
/** Header tokens a loop check reads at most; a longer header is judged on its start. */
|
|
144
|
+
const HEADER_TOKENS = 64;
|
|
145
|
+
function headerHas(scan, header, test) {
|
|
146
|
+
const end = Math.min(scan.match[header], header + HEADER_TOKENS);
|
|
147
|
+
for (let k = header + 1; k < end; k++)
|
|
148
|
+
if (test(k))
|
|
149
|
+
return true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
/** How many qualifying loop bodies hold each token: a difference array, so linear. */
|
|
153
|
+
function loopCover(scan, qualifies) {
|
|
154
|
+
const count = scan.tokens.length;
|
|
155
|
+
const diff = new Int32Array(count + 1);
|
|
156
|
+
for (const loop of scan.loops) {
|
|
157
|
+
if (loop.body < 0 || !qualifies(loop))
|
|
158
|
+
continue;
|
|
159
|
+
diff[loop.body + 1]++;
|
|
160
|
+
diff[scan.match[loop.body]]--;
|
|
161
|
+
}
|
|
162
|
+
let depth = 0;
|
|
163
|
+
for (let k = 0; k < count; k++) {
|
|
164
|
+
depth += diff[k];
|
|
165
|
+
diff[k] = depth;
|
|
166
|
+
}
|
|
167
|
+
return diff;
|
|
168
|
+
}
|
|
169
|
+
const isQueryCall = (scan, k) => scan.tokens[k].kind === script_scan_js_1.TokenKind.Identifier && scan.tokens[k].value === "query" && scan.tokens[k - 1]?.value === "." && scan.tokens[k + 1]?.value === "(";
|
|
170
|
+
/** Names that evaluate code when called through bracket access. */
|
|
171
|
+
const DYNAMIC_CODE_NAMES = new Set(["eval", "GlideEvaluator", "GlideScopedEvaluator"]);
|
|
172
|
+
const RESTRICTING_METHODS = new Set([
|
|
173
|
+
"addQuery", "addEncodedQuery", "addActiveQuery", "addInactiveQuery", "addNullQuery", "addNotNullQuery",
|
|
174
|
+
"addJoinQuery", "addDomainQuery", "setLimit", "chooseWindow", "get",
|
|
175
|
+
]);
|
|
176
|
+
const ELEVATED_ROLES = new Set([
|
|
177
|
+
"admin", "security_admin", "maint", "impersonator", "oauth_admin", "user_admin", "web_service_admin",
|
|
178
|
+
"snc_internal_admin", "credential_admin", "sn_vault_admin",
|
|
179
|
+
]);
|
|
180
|
+
const SECURITY_PROPERTY_PREFIXES = [
|
|
181
|
+
"glide.security.", "glide.authenticate.", "glide.basicauth.", "glide.oauth.", "glide.sso.", "glide.cookies.",
|
|
182
|
+
"glide.login.", "glide.password.", "glide.ui.escape", "glide.html.escape", "glide.xmlhttp.", "glide.sys.restrict",
|
|
183
|
+
"glide.script.block", "glide.http.outbound", "glide.attachment.", "glide.entropy", "glide.ui.session_timeout",
|
|
184
|
+
"glide.ui.attachment", "glide.cors.", "glide.rest.", "com.glide.communications.httpclient",
|
|
185
|
+
];
|
|
186
|
+
/** `g_form` calls that show a field's label or a message: the second argument is text, not a credential. */
|
|
187
|
+
const UI_DISPLAY_CALLS = new Set([
|
|
188
|
+
"showFieldMsg", "hideFieldMsg", "setLabelOf", "getLabelOf", "setMandatory", "setDisplay", "setVisible",
|
|
189
|
+
"setReadOnly", "setReadonly", "setDisabled", "addDecoration", "removeDecoration", "flash", "addInfoMessage",
|
|
190
|
+
"addErrorMessage", "showErrorBox", "hideErrorBox",
|
|
191
|
+
]);
|
|
192
|
+
/** Calls whose argument is a filter: a matched `key=value` is usually a condition, not a credential. */
|
|
193
|
+
const QUERY_CALLS = new Set(["addEncodedQuery", "addQuery", "setEncodedQuery", "addOrCondition", "addCondition"]);
|
|
194
|
+
const isQuote = (c) => c === 39 || c === 34 || c === 96;
|
|
195
|
+
const isSpace = (c) => c === 32 || c === 9 || c === 10 || c === 13;
|
|
196
|
+
const isIdent = (c) => (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 95 || c === 36;
|
|
197
|
+
function backOverSpace(text, from) {
|
|
198
|
+
let i = from;
|
|
199
|
+
const stop = Math.max(-1, from - 16);
|
|
200
|
+
while (i > stop && isSpace(text.charCodeAt(i)))
|
|
201
|
+
i--;
|
|
202
|
+
return i;
|
|
203
|
+
}
|
|
204
|
+
function identBefore(text, end) {
|
|
205
|
+
let i = end;
|
|
206
|
+
const stop = Math.max(-1, end - 64);
|
|
207
|
+
while (i > stop && isIdent(text.charCodeAt(i)))
|
|
208
|
+
i--;
|
|
209
|
+
return text.slice(i + 1, end + 1);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The call a matched value is an argument of: `g_form.setMandatory('password', '…')`
|
|
213
|
+
* or `gr.addEncodedQuery('…key=…')`. Every backward read is bounded, so a
|
|
214
|
+
* check costs a constant; null when the shape is anything else.
|
|
215
|
+
*/
|
|
216
|
+
function callBefore(text, start) {
|
|
217
|
+
let i = start - 1;
|
|
218
|
+
const floor = Math.max(0, start - 1024);
|
|
219
|
+
while (i >= floor) {
|
|
220
|
+
const c = text.charCodeAt(i);
|
|
221
|
+
if (isQuote(c))
|
|
222
|
+
break;
|
|
223
|
+
if (c === 10 || c === 13)
|
|
224
|
+
return null;
|
|
225
|
+
i--;
|
|
226
|
+
}
|
|
227
|
+
if (i < floor || text.charCodeAt(i - 1) === 92)
|
|
228
|
+
return null; // an escaped quote: a nested string
|
|
229
|
+
i = backOverSpace(text, i - 1);
|
|
230
|
+
if (text.charCodeAt(i) === 44) {
|
|
231
|
+
// , a quoted key argument comes first
|
|
232
|
+
i = backOverSpace(text, i - 1);
|
|
233
|
+
const quote = text.charCodeAt(i);
|
|
234
|
+
if (!isQuote(quote))
|
|
235
|
+
return null;
|
|
236
|
+
let j = i - 1;
|
|
237
|
+
const keyFloor = Math.max(0, i - 256);
|
|
238
|
+
while (j >= keyFloor && text.charCodeAt(j) !== quote) {
|
|
239
|
+
if (text.charCodeAt(j) === 10)
|
|
240
|
+
return null;
|
|
241
|
+
j--;
|
|
242
|
+
}
|
|
243
|
+
if (j < keyFloor)
|
|
244
|
+
return null;
|
|
245
|
+
i = backOverSpace(text, j - 1);
|
|
246
|
+
}
|
|
247
|
+
if (text.charCodeAt(i) !== 40)
|
|
248
|
+
return null; // (
|
|
249
|
+
i = backOverSpace(text, i - 1);
|
|
250
|
+
const method = identBefore(text, i);
|
|
251
|
+
if (method.length === 0)
|
|
252
|
+
return null;
|
|
253
|
+
i -= method.length;
|
|
254
|
+
const receiver = text.charCodeAt(i) === 46 ? identBefore(text, i - 1) : "";
|
|
255
|
+
return { receiver, method };
|
|
256
|
+
}
|
|
257
|
+
exports.ROW_RULES = Object.freeze([
|
|
258
|
+
{
|
|
259
|
+
id: "PERF001",
|
|
260
|
+
needs: "payload",
|
|
261
|
+
run(row, _input, emit) {
|
|
262
|
+
for (const script of scriptsOf(row, "server")) {
|
|
263
|
+
const scan = script.scan;
|
|
264
|
+
const cover = loopCover(scan, (loop) => {
|
|
265
|
+
const keyword = scan.tokens[loop.keyword].value;
|
|
266
|
+
if (keyword !== "while")
|
|
267
|
+
return keyword === "for";
|
|
268
|
+
return headerHas(scan, loop.header, (k) => isQueryNext(scan, k));
|
|
269
|
+
});
|
|
270
|
+
for (let k = 0; k < scan.tokens.length; k++) {
|
|
271
|
+
if (cover[k] === 0)
|
|
272
|
+
continue;
|
|
273
|
+
const t = scan.tokens[k];
|
|
274
|
+
const hit = (t.value === "new" && isNewAt(scan, k, QUERY_CLASSES)) || isQueryCall(scan, k);
|
|
275
|
+
if (hit) {
|
|
276
|
+
emit({ rule_id: "PERF001", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.PERF001, ...at(script, k) });
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
id: "PERF002",
|
|
285
|
+
needs: "payload",
|
|
286
|
+
run(row, _input, emit) {
|
|
287
|
+
for (const script of scriptsOf(row, "server")) {
|
|
288
|
+
const { tokens } = script.scan;
|
|
289
|
+
const records = new Set();
|
|
290
|
+
for (let k = 2; k + 1 < tokens.length; k++) {
|
|
291
|
+
if (tokens[k].value === "new" && tokens[k - 1].value === "=" && tokens[k - 2].kind === script_scan_js_1.TokenKind.Identifier) {
|
|
292
|
+
if (isNewAt(script.scan, k, RECORD_CLASSES))
|
|
293
|
+
records.add(tokens[k - 2].value);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (records.size === 0)
|
|
297
|
+
continue;
|
|
298
|
+
const restricted = new Set();
|
|
299
|
+
const queried = new Map();
|
|
300
|
+
for (let k = 2; k + 1 < tokens.length; k++) {
|
|
301
|
+
const name = tokens[k - 2].value;
|
|
302
|
+
if (tokens[k - 1].value !== "." || tokens[k + 1].value !== "(" || !records.has(name))
|
|
303
|
+
continue;
|
|
304
|
+
if (tokens[k - 2].kind !== script_scan_js_1.TokenKind.Identifier)
|
|
305
|
+
continue;
|
|
306
|
+
const method = tokens[k].value;
|
|
307
|
+
if (RESTRICTING_METHODS.has(method))
|
|
308
|
+
restricted.add(name);
|
|
309
|
+
else if (method === "query") {
|
|
310
|
+
// query('field', value) filters too.
|
|
311
|
+
if (tokens[k + 2]?.value !== ")")
|
|
312
|
+
restricted.add(name);
|
|
313
|
+
else if (!queried.has(name))
|
|
314
|
+
queried.set(name, k);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
for (const [name, k] of queried) {
|
|
318
|
+
if (restricted.has(name))
|
|
319
|
+
continue;
|
|
320
|
+
emit({ rule_id: "PERF002", severity: "high", confidence: "medium", message: exports.RULE_MESSAGES.PERF002, ...at(script, k) });
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
id: "PERF003",
|
|
328
|
+
needs: "payload",
|
|
329
|
+
run(row, _input, emit) {
|
|
330
|
+
for (const script of scriptsOf(row, "server")) {
|
|
331
|
+
const k = (0, script_scan_js_1.findMethod)(script.scan, "getRowCount");
|
|
332
|
+
if (k >= 0) {
|
|
333
|
+
emit({ rule_id: "PERF003", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.PERF003, ...at(script, k) });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
id: "PERF004",
|
|
341
|
+
needs: "payload",
|
|
342
|
+
run(row, _input, emit) {
|
|
343
|
+
if (row.table !== "sys_script" || !isTrue(field(row, "action_query")))
|
|
344
|
+
return;
|
|
345
|
+
const queries = scriptsOf(row, "server").some((s) => (0, script_scan_js_1.findMethod)(s.scan, "query") >= 0 || findNew(s.scan, QUERY_CLASSES) >= 0);
|
|
346
|
+
emit({
|
|
347
|
+
rule_id: "PERF004",
|
|
348
|
+
severity: queries ? "high" : "medium",
|
|
349
|
+
confidence: "high",
|
|
350
|
+
message: queries ? exports.RULE_MESSAGES.PERF004_QUERY : exports.RULE_MESSAGES.PERF004,
|
|
351
|
+
});
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
id: "PERF005",
|
|
356
|
+
needs: "payload",
|
|
357
|
+
run(row, _input, emit) {
|
|
358
|
+
for (const script of scriptsOf(row, "client")) {
|
|
359
|
+
const scan = script.scan;
|
|
360
|
+
let k = (0, script_scan_js_1.findMethod)(scan, "getXMLWait");
|
|
361
|
+
if (k < 0)
|
|
362
|
+
k = findNew(scan, RECORD_CLASSES);
|
|
363
|
+
if (k < 0) {
|
|
364
|
+
for (let from = 0;; from = k + 1) {
|
|
365
|
+
k = (0, script_scan_js_1.findCall)(scan, "g_form", "getReference", from);
|
|
366
|
+
if (k < 0 || (0, script_scan_js_1.callArguments)(scan, k + 1).length < 2)
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (k >= 0) {
|
|
371
|
+
emit({ rule_id: "PERF005", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.PERF005, ...at(script, k) });
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
id: "PERF006",
|
|
379
|
+
needs: "payload",
|
|
380
|
+
run(row, _input, emit) {
|
|
381
|
+
if (row.table !== "sys_script")
|
|
382
|
+
return;
|
|
383
|
+
const when = (field(row, "when") ?? "").trim().toLowerCase();
|
|
384
|
+
if (when === "async" || when === "async_always")
|
|
385
|
+
return;
|
|
386
|
+
for (const script of scriptsOf(row, "server")) {
|
|
387
|
+
const outbound = (0, script_scan_js_1.findIdentifier)(script.scan, "RESTMessageV2") >= 0 || (0, script_scan_js_1.findIdentifier)(script.scan, "SOAPMessageV2") >= 0;
|
|
388
|
+
const k = outbound ? (0, script_scan_js_1.findMethod)(script.scan, "execute") : -1;
|
|
389
|
+
if (k >= 0) {
|
|
390
|
+
emit({ rule_id: "PERF006", severity: "medium", confidence: "medium", message: exports.RULE_MESSAGES.PERF006, ...at(script, k) });
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
id: "PERF007",
|
|
398
|
+
needs: "payload",
|
|
399
|
+
run(row, _input, emit) {
|
|
400
|
+
if (row.table !== "sys_script")
|
|
401
|
+
return;
|
|
402
|
+
for (const script of scriptsOf(row, "server")) {
|
|
403
|
+
const k = (0, script_scan_js_1.findCall)(script.scan, "current", "update");
|
|
404
|
+
if (k >= 0) {
|
|
405
|
+
emit({ rule_id: "PERF007", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.PERF007, ...at(script, k) });
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
id: "PERF008",
|
|
413
|
+
needs: "payload",
|
|
414
|
+
run(row, _input, emit) {
|
|
415
|
+
const clock = new Set(["Date", "GlideDateTime", "getNumericValue", "getTime", "nowDateTime"]);
|
|
416
|
+
for (const script of scriptsOf(row)) {
|
|
417
|
+
const scan = script.scan;
|
|
418
|
+
const sleep = (0, script_scan_js_1.findCall)(scan, "gs", "sleep");
|
|
419
|
+
if (sleep >= 0) {
|
|
420
|
+
emit({ rule_id: "PERF008", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.PERF008, ...at(script, sleep) });
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
for (const loop of scan.loops) {
|
|
424
|
+
if (loop.header < 0 || scan.tokens[loop.keyword].value !== "while")
|
|
425
|
+
continue;
|
|
426
|
+
if (headerHas(scan, loop.header, (k) => scan.tokens[k].kind === script_scan_js_1.TokenKind.Identifier && clock.has(scan.tokens[k].value))) {
|
|
427
|
+
emit({ rule_id: "PERF008", severity: "medium", confidence: "low", message: exports.RULE_MESSAGES.PERF008, ...at(script, loop.keyword) });
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
id: "SEC001",
|
|
436
|
+
needs: "metadata",
|
|
437
|
+
run(row, _input, emit) {
|
|
438
|
+
if (row.table !== "sys_security_acl")
|
|
439
|
+
return;
|
|
440
|
+
let high = isDelete(row);
|
|
441
|
+
const confidence = row.payload === "read" ? "high" : "medium";
|
|
442
|
+
if (!high && row.payload === "read") {
|
|
443
|
+
const script = row.scripts.find((s) => s.record === 0 && s.field === "script");
|
|
444
|
+
// The whole script is `answer = true;` (a few tokens), with no condition around it.
|
|
445
|
+
const alwaysTrue = script !== undefined &&
|
|
446
|
+
script.scan.tokens.length <= 6 &&
|
|
447
|
+
script.scan.tokens.filter((t) => t.value !== ";" && t.value !== "var").map((t) => t.value).join(" ") === "answer = true";
|
|
448
|
+
const hasRole = row.records.some((r) => r.table === "sys_security_acl_role");
|
|
449
|
+
const condition = (field(row, "condition") ?? "").trim();
|
|
450
|
+
const advanced = isTrue(field(row, "advanced"));
|
|
451
|
+
const noScript = !advanced || script === undefined;
|
|
452
|
+
high = alwaysTrue || (!hasRole && condition.length === 0 && noScript);
|
|
453
|
+
}
|
|
454
|
+
emit({ rule_id: "SEC001", severity: high ? "high" : "medium", confidence, message: high ? exports.RULE_MESSAGES.SEC001_HIGH : exports.RULE_MESSAGES.SEC001 });
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
id: "SEC002",
|
|
459
|
+
needs: "metadata",
|
|
460
|
+
run(row, _input, emit) {
|
|
461
|
+
const tables = ["sys_user_role", "sys_user_role_contains", "sys_user_has_role", "sys_user_group_has_role"];
|
|
462
|
+
if (row.table === null || !tables.includes(row.table))
|
|
463
|
+
return;
|
|
464
|
+
let elevated = false;
|
|
465
|
+
for (const record of row.records) {
|
|
466
|
+
const names = [record.fields.get("name"), record.displayValues.get("role"), record.displayValues.get("contains")];
|
|
467
|
+
if (names.some((n) => n !== undefined && ELEVATED_ROLES.has(n.trim().toLowerCase())))
|
|
468
|
+
elevated = true;
|
|
469
|
+
if (isTrue(record.fields.get("elevated_privilege")))
|
|
470
|
+
elevated = true;
|
|
471
|
+
}
|
|
472
|
+
emit({
|
|
473
|
+
rule_id: "SEC002",
|
|
474
|
+
severity: elevated ? "critical" : "high",
|
|
475
|
+
confidence: row.payload === "read" ? "high" : "medium",
|
|
476
|
+
message: elevated ? exports.RULE_MESSAGES.SEC002_CRITICAL : exports.RULE_MESSAGES.SEC002,
|
|
477
|
+
});
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
id: "SEC003",
|
|
482
|
+
needs: "payload",
|
|
483
|
+
run(row, _input, emit) {
|
|
484
|
+
if (row.table !== "sys_script_include" || !isTrue(field(row, "client_callable")))
|
|
485
|
+
return;
|
|
486
|
+
let publicTrue = false;
|
|
487
|
+
for (const script of scriptsOf(row, "server")) {
|
|
488
|
+
const { tokens } = script.scan;
|
|
489
|
+
for (let k = 0; k < tokens.length && !publicTrue; k++) {
|
|
490
|
+
if (tokens[k].value !== "isPublic")
|
|
491
|
+
continue;
|
|
492
|
+
publicTrue =
|
|
493
|
+
(0, script_scan_js_1.tokensAre)(script.scan, k + 1, [":", "function", "(", ")", "{", "return", "true"]) ||
|
|
494
|
+
(0, script_scan_js_1.tokensAre)(script.scan, k + 1, ["(", ")", "{", "return", "true"]);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
emit({
|
|
498
|
+
rule_id: "SEC003",
|
|
499
|
+
severity: publicTrue ? "high" : "medium",
|
|
500
|
+
confidence: "high",
|
|
501
|
+
message: publicTrue ? exports.RULE_MESSAGES.SEC003_HIGH : exports.RULE_MESSAGES.SEC003,
|
|
502
|
+
});
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
id: "SEC004",
|
|
507
|
+
needs: "payload",
|
|
508
|
+
run(row, _input, emit) {
|
|
509
|
+
for (const script of scriptsOf(row)) {
|
|
510
|
+
const scan = script.scan;
|
|
511
|
+
const { tokens } = scan;
|
|
512
|
+
for (let k = 0; k < tokens.length; k++) {
|
|
513
|
+
const t = tokens[k];
|
|
514
|
+
if (t.kind !== script_scan_js_1.TokenKind.Identifier && t.kind !== script_scan_js_1.TokenKind.String)
|
|
515
|
+
continue;
|
|
516
|
+
const previous = tokens[k - 1]?.value;
|
|
517
|
+
const hit = t.kind === script_scan_js_1.TokenKind.Identifier &&
|
|
518
|
+
((t.value === "eval" && tokens[k + 1]?.value === "(" && (previous !== "." || tokens[k - 2]?.value === "gs")) ||
|
|
519
|
+
t.value === "GlideEvaluator" ||
|
|
520
|
+
t.value === "GlideScopedEvaluator" ||
|
|
521
|
+
(t.value === "Function" && previous === "new" && tokens[k + 1]?.value === "("));
|
|
522
|
+
// Bracket access with a constant name: gs['eval'](…), this["GlideEvaluator"].
|
|
523
|
+
const bracket = t.kind === script_scan_js_1.TokenKind.String &&
|
|
524
|
+
DYNAMIC_CODE_NAMES.has(t.value) &&
|
|
525
|
+
previous === "[" &&
|
|
526
|
+
tokens[k + 1]?.value === "]";
|
|
527
|
+
if (bracket) {
|
|
528
|
+
emit({ rule_id: "SEC004", severity: "high", confidence: "medium", message: exports.RULE_MESSAGES.SEC004, ...at(script, k) });
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (hit) {
|
|
532
|
+
emit({ rule_id: "SEC004", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.SEC004, ...at(script, k) });
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
id: "SEC005",
|
|
541
|
+
needs: "payload",
|
|
542
|
+
run(row, _input, emit) {
|
|
543
|
+
let real = false;
|
|
544
|
+
let doubtful = false;
|
|
545
|
+
let examined = 0;
|
|
546
|
+
outer: for (const secrets of row.secrets) {
|
|
547
|
+
for (const match of secrets.matches) {
|
|
548
|
+
if (++examined > 64) {
|
|
549
|
+
// Too many to look at each one: report rather than skip.
|
|
550
|
+
real = true;
|
|
551
|
+
break outer;
|
|
552
|
+
}
|
|
553
|
+
const call = callBefore(secrets.text, match.start);
|
|
554
|
+
if (call !== null && call.receiver === "g_form" && UI_DISPLAY_CALLS.has(call.method))
|
|
555
|
+
continue;
|
|
556
|
+
if (call !== null && QUERY_CALLS.has(call.method)) {
|
|
557
|
+
doubtful = true;
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
real = true;
|
|
561
|
+
break outer;
|
|
562
|
+
}
|
|
563
|
+
if (secrets.truncated)
|
|
564
|
+
doubtful = true;
|
|
565
|
+
}
|
|
566
|
+
if (!real && !doubtful)
|
|
567
|
+
return;
|
|
568
|
+
// No field, no line, no text: where a credential sits is information about it.
|
|
569
|
+
emit({
|
|
570
|
+
rule_id: "SEC005",
|
|
571
|
+
severity: real ? "high" : "medium",
|
|
572
|
+
confidence: real ? "high" : "low",
|
|
573
|
+
message: exports.RULE_MESSAGES.SEC005,
|
|
574
|
+
});
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
id: "SEC006",
|
|
579
|
+
needs: "metadata",
|
|
580
|
+
run(row, _input, emit) {
|
|
581
|
+
if (row.table !== "sys_properties")
|
|
582
|
+
return;
|
|
583
|
+
const name = (field(row, "name") ?? row.update.target_name ?? "").trim().toLowerCase();
|
|
584
|
+
const type = (field(row, "type") ?? "").trim().toLowerCase();
|
|
585
|
+
const high = type === "password" || type === "password2" || SECURITY_PROPERTY_PREFIXES.some((p) => name.startsWith(p));
|
|
586
|
+
emit({
|
|
587
|
+
rule_id: "SEC006",
|
|
588
|
+
severity: high ? "high" : "medium",
|
|
589
|
+
confidence: name.length > 0 ? "high" : "medium",
|
|
590
|
+
message: high ? exports.RULE_MESSAGES.SEC006_HIGH : exports.RULE_MESSAGES.SEC006,
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
id: "SEC007",
|
|
596
|
+
needs: "payload",
|
|
597
|
+
run(row, _input, emit) {
|
|
598
|
+
const record = mainRecord(row);
|
|
599
|
+
if (record === undefined)
|
|
600
|
+
return;
|
|
601
|
+
const allowed = (name) => (record.fields.get(name) ?? "").trim().toLowerCase() === "allowed" ||
|
|
602
|
+
(record.displayValues.get(name) ?? "").trim().toLowerCase() === "allowed";
|
|
603
|
+
const hit = ((row.table === "sys_scope_privilege" || row.table === "sys_restricted_caller_access") && allowed("status")) ||
|
|
604
|
+
(row.table === "sys_script_include" && (record.fields.get("access") ?? "").trim() === "public");
|
|
605
|
+
if (hit)
|
|
606
|
+
emit({ rule_id: "SEC007", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.SEC007 });
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
id: "SEC008",
|
|
611
|
+
needs: "payload",
|
|
612
|
+
run(row, _input, emit) {
|
|
613
|
+
const record = mainRecord(row);
|
|
614
|
+
if (record === undefined || isDelete(row))
|
|
615
|
+
return;
|
|
616
|
+
const f = (name) => record.fields.get(name);
|
|
617
|
+
const hit = (row.table === "sys_public" && !isFalse(f("active"))) ||
|
|
618
|
+
(row.table === "sp_page" && isTrue(f("public"))) ||
|
|
619
|
+
(row.table === "sys_ws_operation" && isFalse(f("requires_authentication"))) ||
|
|
620
|
+
(row.table === "sys_processor" && isFalse(f("require_role")));
|
|
621
|
+
if (hit) {
|
|
622
|
+
emit({
|
|
623
|
+
rule_id: "SEC008",
|
|
624
|
+
severity: "high",
|
|
625
|
+
confidence: row.table === "sys_processor" ? "medium" : "high",
|
|
626
|
+
message: exports.RULE_MESSAGES.SEC008,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
id: "SEC009",
|
|
633
|
+
needs: "payload",
|
|
634
|
+
run(row, _input, emit) {
|
|
635
|
+
for (const script of scriptsOf(row, "server")) {
|
|
636
|
+
const { tokens } = script.scan;
|
|
637
|
+
for (let k = 1; k < tokens.length; k++) {
|
|
638
|
+
const name = tokens[k].value;
|
|
639
|
+
if ((name !== "setWorkflow" && name !== "autoSysFields") || tokens[k - 1].value !== ".")
|
|
640
|
+
continue;
|
|
641
|
+
// false, 0 and !1 all turn it off.
|
|
642
|
+
const off = (0, script_scan_js_1.tokensAre)(script.scan, k + 1, ["(", "false", ")"]) ||
|
|
643
|
+
(0, script_scan_js_1.tokensAre)(script.scan, k + 1, ["(", "0", ")"]) ||
|
|
644
|
+
(0, script_scan_js_1.tokensAre)(script.scan, k + 1, ["(", "!", "1", ")"]);
|
|
645
|
+
if (off) {
|
|
646
|
+
emit({ rule_id: "SEC009", severity: "low", confidence: "high", message: exports.RULE_MESSAGES.SEC009, ...at(script, k) });
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
id: "SEC010",
|
|
655
|
+
needs: "metadata",
|
|
656
|
+
run(row, input, emit, notes) {
|
|
657
|
+
const table = row.table;
|
|
658
|
+
if (table === null)
|
|
659
|
+
return;
|
|
660
|
+
const found = () => emit({ rule_id: "SEC010", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.SEC010 });
|
|
661
|
+
if (row.payload === "credential" || input.context.isCredentialTable(table))
|
|
662
|
+
return found();
|
|
663
|
+
if (row.payload !== "read")
|
|
664
|
+
return;
|
|
665
|
+
const record = mainRecord(row);
|
|
666
|
+
if (record === undefined)
|
|
667
|
+
return;
|
|
668
|
+
if (/^sys_(?:rest|soap)_message(?:_fn|_function)?$/u.test(table)) {
|
|
669
|
+
const auth = (record.fields.get("authentication_type") ?? "").trim().toLowerCase();
|
|
670
|
+
if (auth.length > 0 && auth !== "no_authentication" && auth !== "inherit_from_parent")
|
|
671
|
+
return found();
|
|
672
|
+
}
|
|
673
|
+
const hidden = input.context.hiddenFieldNames(table);
|
|
674
|
+
if (hidden === "unavailable") {
|
|
675
|
+
notes.unavailable++;
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
for (const [name, value] of record.fields) {
|
|
679
|
+
if (hidden.has(name) && value.trim().length > 0)
|
|
680
|
+
return found();
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
id: "SEC011",
|
|
686
|
+
needs: "metadata",
|
|
687
|
+
run(row, input, emit, notes) {
|
|
688
|
+
const table = row.table;
|
|
689
|
+
if (table === null || isDelete(row))
|
|
690
|
+
return;
|
|
691
|
+
const metadata = input.context.extendsMetadata(table);
|
|
692
|
+
if (metadata === "unknown") {
|
|
693
|
+
notes.unavailable++;
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (metadata)
|
|
697
|
+
return;
|
|
698
|
+
emit({
|
|
699
|
+
rule_id: "SEC011",
|
|
700
|
+
severity: "medium",
|
|
701
|
+
confidence: "high",
|
|
702
|
+
message: exports.RULE_MESSAGES.SEC011,
|
|
703
|
+
...((0, prepare_js_1.isTableName)(table) ? { table } : {}),
|
|
704
|
+
});
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
id: "BP003",
|
|
709
|
+
needs: "metadata",
|
|
710
|
+
run(row, _input, emit) {
|
|
711
|
+
if (isDelete(row))
|
|
712
|
+
emit({ rule_id: "BP003", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.BP003 });
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
id: "BP004",
|
|
717
|
+
needs: "metadata",
|
|
718
|
+
run(row, input, emit) {
|
|
719
|
+
if (input.source === "remote") {
|
|
720
|
+
const blocking = (input.problems ?? []).some((p) => p.remote_update === row.update.sys_id && !exports.RESOLVED_PROBLEM_STATUS.has((p.status ?? "").trim()));
|
|
721
|
+
if (blocking)
|
|
722
|
+
emit({ rule_id: "BP004", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.BP004 });
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const others = input.open_set_collisions?.get(row.update.name) ?? 0;
|
|
726
|
+
if (others > 0)
|
|
727
|
+
emit({ rule_id: "BP004", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.BP004_LOCAL });
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
id: "BP005",
|
|
732
|
+
needs: "metadata",
|
|
733
|
+
run(row, input, emit, notes) {
|
|
734
|
+
const versions = input.baseline_versions;
|
|
735
|
+
if (versions === undefined)
|
|
736
|
+
return;
|
|
737
|
+
const source = versions.get(row.update.name);
|
|
738
|
+
if (source === undefined)
|
|
739
|
+
notes.unavailable++;
|
|
740
|
+
else if (source === "baseline")
|
|
741
|
+
emit({ rule_id: "BP005", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.BP005 });
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
id: "BP010",
|
|
746
|
+
needs: "payload",
|
|
747
|
+
run(row, _input, emit) {
|
|
748
|
+
for (const script of scriptsOf(row)) {
|
|
749
|
+
const { tokens } = script.scan;
|
|
750
|
+
for (let k = 0; k < tokens.length; k++) {
|
|
751
|
+
const t = tokens[k];
|
|
752
|
+
if (t.kind === script_scan_js_1.TokenKind.String && t.value.length === 32 && /^[0-9a-f]{32}$/iu.test(t.value)) {
|
|
753
|
+
emit({ rule_id: "BP010", severity: "low", confidence: "high", message: exports.RULE_MESSAGES.BP010, ...at(script, k) });
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
id: "BP011",
|
|
762
|
+
needs: "payload",
|
|
763
|
+
run(row, _input, emit) {
|
|
764
|
+
for (const script of scriptsOf(row, "server")) {
|
|
765
|
+
let k = (0, script_scan_js_1.findCall)(script.scan, "gs", "log");
|
|
766
|
+
if (k < 0)
|
|
767
|
+
k = (0, script_scan_js_1.findCall)(script.scan, "gs", "print");
|
|
768
|
+
if (k < 0)
|
|
769
|
+
k = (0, script_scan_js_1.findCall)(script.scan, "console", "log");
|
|
770
|
+
if (k >= 0) {
|
|
771
|
+
emit({ rule_id: "BP011", severity: "low", confidence: "high", message: exports.RULE_MESSAGES.BP011, ...at(script, k) });
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
id: "BP012",
|
|
779
|
+
needs: "metadata",
|
|
780
|
+
run(row, _input, emit) {
|
|
781
|
+
if (row.update.replace_on_upgrade === true) {
|
|
782
|
+
emit({ rule_id: "BP012", severity: "info", confidence: "high", message: exports.RULE_MESSAGES.BP012 });
|
|
783
|
+
}
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
]);
|
|
787
|
+
function isQueryNext(scan, k) {
|
|
788
|
+
const t = scan.tokens[k];
|
|
789
|
+
return t.kind === script_scan_js_1.TokenKind.Identifier && t.value === "next" && scan.tokens[k - 1]?.value === "." && scan.tokens[k + 1]?.value === "(";
|
|
790
|
+
}
|
|
791
|
+
/** Preview-problem statuses that no longer block a commit; anything else, empty included, blocks. */
|
|
792
|
+
exports.RESOLVED_PROBLEM_STATUS = new Set(["ignored", "skipped", "skip_collision"]);
|
|
793
|
+
exports.SET_RULES = Object.freeze([
|
|
794
|
+
{
|
|
795
|
+
id: "PERF009",
|
|
796
|
+
run(input, emit) {
|
|
797
|
+
for (const set of input.sets) {
|
|
798
|
+
if (set.update_count > 5_000)
|
|
799
|
+
emit(set, { rule_id: "PERF009", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.PERF009_HIGH });
|
|
800
|
+
else if (set.update_count > 1_000)
|
|
801
|
+
emit(set, { rule_id: "PERF009", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.PERF009 });
|
|
802
|
+
}
|
|
803
|
+
const root = input.sets.find((s) => s.sys_id === input.batch_root);
|
|
804
|
+
if (root === undefined || input.sets.length < 2 || root.update_count > 1_000)
|
|
805
|
+
return;
|
|
806
|
+
const total = input.sets.reduce((sum, s) => sum + Math.max(0, s.update_count), 0);
|
|
807
|
+
if (total > 5_000)
|
|
808
|
+
emit(root, { rule_id: "PERF009", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.PERF009_BATCH_HIGH });
|
|
809
|
+
else if (total > 1_000)
|
|
810
|
+
emit(root, { rule_id: "PERF009", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.PERF009_BATCH });
|
|
811
|
+
},
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
id: "BP001",
|
|
815
|
+
run(input, emit) {
|
|
816
|
+
for (const set of input.sets) {
|
|
817
|
+
if (set.is_default === true)
|
|
818
|
+
emit(set, { rule_id: "BP001", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.BP001 });
|
|
819
|
+
}
|
|
820
|
+
},
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
id: "BP002",
|
|
824
|
+
run(input, emit) {
|
|
825
|
+
const bySet = new Map();
|
|
826
|
+
for (const update of input.updates) {
|
|
827
|
+
if (typeof update.application !== "string" || update.application.length === 0)
|
|
828
|
+
continue;
|
|
829
|
+
let apps = bySet.get(update.update_set);
|
|
830
|
+
if (apps === undefined)
|
|
831
|
+
bySet.set(update.update_set, (apps = new Set()));
|
|
832
|
+
apps.add(update.application);
|
|
833
|
+
}
|
|
834
|
+
for (const set of input.sets) {
|
|
835
|
+
const apps = bySet.get(set.sys_id);
|
|
836
|
+
if (apps === undefined)
|
|
837
|
+
continue;
|
|
838
|
+
const own = typeof set.application === "string" && set.application.length > 0 ? set.application : null;
|
|
839
|
+
if (apps.size > 1 || (own !== null && !apps.has(own))) {
|
|
840
|
+
emit(set, { rule_id: "BP002", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.BP002 });
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
},
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
id: "BP004",
|
|
847
|
+
run(input, emit, notes) {
|
|
848
|
+
if (input.source === "remote") {
|
|
849
|
+
if (input.problems === undefined) {
|
|
850
|
+
notes.unavailable++;
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
// A blocking problem with no row in scope is reported on the first set.
|
|
854
|
+
const rows = new Set(input.updates.map((u) => u.sys_id));
|
|
855
|
+
const orphan = input.problems.some((p) => !exports.RESOLVED_PROBLEM_STATUS.has((p.status ?? "").trim()) && (typeof p.remote_update !== "string" || !rows.has(p.remote_update)));
|
|
856
|
+
if (orphan && input.sets[0] !== undefined) {
|
|
857
|
+
emit(input.sets[0], { rule_id: "BP004", severity: "high", confidence: "high", message: exports.RULE_MESSAGES.BP004 });
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
else if (input.open_set_collisions === undefined) {
|
|
861
|
+
notes.unavailable++;
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
id: "BP005",
|
|
867
|
+
run(input, _emit, notes) {
|
|
868
|
+
if (input.baseline_versions === undefined)
|
|
869
|
+
notes.unavailable++;
|
|
870
|
+
},
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
id: "BP006",
|
|
874
|
+
run(input, emit) {
|
|
875
|
+
for (const set of input.sets) {
|
|
876
|
+
if (set.has_description === false)
|
|
877
|
+
emit(set, { rule_id: "BP006", severity: "low", confidence: "high", message: exports.RULE_MESSAGES.BP006 });
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
id: "BP007",
|
|
883
|
+
run(input, emit) {
|
|
884
|
+
const root = input.sets.find((s) => s.sys_id === input.batch_root);
|
|
885
|
+
if (root === undefined)
|
|
886
|
+
return;
|
|
887
|
+
const state = (s) => (s.state ?? "").trim().toLowerCase();
|
|
888
|
+
for (const set of input.sets) {
|
|
889
|
+
if (set === root)
|
|
890
|
+
continue;
|
|
891
|
+
const mismatch = (state(set) === "in progress" && state(root) === "complete") || (state(set) === "complete" && state(root) === "in progress");
|
|
892
|
+
if (mismatch)
|
|
893
|
+
emit(set, { rule_id: "BP007", severity: "medium", confidence: "high", message: exports.RULE_MESSAGES.BP007 });
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
id: "BP009",
|
|
899
|
+
run(input, emit) {
|
|
900
|
+
for (const set of input.sets) {
|
|
901
|
+
if (set.update_count === 0)
|
|
902
|
+
emit(set, { rule_id: "BP009", severity: "low", confidence: "high", message: exports.RULE_MESSAGES.BP009 });
|
|
903
|
+
}
|
|
904
|
+
},
|
|
905
|
+
},
|
|
906
|
+
]);
|
|
907
|
+
/**
|
|
908
|
+
* BP008 needs every row of the batch at once: the same update name in more
|
|
909
|
+
* than one set. It reports each row whose name another set also holds.
|
|
910
|
+
*/
|
|
911
|
+
function duplicateNamesAcrossSets(input) {
|
|
912
|
+
if (input.sets.length < 2)
|
|
913
|
+
return new Set();
|
|
914
|
+
const setsByName = new Map();
|
|
915
|
+
for (const update of input.updates) {
|
|
916
|
+
let sets = setsByName.get(update.name);
|
|
917
|
+
if (sets === undefined)
|
|
918
|
+
setsByName.set(update.name, (sets = new Set()));
|
|
919
|
+
sets.add(update.update_set);
|
|
920
|
+
}
|
|
921
|
+
const out = new Set();
|
|
922
|
+
for (const [name, sets] of setsByName)
|
|
923
|
+
if (sets.size > 1)
|
|
924
|
+
out.add(name);
|
|
925
|
+
return out;
|
|
926
|
+
}
|
|
927
|
+
//# sourceMappingURL=rules.js.map
|