@agenticcli/shipguard 0.2.1 → 0.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/LICENSE +91 -0
- package/README.md +4 -0
- package/dist/checksum-manifest.json +7 -0
- package/dist/{chunk-BZWSFLBO.js → chunk-ALFVS2BH.js} +30 -13
- package/dist/chunk-ANTCYKRO.js +2024 -0
- package/dist/chunk-ZGFTTSVM.js +3143 -0
- package/dist/cli.js +88 -25
- package/dist/{config-generator-Q2YTMBZ5.js → config-generator-RMWNQQHW.js} +2 -1
- package/dist/dist-PCVBV5S6.js +74 -0
- package/dist/pro-scanner-K7QKKY4E.js +15 -0
- package/package.json +20 -6
- package/dist/chunk-2N3P2DUE.js +0 -1574
- package/dist/pro-scanner-ER2RYPI5.js +0 -10
|
@@ -0,0 +1,2024 @@
|
|
|
1
|
+
// ../matcher-contract/dist/flags.js
|
|
2
|
+
var REJECTED_CHARS = /* @__PURE__ */ new Set(["g", "y", "u", "x"]);
|
|
3
|
+
function parseFlags(input) {
|
|
4
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5
|
+
for (const ch of input) {
|
|
6
|
+
if (seen.has(ch)) {
|
|
7
|
+
return { ok: false, reason: `Duplicate flag character: "${ch}" (input: "${input}")` };
|
|
8
|
+
}
|
|
9
|
+
seen.add(ch);
|
|
10
|
+
if (REJECTED_CHARS.has(ch)) {
|
|
11
|
+
return {
|
|
12
|
+
ok: false,
|
|
13
|
+
reason: `Unsupported flag: "${ch}" \u2014 only "i", "m", "s" are permitted (got: "${input}")`
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (ch !== "i" && ch !== "m" && ch !== "s") {
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
reason: `Unknown flag character: "${ch}" \u2014 only "i", "m", "s" are permitted (got: "${input}")`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { ok: true, flags: new Set(seen) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ../matcher-contract/dist/canonical.js
|
|
27
|
+
function serializeNumber(n) {
|
|
28
|
+
if (Number.isNaN(n) || !Number.isFinite(n)) {
|
|
29
|
+
throw new TypeError(`canonicalJson: NaN and Infinity are not valid JSON values (got ${n})`);
|
|
30
|
+
}
|
|
31
|
+
if (!Number.isSafeInteger(n) && !Object.is(n, -0)) {
|
|
32
|
+
throw new TypeError(`canonicalJson: number ${n} is not a safe integer \u2014 fractional or out-of-range numbers are rejected in signed objects (LOCKED-SPEC \xA72 / FIX 9). Only safe integers (\u22122^53+1 to 2^53\u22121) are permitted.`);
|
|
33
|
+
}
|
|
34
|
+
if (Object.is(n, -0))
|
|
35
|
+
return "0";
|
|
36
|
+
return String(n);
|
|
37
|
+
}
|
|
38
|
+
function serializeString(s) {
|
|
39
|
+
return JSON.stringify(s);
|
|
40
|
+
}
|
|
41
|
+
function serializeValue(value) {
|
|
42
|
+
if (value === null)
|
|
43
|
+
return "null";
|
|
44
|
+
if (typeof value === "boolean")
|
|
45
|
+
return value ? "true" : "false";
|
|
46
|
+
if (typeof value === "number")
|
|
47
|
+
return serializeNumber(value);
|
|
48
|
+
if (typeof value === "string")
|
|
49
|
+
return serializeString(value);
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
const items = value.map(serializeValue);
|
|
52
|
+
return "[" + items.join(",") + "]";
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === "object") {
|
|
55
|
+
const obj = value;
|
|
56
|
+
const keys = Object.keys(obj).sort((a, b) => {
|
|
57
|
+
if (a < b)
|
|
58
|
+
return -1;
|
|
59
|
+
if (a > b)
|
|
60
|
+
return 1;
|
|
61
|
+
return 0;
|
|
62
|
+
});
|
|
63
|
+
const members = keys.map((k) => serializeString(k) + ":" + serializeValue(obj[k]));
|
|
64
|
+
return "{" + members.join(",") + "}";
|
|
65
|
+
}
|
|
66
|
+
throw new TypeError(`canonicalJson: value of type "${typeof value}" is not representable in JSON`);
|
|
67
|
+
}
|
|
68
|
+
function canonicalJson(value) {
|
|
69
|
+
return serializeValue(value);
|
|
70
|
+
}
|
|
71
|
+
function findDuplicateKey(json) {
|
|
72
|
+
const len = json.length;
|
|
73
|
+
let i = 0;
|
|
74
|
+
let duplicateKey = null;
|
|
75
|
+
function skipWs() {
|
|
76
|
+
while (i < len && (json[i] === " " || json[i] === " " || json[i] === "\n" || json[i] === "\r")) {
|
|
77
|
+
i++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function consumeStr() {
|
|
81
|
+
i++;
|
|
82
|
+
let s = "";
|
|
83
|
+
while (i < len) {
|
|
84
|
+
const c = json[i];
|
|
85
|
+
if (c === "\\") {
|
|
86
|
+
i++;
|
|
87
|
+
const esc = json[i++];
|
|
88
|
+
if (esc === "u") {
|
|
89
|
+
s += String.fromCharCode(parseInt(json.slice(i, i + 4), 16));
|
|
90
|
+
i += 4;
|
|
91
|
+
} else {
|
|
92
|
+
s += esc;
|
|
93
|
+
}
|
|
94
|
+
} else if (c === '"') {
|
|
95
|
+
i++;
|
|
96
|
+
break;
|
|
97
|
+
} else {
|
|
98
|
+
s += c;
|
|
99
|
+
i++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return s;
|
|
103
|
+
}
|
|
104
|
+
function scanValue() {
|
|
105
|
+
skipWs();
|
|
106
|
+
if (i >= len || duplicateKey)
|
|
107
|
+
return;
|
|
108
|
+
const ch = json[i];
|
|
109
|
+
if (ch === '"') {
|
|
110
|
+
consumeStr();
|
|
111
|
+
} else if (ch === "{") {
|
|
112
|
+
i++;
|
|
113
|
+
const scope = /* @__PURE__ */ new Set();
|
|
114
|
+
skipWs();
|
|
115
|
+
if (i < len && json[i] === "}") {
|
|
116
|
+
i++;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
while (i < len) {
|
|
120
|
+
if (duplicateKey)
|
|
121
|
+
return;
|
|
122
|
+
skipWs();
|
|
123
|
+
if (i >= len || json[i] !== '"')
|
|
124
|
+
break;
|
|
125
|
+
const key = consumeStr();
|
|
126
|
+
if (duplicateKey)
|
|
127
|
+
return;
|
|
128
|
+
if (scope.has(key)) {
|
|
129
|
+
duplicateKey = key;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
scope.add(key);
|
|
133
|
+
skipWs();
|
|
134
|
+
if (i < len && json[i] === ":")
|
|
135
|
+
i++;
|
|
136
|
+
scanValue();
|
|
137
|
+
if (duplicateKey)
|
|
138
|
+
return;
|
|
139
|
+
skipWs();
|
|
140
|
+
if (i < len && json[i] === ",") {
|
|
141
|
+
i++;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (i < len && json[i] === "}") {
|
|
145
|
+
i++;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
} else if (ch === "[") {
|
|
151
|
+
i++;
|
|
152
|
+
skipWs();
|
|
153
|
+
if (i < len && json[i] === "]") {
|
|
154
|
+
i++;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
while (i < len) {
|
|
158
|
+
if (duplicateKey)
|
|
159
|
+
return;
|
|
160
|
+
scanValue();
|
|
161
|
+
skipWs();
|
|
162
|
+
if (i < len && json[i] === ",") {
|
|
163
|
+
i++;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (i < len && json[i] === "]") {
|
|
167
|
+
i++;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
while (i < len && json[i] !== "," && json[i] !== "}" && json[i] !== "]" && json[i] !== " " && json[i] !== " " && json[i] !== "\n" && json[i] !== "\r") {
|
|
174
|
+
i++;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
scanValue();
|
|
179
|
+
return duplicateKey;
|
|
180
|
+
}
|
|
181
|
+
function parseStrictNoDup(json) {
|
|
182
|
+
const dup = findDuplicateKey(json);
|
|
183
|
+
if (dup !== null) {
|
|
184
|
+
throw new Error(`Duplicate JSON key "${dup}" \u2014 duplicate object members are rejected (RFC 8785 / parseStrictNoDup)`);
|
|
185
|
+
}
|
|
186
|
+
return JSON.parse(json);
|
|
187
|
+
}
|
|
188
|
+
function canonicalizeFinding(f) {
|
|
189
|
+
return {
|
|
190
|
+
blocking: f.blocking,
|
|
191
|
+
column: f.column,
|
|
192
|
+
evidence: f.evidence,
|
|
193
|
+
file: f.file,
|
|
194
|
+
id: f.id,
|
|
195
|
+
line: f.line,
|
|
196
|
+
matcherType: f.matcherType,
|
|
197
|
+
releaseId: f.releaseId,
|
|
198
|
+
severity: f.severity,
|
|
199
|
+
suppressionState: f.suppressionState
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ../matcher-contract/dist/normalize.js
|
|
204
|
+
var UNICODE_NORMALIZATION_POLICY = "none";
|
|
205
|
+
var hugeSingleLineCap = 10 * 1024 * 1024;
|
|
206
|
+
function decodeUtf8Strict(buf) {
|
|
207
|
+
try {
|
|
208
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
209
|
+
const text = decoder.decode(buf);
|
|
210
|
+
return { ok: true, text };
|
|
211
|
+
} catch (err) {
|
|
212
|
+
const reason = err instanceof Error ? err.message : `Unknown UTF-8 decode error (${String(err)})`;
|
|
213
|
+
return { ok: false, reason };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function stripBom(s) {
|
|
217
|
+
if (s.charCodeAt(0) === 65279) {
|
|
218
|
+
return s.slice(1);
|
|
219
|
+
}
|
|
220
|
+
return s;
|
|
221
|
+
}
|
|
222
|
+
function normalizeNewlines(s) {
|
|
223
|
+
return s.replace(/\r/g, "");
|
|
224
|
+
}
|
|
225
|
+
function detectBinary(buf) {
|
|
226
|
+
if (buf.length === 0)
|
|
227
|
+
return false;
|
|
228
|
+
for (let i = 0; i < buf.length; i++) {
|
|
229
|
+
if (buf[i] === 0)
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
const BINARY_SCAN_WINDOW = 32 * 1024;
|
|
233
|
+
const BINARY_NON_PRINTABLE_THRESHOLD = 0.3;
|
|
234
|
+
const windowLen = Math.min(buf.length, BINARY_SCAN_WINDOW);
|
|
235
|
+
let nonPrintableCount = 0;
|
|
236
|
+
for (let i = 0; i < windowLen; i++) {
|
|
237
|
+
const b = buf[i];
|
|
238
|
+
const isWhitespaceControl = b === 9 || b === 10 || b === 12 || b === 13;
|
|
239
|
+
if (!isWhitespaceControl && b < 32) {
|
|
240
|
+
nonPrintableCount++;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return nonPrintableCount / windowLen > BINARY_NON_PRINTABLE_THRESHOLD;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ../matcher-contract/dist/caps.js
|
|
247
|
+
var DEFAULT_CAPS = {
|
|
248
|
+
maxFiles: 5e4,
|
|
249
|
+
maxTotalBytes: 512 * 1024 * 1024,
|
|
250
|
+
// 512 MiB
|
|
251
|
+
maxRules: 1e3,
|
|
252
|
+
maxPatternsPerRule: 20,
|
|
253
|
+
maxTotalPatternBytes: 10 * 1024 * 1024,
|
|
254
|
+
// 10 MiB total pattern content
|
|
255
|
+
maxFindings: 1e5
|
|
256
|
+
};
|
|
257
|
+
var CapTracker = class {
|
|
258
|
+
caps;
|
|
259
|
+
_fileCount = 0;
|
|
260
|
+
_totalBytes = 0;
|
|
261
|
+
_ruleCount = 0;
|
|
262
|
+
_maxPatternsSeenPerRule = 0;
|
|
263
|
+
_totalPatternBytes = 0;
|
|
264
|
+
_findingCount = 0;
|
|
265
|
+
constructor(caps) {
|
|
266
|
+
this.caps = { ...caps };
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Record that one file has been added to the scan.
|
|
270
|
+
*
|
|
271
|
+
* @param byteLength - The decoded byte length of the file's content
|
|
272
|
+
* (UTF-16 code units × 2, or the raw buffer size — whichever the
|
|
273
|
+
* caller uses consistently).
|
|
274
|
+
*/
|
|
275
|
+
addFile(byteLength) {
|
|
276
|
+
this._fileCount++;
|
|
277
|
+
this._totalBytes += byteLength;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Record that one rule has been added to the active bundle.
|
|
281
|
+
*
|
|
282
|
+
* @param patternCount - The number of patterns in this rule.
|
|
283
|
+
* @param patternBytes - The total byte-length of all pattern strings in this rule.
|
|
284
|
+
*/
|
|
285
|
+
addRule(patternCount, patternBytes) {
|
|
286
|
+
this._ruleCount++;
|
|
287
|
+
if (patternCount > this._maxPatternsSeenPerRule) {
|
|
288
|
+
this._maxPatternsSeenPerRule = patternCount;
|
|
289
|
+
}
|
|
290
|
+
this._totalPatternBytes += patternBytes;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Record that `count` findings have been emitted.
|
|
294
|
+
*
|
|
295
|
+
* @param count - Number of new findings to add to the running total.
|
|
296
|
+
*/
|
|
297
|
+
addFindings(count) {
|
|
298
|
+
this._findingCount += count;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Check whether any cap has been exceeded.
|
|
302
|
+
*
|
|
303
|
+
* Returns the FIRST cap violation found (priority: files → bytes → rules
|
|
304
|
+
* → patternsPerRule → totalPatternBytes → findings), or null if all
|
|
305
|
+
* counts are within limits.
|
|
306
|
+
*
|
|
307
|
+
* This method is pure and side-effect-free (read-only on internal state).
|
|
308
|
+
*/
|
|
309
|
+
capHit() {
|
|
310
|
+
if (this._fileCount > this.caps.maxFiles) {
|
|
311
|
+
return {
|
|
312
|
+
reason: "cap-exceeded",
|
|
313
|
+
detail: `maxFiles exceeded: ${this._fileCount} > ${this.caps.maxFiles}`,
|
|
314
|
+
incomplete: true
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (this._totalBytes > this.caps.maxTotalBytes) {
|
|
318
|
+
return {
|
|
319
|
+
reason: "cap-exceeded",
|
|
320
|
+
detail: `maxTotalBytes exceeded: ${this._totalBytes} > ${this.caps.maxTotalBytes}`,
|
|
321
|
+
incomplete: true
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (this._ruleCount > this.caps.maxRules) {
|
|
325
|
+
return {
|
|
326
|
+
reason: "cap-exceeded",
|
|
327
|
+
detail: `maxRules exceeded: ${this._ruleCount} > ${this.caps.maxRules}`,
|
|
328
|
+
incomplete: true
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
if (this._maxPatternsSeenPerRule > this.caps.maxPatternsPerRule) {
|
|
332
|
+
return {
|
|
333
|
+
reason: "cap-exceeded",
|
|
334
|
+
detail: `maxPatternsPerRule exceeded: ${this._maxPatternsSeenPerRule} > ${this.caps.maxPatternsPerRule}`,
|
|
335
|
+
incomplete: true
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (this._totalPatternBytes > this.caps.maxTotalPatternBytes) {
|
|
339
|
+
return {
|
|
340
|
+
reason: "cap-exceeded",
|
|
341
|
+
detail: `maxTotalPatternBytes exceeded: ${this._totalPatternBytes} > ${this.caps.maxTotalPatternBytes}`,
|
|
342
|
+
incomplete: true
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
if (this._findingCount > this.caps.maxFindings) {
|
|
346
|
+
return {
|
|
347
|
+
reason: "cap-exceeded",
|
|
348
|
+
detail: `maxFindings exceeded: ${this._findingCount} > ${this.caps.maxFindings}`,
|
|
349
|
+
incomplete: true
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
// ---------------------------------------------------------------------------
|
|
355
|
+
// Read-only counters (for diagnostics / logging — NOT for control flow)
|
|
356
|
+
// ---------------------------------------------------------------------------
|
|
357
|
+
get fileCount() {
|
|
358
|
+
return this._fileCount;
|
|
359
|
+
}
|
|
360
|
+
get totalBytes() {
|
|
361
|
+
return this._totalBytes;
|
|
362
|
+
}
|
|
363
|
+
get ruleCount() {
|
|
364
|
+
return this._ruleCount;
|
|
365
|
+
}
|
|
366
|
+
get maxPatternsSeenPerRule() {
|
|
367
|
+
return this._maxPatternsSeenPerRule;
|
|
368
|
+
}
|
|
369
|
+
get totalPatternBytes() {
|
|
370
|
+
return this._totalPatternBytes;
|
|
371
|
+
}
|
|
372
|
+
get findingCount() {
|
|
373
|
+
return this._findingCount;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
// ../matcher-contract/dist/failure.js
|
|
378
|
+
var DegradedReason = {
|
|
379
|
+
/**
|
|
380
|
+
* A rule or anti-pattern failed to compile (e.g. invalid regex syntax
|
|
381
|
+
* that slipped past Gate B/C validation, or a flag rejected at runtime).
|
|
382
|
+
* Config-degraded class → exit 2.
|
|
383
|
+
*/
|
|
384
|
+
"compile-failure": "compile-failure",
|
|
385
|
+
/**
|
|
386
|
+
* The delivered rule bundle or manifest does not match the attested corpus
|
|
387
|
+
* (completeness check, hash mismatch, or multiset inequality).
|
|
388
|
+
* Runtime-error class → exit 3.
|
|
389
|
+
*/
|
|
390
|
+
"bundle-or-manifest-mismatch": "bundle-or-manifest-mismatch",
|
|
391
|
+
/**
|
|
392
|
+
* The bundle response is missing a required corpusAttestation, or the
|
|
393
|
+
* attestation is invalid / signed by the wrong key.
|
|
394
|
+
* Runtime-error class → exit 3.
|
|
395
|
+
*/
|
|
396
|
+
"missing-attestation": "missing-attestation",
|
|
397
|
+
/**
|
|
398
|
+
* An uncaught exception occurred inside the matching engine during a scan.
|
|
399
|
+
* Runtime-error class → exit 3.
|
|
400
|
+
*/
|
|
401
|
+
"engine-exception": "engine-exception",
|
|
402
|
+
/**
|
|
403
|
+
* A file could not be read from disk (permission error, deleted during scan,
|
|
404
|
+
* I/O error). The file is skipped but the scan is marked degraded.
|
|
405
|
+
* Runtime-error class → exit 3.
|
|
406
|
+
*/
|
|
407
|
+
"unreadable-file": "unreadable-file",
|
|
408
|
+
/**
|
|
409
|
+
* A file contained invalid UTF-8 byte sequences. TextDecoder(fatal:true)
|
|
410
|
+
* threw; the file is skipped but the scan is marked degraded to prevent
|
|
411
|
+
* silent false-negatives (secrets straddling an invalid boundary).
|
|
412
|
+
* Runtime-error class → exit 3.
|
|
413
|
+
*/
|
|
414
|
+
"invalid-utf8": "invalid-utf8",
|
|
415
|
+
/**
|
|
416
|
+
* A scan-time cap was exceeded (maxFiles, maxTotalBytes, maxRules,
|
|
417
|
+
* maxPatternsPerRule, maxTotalPatternBytes, or maxFindings).
|
|
418
|
+
* Config-degraded class → exit 2.
|
|
419
|
+
*/
|
|
420
|
+
"cap-exceeded": "cap-exceeded",
|
|
421
|
+
/**
|
|
422
|
+
* A coderef module's checksum does not match the expected value in the
|
|
423
|
+
* checksum manifest. The module is considered tampered and the scan is
|
|
424
|
+
* aborted. Runtime-error class → exit 3.
|
|
425
|
+
*/
|
|
426
|
+
"coderef-mismatch": "coderef-mismatch"
|
|
427
|
+
};
|
|
428
|
+
var CONFIG_DEGRADED_REASONS = /* @__PURE__ */ new Set([
|
|
429
|
+
DegradedReason["compile-failure"],
|
|
430
|
+
DegradedReason["cap-exceeded"]
|
|
431
|
+
]);
|
|
432
|
+
function degradedExitCode(reason) {
|
|
433
|
+
return CONFIG_DEGRADED_REASONS.has(reason) ? 2 : 3;
|
|
434
|
+
}
|
|
435
|
+
function resolveExitCode(outcome, strict) {
|
|
436
|
+
if (strict && outcome.hasBlockingFindings) {
|
|
437
|
+
return 1;
|
|
438
|
+
}
|
|
439
|
+
if (outcome.degraded) {
|
|
440
|
+
if (outcome.degradedReason !== void 0) {
|
|
441
|
+
return degradedExitCode(outcome.degradedReason);
|
|
442
|
+
}
|
|
443
|
+
return 3;
|
|
444
|
+
}
|
|
445
|
+
return 0;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// ../matcher-contract/dist/engine-meta.js
|
|
449
|
+
var RE2JS_VERSION = "2.8.3";
|
|
450
|
+
var SUPPORTED_NODE_VERSIONS = ["20", "22"];
|
|
451
|
+
function makeNativeEngineMeta(nodeVersion) {
|
|
452
|
+
return {
|
|
453
|
+
engine: "native",
|
|
454
|
+
version: nodeVersion,
|
|
455
|
+
options: {
|
|
456
|
+
LOOKBEHINDS: false
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function makeRe2jsEngineMeta(lookbehinds = false) {
|
|
461
|
+
return {
|
|
462
|
+
engine: "re2js",
|
|
463
|
+
version: RE2JS_VERSION,
|
|
464
|
+
options: {
|
|
465
|
+
LOOKBEHINDS: lookbehinds
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// ../matcher-contract/dist/runtime-id.js
|
|
471
|
+
import { createHash } from "crypto";
|
|
472
|
+
var RUNTIME_ID_DOMAIN_PREFIX = "shipguard-runtime-v1\0";
|
|
473
|
+
function computeMatcherRuntimeId(input) {
|
|
474
|
+
const preimageObj = {
|
|
475
|
+
adapterImplHash: input.adapterImplHash,
|
|
476
|
+
buildLock: input.buildLock,
|
|
477
|
+
contractPkgVersion: input.contractVersion,
|
|
478
|
+
// Cast options to Record<string, unknown> for JSON serialisation.
|
|
479
|
+
// EngineOptions only contains JSON-representable boolean fields.
|
|
480
|
+
// Double-cast through unknown to satisfy tsc strict assignment check. (as any WHY: EngineOptions lacks an index signature)
|
|
481
|
+
engineOptions: input.engineMeta.options,
|
|
482
|
+
engineVersion: input.engineMeta.version
|
|
483
|
+
};
|
|
484
|
+
const jcsBytes = canonicalJson(preimageObj);
|
|
485
|
+
const preimage = RUNTIME_ID_DOMAIN_PREFIX + jcsBytes;
|
|
486
|
+
const digest = createHash("sha256").update(preimage, "utf8").digest("hex");
|
|
487
|
+
return digest;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ../matcher-contract/dist/selector.js
|
|
491
|
+
function selectExpected(manifest, request) {
|
|
492
|
+
const requestedFrameworks = new Set(request.frameworks);
|
|
493
|
+
let candidates = manifest.rules.filter((r) => r.enabled);
|
|
494
|
+
candidates = candidates.filter((r) => r.framework === "generic" || requestedFrameworks.has(r.framework));
|
|
495
|
+
const genericById = /* @__PURE__ */ new Map();
|
|
496
|
+
const specificById = /* @__PURE__ */ new Map();
|
|
497
|
+
for (const r of candidates) {
|
|
498
|
+
if (r.framework === "generic") {
|
|
499
|
+
if (!genericById.has(r.id)) {
|
|
500
|
+
genericById.set(r.id, r);
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
if (!specificById.has(r.id)) {
|
|
504
|
+
specificById.set(r.id, r);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const dedupedById = /* @__PURE__ */ new Map();
|
|
509
|
+
for (const [id, r] of genericById) {
|
|
510
|
+
dedupedById.set(id, r);
|
|
511
|
+
}
|
|
512
|
+
for (const [id, r] of specificById) {
|
|
513
|
+
dedupedById.set(id, r);
|
|
514
|
+
}
|
|
515
|
+
candidates = Array.from(dedupedById.values());
|
|
516
|
+
if (request.categories !== void 0 && request.categories.length > 0) {
|
|
517
|
+
const requestedCategories = new Set(request.categories);
|
|
518
|
+
candidates = candidates.filter((r) => {
|
|
519
|
+
if (!r.categories || r.categories.length === 0) {
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
return r.categories.some((c) => requestedCategories.has(c));
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
if (!request.isPro) {
|
|
526
|
+
candidates = candidates.filter((r) => r.tier === "free");
|
|
527
|
+
}
|
|
528
|
+
if (candidates.length > manifest.capProfile.maxRules) {
|
|
529
|
+
throw new Error(`FAIL_INCOMPLETE(rule-count-cap-exceeded): ${candidates.length} candidates exceed maxRules=${manifest.capProfile.maxRules}`);
|
|
530
|
+
}
|
|
531
|
+
const sorted = [...candidates].sort((a, b) => {
|
|
532
|
+
if (a.id < b.id)
|
|
533
|
+
return -1;
|
|
534
|
+
if (a.id > b.id)
|
|
535
|
+
return 1;
|
|
536
|
+
return 0;
|
|
537
|
+
});
|
|
538
|
+
return sorted.map((r) => ({ id: r.id, executableHash: r.executableHash }));
|
|
539
|
+
}
|
|
540
|
+
function verifyExactSet(delivered, expected) {
|
|
541
|
+
const violations = [];
|
|
542
|
+
const deliveredMap = /* @__PURE__ */ new Map();
|
|
543
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
544
|
+
for (const entry of delivered) {
|
|
545
|
+
if (seenIds.has(entry.id)) {
|
|
546
|
+
violations.push({
|
|
547
|
+
type: "duplicate-id",
|
|
548
|
+
ruleId: entry.id,
|
|
549
|
+
detail: `Rule id "${entry.id}" appears more than once in the delivered set`
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
seenIds.add(entry.id);
|
|
553
|
+
deliveredMap.set(entry.id, entry.executableHash);
|
|
554
|
+
}
|
|
555
|
+
const expectedMap = /* @__PURE__ */ new Map();
|
|
556
|
+
for (const e of expected) {
|
|
557
|
+
expectedMap.set(e.id, e.executableHash);
|
|
558
|
+
}
|
|
559
|
+
for (const [id, _hash] of expectedMap) {
|
|
560
|
+
if (!deliveredMap.has(id)) {
|
|
561
|
+
violations.push({
|
|
562
|
+
type: "missing-rule",
|
|
563
|
+
ruleId: id,
|
|
564
|
+
detail: `Expected rule "${id}" was not found in the delivered set`
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
for (const [id, _hash] of deliveredMap) {
|
|
569
|
+
if (!expectedMap.has(id)) {
|
|
570
|
+
violations.push({
|
|
571
|
+
type: "extra-rule",
|
|
572
|
+
ruleId: id,
|
|
573
|
+
detail: `Delivered rule "${id}" was not in the expected set (unknown rule)`
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
for (const [id, deliveredHash] of deliveredMap) {
|
|
578
|
+
const expectedHash = expectedMap.get(id);
|
|
579
|
+
if (expectedHash !== void 0 && deliveredHash !== expectedHash) {
|
|
580
|
+
violations.push({
|
|
581
|
+
type: "hash-mismatch",
|
|
582
|
+
ruleId: id,
|
|
583
|
+
detail: `executableHash mismatch for rule "${id}": expected "${expectedHash}", got "${deliveredHash}"`
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (violations.length > 0) {
|
|
588
|
+
return { ok: false, violations };
|
|
589
|
+
}
|
|
590
|
+
return { ok: true };
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// ../matcher-contract/dist/conformance/vectors.js
|
|
594
|
+
var NORM_VECTOR_INVALID_UTF8 = {
|
|
595
|
+
id: "normalization-1",
|
|
596
|
+
description: "Invalid UTF-8 (lone 0xFF byte) \u2192 decodeUtf8Strict returns ok=false",
|
|
597
|
+
category: "normalization",
|
|
598
|
+
executorDependent: false,
|
|
599
|
+
input: {
|
|
600
|
+
matcher: null,
|
|
601
|
+
relativePath: "src/invalid.ts",
|
|
602
|
+
rawBytes: new Uint8Array([104, 101, 108, 108, 111, 255, 119, 111, 114, 108, 100]),
|
|
603
|
+
releaseId: "test-release"
|
|
604
|
+
},
|
|
605
|
+
expectedFindings: null,
|
|
606
|
+
// normalization test — no findings expected (rejects before scan)
|
|
607
|
+
expectedCanonicalHash: null
|
|
608
|
+
};
|
|
609
|
+
var NORM_VECTOR_CRLF = {
|
|
610
|
+
id: "normalization-2",
|
|
611
|
+
description: "CRLF line endings \u2192 normalizeNewlines strips \\r, producing LF-only content",
|
|
612
|
+
category: "normalization",
|
|
613
|
+
executorDependent: false,
|
|
614
|
+
input: {
|
|
615
|
+
matcher: null,
|
|
616
|
+
relativePath: "src/windows-file.ts",
|
|
617
|
+
rawBytes: new Uint8Array([
|
|
618
|
+
// "line1\r\nline2\r\n" in UTF-8
|
|
619
|
+
108,
|
|
620
|
+
105,
|
|
621
|
+
110,
|
|
622
|
+
101,
|
|
623
|
+
49,
|
|
624
|
+
13,
|
|
625
|
+
10,
|
|
626
|
+
108,
|
|
627
|
+
105,
|
|
628
|
+
110,
|
|
629
|
+
101,
|
|
630
|
+
50,
|
|
631
|
+
13,
|
|
632
|
+
10
|
|
633
|
+
]),
|
|
634
|
+
releaseId: "test-release"
|
|
635
|
+
},
|
|
636
|
+
expectedFindings: null,
|
|
637
|
+
// normalization test — expected normalized content is "line1\nline2\n"
|
|
638
|
+
expectedCanonicalHash: null
|
|
639
|
+
};
|
|
640
|
+
var NORM_VECTOR_BOM = {
|
|
641
|
+
id: "normalization-3",
|
|
642
|
+
description: "UTF-8 BOM (EF BB BF) \u2192 stripBom removes the leading U+FEFF",
|
|
643
|
+
category: "normalization",
|
|
644
|
+
executorDependent: false,
|
|
645
|
+
input: {
|
|
646
|
+
matcher: null,
|
|
647
|
+
relativePath: "src/bom-file.ts",
|
|
648
|
+
rawBytes: new Uint8Array([
|
|
649
|
+
// BOM = EF BB BF, then "hello"
|
|
650
|
+
239,
|
|
651
|
+
187,
|
|
652
|
+
191,
|
|
653
|
+
104,
|
|
654
|
+
101,
|
|
655
|
+
108,
|
|
656
|
+
108,
|
|
657
|
+
111
|
|
658
|
+
]),
|
|
659
|
+
releaseId: "test-release"
|
|
660
|
+
},
|
|
661
|
+
expectedFindings: null,
|
|
662
|
+
// normalization test — expected content is "hello" without BOM
|
|
663
|
+
expectedCanonicalHash: null
|
|
664
|
+
};
|
|
665
|
+
var FLAGS_VECTOR_REJECT_G = {
|
|
666
|
+
id: "flags-1",
|
|
667
|
+
description: 'flags="g" \u2192 parseFlags rejects with ok=false (unsupported flag)',
|
|
668
|
+
category: "flags",
|
|
669
|
+
executorDependent: false,
|
|
670
|
+
input: {
|
|
671
|
+
matcher: {
|
|
672
|
+
type: "pattern",
|
|
673
|
+
fileGlob: "**/*.ts",
|
|
674
|
+
patterns: ["test"],
|
|
675
|
+
antiPatterns: [],
|
|
676
|
+
flags: "g"
|
|
677
|
+
// INVALID — must be rejected
|
|
678
|
+
},
|
|
679
|
+
relativePath: "src/test.ts",
|
|
680
|
+
content: "const test = 1",
|
|
681
|
+
releaseId: "test-release"
|
|
682
|
+
},
|
|
683
|
+
expectedFindings: null,
|
|
684
|
+
// rejection test — no findings expected
|
|
685
|
+
expectedCanonicalHash: null
|
|
686
|
+
};
|
|
687
|
+
var FLAGS_VECTOR_ACCEPT_IMS = {
|
|
688
|
+
id: "flags-2",
|
|
689
|
+
description: 'flags="ims" \u2192 parseFlags accepts all three valid flags',
|
|
690
|
+
category: "flags",
|
|
691
|
+
executorDependent: false,
|
|
692
|
+
input: {
|
|
693
|
+
matcher: {
|
|
694
|
+
type: "pattern",
|
|
695
|
+
fileGlob: "**/*.ts",
|
|
696
|
+
patterns: ["test"],
|
|
697
|
+
antiPatterns: [],
|
|
698
|
+
flags: "ims"
|
|
699
|
+
// valid combination
|
|
700
|
+
},
|
|
701
|
+
relativePath: "src/test.ts",
|
|
702
|
+
content: "const test = 1",
|
|
703
|
+
releaseId: "test-release"
|
|
704
|
+
},
|
|
705
|
+
expectedFindings: null,
|
|
706
|
+
// executor-dependent for actual match result
|
|
707
|
+
expectedCanonicalHash: null
|
|
708
|
+
};
|
|
709
|
+
var CAPS_VECTOR_MAXRULES = {
|
|
710
|
+
id: "caps-1",
|
|
711
|
+
description: "selectExpected throws FAIL_INCOMPLETE when candidates > maxRules",
|
|
712
|
+
category: "caps",
|
|
713
|
+
executorDependent: false,
|
|
714
|
+
input: {
|
|
715
|
+
matcher: null,
|
|
716
|
+
relativePath: "src/test.ts",
|
|
717
|
+
content: "const x = 1",
|
|
718
|
+
releaseId: "test-release"
|
|
719
|
+
},
|
|
720
|
+
expectedFindings: null,
|
|
721
|
+
// cap test — throws before producing findings
|
|
722
|
+
expectedCanonicalHash: null
|
|
723
|
+
};
|
|
724
|
+
var PATTERN_VECTOR_NO_FLAGS = {
|
|
725
|
+
id: "pattern-1",
|
|
726
|
+
description: 'PatternMatcher flags="" \u2014 basic pattern match, no flags',
|
|
727
|
+
category: "pattern",
|
|
728
|
+
executorDependent: true,
|
|
729
|
+
input: {
|
|
730
|
+
matcher: {
|
|
731
|
+
type: "pattern",
|
|
732
|
+
fileGlob: "**/*.ts",
|
|
733
|
+
patterns: ["SECRET_KEY"],
|
|
734
|
+
antiPatterns: [],
|
|
735
|
+
flags: ""
|
|
736
|
+
},
|
|
737
|
+
relativePath: "src/config.ts",
|
|
738
|
+
content: 'const SECRET_KEY = "abc123"\n',
|
|
739
|
+
releaseId: "test-release"
|
|
740
|
+
},
|
|
741
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
742
|
+
expectedFindings: null,
|
|
743
|
+
expectedCanonicalHash: "d2d2b68c73d5fc06343323edac63d306b79f7942cfa9a09d91b322179eea632d"
|
|
744
|
+
};
|
|
745
|
+
var PATTERN_VECTOR_FLAG_I = {
|
|
746
|
+
id: "pattern-2",
|
|
747
|
+
description: 'PatternMatcher flags="i" \u2014 case-insensitive match',
|
|
748
|
+
category: "pattern",
|
|
749
|
+
executorDependent: true,
|
|
750
|
+
input: {
|
|
751
|
+
matcher: {
|
|
752
|
+
type: "pattern",
|
|
753
|
+
fileGlob: "**/*.ts",
|
|
754
|
+
patterns: ["secret_key"],
|
|
755
|
+
antiPatterns: [],
|
|
756
|
+
flags: "i"
|
|
757
|
+
},
|
|
758
|
+
relativePath: "src/config.ts",
|
|
759
|
+
content: 'const SECRET_KEY = "abc123"\n',
|
|
760
|
+
releaseId: "test-release"
|
|
761
|
+
},
|
|
762
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
763
|
+
expectedFindings: null,
|
|
764
|
+
expectedCanonicalHash: "d2d2b68c73d5fc06343323edac63d306b79f7942cfa9a09d91b322179eea632d"
|
|
765
|
+
};
|
|
766
|
+
var PATTERN_VECTOR_FLAG_M = {
|
|
767
|
+
id: "pattern-3",
|
|
768
|
+
description: 'PatternMatcher flags="m" \u2014 multiline anchor match',
|
|
769
|
+
category: "pattern",
|
|
770
|
+
executorDependent: true,
|
|
771
|
+
input: {
|
|
772
|
+
matcher: {
|
|
773
|
+
type: "pattern",
|
|
774
|
+
fileGlob: "**/*.ts",
|
|
775
|
+
patterns: ["^SECRET"],
|
|
776
|
+
antiPatterns: [],
|
|
777
|
+
flags: "m"
|
|
778
|
+
},
|
|
779
|
+
relativePath: "src/config.ts",
|
|
780
|
+
content: 'const x = 1\nSECRET_KEY = "abc"\nconst y = 2\n',
|
|
781
|
+
releaseId: "test-release"
|
|
782
|
+
},
|
|
783
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
784
|
+
expectedFindings: null,
|
|
785
|
+
expectedCanonicalHash: "ea8b323d240ba9fc7db805bce32a343d6cb66294ae1c854732f86e30333c9649"
|
|
786
|
+
};
|
|
787
|
+
var PATTERN_VECTOR_FLAG_S = {
|
|
788
|
+
id: "pattern-4",
|
|
789
|
+
description: 'PatternMatcher flags="s" \u2014 dotAll, pattern spans newlines',
|
|
790
|
+
category: "pattern",
|
|
791
|
+
executorDependent: true,
|
|
792
|
+
input: {
|
|
793
|
+
matcher: {
|
|
794
|
+
type: "pattern",
|
|
795
|
+
fileGlob: "**/*.ts",
|
|
796
|
+
patterns: ["begin.+end"],
|
|
797
|
+
antiPatterns: [],
|
|
798
|
+
flags: "s"
|
|
799
|
+
},
|
|
800
|
+
relativePath: "src/config.ts",
|
|
801
|
+
content: "begin\nsome content\nend\n",
|
|
802
|
+
releaseId: "test-release"
|
|
803
|
+
},
|
|
804
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
805
|
+
expectedFindings: null,
|
|
806
|
+
expectedCanonicalHash: "bcf11d7a3a1611058df0afca8875d528a7f62a8f361084f7788854c079048a05"
|
|
807
|
+
};
|
|
808
|
+
var PATTERN_VECTOR_FLAG_IM = {
|
|
809
|
+
id: "pattern-5",
|
|
810
|
+
description: 'PatternMatcher flags="im" \u2014 case-insensitive multiline',
|
|
811
|
+
category: "pattern",
|
|
812
|
+
executorDependent: true,
|
|
813
|
+
input: {
|
|
814
|
+
matcher: {
|
|
815
|
+
type: "pattern",
|
|
816
|
+
fileGlob: "**/*.ts",
|
|
817
|
+
patterns: ["^secret"],
|
|
818
|
+
antiPatterns: [],
|
|
819
|
+
flags: "im"
|
|
820
|
+
},
|
|
821
|
+
relativePath: "src/config.ts",
|
|
822
|
+
content: 'const x = 1\nSECRET_KEY = "abc"\n',
|
|
823
|
+
releaseId: "test-release"
|
|
824
|
+
},
|
|
825
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
826
|
+
expectedFindings: null,
|
|
827
|
+
expectedCanonicalHash: "ea8b323d240ba9fc7db805bce32a343d6cb66294ae1c854732f86e30333c9649"
|
|
828
|
+
};
|
|
829
|
+
var FILE_PRESENCE_VECTOR = {
|
|
830
|
+
id: "file-presence-1",
|
|
831
|
+
description: "FilePresenceMatcher presenceRule=must-not-exist \u2014 triggers when file exists",
|
|
832
|
+
category: "file-presence",
|
|
833
|
+
executorDependent: true,
|
|
834
|
+
input: {
|
|
835
|
+
matcher: {
|
|
836
|
+
type: "file-presence",
|
|
837
|
+
fileGlob: "**/.env",
|
|
838
|
+
presenceRule: "must-not-exist"
|
|
839
|
+
},
|
|
840
|
+
relativePath: ".env",
|
|
841
|
+
content: "SECRET=abc",
|
|
842
|
+
allRelativePaths: [".env", "src/index.ts"],
|
|
843
|
+
releaseId: "test-release"
|
|
844
|
+
},
|
|
845
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
846
|
+
expectedFindings: null,
|
|
847
|
+
expectedCanonicalHash: "e827fd2dce5bd45b62a211a5b92a783b3d406e0a33be77e98361df5a6f61a3be"
|
|
848
|
+
};
|
|
849
|
+
var ANTI_PATTERN_VECTOR = {
|
|
850
|
+
id: "anti-pattern-1",
|
|
851
|
+
description: "Anti-pattern per-line scoping: safe line suppressed, unsafe line active",
|
|
852
|
+
category: "anti-pattern",
|
|
853
|
+
executorDependent: true,
|
|
854
|
+
input: {
|
|
855
|
+
matcher: {
|
|
856
|
+
type: "pattern",
|
|
857
|
+
fileGlob: "**/*.ts",
|
|
858
|
+
patterns: ["SECRET_KEY"],
|
|
859
|
+
antiPatterns: ["// safe:"],
|
|
860
|
+
flags: ""
|
|
861
|
+
},
|
|
862
|
+
relativePath: "src/mixed.ts",
|
|
863
|
+
// Line 1: safe (anti-pattern matches) → suppressed
|
|
864
|
+
// Line 2: unsafe (no anti-pattern) → active finding
|
|
865
|
+
content: "const x = SECRET_KEY // safe: this is ok\nconst y = SECRET_KEY\n",
|
|
866
|
+
releaseId: "test-release"
|
|
867
|
+
},
|
|
868
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
869
|
+
expectedFindings: null,
|
|
870
|
+
expectedCanonicalHash: "62e6c66067ad113a6efde1e8821d68173d226050b75ebae42a66340f9add3b95"
|
|
871
|
+
};
|
|
872
|
+
var ZERO_WIDTH_VECTOR = {
|
|
873
|
+
id: "zero-width-1",
|
|
874
|
+
description: "Zero-width match: executor advances lastIndex by 1 to prevent infinite loop",
|
|
875
|
+
category: "zero-width",
|
|
876
|
+
executorDependent: true,
|
|
877
|
+
input: {
|
|
878
|
+
matcher: {
|
|
879
|
+
type: "pattern",
|
|
880
|
+
fileGlob: "**/*.ts",
|
|
881
|
+
patterns: ["(?=SECRET)"],
|
|
882
|
+
antiPatterns: [],
|
|
883
|
+
flags: ""
|
|
884
|
+
},
|
|
885
|
+
relativePath: "src/test.ts",
|
|
886
|
+
content: "const SECRET = 1\n",
|
|
887
|
+
releaseId: "test-release"
|
|
888
|
+
},
|
|
889
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
890
|
+
expectedFindings: null,
|
|
891
|
+
expectedCanonicalHash: "3b73dd36f79009f27ec6551c4519fc4166c07008bc62655960b5f4ed9ab12bc3"
|
|
892
|
+
};
|
|
893
|
+
var FILE_RELATIONSHIP_VECTOR = {
|
|
894
|
+
id: "file-relationship-1",
|
|
895
|
+
description: "FileRelationshipMatcher \u2014 companion file must exist alongside primary",
|
|
896
|
+
category: "file-relationship",
|
|
897
|
+
executorDependent: true,
|
|
898
|
+
input: {
|
|
899
|
+
matcher: {
|
|
900
|
+
type: "file-relationship",
|
|
901
|
+
fileGlob: "**/.env",
|
|
902
|
+
context: {
|
|
903
|
+
requiresFile: "**/.env.example"
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
relativePath: ".env",
|
|
907
|
+
content: "SECRET=abc",
|
|
908
|
+
// .env exists but .env.example does NOT — should trigger a finding
|
|
909
|
+
allRelativePaths: [".env", "src/index.ts"],
|
|
910
|
+
releaseId: "test-release"
|
|
911
|
+
},
|
|
912
|
+
// Frozen by Phase B.1 (native-v1 executor, 2026-06-25)
|
|
913
|
+
expectedFindings: null,
|
|
914
|
+
expectedCanonicalHash: "bca83c88305d62652e11e6bc6163841181bd2e0e28c4b94c795cf02f605d41b5"
|
|
915
|
+
};
|
|
916
|
+
var ANTI_PATTERN_SCOPE_FUNCTION_SUPPRESSED = {
|
|
917
|
+
id: "anti-pattern-scope-function-1",
|
|
918
|
+
description: 'antiPatternScope="function": auth-in-body suppresses match on function declaration line',
|
|
919
|
+
category: "anti-pattern",
|
|
920
|
+
executorDependent: true,
|
|
921
|
+
input: {
|
|
922
|
+
matcher: {
|
|
923
|
+
type: "pattern",
|
|
924
|
+
fileGlob: "**/*.ts",
|
|
925
|
+
patterns: ["export async function POST"],
|
|
926
|
+
antiPatterns: ["getServerSession"],
|
|
927
|
+
flags: "",
|
|
928
|
+
antiPatternScope: "function"
|
|
929
|
+
},
|
|
930
|
+
relativePath: "src/app/api/route.ts",
|
|
931
|
+
content: [
|
|
932
|
+
"export async function POST(req: Request) {",
|
|
933
|
+
" const body = await req.json()",
|
|
934
|
+
" const session = await getServerSession(authOptions)",
|
|
935
|
+
' if (!session) return Response.json({error:"Unauthorized"},{status:401})',
|
|
936
|
+
" return Response.json({ ok: true })",
|
|
937
|
+
"}"
|
|
938
|
+
].join("\n") + "\n",
|
|
939
|
+
releaseId: "test-release"
|
|
940
|
+
},
|
|
941
|
+
expectedFindings: null,
|
|
942
|
+
expectedCanonicalHash: "f671c66d296f554c889f7563aa285fdc8ededf7e113ed91b0265ea2b808c377a"
|
|
943
|
+
};
|
|
944
|
+
var ANTI_PATTERN_SCOPE_FILE_SUPPRESSED = {
|
|
945
|
+
id: "anti-pattern-scope-file-1",
|
|
946
|
+
description: 'antiPatternScope="file": import at line 1 suppresses match at line 40',
|
|
947
|
+
category: "anti-pattern",
|
|
948
|
+
executorDependent: true,
|
|
949
|
+
input: {
|
|
950
|
+
matcher: {
|
|
951
|
+
type: "pattern",
|
|
952
|
+
fileGlob: "**/*.ts",
|
|
953
|
+
patterns: ["userInput"],
|
|
954
|
+
antiPatterns: ["import.*sanitize"],
|
|
955
|
+
flags: "",
|
|
956
|
+
antiPatternScope: "file"
|
|
957
|
+
},
|
|
958
|
+
relativePath: "src/handler.ts",
|
|
959
|
+
content: (() => {
|
|
960
|
+
const ls = ['import { sanitize } from "./sanitize"'];
|
|
961
|
+
for (let i = 2; i <= 39; i++)
|
|
962
|
+
ls.push(`// line ${i}`);
|
|
963
|
+
ls.push("const result = sanitize(userInput)");
|
|
964
|
+
return ls.join("\n") + "\n";
|
|
965
|
+
})(),
|
|
966
|
+
releaseId: "test-release"
|
|
967
|
+
},
|
|
968
|
+
expectedFindings: null,
|
|
969
|
+
expectedCanonicalHash: "5c8f008880f0828156ed1ae1bdd28c14aaa2645cbef39e26c3e6c9e194877582"
|
|
970
|
+
};
|
|
971
|
+
var ANTI_PATTERN_SCOPE_LINES0_ACTIVE = {
|
|
972
|
+
id: "anti-pattern-scope-lines0-1",
|
|
973
|
+
description: "antiPatternScope={lines:0}: anti-pattern on adjacent line does NOT suppress",
|
|
974
|
+
category: "anti-pattern",
|
|
975
|
+
executorDependent: true,
|
|
976
|
+
input: {
|
|
977
|
+
matcher: {
|
|
978
|
+
type: "pattern",
|
|
979
|
+
fileGlob: "**/*.ts",
|
|
980
|
+
patterns: ["SECRET"],
|
|
981
|
+
antiPatterns: ["validate"],
|
|
982
|
+
flags: "",
|
|
983
|
+
antiPatternScope: { lines: 0 }
|
|
984
|
+
},
|
|
985
|
+
relativePath: "src/test.ts",
|
|
986
|
+
content: "const SECRET = getValue()\nconst check = validate()\n",
|
|
987
|
+
releaseId: "test-release"
|
|
988
|
+
},
|
|
989
|
+
expectedFindings: null,
|
|
990
|
+
expectedCanonicalHash: "9354567a60d370bd25a3578cc236917540f9c6a608dde03d2c2bec015f88f39a"
|
|
991
|
+
};
|
|
992
|
+
var ANTI_PATTERN_SCOPE_STATEMENT_SUPPRESSED = {
|
|
993
|
+
id: "anti-pattern-scope-statement-1",
|
|
994
|
+
description: 'antiPatternScope="statement" (default): cookie option on next line suppresses match',
|
|
995
|
+
category: "anti-pattern",
|
|
996
|
+
executorDependent: true,
|
|
997
|
+
input: {
|
|
998
|
+
matcher: {
|
|
999
|
+
type: "pattern",
|
|
1000
|
+
fileGlob: "**/*.ts",
|
|
1001
|
+
patterns: ["setCookie"],
|
|
1002
|
+
antiPatterns: ["httpOnly"],
|
|
1003
|
+
flags: ""
|
|
1004
|
+
// no antiPatternScope → defaults to "statement"
|
|
1005
|
+
},
|
|
1006
|
+
relativePath: "src/middleware.ts",
|
|
1007
|
+
content: [
|
|
1008
|
+
"setCookie(name, value, {",
|
|
1009
|
+
" httpOnly: true,",
|
|
1010
|
+
" secure: true,",
|
|
1011
|
+
"})"
|
|
1012
|
+
].join("\n") + "\n",
|
|
1013
|
+
releaseId: "test-release"
|
|
1014
|
+
},
|
|
1015
|
+
expectedFindings: null,
|
|
1016
|
+
expectedCanonicalHash: "d893dbebdc1ca35b703871d7e9482d9ce36a6cd348c5ebe2e2e8e03ce73df8db"
|
|
1017
|
+
};
|
|
1018
|
+
var executorIndependentVectors = [
|
|
1019
|
+
NORM_VECTOR_INVALID_UTF8,
|
|
1020
|
+
NORM_VECTOR_CRLF,
|
|
1021
|
+
NORM_VECTOR_BOM,
|
|
1022
|
+
FLAGS_VECTOR_REJECT_G,
|
|
1023
|
+
FLAGS_VECTOR_ACCEPT_IMS,
|
|
1024
|
+
CAPS_VECTOR_MAXRULES
|
|
1025
|
+
];
|
|
1026
|
+
var executorDependentVectors = [
|
|
1027
|
+
PATTERN_VECTOR_NO_FLAGS,
|
|
1028
|
+
PATTERN_VECTOR_FLAG_I,
|
|
1029
|
+
PATTERN_VECTOR_FLAG_M,
|
|
1030
|
+
PATTERN_VECTOR_FLAG_S,
|
|
1031
|
+
PATTERN_VECTOR_FLAG_IM,
|
|
1032
|
+
FILE_PRESENCE_VECTOR,
|
|
1033
|
+
ANTI_PATTERN_VECTOR,
|
|
1034
|
+
ZERO_WIDTH_VECTOR,
|
|
1035
|
+
FILE_RELATIONSHIP_VECTOR,
|
|
1036
|
+
ANTI_PATTERN_SCOPE_FUNCTION_SUPPRESSED,
|
|
1037
|
+
ANTI_PATTERN_SCOPE_FILE_SUPPRESSED,
|
|
1038
|
+
ANTI_PATTERN_SCOPE_LINES0_ACTIVE,
|
|
1039
|
+
ANTI_PATTERN_SCOPE_STATEMENT_SUPPRESSED
|
|
1040
|
+
];
|
|
1041
|
+
var allConformanceVectors = [
|
|
1042
|
+
...executorIndependentVectors,
|
|
1043
|
+
...executorDependentVectors
|
|
1044
|
+
];
|
|
1045
|
+
|
|
1046
|
+
// ../matcher-contract/dist/conformance/harness.js
|
|
1047
|
+
import { createHash as createHash2 } from "crypto";
|
|
1048
|
+
function hashFindingSet(findings) {
|
|
1049
|
+
const canonicalForms = findings.map((f) => canonicalJson(canonicalizeFinding(f))).sort();
|
|
1050
|
+
const setJson = "[" + canonicalForms.join(",") + "]";
|
|
1051
|
+
return createHash2("sha256").update(setJson, "utf8").digest("hex");
|
|
1052
|
+
}
|
|
1053
|
+
function runIndependentVector(vector) {
|
|
1054
|
+
const base = { vectorId: vector.id, computedHash: null, expectedHash: null, computedFindings: null };
|
|
1055
|
+
switch (vector.category) {
|
|
1056
|
+
case "normalization": {
|
|
1057
|
+
const rawBytes = vector.input.rawBytes;
|
|
1058
|
+
if (!rawBytes) {
|
|
1059
|
+
return { ...base, status: "fail", detail: "normalization vector missing rawBytes" };
|
|
1060
|
+
}
|
|
1061
|
+
const decodeResult = decodeUtf8Strict(rawBytes);
|
|
1062
|
+
if (vector.id === "normalization-1") {
|
|
1063
|
+
if (decodeResult.ok) {
|
|
1064
|
+
return { ...base, status: "fail", detail: "Expected decodeUtf8Strict to fail on invalid UTF-8 but it succeeded" };
|
|
1065
|
+
}
|
|
1066
|
+
return { ...base, status: "pass", detail: `decodeUtf8Strict correctly rejected invalid UTF-8: ${decodeResult.reason}` };
|
|
1067
|
+
}
|
|
1068
|
+
if (vector.id === "normalization-2") {
|
|
1069
|
+
if (!decodeResult.ok) {
|
|
1070
|
+
return { ...base, status: "fail", detail: `Unexpected UTF-8 decode failure: ${decodeResult.reason}` };
|
|
1071
|
+
}
|
|
1072
|
+
const normalized = normalizeNewlines(decodeResult.text);
|
|
1073
|
+
if (normalized.includes("\r")) {
|
|
1074
|
+
return { ...base, status: "fail", detail: "normalizeNewlines failed: \\r still present in output" };
|
|
1075
|
+
}
|
|
1076
|
+
if (normalized !== "line1\nline2\n") {
|
|
1077
|
+
return { ...base, status: "fail", detail: `Expected "line1\\nline2\\n" but got: ${JSON.stringify(normalized)}` };
|
|
1078
|
+
}
|
|
1079
|
+
return { ...base, status: "pass", detail: "CRLF normalized to LF correctly" };
|
|
1080
|
+
}
|
|
1081
|
+
if (vector.id === "normalization-3") {
|
|
1082
|
+
if (!decodeResult.ok) {
|
|
1083
|
+
return { ...base, status: "fail", detail: `Unexpected UTF-8 decode failure: ${decodeResult.reason}` };
|
|
1084
|
+
}
|
|
1085
|
+
const stripped = stripBom(decodeResult.text);
|
|
1086
|
+
if (stripped.charCodeAt(0) === 65279) {
|
|
1087
|
+
return { ...base, status: "fail", detail: "stripBom failed: BOM still present at position 0" };
|
|
1088
|
+
}
|
|
1089
|
+
if (stripped !== "hello") {
|
|
1090
|
+
return { ...base, status: "fail", detail: `Expected "hello" after BOM strip but got: ${JSON.stringify(stripped)}` };
|
|
1091
|
+
}
|
|
1092
|
+
return { ...base, status: "pass", detail: 'BOM stripped correctly, content is "hello"' };
|
|
1093
|
+
}
|
|
1094
|
+
return { ...base, status: "fail", detail: `Unknown normalization vector id: ${vector.id}` };
|
|
1095
|
+
}
|
|
1096
|
+
case "flags": {
|
|
1097
|
+
const matcher = vector.input.matcher;
|
|
1098
|
+
if (!matcher) {
|
|
1099
|
+
return { ...base, status: "fail", detail: "flags vector missing matcher" };
|
|
1100
|
+
}
|
|
1101
|
+
const result = parseFlags(matcher.flags);
|
|
1102
|
+
if (vector.id === "flags-1") {
|
|
1103
|
+
if (result.ok) {
|
|
1104
|
+
return { ...base, status: "fail", detail: `Expected parseFlags("g") to fail but got ok=true` };
|
|
1105
|
+
}
|
|
1106
|
+
return { ...base, status: "pass", detail: `parseFlags("g") correctly rejected: ${result.reason}` };
|
|
1107
|
+
}
|
|
1108
|
+
if (vector.id === "flags-2") {
|
|
1109
|
+
if (!result.ok) {
|
|
1110
|
+
return { ...base, status: "fail", detail: `Expected parseFlags("ims") to succeed but got: ${result.reason}` };
|
|
1111
|
+
}
|
|
1112
|
+
if (!result.flags.has("i") || !result.flags.has("m") || !result.flags.has("s")) {
|
|
1113
|
+
return { ...base, status: "fail", detail: `parseFlags("ims") succeeded but missing expected flags: ${JSON.stringify([...result.flags])}` };
|
|
1114
|
+
}
|
|
1115
|
+
return { ...base, status: "pass", detail: 'parseFlags("ims") correctly accepted all three flags' };
|
|
1116
|
+
}
|
|
1117
|
+
return { ...base, status: "fail", detail: `Unknown flags vector id: ${vector.id}` };
|
|
1118
|
+
}
|
|
1119
|
+
case "caps": {
|
|
1120
|
+
if (vector.id === "caps-1") {
|
|
1121
|
+
return { ...base, status: "pass", detail: "caps-1: cap enforcement verified in selector.test.ts (selectExpected throws on maxRules exceeded)" };
|
|
1122
|
+
}
|
|
1123
|
+
return { ...base, status: "fail", detail: `Unknown caps vector id: ${vector.id}` };
|
|
1124
|
+
}
|
|
1125
|
+
default:
|
|
1126
|
+
return { ...base, status: "fail", detail: `Unhandled executor-independent category: ${vector.category}` };
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
function runConformance(executor, vectors) {
|
|
1130
|
+
const results = [];
|
|
1131
|
+
for (const vector of vectors) {
|
|
1132
|
+
if (!vector.executorDependent) {
|
|
1133
|
+
results.push(runIndependentVector(vector));
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
if (executor === null) {
|
|
1137
|
+
results.push({
|
|
1138
|
+
vectorId: vector.id,
|
|
1139
|
+
status: "skip",
|
|
1140
|
+
detail: "Executor-dependent vector skipped: no executor provided (Phase B/D will run this)",
|
|
1141
|
+
computedHash: null,
|
|
1142
|
+
expectedHash: vector.expectedCanonicalHash,
|
|
1143
|
+
computedFindings: null
|
|
1144
|
+
});
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
const input = vector.input;
|
|
1148
|
+
if (!input.matcher) {
|
|
1149
|
+
results.push({
|
|
1150
|
+
vectorId: vector.id,
|
|
1151
|
+
status: "fail",
|
|
1152
|
+
detail: "executor-dependent vector has no matcher",
|
|
1153
|
+
computedHash: null,
|
|
1154
|
+
expectedHash: vector.expectedCanonicalHash,
|
|
1155
|
+
computedFindings: null
|
|
1156
|
+
});
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
1159
|
+
let computedFindings = [];
|
|
1160
|
+
let execError = null;
|
|
1161
|
+
try {
|
|
1162
|
+
const ctx = {
|
|
1163
|
+
allRelativePaths: input.allRelativePaths ?? [input.relativePath],
|
|
1164
|
+
releaseId: input.releaseId
|
|
1165
|
+
};
|
|
1166
|
+
computedFindings = executor.evaluate(input.matcher, { relativePath: input.relativePath, content: input.content ?? "" }, ctx);
|
|
1167
|
+
} catch (err) {
|
|
1168
|
+
execError = err instanceof Error ? err.message : String(err);
|
|
1169
|
+
}
|
|
1170
|
+
if (execError !== null) {
|
|
1171
|
+
results.push({
|
|
1172
|
+
vectorId: vector.id,
|
|
1173
|
+
status: "fail",
|
|
1174
|
+
detail: `Executor threw: ${execError}`,
|
|
1175
|
+
computedHash: null,
|
|
1176
|
+
expectedHash: vector.expectedCanonicalHash,
|
|
1177
|
+
computedFindings: null
|
|
1178
|
+
});
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
const computedHash = hashFindingSet(computedFindings);
|
|
1182
|
+
if (vector.expectedCanonicalHash === null) {
|
|
1183
|
+
results.push({
|
|
1184
|
+
vectorId: vector.id,
|
|
1185
|
+
status: "hash-recorded",
|
|
1186
|
+
detail: `Hash recorded (not yet frozen): ${computedHash}`,
|
|
1187
|
+
computedHash,
|
|
1188
|
+
expectedHash: null,
|
|
1189
|
+
computedFindings
|
|
1190
|
+
});
|
|
1191
|
+
} else if (computedHash === vector.expectedCanonicalHash) {
|
|
1192
|
+
results.push({
|
|
1193
|
+
vectorId: vector.id,
|
|
1194
|
+
status: "hash-frozen",
|
|
1195
|
+
detail: `Canonical hash matches frozen value: ${computedHash}`,
|
|
1196
|
+
computedHash,
|
|
1197
|
+
expectedHash: vector.expectedCanonicalHash,
|
|
1198
|
+
computedFindings
|
|
1199
|
+
});
|
|
1200
|
+
} else {
|
|
1201
|
+
results.push({
|
|
1202
|
+
vectorId: vector.id,
|
|
1203
|
+
status: "fail",
|
|
1204
|
+
detail: `Canonical hash mismatch: expected ${vector.expectedCanonicalHash}, got ${computedHash}`,
|
|
1205
|
+
computedHash,
|
|
1206
|
+
expectedHash: vector.expectedCanonicalHash,
|
|
1207
|
+
computedFindings
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
const passed = results.filter((r) => r.status === "pass" || r.status === "hash-frozen").length;
|
|
1212
|
+
const failed = results.filter((r) => r.status === "fail").length;
|
|
1213
|
+
const skipped = results.filter((r) => r.status === "skip").length;
|
|
1214
|
+
const recorded = results.filter((r) => r.status === "hash-recorded").length;
|
|
1215
|
+
return {
|
|
1216
|
+
totalVectors: vectors.length,
|
|
1217
|
+
passed,
|
|
1218
|
+
failed,
|
|
1219
|
+
skipped,
|
|
1220
|
+
recorded,
|
|
1221
|
+
results
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// ../matcher-contract/dist/adapters/native-v1.js
|
|
1226
|
+
function lineCol(content, offset) {
|
|
1227
|
+
let line = 1;
|
|
1228
|
+
let lastNl = -1;
|
|
1229
|
+
for (let i = 0; i < offset; i++) {
|
|
1230
|
+
if (content[i] === "\n") {
|
|
1231
|
+
line++;
|
|
1232
|
+
lastNl = i;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return { line, column: offset - lastNl };
|
|
1236
|
+
}
|
|
1237
|
+
function resolveAntiPatternWindow(lines, matchLine, scope) {
|
|
1238
|
+
const totalLines = lines.length;
|
|
1239
|
+
if (scope === "file") {
|
|
1240
|
+
return { startLine: 1, endLine: totalLines };
|
|
1241
|
+
}
|
|
1242
|
+
if (typeof scope === "object" && "lines" in scope) {
|
|
1243
|
+
const n = scope.lines;
|
|
1244
|
+
return {
|
|
1245
|
+
startLine: Math.max(1, matchLine - n),
|
|
1246
|
+
endLine: Math.min(totalLines, matchLine + n)
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
if (scope === "statement") {
|
|
1250
|
+
const matchLineText = lines[matchLine - 1] ?? "";
|
|
1251
|
+
const matchLineParenNet = (matchLineText.match(/\(/g) ?? []).length - (matchLineText.match(/\)/g) ?? []).length;
|
|
1252
|
+
if (matchLineParenNet <= 0) {
|
|
1253
|
+
return { startLine: matchLine, endLine: matchLine };
|
|
1254
|
+
}
|
|
1255
|
+
let balance = (matchLineText.match(/[{(]/g) ?? []).length - (matchLineText.match(/[})]/g) ?? []).length;
|
|
1256
|
+
let endLine = matchLine;
|
|
1257
|
+
for (let i = matchLine + 1; i <= totalLines; i++) {
|
|
1258
|
+
const l = lines[i - 1];
|
|
1259
|
+
const opens = (l.match(/[{(]/g) ?? []).length;
|
|
1260
|
+
const closes = (l.match(/[})]/g) ?? []).length;
|
|
1261
|
+
balance += opens - closes;
|
|
1262
|
+
endLine = i;
|
|
1263
|
+
if (balance <= 0)
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
return { startLine: matchLine, endLine };
|
|
1267
|
+
}
|
|
1268
|
+
if (scope === "block") {
|
|
1269
|
+
let balance = 0;
|
|
1270
|
+
let blockStart = matchLine;
|
|
1271
|
+
for (let i = matchLine; i >= 1; i--) {
|
|
1272
|
+
const l = lines[i - 1];
|
|
1273
|
+
const opens = (l.match(/\{/g) ?? []).length;
|
|
1274
|
+
const closes = (l.match(/\}/g) ?? []).length;
|
|
1275
|
+
balance += closes - opens;
|
|
1276
|
+
if (balance < 0) {
|
|
1277
|
+
blockStart = i;
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
balance = 0;
|
|
1282
|
+
let blockEnd = matchLine;
|
|
1283
|
+
for (let i = blockStart; i <= totalLines; i++) {
|
|
1284
|
+
const l = lines[i - 1];
|
|
1285
|
+
const opens = (l.match(/\{/g) ?? []).length;
|
|
1286
|
+
const closes = (l.match(/\}/g) ?? []).length;
|
|
1287
|
+
balance += opens - closes;
|
|
1288
|
+
blockEnd = i;
|
|
1289
|
+
if (balance <= 0)
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
return { startLine: blockStart, endLine: blockEnd };
|
|
1293
|
+
}
|
|
1294
|
+
if (scope === "function") {
|
|
1295
|
+
const FUNC_RE = /\bfunction\b|=>|\bdef\b/;
|
|
1296
|
+
let funcStart = matchLine;
|
|
1297
|
+
for (let i = matchLine; i >= 1; i--) {
|
|
1298
|
+
const l = lines[i - 1];
|
|
1299
|
+
if (FUNC_RE.test(l)) {
|
|
1300
|
+
funcStart = i;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
let balance = 0;
|
|
1305
|
+
let funcEnd = matchLine;
|
|
1306
|
+
for (let i = funcStart; i <= totalLines; i++) {
|
|
1307
|
+
const l = lines[i - 1];
|
|
1308
|
+
const opens = (l.match(/\{/g) ?? []).length;
|
|
1309
|
+
const closes = (l.match(/\}/g) ?? []).length;
|
|
1310
|
+
balance += opens - closes;
|
|
1311
|
+
funcEnd = i;
|
|
1312
|
+
if (balance <= 0 && i > funcStart)
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
return { startLine: funcStart, endLine: funcEnd };
|
|
1316
|
+
}
|
|
1317
|
+
return { startLine: matchLine, endLine: matchLine };
|
|
1318
|
+
}
|
|
1319
|
+
function isTokenChar(ch) {
|
|
1320
|
+
if (ch.length === 0)
|
|
1321
|
+
return false;
|
|
1322
|
+
const c = ch.charCodeAt(0);
|
|
1323
|
+
return c >= 65 && c <= 90 || // A-Z
|
|
1324
|
+
c >= 97 && c <= 122 || // a-z
|
|
1325
|
+
c >= 48 && c <= 57 || // 0-9
|
|
1326
|
+
c === 95 || // _
|
|
1327
|
+
c === 45;
|
|
1328
|
+
}
|
|
1329
|
+
function isWordChar(ch) {
|
|
1330
|
+
if (ch.length === 0)
|
|
1331
|
+
return false;
|
|
1332
|
+
const c = ch.charCodeAt(0);
|
|
1333
|
+
return c >= 65 && c <= 90 || // A-Z
|
|
1334
|
+
c >= 97 && c <= 122 || // a-z
|
|
1335
|
+
c >= 48 && c <= 57 || // 0-9
|
|
1336
|
+
c === 95;
|
|
1337
|
+
}
|
|
1338
|
+
function stubId(matcherType) {
|
|
1339
|
+
switch (matcherType) {
|
|
1340
|
+
case "pattern":
|
|
1341
|
+
return "rule:pattern";
|
|
1342
|
+
case "file-presence":
|
|
1343
|
+
return "rule:file-presence";
|
|
1344
|
+
case "file-relationship":
|
|
1345
|
+
return "rule:file-relationship";
|
|
1346
|
+
default:
|
|
1347
|
+
return "rule:unknown";
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
var STUB_SEVERITY = "medium";
|
|
1351
|
+
var STUB_BLOCKING = false;
|
|
1352
|
+
function globToRegExp(glob) {
|
|
1353
|
+
let regexStr = "^";
|
|
1354
|
+
let i = 0;
|
|
1355
|
+
while (i < glob.length) {
|
|
1356
|
+
if (glob[i] === "*" && glob[i + 1] === "*") {
|
|
1357
|
+
regexStr += ".*";
|
|
1358
|
+
i += 2;
|
|
1359
|
+
if (glob[i] === "/")
|
|
1360
|
+
i++;
|
|
1361
|
+
} else if (glob[i] === "*") {
|
|
1362
|
+
regexStr += "[^/]*";
|
|
1363
|
+
i++;
|
|
1364
|
+
} else if (glob[i] === ".") {
|
|
1365
|
+
regexStr += "\\.";
|
|
1366
|
+
i++;
|
|
1367
|
+
} else {
|
|
1368
|
+
const ch = glob[i];
|
|
1369
|
+
if (/[+?^${}()|[\]\\]/.test(ch)) {
|
|
1370
|
+
regexStr += "\\" + ch;
|
|
1371
|
+
} else {
|
|
1372
|
+
regexStr += ch;
|
|
1373
|
+
}
|
|
1374
|
+
i++;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
regexStr += "$";
|
|
1378
|
+
return new RegExp(regexStr);
|
|
1379
|
+
}
|
|
1380
|
+
function evaluatePattern(matcher, file, ctx) {
|
|
1381
|
+
const flagsResult = parseFlags(matcher.flags);
|
|
1382
|
+
if (!flagsResult.ok) {
|
|
1383
|
+
return [];
|
|
1384
|
+
}
|
|
1385
|
+
const internalFlagsStr = [...flagsResult.flags].join("") + "g";
|
|
1386
|
+
const findings = [];
|
|
1387
|
+
const id = stubId("pattern");
|
|
1388
|
+
const boundary = matcher.boundary ?? "none";
|
|
1389
|
+
for (const patternStr of matcher.patterns) {
|
|
1390
|
+
let re;
|
|
1391
|
+
try {
|
|
1392
|
+
re = new RegExp(patternStr, internalFlagsStr);
|
|
1393
|
+
} catch {
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
let match;
|
|
1397
|
+
while ((match = re.exec(file.content)) !== null) {
|
|
1398
|
+
const matchStart = match.index;
|
|
1399
|
+
const matchEnd = matchStart + match[0].length;
|
|
1400
|
+
if (match[0].length === 0) {
|
|
1401
|
+
re.lastIndex = matchStart + 1;
|
|
1402
|
+
}
|
|
1403
|
+
if (boundary !== "none") {
|
|
1404
|
+
const nextChar = matchEnd < file.content.length ? file.content[matchEnd] : "";
|
|
1405
|
+
if (boundary === "token" && isTokenChar(nextChar)) {
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
if (boundary === "word" && isWordChar(nextChar)) {
|
|
1409
|
+
continue;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
const { line, column } = lineCol(file.content, matchStart);
|
|
1413
|
+
let suppressionState = "active";
|
|
1414
|
+
if (matcher.antiPatterns.length > 0) {
|
|
1415
|
+
const scope = matcher.antiPatternScope ?? "statement";
|
|
1416
|
+
const allLines = file.content.split("\n");
|
|
1417
|
+
const { startLine, endLine } = resolveAntiPatternWindow(allLines, line, scope);
|
|
1418
|
+
const windowText = allLines.slice(startLine - 1, endLine).join("\n");
|
|
1419
|
+
for (const antiStr of matcher.antiPatterns) {
|
|
1420
|
+
let antiRe;
|
|
1421
|
+
try {
|
|
1422
|
+
antiRe = new RegExp(antiStr, [...flagsResult.flags].join(""));
|
|
1423
|
+
} catch {
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
if (antiRe.test(windowText)) {
|
|
1427
|
+
suppressionState = "suppressed";
|
|
1428
|
+
break;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
findings.push({
|
|
1433
|
+
id,
|
|
1434
|
+
file: file.relativePath,
|
|
1435
|
+
line,
|
|
1436
|
+
column,
|
|
1437
|
+
evidence: match[0],
|
|
1438
|
+
severity: STUB_SEVERITY,
|
|
1439
|
+
blocking: STUB_BLOCKING,
|
|
1440
|
+
suppressionState,
|
|
1441
|
+
releaseId: ctx.releaseId,
|
|
1442
|
+
matcherType: "pattern"
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
return findings;
|
|
1447
|
+
}
|
|
1448
|
+
function evaluateFilePresence(matcher, file, ctx) {
|
|
1449
|
+
if (matcher.presenceRule === "must-not-exist") {
|
|
1450
|
+
return [
|
|
1451
|
+
{
|
|
1452
|
+
id: stubId("file-presence"),
|
|
1453
|
+
file: file.relativePath,
|
|
1454
|
+
line: 1,
|
|
1455
|
+
column: 1,
|
|
1456
|
+
evidence: file.relativePath,
|
|
1457
|
+
severity: STUB_SEVERITY,
|
|
1458
|
+
blocking: STUB_BLOCKING,
|
|
1459
|
+
suppressionState: "active",
|
|
1460
|
+
releaseId: ctx.releaseId,
|
|
1461
|
+
matcherType: "file-presence"
|
|
1462
|
+
}
|
|
1463
|
+
];
|
|
1464
|
+
}
|
|
1465
|
+
return [];
|
|
1466
|
+
}
|
|
1467
|
+
function evaluateFileRelationship(matcher, file, ctx) {
|
|
1468
|
+
const { requiresFile, requiresPattern } = matcher.context;
|
|
1469
|
+
if (requiresFile !== void 0) {
|
|
1470
|
+
const globRe = globToRegExp(requiresFile);
|
|
1471
|
+
const found = ctx.allRelativePaths.some((p) => globRe.test(p));
|
|
1472
|
+
if (!found) {
|
|
1473
|
+
return [
|
|
1474
|
+
{
|
|
1475
|
+
id: stubId("file-relationship"),
|
|
1476
|
+
file: file.relativePath,
|
|
1477
|
+
line: 1,
|
|
1478
|
+
column: 1,
|
|
1479
|
+
evidence: file.relativePath,
|
|
1480
|
+
severity: STUB_SEVERITY,
|
|
1481
|
+
blocking: STUB_BLOCKING,
|
|
1482
|
+
suppressionState: "active",
|
|
1483
|
+
releaseId: ctx.releaseId,
|
|
1484
|
+
matcherType: "file-relationship"
|
|
1485
|
+
}
|
|
1486
|
+
];
|
|
1487
|
+
}
|
|
1488
|
+
if (requiresPattern === void 0) {
|
|
1489
|
+
return [];
|
|
1490
|
+
}
|
|
1491
|
+
return [
|
|
1492
|
+
{
|
|
1493
|
+
id: stubId("file-relationship"),
|
|
1494
|
+
file: file.relativePath,
|
|
1495
|
+
line: 1,
|
|
1496
|
+
column: 1,
|
|
1497
|
+
evidence: `${file.relativePath} + requiresPattern "${requiresPattern}" (companion content unavailable \u2014 fail closed)`,
|
|
1498
|
+
severity: STUB_SEVERITY,
|
|
1499
|
+
blocking: STUB_BLOCKING,
|
|
1500
|
+
suppressionState: "active",
|
|
1501
|
+
releaseId: ctx.releaseId,
|
|
1502
|
+
matcherType: "file-relationship"
|
|
1503
|
+
}
|
|
1504
|
+
];
|
|
1505
|
+
}
|
|
1506
|
+
return [
|
|
1507
|
+
{
|
|
1508
|
+
id: stubId("file-relationship"),
|
|
1509
|
+
file: file.relativePath,
|
|
1510
|
+
line: 1,
|
|
1511
|
+
column: 1,
|
|
1512
|
+
evidence: `requiresPattern "${requiresPattern}" (file content unavailable \u2014 fail closed)`,
|
|
1513
|
+
severity: STUB_SEVERITY,
|
|
1514
|
+
blocking: STUB_BLOCKING,
|
|
1515
|
+
suppressionState: "active",
|
|
1516
|
+
releaseId: ctx.releaseId,
|
|
1517
|
+
matcherType: "file-relationship"
|
|
1518
|
+
}
|
|
1519
|
+
];
|
|
1520
|
+
}
|
|
1521
|
+
var nativeV1Executor = {
|
|
1522
|
+
evaluate(matcher, file, ctx) {
|
|
1523
|
+
const fileView = {
|
|
1524
|
+
relativePath: file.relativePath,
|
|
1525
|
+
content: file.content
|
|
1526
|
+
};
|
|
1527
|
+
switch (matcher.type) {
|
|
1528
|
+
case "pattern":
|
|
1529
|
+
return evaluatePattern(matcher, fileView, ctx);
|
|
1530
|
+
case "file-presence":
|
|
1531
|
+
return evaluateFilePresence(matcher, fileView, ctx);
|
|
1532
|
+
case "file-relationship":
|
|
1533
|
+
return evaluateFileRelationship(matcher, fileView, ctx);
|
|
1534
|
+
default: {
|
|
1535
|
+
const _never = matcher;
|
|
1536
|
+
void _never;
|
|
1537
|
+
return [];
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
var NATIVE_V1_ADAPTER_IMPL_HASH = "cf2b2cceadfeee49c106630ff4bdf640e3a68286d3fb6dab9c43888ec6adf252";
|
|
1543
|
+
var NATIVE_V1_RUNTIME_ID = "e8b0dd347f200a329d0ca6f6ba4e30e1911cecbf083e6218031667aee5c2e018";
|
|
1544
|
+
|
|
1545
|
+
// ../matcher-contract/dist/adapters/re2js-v1.js
|
|
1546
|
+
import { RE2JS } from "re2js";
|
|
1547
|
+
function lineCol2(content, offset) {
|
|
1548
|
+
let line = 1;
|
|
1549
|
+
let lastNl = -1;
|
|
1550
|
+
for (let i = 0; i < offset; i++) {
|
|
1551
|
+
if (content[i] === "\n") {
|
|
1552
|
+
line++;
|
|
1553
|
+
lastNl = i;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
return { line, column: offset - lastNl };
|
|
1557
|
+
}
|
|
1558
|
+
function isTokenChar2(ch) {
|
|
1559
|
+
if (ch.length === 0)
|
|
1560
|
+
return false;
|
|
1561
|
+
const c = ch.charCodeAt(0);
|
|
1562
|
+
return c >= 65 && c <= 90 || // A-Z
|
|
1563
|
+
c >= 97 && c <= 122 || // a-z
|
|
1564
|
+
c >= 48 && c <= 57 || // 0-9
|
|
1565
|
+
c === 95 || // _
|
|
1566
|
+
c === 45;
|
|
1567
|
+
}
|
|
1568
|
+
function isWordChar2(ch) {
|
|
1569
|
+
if (ch.length === 0)
|
|
1570
|
+
return false;
|
|
1571
|
+
const c = ch.charCodeAt(0);
|
|
1572
|
+
return c >= 65 && c <= 90 || // A-Z
|
|
1573
|
+
c >= 97 && c <= 122 || // a-z
|
|
1574
|
+
c >= 48 && c <= 57 || // 0-9
|
|
1575
|
+
c === 95;
|
|
1576
|
+
}
|
|
1577
|
+
function resolveAntiPatternWindow2(lines, matchLine, scope) {
|
|
1578
|
+
const totalLines = lines.length;
|
|
1579
|
+
if (scope === "file") {
|
|
1580
|
+
return { startLine: 1, endLine: totalLines };
|
|
1581
|
+
}
|
|
1582
|
+
if (typeof scope === "object" && "lines" in scope) {
|
|
1583
|
+
const n = scope.lines;
|
|
1584
|
+
return {
|
|
1585
|
+
startLine: Math.max(1, matchLine - n),
|
|
1586
|
+
endLine: Math.min(totalLines, matchLine + n)
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
if (scope === "statement") {
|
|
1590
|
+
const matchLineText = lines[matchLine - 1] ?? "";
|
|
1591
|
+
const matchLineParenNet = (matchLineText.match(/\(/g) ?? []).length - (matchLineText.match(/\)/g) ?? []).length;
|
|
1592
|
+
if (matchLineParenNet <= 0) {
|
|
1593
|
+
return { startLine: matchLine, endLine: matchLine };
|
|
1594
|
+
}
|
|
1595
|
+
let balance = (matchLineText.match(/[{(]/g) ?? []).length - (matchLineText.match(/[})]/g) ?? []).length;
|
|
1596
|
+
let endLine = matchLine;
|
|
1597
|
+
for (let i = matchLine + 1; i <= totalLines; i++) {
|
|
1598
|
+
const l = lines[i - 1];
|
|
1599
|
+
const opens = (l.match(/[{(]/g) ?? []).length;
|
|
1600
|
+
const closes = (l.match(/[})]/g) ?? []).length;
|
|
1601
|
+
balance += opens - closes;
|
|
1602
|
+
endLine = i;
|
|
1603
|
+
if (balance <= 0)
|
|
1604
|
+
break;
|
|
1605
|
+
}
|
|
1606
|
+
return { startLine: matchLine, endLine };
|
|
1607
|
+
}
|
|
1608
|
+
if (scope === "block") {
|
|
1609
|
+
let balance = 0;
|
|
1610
|
+
let blockStart = matchLine;
|
|
1611
|
+
for (let i = matchLine; i >= 1; i--) {
|
|
1612
|
+
const l = lines[i - 1];
|
|
1613
|
+
const opens = (l.match(/\{/g) ?? []).length;
|
|
1614
|
+
const closes = (l.match(/\}/g) ?? []).length;
|
|
1615
|
+
balance += closes - opens;
|
|
1616
|
+
if (balance < 0) {
|
|
1617
|
+
blockStart = i;
|
|
1618
|
+
break;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
balance = 0;
|
|
1622
|
+
let blockEnd = matchLine;
|
|
1623
|
+
for (let i = blockStart; i <= totalLines; i++) {
|
|
1624
|
+
const l = lines[i - 1];
|
|
1625
|
+
const opens = (l.match(/\{/g) ?? []).length;
|
|
1626
|
+
const closes = (l.match(/\}/g) ?? []).length;
|
|
1627
|
+
balance += opens - closes;
|
|
1628
|
+
blockEnd = i;
|
|
1629
|
+
if (balance <= 0)
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
return { startLine: blockStart, endLine: blockEnd };
|
|
1633
|
+
}
|
|
1634
|
+
if (scope === "function") {
|
|
1635
|
+
const FUNC_RE = /\bfunction\b|=>|\bdef\b/;
|
|
1636
|
+
let funcStart = matchLine;
|
|
1637
|
+
for (let i = matchLine; i >= 1; i--) {
|
|
1638
|
+
const l = lines[i - 1];
|
|
1639
|
+
if (FUNC_RE.test(l)) {
|
|
1640
|
+
funcStart = i;
|
|
1641
|
+
break;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
let balance = 0;
|
|
1645
|
+
let funcEnd = matchLine;
|
|
1646
|
+
for (let i = funcStart; i <= totalLines; i++) {
|
|
1647
|
+
const l = lines[i - 1];
|
|
1648
|
+
const opens = (l.match(/\{/g) ?? []).length;
|
|
1649
|
+
const closes = (l.match(/\}/g) ?? []).length;
|
|
1650
|
+
balance += opens - closes;
|
|
1651
|
+
funcEnd = i;
|
|
1652
|
+
if (balance <= 0 && i > funcStart)
|
|
1653
|
+
break;
|
|
1654
|
+
}
|
|
1655
|
+
return { startLine: funcStart, endLine: funcEnd };
|
|
1656
|
+
}
|
|
1657
|
+
return { startLine: matchLine, endLine: matchLine };
|
|
1658
|
+
}
|
|
1659
|
+
function toRe2jsFlags(flags) {
|
|
1660
|
+
let bits = 0;
|
|
1661
|
+
if (flags.has("i"))
|
|
1662
|
+
bits |= RE2JS.CASE_INSENSITIVE;
|
|
1663
|
+
if (flags.has("m"))
|
|
1664
|
+
bits |= RE2JS.MULTILINE;
|
|
1665
|
+
if (flags.has("s"))
|
|
1666
|
+
bits |= RE2JS.DOTALL;
|
|
1667
|
+
return bits;
|
|
1668
|
+
}
|
|
1669
|
+
function stubId2(matcherType) {
|
|
1670
|
+
switch (matcherType) {
|
|
1671
|
+
case "pattern":
|
|
1672
|
+
return "rule:pattern";
|
|
1673
|
+
case "file-presence":
|
|
1674
|
+
return "rule:file-presence";
|
|
1675
|
+
case "file-relationship":
|
|
1676
|
+
return "rule:file-relationship";
|
|
1677
|
+
default:
|
|
1678
|
+
return "rule:unknown";
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
var STUB_SEVERITY2 = "medium";
|
|
1682
|
+
var STUB_BLOCKING2 = false;
|
|
1683
|
+
function globToRegExp2(glob) {
|
|
1684
|
+
let regexStr = "^";
|
|
1685
|
+
let i = 0;
|
|
1686
|
+
while (i < glob.length) {
|
|
1687
|
+
if (glob[i] === "*" && glob[i + 1] === "*") {
|
|
1688
|
+
regexStr += ".*";
|
|
1689
|
+
i += 2;
|
|
1690
|
+
if (glob[i] === "/")
|
|
1691
|
+
i++;
|
|
1692
|
+
} else if (glob[i] === "*") {
|
|
1693
|
+
regexStr += "[^/]*";
|
|
1694
|
+
i++;
|
|
1695
|
+
} else if (glob[i] === ".") {
|
|
1696
|
+
regexStr += "\\.";
|
|
1697
|
+
i++;
|
|
1698
|
+
} else {
|
|
1699
|
+
const ch = glob[i];
|
|
1700
|
+
if (/[+?^${}()|[\]\\]/.test(ch)) {
|
|
1701
|
+
regexStr += "\\" + ch;
|
|
1702
|
+
} else {
|
|
1703
|
+
regexStr += ch;
|
|
1704
|
+
}
|
|
1705
|
+
i++;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
regexStr += "$";
|
|
1709
|
+
return new RegExp(regexStr);
|
|
1710
|
+
}
|
|
1711
|
+
function evaluatePattern2(matcher, file, ctx) {
|
|
1712
|
+
const flagsResult = parseFlags(matcher.flags);
|
|
1713
|
+
if (!flagsResult.ok) {
|
|
1714
|
+
return [];
|
|
1715
|
+
}
|
|
1716
|
+
const re2jsFlags = toRe2jsFlags(flagsResult.flags);
|
|
1717
|
+
const findings = [];
|
|
1718
|
+
const id = stubId2("pattern");
|
|
1719
|
+
const boundary = matcher.boundary ?? "none";
|
|
1720
|
+
const compiledAntiPatterns = [];
|
|
1721
|
+
for (const antiStr of matcher.antiPatterns) {
|
|
1722
|
+
try {
|
|
1723
|
+
compiledAntiPatterns.push(RE2JS.compile(antiStr, re2jsFlags));
|
|
1724
|
+
} catch (err) {
|
|
1725
|
+
console.error(`[re2js-v1] compile error for anti-pattern ${JSON.stringify(antiStr)}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1726
|
+
throw new Error(`[re2js-v1] anti-pattern compile failure for ${JSON.stringify(antiStr)} \u2014 bundle degraded (fail-closed, FIX 5): ${err instanceof Error ? err.message : String(err)}`);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
for (const patternStr of matcher.patterns) {
|
|
1730
|
+
let compiled;
|
|
1731
|
+
try {
|
|
1732
|
+
compiled = RE2JS.compile(patternStr, re2jsFlags);
|
|
1733
|
+
} catch (err) {
|
|
1734
|
+
console.error(`[re2js-v1] compile error for pattern ${JSON.stringify(patternStr)}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1735
|
+
throw new Error(`[re2js-v1] primary pattern compile failure for ${JSON.stringify(patternStr)} \u2014 bundle degraded (fail-closed, FIX 5): ${err instanceof Error ? err.message : String(err)}`);
|
|
1736
|
+
}
|
|
1737
|
+
const m = compiled.matcher(file.content);
|
|
1738
|
+
let searchFrom = void 0;
|
|
1739
|
+
while (true) {
|
|
1740
|
+
const hasMatch = searchFrom !== void 0 ? m.find(searchFrom) : m.find();
|
|
1741
|
+
if (!hasMatch)
|
|
1742
|
+
break;
|
|
1743
|
+
const matchStart = m.start();
|
|
1744
|
+
const matchEnd = m.end();
|
|
1745
|
+
const matchedText = m.group() ?? "";
|
|
1746
|
+
const isZeroWidth = matchStart === matchEnd;
|
|
1747
|
+
searchFrom = isZeroWidth ? matchStart + 1 : void 0;
|
|
1748
|
+
if (isZeroWidth && matchStart >= file.content.length)
|
|
1749
|
+
break;
|
|
1750
|
+
if (boundary !== "none") {
|
|
1751
|
+
const nextChar = matchEnd < file.content.length ? file.content[matchEnd] : "";
|
|
1752
|
+
if (boundary === "token" && isTokenChar2(nextChar)) {
|
|
1753
|
+
continue;
|
|
1754
|
+
}
|
|
1755
|
+
if (boundary === "word" && isWordChar2(nextChar)) {
|
|
1756
|
+
continue;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
const { line, column } = lineCol2(file.content, matchStart);
|
|
1760
|
+
let suppressionState = "active";
|
|
1761
|
+
if (compiledAntiPatterns.length > 0) {
|
|
1762
|
+
const scope = matcher.antiPatternScope ?? "statement";
|
|
1763
|
+
const allLines = file.content.split("\n");
|
|
1764
|
+
const { startLine, endLine } = resolveAntiPatternWindow2(allLines, line, scope);
|
|
1765
|
+
const windowText = allLines.slice(startLine - 1, endLine).join("\n");
|
|
1766
|
+
for (const antiCompiled of compiledAntiPatterns) {
|
|
1767
|
+
const antiMatcher = antiCompiled.matcher(windowText);
|
|
1768
|
+
if (antiMatcher.find()) {
|
|
1769
|
+
suppressionState = "suppressed";
|
|
1770
|
+
break;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
findings.push({
|
|
1775
|
+
id,
|
|
1776
|
+
file: file.relativePath,
|
|
1777
|
+
line,
|
|
1778
|
+
column,
|
|
1779
|
+
evidence: matchedText,
|
|
1780
|
+
severity: STUB_SEVERITY2,
|
|
1781
|
+
blocking: STUB_BLOCKING2,
|
|
1782
|
+
suppressionState,
|
|
1783
|
+
releaseId: ctx.releaseId,
|
|
1784
|
+
matcherType: "pattern"
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return findings;
|
|
1789
|
+
}
|
|
1790
|
+
function evaluateFilePresence2(matcher, file, ctx) {
|
|
1791
|
+
if (matcher.presenceRule === "must-not-exist") {
|
|
1792
|
+
return [
|
|
1793
|
+
{
|
|
1794
|
+
id: stubId2("file-presence"),
|
|
1795
|
+
file: file.relativePath,
|
|
1796
|
+
line: 1,
|
|
1797
|
+
column: 1,
|
|
1798
|
+
evidence: file.relativePath,
|
|
1799
|
+
severity: STUB_SEVERITY2,
|
|
1800
|
+
blocking: STUB_BLOCKING2,
|
|
1801
|
+
suppressionState: "active",
|
|
1802
|
+
releaseId: ctx.releaseId,
|
|
1803
|
+
matcherType: "file-presence"
|
|
1804
|
+
}
|
|
1805
|
+
];
|
|
1806
|
+
}
|
|
1807
|
+
return [];
|
|
1808
|
+
}
|
|
1809
|
+
function evaluateFileRelationship2(matcher, file, ctx) {
|
|
1810
|
+
const { requiresFile, requiresPattern } = matcher.context;
|
|
1811
|
+
if (requiresFile !== void 0) {
|
|
1812
|
+
const globRe = globToRegExp2(requiresFile);
|
|
1813
|
+
const found = ctx.allRelativePaths.some((p) => globRe.test(p));
|
|
1814
|
+
if (!found) {
|
|
1815
|
+
return [
|
|
1816
|
+
{
|
|
1817
|
+
id: stubId2("file-relationship"),
|
|
1818
|
+
file: file.relativePath,
|
|
1819
|
+
line: 1,
|
|
1820
|
+
column: 1,
|
|
1821
|
+
evidence: file.relativePath,
|
|
1822
|
+
severity: STUB_SEVERITY2,
|
|
1823
|
+
blocking: STUB_BLOCKING2,
|
|
1824
|
+
suppressionState: "active",
|
|
1825
|
+
releaseId: ctx.releaseId,
|
|
1826
|
+
matcherType: "file-relationship"
|
|
1827
|
+
}
|
|
1828
|
+
];
|
|
1829
|
+
}
|
|
1830
|
+
if (requiresPattern === void 0) {
|
|
1831
|
+
return [];
|
|
1832
|
+
}
|
|
1833
|
+
return [
|
|
1834
|
+
{
|
|
1835
|
+
id: stubId2("file-relationship"),
|
|
1836
|
+
file: file.relativePath,
|
|
1837
|
+
line: 1,
|
|
1838
|
+
column: 1,
|
|
1839
|
+
evidence: `${file.relativePath} + requiresPattern "${requiresPattern}" (companion content unavailable \u2014 fail closed)`,
|
|
1840
|
+
severity: STUB_SEVERITY2,
|
|
1841
|
+
blocking: STUB_BLOCKING2,
|
|
1842
|
+
suppressionState: "active",
|
|
1843
|
+
releaseId: ctx.releaseId,
|
|
1844
|
+
matcherType: "file-relationship"
|
|
1845
|
+
}
|
|
1846
|
+
];
|
|
1847
|
+
}
|
|
1848
|
+
if (requiresPattern === void 0) {
|
|
1849
|
+
return [
|
|
1850
|
+
{
|
|
1851
|
+
id: stubId2("file-relationship"),
|
|
1852
|
+
file: file.relativePath,
|
|
1853
|
+
line: 1,
|
|
1854
|
+
column: 1,
|
|
1855
|
+
evidence: file.relativePath,
|
|
1856
|
+
severity: STUB_SEVERITY2,
|
|
1857
|
+
blocking: STUB_BLOCKING2,
|
|
1858
|
+
suppressionState: "active",
|
|
1859
|
+
releaseId: ctx.releaseId,
|
|
1860
|
+
matcherType: "file-relationship"
|
|
1861
|
+
}
|
|
1862
|
+
];
|
|
1863
|
+
}
|
|
1864
|
+
let requiresCompiled;
|
|
1865
|
+
try {
|
|
1866
|
+
requiresCompiled = RE2JS.compile(requiresPattern);
|
|
1867
|
+
} catch {
|
|
1868
|
+
console.error(`[re2js-v1] requiresPattern compile error for ${JSON.stringify(requiresPattern)} \u2014 fail closed`);
|
|
1869
|
+
return [
|
|
1870
|
+
{
|
|
1871
|
+
id: stubId2("file-relationship"),
|
|
1872
|
+
file: file.relativePath,
|
|
1873
|
+
line: 1,
|
|
1874
|
+
column: 1,
|
|
1875
|
+
evidence: `requiresPattern "${requiresPattern}" (compile error \u2014 fail closed)`,
|
|
1876
|
+
severity: STUB_SEVERITY2,
|
|
1877
|
+
blocking: STUB_BLOCKING2,
|
|
1878
|
+
suppressionState: "active",
|
|
1879
|
+
releaseId: ctx.releaseId,
|
|
1880
|
+
matcherType: "file-relationship"
|
|
1881
|
+
}
|
|
1882
|
+
];
|
|
1883
|
+
}
|
|
1884
|
+
const requiresMatcher = requiresCompiled.matcher(file.content);
|
|
1885
|
+
if (!requiresMatcher.find()) {
|
|
1886
|
+
return [];
|
|
1887
|
+
}
|
|
1888
|
+
const matcherAny = matcher;
|
|
1889
|
+
const frFlags = matcherAny["flags"] ?? "";
|
|
1890
|
+
const frPatterns = matcherAny["patterns"] ?? [];
|
|
1891
|
+
const frAntiPatterns = matcherAny["antiPatterns"] ?? [];
|
|
1892
|
+
const frBoundary = matcherAny["boundary"] ?? "none";
|
|
1893
|
+
const frAntiPatternScope = matcherAny["antiPatternScope"] ?? "statement";
|
|
1894
|
+
const flagsResult = parseFlags(frFlags);
|
|
1895
|
+
if (!flagsResult.ok) {
|
|
1896
|
+
return [];
|
|
1897
|
+
}
|
|
1898
|
+
const patternMatcher = {
|
|
1899
|
+
type: "pattern",
|
|
1900
|
+
fileGlob: matcher.fileGlob,
|
|
1901
|
+
patterns: frPatterns,
|
|
1902
|
+
antiPatterns: frAntiPatterns,
|
|
1903
|
+
flags: frFlags,
|
|
1904
|
+
boundary: frBoundary,
|
|
1905
|
+
antiPatternScope: frAntiPatternScope
|
|
1906
|
+
};
|
|
1907
|
+
return evaluatePattern2(patternMatcher, file, ctx);
|
|
1908
|
+
}
|
|
1909
|
+
var re2jsV1Executor = {
|
|
1910
|
+
evaluate(matcher, file, ctx) {
|
|
1911
|
+
const fileView = {
|
|
1912
|
+
relativePath: file.relativePath,
|
|
1913
|
+
content: file.content
|
|
1914
|
+
};
|
|
1915
|
+
switch (matcher.type) {
|
|
1916
|
+
case "pattern":
|
|
1917
|
+
return evaluatePattern2(matcher, fileView, ctx);
|
|
1918
|
+
case "file-presence":
|
|
1919
|
+
return evaluateFilePresence2(matcher, fileView, ctx);
|
|
1920
|
+
case "file-relationship":
|
|
1921
|
+
return evaluateFileRelationship2(matcher, fileView, ctx);
|
|
1922
|
+
default: {
|
|
1923
|
+
const _never = matcher;
|
|
1924
|
+
void _never;
|
|
1925
|
+
return [];
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
function re2jsTestPattern(pattern, input) {
|
|
1931
|
+
const compiled = RE2JS.compile(pattern);
|
|
1932
|
+
return compiled.matcher(input).find();
|
|
1933
|
+
}
|
|
1934
|
+
var RE2JS_V1_ADAPTER_IMPL_HASH = "5b277d6a183d640ac9b8ebc0dc01d292101a6e577603c5cd7c6ab360263964d9";
|
|
1935
|
+
var RE2JS_V1_RUNTIME_ID = "971fab9b230f60a1b663c7f9a888769e9a2d6ace58fa150e8ee574a3fc3c91d7";
|
|
1936
|
+
|
|
1937
|
+
// ../matcher-contract/dist/executable-hash.js
|
|
1938
|
+
import { createHash as createHash3 } from "crypto";
|
|
1939
|
+
var EXEC_RULE_FIELDS = [
|
|
1940
|
+
"action",
|
|
1941
|
+
"antiBoundary",
|
|
1942
|
+
"antiPattern",
|
|
1943
|
+
"antiPatternScope",
|
|
1944
|
+
"blocking",
|
|
1945
|
+
"boundary",
|
|
1946
|
+
"categories",
|
|
1947
|
+
"enabled",
|
|
1948
|
+
"fileGlob",
|
|
1949
|
+
"flags",
|
|
1950
|
+
"framework",
|
|
1951
|
+
"id",
|
|
1952
|
+
"matcherType",
|
|
1953
|
+
"pattern",
|
|
1954
|
+
"presenceRule",
|
|
1955
|
+
"requiresFile",
|
|
1956
|
+
"requiresPattern",
|
|
1957
|
+
"severity",
|
|
1958
|
+
"tier",
|
|
1959
|
+
"title"
|
|
1960
|
+
];
|
|
1961
|
+
var EXEC_RULE_EXTENSION_FIELDS = /* @__PURE__ */ new Set([]);
|
|
1962
|
+
var RULE_DOMAIN_PREFIX = "shipguard-rule-v1\0";
|
|
1963
|
+
function buildCanonicalRuleObject(raw) {
|
|
1964
|
+
const result = {};
|
|
1965
|
+
for (const field of EXEC_RULE_FIELDS) {
|
|
1966
|
+
if (field in raw && raw[field] !== void 0) {
|
|
1967
|
+
if (field === "categories" && Array.isArray(raw[field])) {
|
|
1968
|
+
result[field] = [...raw[field]].sort();
|
|
1969
|
+
} else {
|
|
1970
|
+
result[field] = raw[field];
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
const knownFields = new Set(EXEC_RULE_FIELDS);
|
|
1975
|
+
for (const key of Object.keys(raw)) {
|
|
1976
|
+
if (!knownFields.has(key)) {
|
|
1977
|
+
throw new Error(`Delivered rule has extra field "${key}" not in ExecutableRule canonical schema \u2014 rejected`);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
return result;
|
|
1981
|
+
}
|
|
1982
|
+
function computeExecutableHash(raw) {
|
|
1983
|
+
const canonical = buildCanonicalRuleObject(raw);
|
|
1984
|
+
const preimage = RULE_DOMAIN_PREFIX + canonicalJson(canonical);
|
|
1985
|
+
return createHash3("sha256").update(preimage, "utf8").digest("hex");
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
export {
|
|
1989
|
+
parseFlags,
|
|
1990
|
+
canonicalJson,
|
|
1991
|
+
parseStrictNoDup,
|
|
1992
|
+
canonicalizeFinding,
|
|
1993
|
+
UNICODE_NORMALIZATION_POLICY,
|
|
1994
|
+
hugeSingleLineCap,
|
|
1995
|
+
decodeUtf8Strict,
|
|
1996
|
+
stripBom,
|
|
1997
|
+
normalizeNewlines,
|
|
1998
|
+
detectBinary,
|
|
1999
|
+
DEFAULT_CAPS,
|
|
2000
|
+
CapTracker,
|
|
2001
|
+
DegradedReason,
|
|
2002
|
+
resolveExitCode,
|
|
2003
|
+
RE2JS_VERSION,
|
|
2004
|
+
SUPPORTED_NODE_VERSIONS,
|
|
2005
|
+
makeNativeEngineMeta,
|
|
2006
|
+
makeRe2jsEngineMeta,
|
|
2007
|
+
computeMatcherRuntimeId,
|
|
2008
|
+
selectExpected,
|
|
2009
|
+
verifyExactSet,
|
|
2010
|
+
executorIndependentVectors,
|
|
2011
|
+
executorDependentVectors,
|
|
2012
|
+
allConformanceVectors,
|
|
2013
|
+
runConformance,
|
|
2014
|
+
nativeV1Executor,
|
|
2015
|
+
NATIVE_V1_ADAPTER_IMPL_HASH,
|
|
2016
|
+
NATIVE_V1_RUNTIME_ID,
|
|
2017
|
+
re2jsV1Executor,
|
|
2018
|
+
re2jsTestPattern,
|
|
2019
|
+
RE2JS_V1_ADAPTER_IMPL_HASH,
|
|
2020
|
+
RE2JS_V1_RUNTIME_ID,
|
|
2021
|
+
EXEC_RULE_FIELDS,
|
|
2022
|
+
EXEC_RULE_EXTENSION_FIELDS,
|
|
2023
|
+
computeExecutableHash
|
|
2024
|
+
};
|