@akasecurity/ai-tc-codex 0.9.14 → 0.9.15
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/.codex-plugin/plugin.json +1 -1
- package/package.json +4 -4
- package/scripts/apply-suppressions.js +366 -80
- package/scripts/backfill.js +470 -121
- package/scripts/content-retention.js +184 -55
- package/scripts/filescan.js +470 -121
- package/scripts/firstrun.js +256 -81
- package/scripts/history-sync.js +190 -61
- package/scripts/intro.js +59 -10
- package/scripts/onboard.js +164 -43
- package/scripts/post-tool-use.js +514 -124
- package/scripts/pre-tool-use.js +514 -124
- package/scripts/query.js +255 -80
- package/scripts/reconcile.js +451 -111
- package/scripts/remediate.js +471 -122
- package/scripts/scan-worker.js +241 -34
- package/scripts/session-start.js +507 -126
- package/scripts/start-light.js +59 -10
- package/scripts/stop.js +147 -29
- package/scripts/sync.js +473 -124
- package/scripts/user-prompt-submit.js +514 -124
package/scripts/reconcile.js
CHANGED
|
@@ -32,9 +32,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
mod
|
|
33
33
|
));
|
|
34
34
|
|
|
35
|
-
// ../../node_modules/.pnpm/ignore@7.0.
|
|
35
|
+
// ../../node_modules/.pnpm/ignore@7.0.10/node_modules/ignore/index.js
|
|
36
36
|
var require_ignore = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/ignore@7.0.
|
|
37
|
+
"../../node_modules/.pnpm/ignore@7.0.10/node_modules/ignore/index.js"(exports, module) {
|
|
38
38
|
"use strict";
|
|
39
39
|
function makeArray(subject) {
|
|
40
40
|
return Array.isArray(subject) ? subject : [subject];
|
|
@@ -429,6 +429,13 @@ var require_ignore = __commonJS({
|
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
431
|
var WILDCARD = "[^\\/]*";
|
|
432
|
+
var separatorAfter = (run, at) => {
|
|
433
|
+
let separator = EMPTY;
|
|
434
|
+
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
435
|
+
separator += run[index].single;
|
|
436
|
+
}
|
|
437
|
+
return separator;
|
|
438
|
+
};
|
|
432
439
|
var pinWildcards = (source) => {
|
|
433
440
|
if (source.indexOf(WILDCARD) < 0) {
|
|
434
441
|
return source;
|
|
@@ -498,7 +505,7 @@ var require_ignore = __commonJS({
|
|
|
498
505
|
out += token.single;
|
|
499
506
|
return;
|
|
500
507
|
}
|
|
501
|
-
out += at === lastWildcard ? WILDCARD : `(?:(?!${run
|
|
508
|
+
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
502
509
|
});
|
|
503
510
|
run = [];
|
|
504
511
|
};
|
|
@@ -675,13 +682,13 @@ var require_ignore = __commonJS({
|
|
|
675
682
|
const rules = this._rules;
|
|
676
683
|
const { length } = rules;
|
|
677
684
|
const shortcut = this._basenameCount * 2 >= length;
|
|
678
|
-
const
|
|
685
|
+
const basename7 = shortcut ? basenameOf(path) : path;
|
|
679
686
|
for (let index = 0; index < length; index++) {
|
|
680
687
|
const rule = rules[index];
|
|
681
688
|
const { negative } = rule;
|
|
682
689
|
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
683
690
|
if (!skip && rule[mode].test(
|
|
684
|
-
shortcut && rule._basenameOnly ?
|
|
691
|
+
shortcut && rule._basenameOnly ? basename7 : path
|
|
685
692
|
)) {
|
|
686
693
|
ignored = !negative;
|
|
687
694
|
unignored = negative;
|
|
@@ -1002,6 +1009,10 @@ var SQLITE_MIGRATIONS = [
|
|
|
1002
1009
|
{
|
|
1003
1010
|
tag: "0035_share_destination_provider_id",
|
|
1004
1011
|
sql: "ALTER TABLE `share_destination` ADD `provider_id` text;"
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
tag: "0036_secret_vault_identity_fingerprint",
|
|
1015
|
+
sql: "ALTER TABLE `secret_vault` ADD `value_identity_fingerprint` text DEFAULT '' NOT NULL;--> statement-breakpoint\nUPDATE `secret_vault` SET `value_identity_fingerprint` = `value_fingerprint`;\n"
|
|
1005
1016
|
}
|
|
1006
1017
|
];
|
|
1007
1018
|
|
|
@@ -6037,7 +6048,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
6037
6048
|
var NONE = 0;
|
|
6038
6049
|
var ASSUMED = 1;
|
|
6039
6050
|
var PROVEN = 2;
|
|
6040
|
-
function isRecursive(inst, stack,
|
|
6051
|
+
function isRecursive(inst, stack, resolve3) {
|
|
6041
6052
|
const cached2 = recursive.get(inst);
|
|
6042
6053
|
if (cached2 !== void 0)
|
|
6043
6054
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6047,7 +6058,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6047
6058
|
let result = NONE;
|
|
6048
6059
|
const check2 = (child) => {
|
|
6049
6060
|
if (result !== PROVEN && child?._zod) {
|
|
6050
|
-
const answer = isRecursive(child, stack,
|
|
6061
|
+
const answer = isRecursive(child, stack, resolve3);
|
|
6051
6062
|
if (answer > result)
|
|
6052
6063
|
result = answer;
|
|
6053
6064
|
}
|
|
@@ -6058,7 +6069,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6058
6069
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6059
6070
|
if (spread && !desc.enumerable)
|
|
6060
6071
|
continue;
|
|
6061
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6072
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
|
|
6062
6073
|
if (child > answer)
|
|
6063
6074
|
answer = child;
|
|
6064
6075
|
}
|
|
@@ -6122,7 +6133,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6122
6133
|
break;
|
|
6123
6134
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
6124
6135
|
case "lazy": {
|
|
6125
|
-
const inner = def._cachedInner ?? (
|
|
6136
|
+
const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
6126
6137
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
6127
6138
|
break;
|
|
6128
6139
|
}
|
|
@@ -23406,7 +23417,29 @@ var StorePosturePlugin = external_exports.object({
|
|
|
23406
23417
|
*/
|
|
23407
23418
|
policyBundleVersion: external_exports.string().max(200).nullable(),
|
|
23408
23419
|
/** Epoch millis, on the CLIENT clock, of that fetch. */
|
|
23409
|
-
policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable()
|
|
23420
|
+
policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable(),
|
|
23421
|
+
/**
|
|
23422
|
+
* The newest version the host's own install record holds for this plugin —
|
|
23423
|
+
* what is on disk. After an update it leads `version` (the running copy) by
|
|
23424
|
+
* one launch. Null when no usable version can be read: no install record
|
|
23425
|
+
* (a plugin run from a checkout), no entry with a valid version, or every
|
|
23426
|
+
* such entry names an `installPath` that no longer exists; OPTIONAL, not
|
|
23427
|
+
* required, so a build that predates the member keeps getting its 200.
|
|
23428
|
+
* Bounded like `version`.
|
|
23429
|
+
*/
|
|
23430
|
+
installedVersion: external_exports.string().max(64).nullable().optional(),
|
|
23431
|
+
/**
|
|
23432
|
+
* The local-store schema version this running build migrates a store to:
|
|
23433
|
+
* the number of store migrations it carries, the count it stamps into
|
|
23434
|
+
* `PRAGMA user_version`. A snapshot whose `schemaVersion` is above it
|
|
23435
|
+
* usually describes a store a newer build migrated. It is a hint, not a
|
|
23436
|
+
* verdict: the stamp is write-only, so a store whose count ran past this
|
|
23437
|
+
* build's while this build knows every migration in its ledger reads above
|
|
23438
|
+
* it too, which is why describeStoreSkew decides skew on ledger tags and
|
|
23439
|
+
* never on the count. OPTIONAL for the same reason as `installedVersion`;
|
|
23440
|
+
* bounded like `schemaVersion`.
|
|
23441
|
+
*/
|
|
23442
|
+
buildSchemaVersion: external_exports.number().int().min(0).max(MAX_INT4).optional()
|
|
23410
23443
|
}).meta({ id: "StorePosturePlugin" });
|
|
23411
23444
|
var StorePostureSnapshot = external_exports.object({
|
|
23412
23445
|
deviceId: external_exports.guid(),
|
|
@@ -25044,10 +25077,15 @@ var ParsedPointer = external_exports.object({
|
|
|
25044
25077
|
});
|
|
25045
25078
|
var VaultEntry = external_exports.object({
|
|
25046
25079
|
pointerId: external_exports.string(),
|
|
25047
|
-
// The keyed HMAC of the raw
|
|
25048
|
-
// derived under.
|
|
25049
|
-
// independently of the vault encryption
|
|
25080
|
+
// The keyed HMAC of the EXACT raw bytes under `exception.key`, and the epoch it
|
|
25081
|
+
// was derived under. The vault's own dedupe key: a value and its invisibly
|
|
25082
|
+
// padded twin are two rows. It rotates independently of the vault encryption
|
|
25083
|
+
// key below. Never matched against an exception or grant.
|
|
25050
25084
|
valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
25085
|
+
// The same HMAC over the raw with invisible padding removed: the identity a
|
|
25086
|
+
// reveal-to-model grant and every exception match on. Shared by a value and
|
|
25087
|
+
// its padded twin.
|
|
25088
|
+
valueIdentityFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
25051
25089
|
fingerprintKeyVersion: external_exports.number().int().positive(),
|
|
25052
25090
|
// The vault-key epoch this row's ciphertext was sealed under.
|
|
25053
25091
|
keyVersion: external_exports.number().int().positive(),
|
|
@@ -25620,10 +25658,18 @@ var SeveritySummaryItem = external_exports.object({
|
|
|
25620
25658
|
count: external_exports.number().int().nonnegative(),
|
|
25621
25659
|
// Resolution-aware breakdown (optional, additive). Populated once findings
|
|
25622
25660
|
// carry lifecycle state: `caught` = handled in-flight (enforced); `openAtRest`
|
|
25623
|
-
// = still open with no in-flight enforcement (needs remediation)
|
|
25624
|
-
//
|
|
25661
|
+
// = still open with no in-flight enforcement (needs remediation); `dismissed`
|
|
25662
|
+
// = closed by a human judgement rather than a fix — visible, but not counted as
|
|
25663
|
+
// needing remediation. The three are disjoint. Absent on the legacy count-only
|
|
25664
|
+
// response until the resolution feature lands.
|
|
25625
25665
|
caught: external_exports.number().int().nonnegative().optional(),
|
|
25626
|
-
openAtRest: external_exports.number().int().nonnegative().optional()
|
|
25666
|
+
openAtRest: external_exports.number().int().nonnegative().optional(),
|
|
25667
|
+
dismissed: external_exports.number().int().nonnegative().optional(),
|
|
25668
|
+
// The two halves of `caught`, for a reader that wants them apart: `handled` =
|
|
25669
|
+
// in-flight findings an enforcement action already contained; `resolved` =
|
|
25670
|
+
// at-rest findings closed out by fixing them. `handled + resolved === caught`.
|
|
25671
|
+
handled: external_exports.number().int().nonnegative().optional(),
|
|
25672
|
+
resolved: external_exports.number().int().nonnegative().optional()
|
|
25627
25673
|
}).meta({ id: "SeveritySummaryItem" });
|
|
25628
25674
|
var SeveritySummaryResponse = external_exports.object({
|
|
25629
25675
|
// Sum of bySeverity[].count.
|
|
@@ -25631,6 +25677,9 @@ var SeveritySummaryResponse = external_exports.object({
|
|
|
25631
25677
|
// Findings still open at rest (sum of bySeverity[].openAtRest). Optional and
|
|
25632
25678
|
// additive — absent on the legacy response until the resolution feature lands.
|
|
25633
25679
|
needsRemediation: external_exports.number().int().nonnegative().optional(),
|
|
25680
|
+
// Findings a user dismissed (sum of bySeverity[].dismissed). Excluded from
|
|
25681
|
+
// needsRemediation, and kept visible here so an accepted risk is not erased.
|
|
25682
|
+
dismissed: external_exports.number().int().nonnegative().optional(),
|
|
25634
25683
|
// All four severity levels are always present (count may be 0).
|
|
25635
25684
|
bySeverity: external_exports.array(SeveritySummaryItem)
|
|
25636
25685
|
}).meta({ id: "SeveritySummaryResponse" });
|
|
@@ -26228,11 +26277,11 @@ function repairOrRefuseMode(file2) {
|
|
|
26228
26277
|
const link = lstatSync2(file2, { throwIfNoEntry: false });
|
|
26229
26278
|
if (link === void 0) return "absent";
|
|
26230
26279
|
if (link.isSymbolicLink()) return "untrusted";
|
|
26231
|
-
const
|
|
26232
|
-
if (
|
|
26280
|
+
const stat2 = statSync(file2, { throwIfNoEntry: false });
|
|
26281
|
+
if (stat2 === void 0) return "absent";
|
|
26233
26282
|
const uid = process.getuid?.();
|
|
26234
|
-
if (uid !== void 0 &&
|
|
26235
|
-
if (process.platform !== "win32" && (
|
|
26283
|
+
if (uid !== void 0 && stat2.uid !== uid) return "untrusted";
|
|
26284
|
+
if (process.platform !== "win32" && (stat2.mode & 511) !== DATA_FILE_MODE) {
|
|
26236
26285
|
try {
|
|
26237
26286
|
chmodSync2(file2, DATA_FILE_MODE);
|
|
26238
26287
|
} catch {
|
|
@@ -26244,9 +26293,9 @@ function repairOrRefuseMode(file2) {
|
|
|
26244
26293
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26245
26294
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26246
26295
|
let raw;
|
|
26247
|
-
const
|
|
26248
|
-
if (
|
|
26249
|
-
if (
|
|
26296
|
+
const gate2 = repairOrRefuseMode(file2);
|
|
26297
|
+
if (gate2 === "absent") return { usable: false, reason: "absent" };
|
|
26298
|
+
if (gate2 === "untrusted") return { usable: false, reason: "untrusted-file" };
|
|
26250
26299
|
try {
|
|
26251
26300
|
raw = readFileSync(file2, "utf8");
|
|
26252
26301
|
} catch (err) {
|
|
@@ -32381,7 +32430,10 @@ var SqliteResolutionsRepository = class {
|
|
|
32381
32430
|
* Insert many dispositions as ONE transaction — all of them or none.
|
|
32382
32431
|
*
|
|
32383
32432
|
* A dashboard dismissal closes every open finding of a rule, which is one
|
|
32384
|
-
* write per key
|
|
32433
|
+
* write per key. It reaches this through
|
|
32434
|
+
* `LocalDatabase.dismissOpenFindingsForRule`, which calls it inside the
|
|
32435
|
+
* transaction that selected the keys, so there it runs as a SAVEPOINT of
|
|
32436
|
+
* that transaction. Run loose, a fault partway leaves half a rule closed with
|
|
32385
32437
|
* nothing recording that the other half was meant to be. The caller then has
|
|
32386
32438
|
* no way to tell a partial run from a complete one, because the card it
|
|
32387
32439
|
* refreshes into just shows a smaller number either way.
|
|
@@ -32601,6 +32653,7 @@ function toSighting(row) {
|
|
|
32601
32653
|
var SELECT_COLUMNS = `
|
|
32602
32654
|
pointer_id AS pointerId,
|
|
32603
32655
|
value_fingerprint AS valueFingerprint,
|
|
32656
|
+
value_identity_fingerprint AS valueIdentityFingerprint,
|
|
32604
32657
|
fingerprint_key_version AS fingerprintKeyVersion,
|
|
32605
32658
|
key_version AS keyVersion,
|
|
32606
32659
|
format_version AS formatVersion,
|
|
@@ -32625,13 +32678,13 @@ var SqliteSecretVaultRepository = class {
|
|
|
32625
32678
|
this.db = db;
|
|
32626
32679
|
this.insertStmt = db.prepare(
|
|
32627
32680
|
`INSERT INTO secret_vault (
|
|
32628
|
-
pointer_id, value_fingerprint,
|
|
32629
|
-
format_version, category, rule_id, masked_match, provider,
|
|
32681
|
+
pointer_id, value_fingerprint, value_identity_fingerprint,
|
|
32682
|
+
fingerprint_key_version, key_version, format_version, category, rule_id, masked_match, provider,
|
|
32630
32683
|
ciphertext, nonce, auth_tag,
|
|
32631
32684
|
user_authorized, occurrence_count, first_seen, last_seen
|
|
32632
32685
|
) VALUES (
|
|
32633
|
-
:pointerId, :valueFingerprint, :
|
|
32634
|
-
:formatVersion, :category, :ruleId, :maskedMatch, :provider,
|
|
32686
|
+
:pointerId, :valueFingerprint, :valueIdentityFingerprint,
|
|
32687
|
+
:fingerprintKeyVersion, :keyVersion, :formatVersion, :category, :ruleId, :maskedMatch, :provider,
|
|
32635
32688
|
:ciphertext, :nonce, :authTag,
|
|
32636
32689
|
:userAuthorized, 1, :now, :now
|
|
32637
32690
|
)`
|
|
@@ -32656,7 +32709,13 @@ var SqliteSecretVaultRepository = class {
|
|
|
32656
32709
|
);
|
|
32657
32710
|
this.refreshFingerprintStmt = db.prepare(
|
|
32658
32711
|
`UPDATE secret_vault
|
|
32659
|
-
SET value_fingerprint = :valueFingerprint,
|
|
32712
|
+
SET value_fingerprint = :valueFingerprint,
|
|
32713
|
+
value_identity_fingerprint = :valueIdentityFingerprint,
|
|
32714
|
+
fingerprint_key_version = :fingerprintKeyVersion
|
|
32715
|
+
WHERE pointer_id = :pointerId`
|
|
32716
|
+
);
|
|
32717
|
+
this.setIdentityStmt = db.prepare(
|
|
32718
|
+
`UPDATE secret_vault SET value_identity_fingerprint = :valueIdentityFingerprint
|
|
32660
32719
|
WHERE pointer_id = :pointerId`
|
|
32661
32720
|
);
|
|
32662
32721
|
this.deleteByPointerStmt = db.prepare(`DELETE FROM secret_vault WHERE pointer_id = :pointerId`);
|
|
@@ -32673,6 +32732,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32673
32732
|
listStmt;
|
|
32674
32733
|
replaceCiphertextStmt;
|
|
32675
32734
|
refreshFingerprintStmt;
|
|
32735
|
+
setIdentityStmt;
|
|
32676
32736
|
deleteByPointerStmt;
|
|
32677
32737
|
derefStmt;
|
|
32678
32738
|
/**
|
|
@@ -32703,6 +32763,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32703
32763
|
bindParams({
|
|
32704
32764
|
pointerId: input2.pointerId,
|
|
32705
32765
|
valueFingerprint: input2.valueFingerprint,
|
|
32766
|
+
valueIdentityFingerprint: input2.valueIdentityFingerprint,
|
|
32706
32767
|
fingerprintKeyVersion: input2.fingerprintKeyVersion,
|
|
32707
32768
|
keyVersion: input2.keyVersion,
|
|
32708
32769
|
formatVersion: input2.formatVersion ?? POINTER_FORMAT_VERSION,
|
|
@@ -32764,7 +32825,15 @@ var SqliteSecretVaultRepository = class {
|
|
|
32764
32825
|
replaceCiphertext(pointerId, next) {
|
|
32765
32826
|
this.replaceCiphertextStmt.run({ pointerId, ...next });
|
|
32766
32827
|
}
|
|
32767
|
-
/**
|
|
32828
|
+
/**
|
|
32829
|
+
* Correct an entry's identity fingerprint in place, leaving its exact
|
|
32830
|
+
* fingerprint and key epoch alone. For a row whose identity column still holds
|
|
32831
|
+
* the exact value copied in by the migration that added it.
|
|
32832
|
+
*/
|
|
32833
|
+
setIdentityFingerprint(pointerId, valueIdentityFingerprint) {
|
|
32834
|
+
this.setIdentityStmt.run({ pointerId, valueIdentityFingerprint });
|
|
32835
|
+
}
|
|
32836
|
+
/** Re-derive an entry's fingerprints under a new fingerprint-key epoch. */
|
|
32768
32837
|
refreshFingerprint(pointerId, next) {
|
|
32769
32838
|
this.refreshFingerprintStmt.run({ pointerId, ...next });
|
|
32770
32839
|
}
|
|
@@ -32895,7 +32964,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32895
32964
|
`SELECT ${INVENTORY_COLUMNS},
|
|
32896
32965
|
(SELECT e.id FROM exceptions e
|
|
32897
32966
|
WHERE e.rule_id = v.rule_id
|
|
32898
|
-
AND e.value_fingerprint = v.
|
|
32967
|
+
AND e.value_fingerprint = v.value_identity_fingerprint
|
|
32899
32968
|
AND e.key_version = v.fingerprint_key_version
|
|
32900
32969
|
AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
|
|
32901
32970
|
LIMIT 1) AS grant_id
|
|
@@ -32938,7 +33007,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32938
33007
|
`SELECT ${INVENTORY_COLUMNS},
|
|
32939
33008
|
(SELECT e.id FROM exceptions e
|
|
32940
33009
|
WHERE e.rule_id = v.rule_id
|
|
32941
|
-
AND e.value_fingerprint = v.
|
|
33010
|
+
AND e.value_fingerprint = v.value_identity_fingerprint
|
|
32942
33011
|
AND e.key_version = v.fingerprint_key_version
|
|
32943
33012
|
AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
|
|
32944
33013
|
LIMIT 1) AS grant_id
|
|
@@ -33042,6 +33111,18 @@ var OPEN_AT_REST_FINDINGS_SQL = `FROM inspection_findings f
|
|
|
33042
33111
|
OR latest.status IS NULL
|
|
33043
33112
|
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
33044
33113
|
)`;
|
|
33114
|
+
function selectOpenFindingKeysForRule(db, ruleId) {
|
|
33115
|
+
const rows = allRows(
|
|
33116
|
+
db.prepare(
|
|
33117
|
+
`SELECT DISTINCT f.finding_key AS finding_key
|
|
33118
|
+
${OPEN_AT_REST_FINDINGS_SQL}
|
|
33119
|
+
AND d.rule_id = :ruleId
|
|
33120
|
+
AND f.finding_key IS NOT NULL`
|
|
33121
|
+
),
|
|
33122
|
+
{ ruleId }
|
|
33123
|
+
);
|
|
33124
|
+
return rows.map((r) => r.finding_key);
|
|
33125
|
+
}
|
|
33045
33126
|
var SEVERITIES = ["critical", "high", "medium", "low"];
|
|
33046
33127
|
var ACTION_TO_KIND = {
|
|
33047
33128
|
block: "blocked",
|
|
@@ -33098,16 +33179,16 @@ var SqliteSecurityRepository = class {
|
|
|
33098
33179
|
// findings are caught only once their latest disposition is resolved,
|
|
33099
33180
|
// otherwise they are open-at-rest.
|
|
33100
33181
|
//
|
|
33101
|
-
//
|
|
33102
|
-
//
|
|
33103
|
-
//
|
|
33104
|
-
//
|
|
33105
|
-
// be bucketed as caught
|
|
33182
|
+
// Only latest status 'resolved' counts as caught above. 'dismissed' is its
|
|
33183
|
+
// own bucket: a judgement rather than a fix, so it is neither caught nor
|
|
33184
|
+
// needing remediation, and stays countable. A further manual disposition
|
|
33185
|
+
// (acknowledged, false-positive) must be placed deliberately — 'acknowledged'
|
|
33186
|
+
// is accepted risk, not a fix, and must NOT be bucketed as caught.
|
|
33106
33187
|
//
|
|
33107
33188
|
// Legacy at-rest findings from pre-branch scans carry finding_key = NULL —
|
|
33108
33189
|
// the resolution lifecycle is keyed by finding_key, so it can never attach a
|
|
33109
33190
|
// disposition to (or clear) one of these on re-scan. They are excluded from
|
|
33110
|
-
//
|
|
33191
|
+
// all three buckets (untracked, not "needs remediation forever"),
|
|
33111
33192
|
// but still counted in total/count below — this keeps this predicate
|
|
33112
33193
|
// consistent with SqliteResolutionsRepository.openAtRestKeysForPath, which
|
|
33113
33194
|
// already filters `finding_key IS NOT NULL`.
|
|
@@ -33130,12 +33211,25 @@ var SqliteSecurityRepository = class {
|
|
|
33130
33211
|
WHEN latest.status = 'resolved' THEN 1
|
|
33131
33212
|
ELSE 0
|
|
33132
33213
|
END) AS caught,
|
|
33214
|
+
SUM(CASE WHEN e.event_type != 'code_change' THEN 1 ELSE 0 END) AS handled,
|
|
33133
33215
|
SUM(CASE
|
|
33134
33216
|
WHEN e.event_type = 'code_change'
|
|
33135
33217
|
AND f.finding_key IS NOT NULL
|
|
33136
|
-
AND
|
|
33218
|
+
AND latest.status = 'resolved' THEN 1
|
|
33137
33219
|
ELSE 0
|
|
33138
|
-
END) AS
|
|
33220
|
+
END) AS resolved,
|
|
33221
|
+
SUM(CASE
|
|
33222
|
+
WHEN e.event_type = 'code_change'
|
|
33223
|
+
AND f.finding_key IS NOT NULL
|
|
33224
|
+
AND (latest.status IS NULL
|
|
33225
|
+
OR latest.status NOT IN ('resolved', 'dismissed')) THEN 1
|
|
33226
|
+
ELSE 0
|
|
33227
|
+
END) AS open_at_rest,
|
|
33228
|
+
SUM(CASE
|
|
33229
|
+
WHEN e.event_type = 'code_change'
|
|
33230
|
+
AND latest.status = 'dismissed' THEN 1
|
|
33231
|
+
ELSE 0
|
|
33232
|
+
END) AS dismissed
|
|
33139
33233
|
FROM inspection_findings f
|
|
33140
33234
|
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
33141
33235
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -33150,11 +33244,15 @@ var SqliteSecurityRepository = class {
|
|
|
33150
33244
|
severity,
|
|
33151
33245
|
count: byRow.get(severity)?.count ?? 0,
|
|
33152
33246
|
caught: byRow.get(severity)?.caught ?? 0,
|
|
33153
|
-
|
|
33247
|
+
handled: byRow.get(severity)?.handled ?? 0,
|
|
33248
|
+
resolved: byRow.get(severity)?.resolved ?? 0,
|
|
33249
|
+
openAtRest: byRow.get(severity)?.open_at_rest ?? 0,
|
|
33250
|
+
dismissed: byRow.get(severity)?.dismissed ?? 0
|
|
33154
33251
|
}));
|
|
33155
33252
|
const total = bySeverity.reduce((sum, s) => sum + s.count, 0);
|
|
33156
33253
|
const needsRemediation = bySeverity.reduce((sum, s) => sum + s.openAtRest, 0);
|
|
33157
|
-
|
|
33254
|
+
const dismissed = bySeverity.reduce((sum, s) => sum + s.dismissed, 0);
|
|
33255
|
+
return Promise.resolve({ total, needsRemediation, dismissed, bySeverity });
|
|
33158
33256
|
}
|
|
33159
33257
|
// Range is echoed but does not change the result today — coverage is a constant
|
|
33160
33258
|
// business fact (see SCAN_COVERAGE), not a measured per-window metric. Order
|
|
@@ -33471,10 +33569,10 @@ var SqliteSecurityRepository = class {
|
|
|
33471
33569
|
* machine, and the second reported "no recommendations" over live exposure.
|
|
33472
33570
|
*
|
|
33473
33571
|
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
33474
|
-
* so a row's count is exactly what `?status=open&type=<rule>` returns.
|
|
33475
|
-
*
|
|
33476
|
-
*
|
|
33477
|
-
*
|
|
33572
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. It
|
|
33573
|
+
* differs from `severitySummary`'s `openAtRest` only in including untracked
|
|
33574
|
+
* legacy rows, which that bucket leaves out; dismissed is excluded from both.
|
|
33575
|
+
* Only this one has to match a link.
|
|
33478
33576
|
*
|
|
33479
33577
|
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
33480
33578
|
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
@@ -33502,6 +33600,8 @@ var SqliteSecurityRepository = class {
|
|
|
33502
33600
|
/**
|
|
33503
33601
|
* The distinct `finding_key`s behind ONE rule's {@link recommendationInputs}
|
|
33504
33602
|
* tally — what a dashboard dismissal of that row writes a disposition for.
|
|
33603
|
+
* The dismissal itself does not call this: it reads the same set through
|
|
33604
|
+
* {@link selectOpenFindingKeysForRule}, inside its own write transaction.
|
|
33505
33605
|
*
|
|
33506
33606
|
* It shares {@link OPEN_AT_REST_FINDINGS_SQL} with the count rather than
|
|
33507
33607
|
* restating the predicate, because a dismissal has to act on exactly the set
|
|
@@ -33518,16 +33618,7 @@ var SqliteSecurityRepository = class {
|
|
|
33518
33618
|
* this set SMALLER than the tally, never larger.
|
|
33519
33619
|
*/
|
|
33520
33620
|
openFindingKeysForRule(ruleId) {
|
|
33521
|
-
|
|
33522
|
-
this.db.prepare(
|
|
33523
|
-
`SELECT DISTINCT f.finding_key AS finding_key
|
|
33524
|
-
${OPEN_AT_REST_FINDINGS_SQL}
|
|
33525
|
-
AND d.rule_id = :ruleId
|
|
33526
|
-
AND f.finding_key IS NOT NULL`
|
|
33527
|
-
),
|
|
33528
|
-
{ ruleId }
|
|
33529
|
-
);
|
|
33530
|
-
return Promise.resolve(rows.map((r) => r.finding_key));
|
|
33621
|
+
return Promise.resolve(selectOpenFindingKeysForRule(this.db, ruleId));
|
|
33531
33622
|
}
|
|
33532
33623
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
33533
33624
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
@@ -34573,6 +34664,31 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34573
34664
|
);
|
|
34574
34665
|
});
|
|
34575
34666
|
}
|
|
34667
|
+
function dismissOpenFindingsForRule(ruleId, disposition) {
|
|
34668
|
+
let dismissed = 0;
|
|
34669
|
+
withTransaction(
|
|
34670
|
+
db,
|
|
34671
|
+
() => {
|
|
34672
|
+
const keys = selectOpenFindingKeysForRule(db, ruleId);
|
|
34673
|
+
resolutions.insertResolutions(
|
|
34674
|
+
keys.map((findingKey) => ({
|
|
34675
|
+
findingKey,
|
|
34676
|
+
status: "dismissed",
|
|
34677
|
+
method: disposition.method,
|
|
34678
|
+
resolvedAt: disposition.resolvedAt,
|
|
34679
|
+
evidence: disposition.evidence
|
|
34680
|
+
}))
|
|
34681
|
+
);
|
|
34682
|
+
dismissed = keys.length;
|
|
34683
|
+
},
|
|
34684
|
+
// IMMEDIATE takes the write lock at BEGIN, before the select, which is
|
|
34685
|
+
// what keeps a concurrent resolve out of the gap. It also makes waiting
|
|
34686
|
+
// on a busy writer an ordinary busy_timeout wait rather than a
|
|
34687
|
+
// read-to-write upgrade SQLite refuses to retry.
|
|
34688
|
+
"IMMEDIATE"
|
|
34689
|
+
);
|
|
34690
|
+
return dismissed;
|
|
34691
|
+
}
|
|
34576
34692
|
function recordCapture(event, detected) {
|
|
34577
34693
|
failOpenTransaction(db, () => {
|
|
34578
34694
|
const sessionId = event.metadata?.sessionId;
|
|
@@ -34756,6 +34872,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34756
34872
|
inspectionDefinitions,
|
|
34757
34873
|
inspectionFindings,
|
|
34758
34874
|
recordCapture,
|
|
34875
|
+
dismissOpenFindingsForRule,
|
|
34759
34876
|
markCaptureDelivered,
|
|
34760
34877
|
markCaptureOwed,
|
|
34761
34878
|
markAuditEventsDelivered,
|
|
@@ -35633,6 +35750,82 @@ function escapeRegExp2(value) {
|
|
|
35633
35750
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
35634
35751
|
}
|
|
35635
35752
|
|
|
35753
|
+
// ../../packages/detections/src/format-chars.ts
|
|
35754
|
+
var HAS_FORMAT_CHAR = new RegExp("\\p{Cf}", "u");
|
|
35755
|
+
var FORMAT_CHAR_GLOBAL = new RegExp("\\p{Cf}", "gu");
|
|
35756
|
+
function normalizeFormatChars(text) {
|
|
35757
|
+
if (!HAS_FORMAT_CHAR.test(text)) return void 0;
|
|
35758
|
+
const normalizedParts = [];
|
|
35759
|
+
const segments = [];
|
|
35760
|
+
let cursor = 0;
|
|
35761
|
+
let normLength = 0;
|
|
35762
|
+
for (const match of text.matchAll(FORMAT_CHAR_GLOBAL)) {
|
|
35763
|
+
const matchStart = match.index;
|
|
35764
|
+
if (matchStart > cursor) {
|
|
35765
|
+
const length = matchStart - cursor;
|
|
35766
|
+
normalizedParts.push(text.slice(cursor, matchStart));
|
|
35767
|
+
segments.push({ normStart: normLength, origStart: cursor, length });
|
|
35768
|
+
normLength += length;
|
|
35769
|
+
}
|
|
35770
|
+
cursor = matchStart + match[0].length;
|
|
35771
|
+
}
|
|
35772
|
+
if (cursor < text.length) {
|
|
35773
|
+
const length = text.length - cursor;
|
|
35774
|
+
normalizedParts.push(text.slice(cursor));
|
|
35775
|
+
segments.push({ normStart: normLength, origStart: cursor, length });
|
|
35776
|
+
}
|
|
35777
|
+
return { normalized: normalizedParts.join(""), segments };
|
|
35778
|
+
}
|
|
35779
|
+
function segmentAt(segments, normPos) {
|
|
35780
|
+
let lo = 0;
|
|
35781
|
+
let hi = segments.length - 1;
|
|
35782
|
+
while (lo < hi) {
|
|
35783
|
+
const mid = lo + hi >> 1;
|
|
35784
|
+
const segment = segments[mid];
|
|
35785
|
+
if (segment !== void 0 && normPos >= segment.normStart + segment.length) {
|
|
35786
|
+
lo = mid + 1;
|
|
35787
|
+
} else {
|
|
35788
|
+
hi = mid;
|
|
35789
|
+
}
|
|
35790
|
+
}
|
|
35791
|
+
const found = segments[lo];
|
|
35792
|
+
if (found === void 0) {
|
|
35793
|
+
throw new Error(`normPos ${String(normPos)} has no covering segment`);
|
|
35794
|
+
}
|
|
35795
|
+
return found;
|
|
35796
|
+
}
|
|
35797
|
+
function mapSpanToOriginal(span, normalization) {
|
|
35798
|
+
const { segments } = normalization;
|
|
35799
|
+
const startSegment = segmentAt(segments, span.start);
|
|
35800
|
+
const start = startSegment.origStart + (span.start - startSegment.normStart);
|
|
35801
|
+
const endSegment = segmentAt(segments, span.end - 1);
|
|
35802
|
+
const end = endSegment.origStart + (span.end - 1 - endSegment.normStart) + 1;
|
|
35803
|
+
return { start, end };
|
|
35804
|
+
}
|
|
35805
|
+
function normalizedOffset(origPos, segments) {
|
|
35806
|
+
let lo = 0;
|
|
35807
|
+
let hi = segments.length;
|
|
35808
|
+
while (lo < hi) {
|
|
35809
|
+
const mid = lo + hi >> 1;
|
|
35810
|
+
const segment = segments[mid];
|
|
35811
|
+
if (segment !== void 0 && segment.origStart + segment.length <= origPos) {
|
|
35812
|
+
lo = mid + 1;
|
|
35813
|
+
} else {
|
|
35814
|
+
hi = mid;
|
|
35815
|
+
}
|
|
35816
|
+
}
|
|
35817
|
+
const found = segments[Math.min(lo, segments.length - 1)];
|
|
35818
|
+
if (found === void 0) return 0;
|
|
35819
|
+
return found.normStart + Math.min(Math.max(0, origPos - found.origStart), found.length);
|
|
35820
|
+
}
|
|
35821
|
+
function mapSpanToNormalized(span, normalization) {
|
|
35822
|
+
const { segments } = normalization;
|
|
35823
|
+
return {
|
|
35824
|
+
start: normalizedOffset(span.start, segments),
|
|
35825
|
+
end: normalizedOffset(span.end, segments)
|
|
35826
|
+
};
|
|
35827
|
+
}
|
|
35828
|
+
|
|
35636
35829
|
// ../../packages/detections/src/regex-cache.ts
|
|
35637
35830
|
var singles = /* @__PURE__ */ new WeakMap();
|
|
35638
35831
|
var keywordLists = /* @__PURE__ */ new WeakMap();
|
|
@@ -35794,29 +35987,35 @@ function registerPack(pack) {
|
|
|
35794
35987
|
function getLoadedRules() {
|
|
35795
35988
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
35796
35989
|
}
|
|
35797
|
-
function
|
|
35990
|
+
function spansOverlap(a, b) {
|
|
35991
|
+
return a.start < b.end && a.end > b.start;
|
|
35992
|
+
}
|
|
35993
|
+
function isCorroborated(candidate, candidates, text, normalization) {
|
|
35798
35994
|
const req = candidate.rule.requiresNearby;
|
|
35799
35995
|
if (!req) return true;
|
|
35800
35996
|
const halfWindow = req.windowChars;
|
|
35801
|
-
const
|
|
35802
|
-
const winStart = start - halfWindow;
|
|
35803
|
-
const winEnd = end + halfWindow;
|
|
35997
|
+
const ns = candidate.normSpan;
|
|
35998
|
+
const winStart = ns.start - halfWindow;
|
|
35999
|
+
const winEnd = ns.end + halfWindow;
|
|
35804
36000
|
const categories = req.categories;
|
|
35805
36001
|
const ruleIds = req.ruleIds;
|
|
35806
36002
|
if (categories?.length || ruleIds?.length) {
|
|
35807
36003
|
for (const other of candidates) {
|
|
35808
36004
|
if (other === candidate) continue;
|
|
35809
|
-
|
|
35810
|
-
|
|
35811
|
-
if (
|
|
35812
|
-
|
|
36005
|
+
if (other.normSpan.end < winStart || other.normSpan.start > winEnd) continue;
|
|
36006
|
+
const relevant = other.match.ruleId !== candidate.match.ruleId && categories?.includes(other.match.category) === true || ruleIds?.includes(other.match.ruleId) === true;
|
|
36007
|
+
if (!relevant) continue;
|
|
36008
|
+
if (other.match.ruleId === candidate.match.ruleId && spansOverlap(other.match.span, candidate.match.span)) {
|
|
36009
|
+
continue;
|
|
35813
36010
|
}
|
|
35814
|
-
|
|
36011
|
+
return true;
|
|
35815
36012
|
}
|
|
35816
36013
|
}
|
|
35817
36014
|
const labels = req.labels;
|
|
35818
36015
|
if (labels && labels.length > 0) {
|
|
35819
|
-
const
|
|
36016
|
+
const { start, end } = candidate.match.span;
|
|
36017
|
+
const haystack = text.slice(Math.max(0, start - halfWindow), end + halfWindow);
|
|
36018
|
+
const normalizedHaystack = normalization === void 0 ? void 0 : normalization.normalized.slice(Math.max(0, winStart), winEnd);
|
|
35820
36019
|
for (const re of memoizedRegExpList(
|
|
35821
36020
|
"label",
|
|
35822
36021
|
req,
|
|
@@ -35825,29 +36024,20 @@ function isCorroborated(candidate, candidates, text) {
|
|
|
35825
36024
|
return trimmed.length === 0 ? void 0 : new RegExp(`(?<![A-Za-z0-9])${escapeRegExp2(trimmed)}(?![A-Za-z0-9])`, "i");
|
|
35826
36025
|
})
|
|
35827
36026
|
)) {
|
|
35828
|
-
if (re
|
|
36027
|
+
if (!re) continue;
|
|
36028
|
+
if (re.test(haystack)) return true;
|
|
36029
|
+
if (normalizedHaystack !== void 0 && re.test(normalizedHaystack)) return true;
|
|
35829
36030
|
}
|
|
35830
36031
|
}
|
|
35831
36032
|
return false;
|
|
35832
36033
|
}
|
|
35833
|
-
function
|
|
35834
|
-
const base = filePath.slice(Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) + 1);
|
|
35835
|
-
const dot = base.lastIndexOf(".");
|
|
35836
|
-
return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
|
|
35837
|
-
}
|
|
35838
|
-
function ruleApplies(rule, extension) {
|
|
35839
|
-
if (!rule.appliesTo || extension === void 0) return true;
|
|
35840
|
-
return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
|
|
35841
|
-
}
|
|
35842
|
-
function scan(text, rules, context) {
|
|
35843
|
-
const ruleset = rules ?? getLoadedRules();
|
|
35844
|
-
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
36034
|
+
function buildCandidates(matchText, ruleset, extension) {
|
|
35845
36035
|
const candidates = [];
|
|
35846
36036
|
for (const rule of ruleset) {
|
|
35847
36037
|
if (!ruleApplies(rule, extension)) continue;
|
|
35848
|
-
const spans = MATCHERS[rule.matcher.type](
|
|
36038
|
+
const spans = MATCHERS[rule.matcher.type](matchText, rule);
|
|
35849
36039
|
for (const span of spans) {
|
|
35850
|
-
const rawMatch =
|
|
36040
|
+
const rawMatch = matchText.slice(span.start, span.end);
|
|
35851
36041
|
if (!passesPostValidators(rule, rawMatch)) continue;
|
|
35852
36042
|
candidates.push({
|
|
35853
36043
|
rule,
|
|
@@ -35858,10 +36048,31 @@ function scan(text, rules, context) {
|
|
|
35858
36048
|
span,
|
|
35859
36049
|
rawMatch,
|
|
35860
36050
|
confidence: 0.9
|
|
35861
|
-
}
|
|
36051
|
+
},
|
|
36052
|
+
// In `matchText`'s own coordinates, which is the normalized text for
|
|
36053
|
+
// a normalized-pass candidate and so already right; an original-pass
|
|
36054
|
+
// candidate on the slow path is re-derived by withNormalizedSpan.
|
|
36055
|
+
normSpan: span
|
|
35862
36056
|
});
|
|
35863
36057
|
}
|
|
35864
36058
|
}
|
|
36059
|
+
return candidates;
|
|
36060
|
+
}
|
|
36061
|
+
function mapCandidateToOriginal(candidate, normalization, text) {
|
|
36062
|
+
const span = mapSpanToOriginal(candidate.match.span, normalization);
|
|
36063
|
+
return {
|
|
36064
|
+
rule: candidate.rule,
|
|
36065
|
+
match: { ...candidate.match, span, rawMatch: text.slice(span.start, span.end) },
|
|
36066
|
+
// Deliberately NOT remapped: `normSpan` is the span the primitive match
|
|
36067
|
+
// was found at in the normalized text, which is exactly the coordinate
|
|
36068
|
+
// space windows are measured in. See the `Candidate` comment.
|
|
36069
|
+
normSpan: candidate.normSpan
|
|
36070
|
+
};
|
|
36071
|
+
}
|
|
36072
|
+
function withNormalizedSpan(candidate, normalization) {
|
|
36073
|
+
return { ...candidate, normSpan: mapSpanToNormalized(candidate.match.span, normalization) };
|
|
36074
|
+
}
|
|
36075
|
+
function gate(candidates, text, normalization) {
|
|
35865
36076
|
const findings = [];
|
|
35866
36077
|
for (const candidate of candidates) {
|
|
35867
36078
|
const req = candidate.rule.requiresNearby;
|
|
@@ -35869,7 +36080,7 @@ function scan(text, rules, context) {
|
|
|
35869
36080
|
findings.push(candidate.match);
|
|
35870
36081
|
continue;
|
|
35871
36082
|
}
|
|
35872
|
-
if (!isCorroborated(candidate, candidates, text)) continue;
|
|
36083
|
+
if (!isCorroborated(candidate, candidates, text, normalization)) continue;
|
|
35873
36084
|
const boost = req.confidenceBoost;
|
|
35874
36085
|
findings.push(
|
|
35875
36086
|
boost ? { ...candidate.match, confidence: Math.min(0.99, candidate.match.confidence + boost) } : candidate.match
|
|
@@ -35877,6 +36088,81 @@ function scan(text, rules, context) {
|
|
|
35877
36088
|
}
|
|
35878
36089
|
return findings;
|
|
35879
36090
|
}
|
|
36091
|
+
function closeRegion(open3, text) {
|
|
36092
|
+
const span = { start: open3.start, end: open3.end };
|
|
36093
|
+
return {
|
|
36094
|
+
ruleId: open3.ruleId,
|
|
36095
|
+
category: open3.category,
|
|
36096
|
+
severity: open3.severity,
|
|
36097
|
+
span,
|
|
36098
|
+
rawMatch: text.slice(span.start, span.end),
|
|
36099
|
+
confidence: open3.confidence
|
|
36100
|
+
};
|
|
36101
|
+
}
|
|
36102
|
+
function mergeOverlappingSameRule(findings, text) {
|
|
36103
|
+
if (findings.length === 0) return findings;
|
|
36104
|
+
const groups = /* @__PURE__ */ new Map();
|
|
36105
|
+
const ruleOrder = [];
|
|
36106
|
+
for (const finding of findings) {
|
|
36107
|
+
const group = groups.get(finding.ruleId);
|
|
36108
|
+
if (group) {
|
|
36109
|
+
group.push(finding);
|
|
36110
|
+
} else {
|
|
36111
|
+
groups.set(finding.ruleId, [finding]);
|
|
36112
|
+
ruleOrder.push(finding.ruleId);
|
|
36113
|
+
}
|
|
36114
|
+
}
|
|
36115
|
+
const merged = [];
|
|
36116
|
+
for (const ruleId of ruleOrder) {
|
|
36117
|
+
const group = groups.get(ruleId) ?? [];
|
|
36118
|
+
const sorted = [...group].sort(
|
|
36119
|
+
(a, b) => a.span.start - b.span.start || a.span.end - b.span.end
|
|
36120
|
+
);
|
|
36121
|
+
let open3;
|
|
36122
|
+
for (const finding of sorted) {
|
|
36123
|
+
if (open3 && finding.span.start < open3.end) {
|
|
36124
|
+
open3.end = Math.max(open3.end, finding.span.end);
|
|
36125
|
+
open3.confidence = Math.max(open3.confidence, finding.confidence);
|
|
36126
|
+
continue;
|
|
36127
|
+
}
|
|
36128
|
+
if (open3) merged.push(closeRegion(open3, text));
|
|
36129
|
+
open3 = {
|
|
36130
|
+
start: finding.span.start,
|
|
36131
|
+
end: finding.span.end,
|
|
36132
|
+
confidence: finding.confidence,
|
|
36133
|
+
ruleId: finding.ruleId,
|
|
36134
|
+
category: finding.category,
|
|
36135
|
+
severity: finding.severity
|
|
36136
|
+
};
|
|
36137
|
+
}
|
|
36138
|
+
if (open3) merged.push(closeRegion(open3, text));
|
|
36139
|
+
}
|
|
36140
|
+
return merged;
|
|
36141
|
+
}
|
|
36142
|
+
function extensionOf(filePath) {
|
|
36143
|
+
const base = filePath.slice(Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) + 1);
|
|
36144
|
+
const dot = base.lastIndexOf(".");
|
|
36145
|
+
return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
|
|
36146
|
+
}
|
|
36147
|
+
function ruleApplies(rule, extension) {
|
|
36148
|
+
if (!rule.appliesTo || extension === void 0) return true;
|
|
36149
|
+
return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
|
|
36150
|
+
}
|
|
36151
|
+
function scan(text, rules, context) {
|
|
36152
|
+
const ruleset = rules ?? getLoadedRules();
|
|
36153
|
+
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
36154
|
+
const normalization = normalizeFormatChars(text);
|
|
36155
|
+
const originalCandidates = buildCandidates(text, ruleset, extension);
|
|
36156
|
+
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
36157
|
+
const pooledOriginal = originalCandidates.map(
|
|
36158
|
+
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
36159
|
+
);
|
|
36160
|
+
const normalizedCandidates = buildCandidates(normalization.normalized, ruleset, extension).map(
|
|
36161
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
36162
|
+
);
|
|
36163
|
+
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
36164
|
+
return mergeOverlappingSameRule(findings, text);
|
|
36165
|
+
}
|
|
35880
36166
|
var SEVERITY_RANK2 = {
|
|
35881
36167
|
critical: 3,
|
|
35882
36168
|
high: 2,
|
|
@@ -38485,7 +38771,7 @@ async function send(options) {
|
|
|
38485
38771
|
}
|
|
38486
38772
|
}
|
|
38487
38773
|
};
|
|
38488
|
-
return new Promise((
|
|
38774
|
+
return new Promise((resolve3, reject) => {
|
|
38489
38775
|
let settled = false;
|
|
38490
38776
|
const fail = (reason, status) => {
|
|
38491
38777
|
if (settled) return;
|
|
@@ -38511,7 +38797,7 @@ async function send(options) {
|
|
|
38511
38797
|
res.on("end", () => {
|
|
38512
38798
|
if (settled) return;
|
|
38513
38799
|
settled = true;
|
|
38514
|
-
|
|
38800
|
+
resolve3({
|
|
38515
38801
|
status: res.statusCode ?? 0,
|
|
38516
38802
|
headers: res.headers,
|
|
38517
38803
|
body: Buffer.concat(chunks).toString("utf8")
|
|
@@ -39507,8 +39793,52 @@ import { spawn } from "child_process";
|
|
|
39507
39793
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
39508
39794
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
39509
39795
|
|
|
39796
|
+
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
39797
|
+
import { readFile as readFile2, stat } from "fs/promises";
|
|
39798
|
+
import { basename as basename6, dirname as dirname6, join as join28, resolve as resolve2 } from "path";
|
|
39799
|
+
async function readInstalledVersion(installRoot) {
|
|
39800
|
+
try {
|
|
39801
|
+
const versionDir = resolve2(installRoot);
|
|
39802
|
+
const pluginDir = dirname6(versionDir);
|
|
39803
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
39804
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
39805
|
+
if (basename6(cacheDir) !== "cache") return null;
|
|
39806
|
+
const key = `${basename6(pluginDir)}@${basename6(marketplaceDir)}`;
|
|
39807
|
+
const record2 = JSON.parse(
|
|
39808
|
+
await readFile2(join28(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
39809
|
+
);
|
|
39810
|
+
const plugins = record2?.plugins;
|
|
39811
|
+
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
39812
|
+
return null;
|
|
39813
|
+
}
|
|
39814
|
+
const entries = plugins[key];
|
|
39815
|
+
if (!Array.isArray(entries)) return null;
|
|
39816
|
+
let newest = null;
|
|
39817
|
+
for (const entry of entries) {
|
|
39818
|
+
const { version: version2, installPath } = entry ?? {};
|
|
39819
|
+
if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) continue;
|
|
39820
|
+
if (!StorePosturePlugin.shape.installedVersion.safeParse(version2).success) continue;
|
|
39821
|
+
if (newest !== null && compareBinaryVersions(version2, newest) <= 0) continue;
|
|
39822
|
+
if (typeof installPath === "string" && !await exists(installPath)) continue;
|
|
39823
|
+
newest = version2;
|
|
39824
|
+
}
|
|
39825
|
+
return newest;
|
|
39826
|
+
} catch {
|
|
39827
|
+
return null;
|
|
39828
|
+
}
|
|
39829
|
+
}
|
|
39830
|
+
async function exists(path) {
|
|
39831
|
+
try {
|
|
39832
|
+
await stat(path);
|
|
39833
|
+
return true;
|
|
39834
|
+
} catch {
|
|
39835
|
+
return false;
|
|
39836
|
+
}
|
|
39837
|
+
}
|
|
39838
|
+
|
|
39510
39839
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
39511
39840
|
import { readFileSync as readFileSync18 } from "fs";
|
|
39841
|
+
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
39512
39842
|
var manifestBuildCache = /* @__PURE__ */ new Map();
|
|
39513
39843
|
function readManifestBuild(manifestUrl, packageName) {
|
|
39514
39844
|
const key = manifestUrl.href;
|
|
@@ -39526,6 +39856,7 @@ function readManifestBuild(manifestUrl, packageName) {
|
|
|
39526
39856
|
}
|
|
39527
39857
|
function createPluginBlock(build, policyStore) {
|
|
39528
39858
|
return async () => {
|
|
39859
|
+
const installed = build.installRoot === void 0 ? void 0 : readInstalledVersionBounded(build.installRoot);
|
|
39529
39860
|
const cached2 = await policyStore.read();
|
|
39530
39861
|
const fetchedAtMs = cached2?.fetchedAtMs;
|
|
39531
39862
|
const block = {
|
|
@@ -39533,16 +39864,25 @@ function createPluginBlock(build, policyStore) {
|
|
|
39533
39864
|
version: build.version,
|
|
39534
39865
|
ossVersion: build.ossVersion ?? null,
|
|
39535
39866
|
policyBundleVersion: cached2 !== null && StorePosturePlugin.shape.policyBundleVersion.safeParse(cached2.bundle.version).success ? cached2.bundle.version : null,
|
|
39536
|
-
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null
|
|
39867
|
+
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null,
|
|
39868
|
+
...installed === void 0 ? {} : { installedVersion: await installed },
|
|
39869
|
+
buildSchemaVersion: SQLITE_MIGRATIONS.length
|
|
39537
39870
|
};
|
|
39538
39871
|
return StorePosturePlugin.safeParse(block).success ? block : void 0;
|
|
39539
39872
|
};
|
|
39540
39873
|
}
|
|
39874
|
+
async function readInstalledVersionBounded(installRoot) {
|
|
39875
|
+
try {
|
|
39876
|
+
return await withTimeout(readInstalledVersion(installRoot), INSTALL_RECORD_READ_TIMEOUT_MS);
|
|
39877
|
+
} catch {
|
|
39878
|
+
return null;
|
|
39879
|
+
}
|
|
39880
|
+
}
|
|
39541
39881
|
|
|
39542
39882
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
39543
39883
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
39544
|
-
import { readFile as
|
|
39545
|
-
import { join as
|
|
39884
|
+
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
39885
|
+
import { join as join29 } from "path";
|
|
39546
39886
|
|
|
39547
39887
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
39548
39888
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -39550,11 +39890,11 @@ var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
|
39550
39890
|
var IMMEDIATE_RETRIES = 8;
|
|
39551
39891
|
var TIMED_RETRIES = 4;
|
|
39552
39892
|
var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
|
|
39553
|
-
var delay = (ms) => new Promise((
|
|
39554
|
-
setTimeout(
|
|
39893
|
+
var delay = (ms) => new Promise((resolve3) => {
|
|
39894
|
+
setTimeout(resolve3, ms);
|
|
39555
39895
|
});
|
|
39556
|
-
var yieldToLoop = () => new Promise((
|
|
39557
|
-
setImmediate(
|
|
39896
|
+
var yieldToLoop = () => new Promise((resolve3) => {
|
|
39897
|
+
setImmediate(resolve3);
|
|
39558
39898
|
});
|
|
39559
39899
|
async function publishByRename(tmp, file2, move = rename2) {
|
|
39560
39900
|
for (let attempt = 1; ; attempt += 1) {
|
|
@@ -39571,10 +39911,10 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
39571
39911
|
|
|
39572
39912
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
39573
39913
|
function createPolicyStore(dir = dataDir()) {
|
|
39574
|
-
const file2 =
|
|
39914
|
+
const file2 = join29(dir, "policy-cache.json");
|
|
39575
39915
|
async function read() {
|
|
39576
39916
|
try {
|
|
39577
|
-
const raw = await
|
|
39917
|
+
const raw = await readFile3(file2, "utf8");
|
|
39578
39918
|
const parsed2 = JSON.parse(raw);
|
|
39579
39919
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
39580
39920
|
const record2 = parsed2;
|
|
@@ -39596,7 +39936,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
39596
39936
|
}
|
|
39597
39937
|
async function priorRecord() {
|
|
39598
39938
|
try {
|
|
39599
|
-
const parsed2 = JSON.parse(await
|
|
39939
|
+
const parsed2 = JSON.parse(await readFile3(file2, "utf8"));
|
|
39600
39940
|
return typeof parsed2 === "object" && parsed2 !== null ? parsed2 : null;
|
|
39601
39941
|
} catch {
|
|
39602
39942
|
return null;
|
|
@@ -39642,7 +39982,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
39642
39982
|
|
|
39643
39983
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
39644
39984
|
import { readFileSync as readFileSync19 } from "fs";
|
|
39645
|
-
import { join as
|
|
39985
|
+
import { join as join30 } from "path";
|
|
39646
39986
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
39647
39987
|
var OUTCOME_KEYS = {
|
|
39648
39988
|
ok: true,
|
|
@@ -39656,7 +39996,7 @@ var OUTCOME_KEYS = {
|
|
|
39656
39996
|
};
|
|
39657
39997
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
39658
39998
|
function postureReportStatePath(dataDir2) {
|
|
39659
|
-
return
|
|
39999
|
+
return join30(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
39660
40000
|
}
|
|
39661
40001
|
function writePostureReportState(dataDir2, state) {
|
|
39662
40002
|
try {
|
|
@@ -39835,12 +40175,12 @@ function readStorePosture(dbPath2) {
|
|
|
39835
40175
|
|
|
39836
40176
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
39837
40177
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
39838
|
-
import { readFile as
|
|
39839
|
-
import { join as
|
|
40178
|
+
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
40179
|
+
import { join as join31 } from "path";
|
|
39840
40180
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
39841
40181
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
39842
|
-
const file2 =
|
|
39843
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
40182
|
+
const file2 = join31(dir, "posture-state.json");
|
|
40183
|
+
const legacyFile = legacyDir === void 0 ? null : join31(legacyDir, "posture-state.json");
|
|
39844
40184
|
async function persist(state) {
|
|
39845
40185
|
await ensureDataDir(dir);
|
|
39846
40186
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -39855,7 +40195,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
39855
40195
|
async function readFrom(path) {
|
|
39856
40196
|
let raw;
|
|
39857
40197
|
try {
|
|
39858
|
-
raw = await
|
|
40198
|
+
raw = await readFile4(path, "utf8");
|
|
39859
40199
|
} catch (err) {
|
|
39860
40200
|
const code = err.code;
|
|
39861
40201
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
@@ -39909,7 +40249,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
39909
40249
|
|
|
39910
40250
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
39911
40251
|
import { readFileSync as readFileSync20 } from "fs";
|
|
39912
|
-
import { join as
|
|
40252
|
+
import { join as join32 } from "path";
|
|
39913
40253
|
|
|
39914
40254
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
39915
40255
|
var REFUSAL_LINES = {
|
|
@@ -39986,12 +40326,12 @@ var StandaloneDataGateway = class {
|
|
|
39986
40326
|
// reconciler drops the whole pass and recovers it idempotently on the next read.
|
|
39987
40327
|
recordLlmCalls(inputs) {
|
|
39988
40328
|
if (inputs.length === 0) return Promise.resolve();
|
|
39989
|
-
return new Promise((
|
|
40329
|
+
return new Promise((resolve3, reject) => {
|
|
39990
40330
|
try {
|
|
39991
40331
|
this.db.auditEvents.runInTransaction(() => {
|
|
39992
40332
|
for (const input2 of inputs) this.db.auditEvents.insertLlmCall(input2);
|
|
39993
40333
|
});
|
|
39994
|
-
|
|
40334
|
+
resolve3();
|
|
39995
40335
|
} catch (err) {
|
|
39996
40336
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
39997
40337
|
}
|
|
@@ -40003,12 +40343,12 @@ var StandaloneDataGateway = class {
|
|
|
40003
40343
|
// drops the whole pass and recovers it idempotently next time.
|
|
40004
40344
|
recordToolCalls(inputs) {
|
|
40005
40345
|
if (inputs.length === 0) return Promise.resolve();
|
|
40006
|
-
return new Promise((
|
|
40346
|
+
return new Promise((resolve3, reject) => {
|
|
40007
40347
|
try {
|
|
40008
40348
|
this.db.auditEvents.runInTransaction(() => {
|
|
40009
40349
|
for (const input2 of inputs) this.writeToolCall(input2);
|
|
40010
40350
|
});
|
|
40011
|
-
|
|
40351
|
+
resolve3();
|
|
40012
40352
|
} catch (err) {
|
|
40013
40353
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
40014
40354
|
}
|
|
@@ -40420,9 +40760,9 @@ import {
|
|
|
40420
40760
|
readSync as readSync2,
|
|
40421
40761
|
writeFileSync as writeFileSync8
|
|
40422
40762
|
} from "fs";
|
|
40423
|
-
import { join as
|
|
40763
|
+
import { join as join33 } from "path";
|
|
40424
40764
|
function offsetsDir(dataDir2) {
|
|
40425
|
-
return
|
|
40765
|
+
return join33(dataDir2, "usage-offsets");
|
|
40426
40766
|
}
|
|
40427
40767
|
var SAFE_SESSION_ID = /^[A-Za-z0-9._-]+$/;
|
|
40428
40768
|
function safeSessionId(sessionId) {
|
|
@@ -40432,7 +40772,7 @@ function safeSessionId(sessionId) {
|
|
|
40432
40772
|
return createHash7("sha256").update(sessionId).digest("hex");
|
|
40433
40773
|
}
|
|
40434
40774
|
function offsetPath(dataDir2, sessionId) {
|
|
40435
|
-
return
|
|
40775
|
+
return join33(offsetsDir(dataDir2), safeSessionId(sessionId));
|
|
40436
40776
|
}
|
|
40437
40777
|
function readOffset(dataDir2, sessionId) {
|
|
40438
40778
|
try {
|
|
@@ -40496,7 +40836,7 @@ function readTail(transcriptPath, startOffset) {
|
|
|
40496
40836
|
// src/history/transcripts.ts
|
|
40497
40837
|
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as readFileSync22, readSync as readSync3, statSync as statSync10 } from "fs";
|
|
40498
40838
|
import { homedir as homedir3 } from "os";
|
|
40499
|
-
import { join as
|
|
40839
|
+
import { join as join34 } from "path";
|
|
40500
40840
|
function isRecord(value) {
|
|
40501
40841
|
return typeof value === "object" && value !== null;
|
|
40502
40842
|
}
|