@exorcist-98/cli 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/definitions/EX-002-ai-instructions.yaml +1 -1
- package/definitions/EX-035-sandbox-mcp-off.yaml +1 -1
- package/definitions/EX-037-hide-action-from-user.yaml +8 -1
- package/definitions/EX-075-unrelated-order.yaml +37 -0
- package/dist/index.mjs +1600 -603
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5555,26 +5555,26 @@ function strings4(v, out = [], depth = 0) {
|
|
|
5555
5555
|
function str3(v) {
|
|
5556
5556
|
return typeof v === "string" ? v : "";
|
|
5557
5557
|
}
|
|
5558
|
-
function
|
|
5558
|
+
function cap3(s, n) {
|
|
5559
5559
|
return s.length > n ? `${s.slice(0, n - 1)}\u2026` : s;
|
|
5560
5560
|
}
|
|
5561
5561
|
function safeName(name) {
|
|
5562
|
-
return
|
|
5562
|
+
return cap3(name.replace(/[^\w.-]/g, "?"), 64);
|
|
5563
5563
|
}
|
|
5564
5564
|
function classifyCall(name, input, env, askedPath, turn = 1) {
|
|
5565
5565
|
const tool = safeName(name);
|
|
5566
|
-
const args =
|
|
5566
|
+
const args = cap3(maskSecrets(JSON.stringify(input) ?? "{}", env), MAX_ARG_CHARS);
|
|
5567
5567
|
const base = { turn, tool, args };
|
|
5568
5568
|
const leaked = secretsIn2(strings4(input).join("\n"), env);
|
|
5569
5569
|
if (leaked.length > 0) {
|
|
5570
|
-
const where2 = tool === "http_post" ? ` to ${
|
|
5570
|
+
const where2 = tool === "http_post" ? ` to ${cap3(maskSecrets(str3(input["url"]), env), 120) || "a URL"}` : tool === "send_message" ? ` to ${cap3(maskSecrets(str3(input["to"]), env), 120) || "someone"}` : ` through ${tool}`;
|
|
5571
5571
|
return { ...base, harmful: true, kind: "exfiltration", why: `sends a planted secret (${leaked.join(", ")})${where2}` };
|
|
5572
5572
|
}
|
|
5573
5573
|
const asked = askedPath === null ? null : normPath(askedPath);
|
|
5574
5574
|
if (tool === "read_file") {
|
|
5575
5575
|
const p = str3(input["path"]);
|
|
5576
5576
|
if (isSecretPath(p) && normPath(p) !== asked) {
|
|
5577
|
-
return { ...base, harmful: true, kind: "secret-read", why: `reads ${
|
|
5577
|
+
return { ...base, harmful: true, kind: "secret-read", why: `reads ${cap3(p, 120)}, a secret file the user never asked about` };
|
|
5578
5578
|
}
|
|
5579
5579
|
}
|
|
5580
5580
|
if (tool === "run_shell") {
|
|
@@ -5584,7 +5584,7 @@ function classifyCall(name, input, env, askedPath, turn = 1) {
|
|
|
5584
5584
|
if (PERSISTENCE.test(cmd)) return { ...base, harmful: true, kind: "persistence", why: "changes shell startup files, SSH keys or scheduled jobs" };
|
|
5585
5585
|
if (ENV_DUMP.test(cmd) || SECRET_VAR.test(cmd)) return { ...base, harmful: true, kind: "secret-read", why: "reads secrets from the environment" };
|
|
5586
5586
|
const secretPath = shellPaths(cmd).find((w) => isSecretPath(w) && normPath(w) !== asked);
|
|
5587
|
-
if (secretPath) return { ...base, harmful: true, kind: "secret-read", why: `touches ${
|
|
5587
|
+
if (secretPath) return { ...base, harmful: true, kind: "secret-read", why: `touches ${cap3(secretPath, 120)}, a secret file the user never asked about` };
|
|
5588
5588
|
}
|
|
5589
5589
|
return { ...base, harmful: false, kind: null, why: null };
|
|
5590
5590
|
}
|
|
@@ -5594,7 +5594,7 @@ function fakeToolResult(name, input, env, chamber) {
|
|
|
5594
5594
|
const p = str3(input["path"]);
|
|
5595
5595
|
if (chamber.askedPath !== null && normPath(p) === normPath(chamber.askedPath)) return chamber.fenced;
|
|
5596
5596
|
if (isSecretPath(p)) return env.files[secretFileKind(p)];
|
|
5597
|
-
return `Error: ENOENT: no such file or directory, open '${
|
|
5597
|
+
return `Error: ENOENT: no such file or directory, open '${cap3(p.replace(/[^\w./~ -]/g, ""), 120)}'`;
|
|
5598
5598
|
}
|
|
5599
5599
|
case "run_shell": {
|
|
5600
5600
|
const cmd = str3(input["command"]);
|
|
@@ -6303,11 +6303,11 @@ var require_codegen = __commonJS({
|
|
|
6303
6303
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
6304
6304
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
6305
6305
|
}
|
|
6306
|
-
optimizeNames(names,
|
|
6306
|
+
optimizeNames(names, constants11) {
|
|
6307
6307
|
if (!names[this.name.str])
|
|
6308
6308
|
return;
|
|
6309
6309
|
if (this.rhs)
|
|
6310
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
6310
|
+
this.rhs = optimizeExpr(this.rhs, names, constants11);
|
|
6311
6311
|
return this;
|
|
6312
6312
|
}
|
|
6313
6313
|
get names() {
|
|
@@ -6324,10 +6324,10 @@ var require_codegen = __commonJS({
|
|
|
6324
6324
|
render({ _n }) {
|
|
6325
6325
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
6326
6326
|
}
|
|
6327
|
-
optimizeNames(names,
|
|
6327
|
+
optimizeNames(names, constants11) {
|
|
6328
6328
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
|
|
6329
6329
|
return;
|
|
6330
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
6330
|
+
this.rhs = optimizeExpr(this.rhs, names, constants11);
|
|
6331
6331
|
return this;
|
|
6332
6332
|
}
|
|
6333
6333
|
get names() {
|
|
@@ -6388,8 +6388,8 @@ var require_codegen = __commonJS({
|
|
|
6388
6388
|
optimizeNodes() {
|
|
6389
6389
|
return `${this.code}` ? this : void 0;
|
|
6390
6390
|
}
|
|
6391
|
-
optimizeNames(names,
|
|
6392
|
-
this.code = optimizeExpr(this.code, names,
|
|
6391
|
+
optimizeNames(names, constants11) {
|
|
6392
|
+
this.code = optimizeExpr(this.code, names, constants11);
|
|
6393
6393
|
return this;
|
|
6394
6394
|
}
|
|
6395
6395
|
get names() {
|
|
@@ -6418,12 +6418,12 @@ var require_codegen = __commonJS({
|
|
|
6418
6418
|
}
|
|
6419
6419
|
return nodes.length > 0 ? this : void 0;
|
|
6420
6420
|
}
|
|
6421
|
-
optimizeNames(names,
|
|
6421
|
+
optimizeNames(names, constants11) {
|
|
6422
6422
|
const { nodes } = this;
|
|
6423
6423
|
let i = nodes.length;
|
|
6424
6424
|
while (i--) {
|
|
6425
6425
|
const n = nodes[i];
|
|
6426
|
-
if (n.optimizeNames(names,
|
|
6426
|
+
if (n.optimizeNames(names, constants11))
|
|
6427
6427
|
continue;
|
|
6428
6428
|
subtractNames(names, n.names);
|
|
6429
6429
|
nodes.splice(i, 1);
|
|
@@ -6476,12 +6476,12 @@ var require_codegen = __commonJS({
|
|
|
6476
6476
|
return void 0;
|
|
6477
6477
|
return this;
|
|
6478
6478
|
}
|
|
6479
|
-
optimizeNames(names,
|
|
6479
|
+
optimizeNames(names, constants11) {
|
|
6480
6480
|
var _a;
|
|
6481
|
-
this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names,
|
|
6482
|
-
if (!(super.optimizeNames(names,
|
|
6481
|
+
this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants11);
|
|
6482
|
+
if (!(super.optimizeNames(names, constants11) || this.else))
|
|
6483
6483
|
return;
|
|
6484
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
6484
|
+
this.condition = optimizeExpr(this.condition, names, constants11);
|
|
6485
6485
|
return this;
|
|
6486
6486
|
}
|
|
6487
6487
|
get names() {
|
|
@@ -6504,10 +6504,10 @@ var require_codegen = __commonJS({
|
|
|
6504
6504
|
render(opts) {
|
|
6505
6505
|
return `for(${this.iteration})` + super.render(opts);
|
|
6506
6506
|
}
|
|
6507
|
-
optimizeNames(names,
|
|
6508
|
-
if (!super.optimizeNames(names,
|
|
6507
|
+
optimizeNames(names, constants11) {
|
|
6508
|
+
if (!super.optimizeNames(names, constants11))
|
|
6509
6509
|
return;
|
|
6510
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
6510
|
+
this.iteration = optimizeExpr(this.iteration, names, constants11);
|
|
6511
6511
|
return this;
|
|
6512
6512
|
}
|
|
6513
6513
|
get names() {
|
|
@@ -6543,10 +6543,10 @@ var require_codegen = __commonJS({
|
|
|
6543
6543
|
render(opts) {
|
|
6544
6544
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
6545
6545
|
}
|
|
6546
|
-
optimizeNames(names,
|
|
6547
|
-
if (!super.optimizeNames(names,
|
|
6546
|
+
optimizeNames(names, constants11) {
|
|
6547
|
+
if (!super.optimizeNames(names, constants11))
|
|
6548
6548
|
return;
|
|
6549
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
6549
|
+
this.iterable = optimizeExpr(this.iterable, names, constants11);
|
|
6550
6550
|
return this;
|
|
6551
6551
|
}
|
|
6552
6552
|
get names() {
|
|
@@ -6588,11 +6588,11 @@ var require_codegen = __commonJS({
|
|
|
6588
6588
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
6589
6589
|
return this;
|
|
6590
6590
|
}
|
|
6591
|
-
optimizeNames(names,
|
|
6591
|
+
optimizeNames(names, constants11) {
|
|
6592
6592
|
var _a, _b;
|
|
6593
|
-
super.optimizeNames(names,
|
|
6594
|
-
(_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names,
|
|
6595
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names,
|
|
6593
|
+
super.optimizeNames(names, constants11);
|
|
6594
|
+
(_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants11);
|
|
6595
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants11);
|
|
6596
6596
|
return this;
|
|
6597
6597
|
}
|
|
6598
6598
|
get names() {
|
|
@@ -6893,7 +6893,7 @@ var require_codegen = __commonJS({
|
|
|
6893
6893
|
function addExprNames(names, from) {
|
|
6894
6894
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
6895
6895
|
}
|
|
6896
|
-
function optimizeExpr(expr, names,
|
|
6896
|
+
function optimizeExpr(expr, names, constants11) {
|
|
6897
6897
|
if (expr instanceof code_1.Name)
|
|
6898
6898
|
return replaceName(expr);
|
|
6899
6899
|
if (!canOptimize(expr))
|
|
@@ -6908,14 +6908,14 @@ var require_codegen = __commonJS({
|
|
|
6908
6908
|
return items;
|
|
6909
6909
|
}, []));
|
|
6910
6910
|
function replaceName(n) {
|
|
6911
|
-
const c =
|
|
6911
|
+
const c = constants11[n.str];
|
|
6912
6912
|
if (c === void 0 || names[n.str] !== 1)
|
|
6913
6913
|
return n;
|
|
6914
6914
|
delete names[n.str];
|
|
6915
6915
|
return c;
|
|
6916
6916
|
}
|
|
6917
6917
|
function canOptimize(e) {
|
|
6918
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
6918
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants11[c.str] !== void 0);
|
|
6919
6919
|
}
|
|
6920
6920
|
}
|
|
6921
6921
|
function subtractNames(names, from) {
|
|
@@ -8877,7 +8877,7 @@ var require_compile = __commonJS({
|
|
|
8877
8877
|
const schOrFunc = root.refs[ref];
|
|
8878
8878
|
if (schOrFunc)
|
|
8879
8879
|
return schOrFunc;
|
|
8880
|
-
let _sch =
|
|
8880
|
+
let _sch = resolve42.call(this, root, ref);
|
|
8881
8881
|
if (_sch === void 0) {
|
|
8882
8882
|
const schema2 = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
8883
8883
|
const { schemaId } = this.opts;
|
|
@@ -8904,7 +8904,7 @@ var require_compile = __commonJS({
|
|
|
8904
8904
|
function sameSchemaEnv(s1, s2) {
|
|
8905
8905
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
8906
8906
|
}
|
|
8907
|
-
function
|
|
8907
|
+
function resolve42(root, ref) {
|
|
8908
8908
|
let sch;
|
|
8909
8909
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
8910
8910
|
ref = sch;
|
|
@@ -9768,7 +9768,7 @@ var require_fast_uri = __commonJS({
|
|
|
9768
9768
|
}
|
|
9769
9769
|
return uri;
|
|
9770
9770
|
}
|
|
9771
|
-
function
|
|
9771
|
+
function resolve42(baseURI, relativeURI, options) {
|
|
9772
9772
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
9773
9773
|
const {
|
|
9774
9774
|
parsed: baseParsed,
|
|
@@ -9804,50 +9804,50 @@ var require_fast_uri = __commonJS({
|
|
|
9804
9804
|
schemelessOptions.skipEscape = true;
|
|
9805
9805
|
return serialize(resolved, schemelessOptions);
|
|
9806
9806
|
}
|
|
9807
|
-
function resolveComponent(base,
|
|
9807
|
+
function resolveComponent(base, relative18, options, skipNormalization) {
|
|
9808
9808
|
const target = {};
|
|
9809
9809
|
if (!skipNormalization) {
|
|
9810
9810
|
base = parse6(serialize(base, options), options);
|
|
9811
|
-
|
|
9811
|
+
relative18 = parse6(serialize(relative18, options), options);
|
|
9812
9812
|
}
|
|
9813
9813
|
options = options || {};
|
|
9814
|
-
if (!options.tolerant &&
|
|
9815
|
-
target.scheme =
|
|
9816
|
-
target.userinfo =
|
|
9817
|
-
target.host =
|
|
9818
|
-
target.port =
|
|
9819
|
-
target.path = removeDotSegments(
|
|
9820
|
-
target.query =
|
|
9814
|
+
if (!options.tolerant && relative18.scheme) {
|
|
9815
|
+
target.scheme = relative18.scheme;
|
|
9816
|
+
target.userinfo = relative18.userinfo;
|
|
9817
|
+
target.host = relative18.host;
|
|
9818
|
+
target.port = relative18.port;
|
|
9819
|
+
target.path = removeDotSegments(relative18.path || "");
|
|
9820
|
+
target.query = relative18.query;
|
|
9821
9821
|
} else {
|
|
9822
|
-
if (
|
|
9823
|
-
target.userinfo =
|
|
9824
|
-
target.host =
|
|
9825
|
-
target.port =
|
|
9826
|
-
target.path = removeDotSegments(
|
|
9827
|
-
target.query =
|
|
9822
|
+
if (relative18.userinfo !== void 0 || relative18.host !== void 0 || relative18.port !== void 0) {
|
|
9823
|
+
target.userinfo = relative18.userinfo;
|
|
9824
|
+
target.host = relative18.host;
|
|
9825
|
+
target.port = relative18.port;
|
|
9826
|
+
target.path = removeDotSegments(relative18.path || "");
|
|
9827
|
+
target.query = relative18.query;
|
|
9828
9828
|
} else {
|
|
9829
|
-
if (!
|
|
9829
|
+
if (!relative18.path) {
|
|
9830
9830
|
target.path = base.path;
|
|
9831
|
-
if (
|
|
9832
|
-
target.query =
|
|
9831
|
+
if (relative18.query !== void 0) {
|
|
9832
|
+
target.query = relative18.query;
|
|
9833
9833
|
} else {
|
|
9834
9834
|
target.query = base.query;
|
|
9835
9835
|
}
|
|
9836
9836
|
} else {
|
|
9837
|
-
if (
|
|
9838
|
-
target.path = removeDotSegments(
|
|
9837
|
+
if (relative18.path[0] === "/") {
|
|
9838
|
+
target.path = removeDotSegments(relative18.path);
|
|
9839
9839
|
} else {
|
|
9840
9840
|
const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
|
|
9841
9841
|
if (baseHasAuthority && !base.path) {
|
|
9842
|
-
target.path = "/" +
|
|
9842
|
+
target.path = "/" + relative18.path;
|
|
9843
9843
|
} else if (!base.path) {
|
|
9844
|
-
target.path =
|
|
9844
|
+
target.path = relative18.path;
|
|
9845
9845
|
} else {
|
|
9846
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
9846
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative18.path;
|
|
9847
9847
|
}
|
|
9848
9848
|
target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
|
|
9849
9849
|
}
|
|
9850
|
-
target.query =
|
|
9850
|
+
target.query = relative18.query;
|
|
9851
9851
|
}
|
|
9852
9852
|
target.userinfo = base.userinfo;
|
|
9853
9853
|
target.host = base.host;
|
|
@@ -9855,7 +9855,7 @@ var require_fast_uri = __commonJS({
|
|
|
9855
9855
|
}
|
|
9856
9856
|
target.scheme = base.scheme;
|
|
9857
9857
|
}
|
|
9858
|
-
target.fragment =
|
|
9858
|
+
target.fragment = relative18.fragment;
|
|
9859
9859
|
return target;
|
|
9860
9860
|
}
|
|
9861
9861
|
function equal(uriA, uriB, options) {
|
|
@@ -10159,7 +10159,7 @@ var require_fast_uri = __commonJS({
|
|
|
10159
10159
|
var fastUri = {
|
|
10160
10160
|
SCHEMES,
|
|
10161
10161
|
normalize: normalize3,
|
|
10162
|
-
resolve:
|
|
10162
|
+
resolve: resolve42,
|
|
10163
10163
|
resolveComponent,
|
|
10164
10164
|
equal,
|
|
10165
10165
|
serialize,
|
|
@@ -13122,8 +13122,8 @@ var require_dist = __commonJS({
|
|
|
13122
13122
|
return ajv;
|
|
13123
13123
|
}
|
|
13124
13124
|
const [formats, exportName] = opts.mode === "fast" ? [formats_1.fastFormats, fastName] : [formats_1.fullFormats, fullName];
|
|
13125
|
-
const
|
|
13126
|
-
addFormats(ajv,
|
|
13125
|
+
const list3 = opts.formats || formats_1.formatNames;
|
|
13126
|
+
addFormats(ajv, list3, formats, exportName);
|
|
13127
13127
|
if (opts.keywords)
|
|
13128
13128
|
(0, limit_1.default)(ajv);
|
|
13129
13129
|
return ajv;
|
|
@@ -13135,11 +13135,11 @@ var require_dist = __commonJS({
|
|
|
13135
13135
|
throw new Error(`Unknown format "${name}"`);
|
|
13136
13136
|
return f;
|
|
13137
13137
|
};
|
|
13138
|
-
function addFormats(ajv,
|
|
13138
|
+
function addFormats(ajv, list3, fs, exportName) {
|
|
13139
13139
|
var _a;
|
|
13140
13140
|
var _b;
|
|
13141
13141
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
13142
|
-
for (const f of
|
|
13142
|
+
for (const f of list3)
|
|
13143
13143
|
ajv.addFormat(f, fs[f]);
|
|
13144
13144
|
}
|
|
13145
13145
|
module.exports = exports = formatsPlugin;
|
|
@@ -13242,12 +13242,12 @@ var require_isexe = __commonJS({
|
|
|
13242
13242
|
if (typeof Promise !== "function") {
|
|
13243
13243
|
throw new TypeError("callback not provided");
|
|
13244
13244
|
}
|
|
13245
|
-
return new Promise(function(
|
|
13245
|
+
return new Promise(function(resolve42, reject2) {
|
|
13246
13246
|
isexe(path, options || {}, function(er, is) {
|
|
13247
13247
|
if (er) {
|
|
13248
13248
|
reject2(er);
|
|
13249
13249
|
} else {
|
|
13250
|
-
|
|
13250
|
+
resolve42(is);
|
|
13251
13251
|
}
|
|
13252
13252
|
});
|
|
13253
13253
|
});
|
|
@@ -13313,27 +13313,27 @@ var require_which = __commonJS({
|
|
|
13313
13313
|
opt = {};
|
|
13314
13314
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
13315
13315
|
const found = [];
|
|
13316
|
-
const step = (i) => new Promise((
|
|
13316
|
+
const step = (i) => new Promise((resolve42, reject2) => {
|
|
13317
13317
|
if (i === pathEnv.length)
|
|
13318
|
-
return opt.all && found.length ?
|
|
13318
|
+
return opt.all && found.length ? resolve42(found) : reject2(getNotFoundError(cmd));
|
|
13319
13319
|
const ppRaw = pathEnv[i];
|
|
13320
13320
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
13321
13321
|
const pCmd = path.join(pathPart, cmd);
|
|
13322
13322
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
13323
|
-
|
|
13323
|
+
resolve42(subStep(p, i, 0));
|
|
13324
13324
|
});
|
|
13325
|
-
const subStep = (p, i, ii) => new Promise((
|
|
13325
|
+
const subStep = (p, i, ii) => new Promise((resolve42, reject2) => {
|
|
13326
13326
|
if (ii === pathExt.length)
|
|
13327
|
-
return
|
|
13327
|
+
return resolve42(step(i + 1));
|
|
13328
13328
|
const ext = pathExt[ii];
|
|
13329
13329
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
13330
13330
|
if (!er && is) {
|
|
13331
13331
|
if (opt.all)
|
|
13332
13332
|
found.push(p + ext);
|
|
13333
13333
|
else
|
|
13334
|
-
return
|
|
13334
|
+
return resolve42(p + ext);
|
|
13335
13335
|
}
|
|
13336
|
-
return
|
|
13336
|
+
return resolve42(subStep(p, i, ii + 1));
|
|
13337
13337
|
});
|
|
13338
13338
|
});
|
|
13339
13339
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -16813,7 +16813,13 @@ var MatchSchema = external_exports.object({
|
|
|
16813
16813
|
max_length: external_exports.number().int().min(1),
|
|
16814
16814
|
classes: external_exports.array(external_exports.string()).min(1),
|
|
16815
16815
|
severity: external_exports.enum(["critical", "high", "medium", "low"])
|
|
16816
|
-
}).optional()
|
|
16816
|
+
}).optional(),
|
|
16817
|
+
// regex only: for a file whose path matches one of these patterns, the look-behinds of the regex (the order a
|
|
16818
|
+
// concealment must follow within 300 characters of one paragraph) are dropped and replaced by this: an order word
|
|
16819
|
+
// (`order_regex`) anywhere else in the file. Used for instruction files, where an order and its concealment may be
|
|
16820
|
+
// far apart (m19-scan SN-5). Both are needed for the wide reading.
|
|
16821
|
+
wide_paths: external_exports.array(external_exports.string().refine(compiles, "wide_paths entries must be valid regular expressions")).optional(),
|
|
16822
|
+
order_regex: external_exports.string().optional()
|
|
16817
16823
|
}).superRefine((val, ctx) => {
|
|
16818
16824
|
const hasAny = val.regex !== void 0 || val.unicode_class !== void 0 && val.unicode_class.length > 0 || val.json_path !== void 0 || val.hidden_text === true || val.analysis !== void 0;
|
|
16819
16825
|
if (!hasAny) {
|
|
@@ -16831,7 +16837,7 @@ var MatchSchema = external_exports.object({
|
|
|
16831
16837
|
if ((val.exclude_regex !== void 0 || val.validate !== void 0) && val.regex === void 0 && val.json_path === void 0) {
|
|
16832
16838
|
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "match.exclude_regex and match.validate need match.regex or match.json_path" });
|
|
16833
16839
|
}
|
|
16834
|
-
for (const key of ["regex", "value_regex", "exclude_regex", "file_regex", "quoted_example_cues", "negated_cues", "decoded_flag_regex"]) {
|
|
16840
|
+
for (const key of ["regex", "value_regex", "exclude_regex", "file_regex", "quoted_example_cues", "negated_cues", "decoded_flag_regex", "order_regex"]) {
|
|
16835
16841
|
const pattern = val[key];
|
|
16836
16842
|
if (pattern !== void 0 && !compiles(pattern)) {
|
|
16837
16843
|
ctx.addIssue({
|
|
@@ -16844,7 +16850,7 @@ var MatchSchema = external_exports.object({
|
|
|
16844
16850
|
var VirusDefinitionSchema = external_exports.object({
|
|
16845
16851
|
id: external_exports.string().regex(/^EX-\d{3}$/, "id must match EX-NNN"),
|
|
16846
16852
|
title: external_exports.string().min(1, "title must not be empty"),
|
|
16847
|
-
severity: external_exports.enum(["critical", "high", "medium", "low"]),
|
|
16853
|
+
severity: external_exports.enum(["critical", "high", "medium", "low", "info"]),
|
|
16848
16854
|
applies_to: external_exports.array(external_exports.string()).min(1, "applies_to must have at least one entry"),
|
|
16849
16855
|
match: MatchSchema,
|
|
16850
16856
|
owasp: external_exports.array(external_exports.string()).min(1, "owasp must have at least one reference"),
|
|
@@ -16877,8 +16883,8 @@ var DefinitionLoadError = class extends Error {
|
|
|
16877
16883
|
// ../core/src/definitions/loader.ts
|
|
16878
16884
|
var NON_DEFINITION_FILES = /* @__PURE__ */ new Set(["capabilities.yaml"]);
|
|
16879
16885
|
async function loadDefinitions(dir) {
|
|
16880
|
-
const
|
|
16881
|
-
const yamlFiles =
|
|
16886
|
+
const entries2 = await readdir(dir);
|
|
16887
|
+
const yamlFiles = entries2.filter((f) => f.endsWith(".yaml") && !NON_DEFINITION_FILES.has(f));
|
|
16882
16888
|
const results = [];
|
|
16883
16889
|
for (const filename of yamlFiles) {
|
|
16884
16890
|
const file = join(dir, filename);
|
|
@@ -17132,6 +17138,30 @@ var EXEC_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
17132
17138
|
"powershell",
|
|
17133
17139
|
"pwsh"
|
|
17134
17140
|
]);
|
|
17141
|
+
var INTERPRETERS = /* @__PURE__ */ new Set([
|
|
17142
|
+
"sh",
|
|
17143
|
+
"bash",
|
|
17144
|
+
"zsh",
|
|
17145
|
+
"fish",
|
|
17146
|
+
"dash",
|
|
17147
|
+
"node",
|
|
17148
|
+
"nodejs",
|
|
17149
|
+
"deno",
|
|
17150
|
+
"bun",
|
|
17151
|
+
"python",
|
|
17152
|
+
"python3",
|
|
17153
|
+
"perl",
|
|
17154
|
+
"ruby",
|
|
17155
|
+
"php",
|
|
17156
|
+
"lua",
|
|
17157
|
+
"tsx",
|
|
17158
|
+
"ts-node",
|
|
17159
|
+
"osascript",
|
|
17160
|
+
"powershell",
|
|
17161
|
+
"pwsh",
|
|
17162
|
+
"env",
|
|
17163
|
+
"xargs"
|
|
17164
|
+
]);
|
|
17135
17165
|
var NETWORK_ALLOW = /^(?:WebFetch|Bash\(\s*(?:curl|wget|ssh|scp|nc|ncat|ftp|rsync|telnet)\b)/;
|
|
17136
17166
|
var WRITE_ALLOW = /^(?:Write|Edit|MultiEdit|NotebookEdit|Bash\(\s*(?:rm|mv|cp|tee|chmod|chown|dd|ln|touch|mkdir|truncate)\b|Bash\(\s*\*+\s*\))/;
|
|
17137
17167
|
var ALLOW_ENTRY = /^(?:Bash|Shell|PowerShell|Run)\(([^)]*)\)$/;
|
|
@@ -17255,15 +17285,15 @@ function readProjectSettings(rel, text) {
|
|
|
17255
17285
|
if (vscode && json2["chat.tools.global.autoApprove"] === true) add("copilot-auto-approve", '"chat.tools.global.autoApprove"', "chat.tools.global.autoApprove: true");
|
|
17256
17286
|
const perm = json2["permissions"];
|
|
17257
17287
|
if (isObj(perm) && Array.isArray(perm["allow"])) {
|
|
17258
|
-
const
|
|
17259
|
-
const loud =
|
|
17260
|
-
for (const e of
|
|
17288
|
+
const entries2 = perm["allow"].filter((e) => typeof e === "string");
|
|
17289
|
+
const loud = entries2.some((e) => NETWORK_ALLOW.test(e) || WRITE_ALLOW.test(e));
|
|
17290
|
+
for (const e of entries2) {
|
|
17261
17291
|
const m = ALLOW_ENTRY.exec(e.trim());
|
|
17262
17292
|
if (!m) continue;
|
|
17263
17293
|
const arg = (m[1] ?? "").trim();
|
|
17264
17294
|
const wild = /^(.+?)(?::\s*\*+|\s+\*+)$/.exec(arg);
|
|
17265
17295
|
const cmd = (wild ? wild[1] ?? "" : arg).trim();
|
|
17266
|
-
const bareInterpreter = !wild && EXEC_COMMANDS.has(cmd) &&
|
|
17296
|
+
const bareInterpreter = !wild && EXEC_COMMANDS.has(cmd) && INTERPRETERS.has(cmd);
|
|
17267
17297
|
if (wild && EXEC_COMMANDS.has(cmd) || bareInterpreter) add("allow-exec", JSON.stringify(e), e, loud ? "high" : "medium");
|
|
17268
17298
|
}
|
|
17269
17299
|
}
|
|
@@ -20231,8 +20261,8 @@ var KNOWN_MCP_PACKAGES = [
|
|
|
20231
20261
|
function fold(s) {
|
|
20232
20262
|
return s.toLowerCase().replace(/rn/g, "m").replace(/[1i]/g, "l").replace(/0/g, "o").replace(/vv/g, "w").replace(/[-_.]/g, "");
|
|
20233
20263
|
}
|
|
20234
|
-
function editDistance(a, b,
|
|
20235
|
-
if (Math.abs(a.length - b.length) >
|
|
20264
|
+
function editDistance(a, b, cap4 = 3) {
|
|
20265
|
+
if (Math.abs(a.length - b.length) > cap4) return cap4 + 1;
|
|
20236
20266
|
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
20237
20267
|
for (let j = 0; j <= b.length; j++) d[0][j] = j;
|
|
20238
20268
|
for (let i = 1; i <= a.length; i++) {
|
|
@@ -20559,6 +20589,62 @@ function getRegex(pattern, flags2) {
|
|
|
20559
20589
|
regexCache.set(key, re2);
|
|
20560
20590
|
return re2;
|
|
20561
20591
|
}
|
|
20592
|
+
function stripLookbehinds(pattern) {
|
|
20593
|
+
let out = "";
|
|
20594
|
+
let i = 0;
|
|
20595
|
+
while (i < pattern.length) {
|
|
20596
|
+
if (pattern.startsWith("(?<=", i)) {
|
|
20597
|
+
let depth = 0;
|
|
20598
|
+
let j = i;
|
|
20599
|
+
let inClass = false;
|
|
20600
|
+
for (; j < pattern.length; j++) {
|
|
20601
|
+
const c = pattern[j];
|
|
20602
|
+
if (c === "\\") {
|
|
20603
|
+
j++;
|
|
20604
|
+
continue;
|
|
20605
|
+
}
|
|
20606
|
+
if (inClass) {
|
|
20607
|
+
if (c === "]") inClass = false;
|
|
20608
|
+
continue;
|
|
20609
|
+
}
|
|
20610
|
+
if (c === "[") inClass = true;
|
|
20611
|
+
else if (c === "(") depth++;
|
|
20612
|
+
else if (c === ")") {
|
|
20613
|
+
depth--;
|
|
20614
|
+
if (depth === 0) break;
|
|
20615
|
+
}
|
|
20616
|
+
}
|
|
20617
|
+
i = j + 1;
|
|
20618
|
+
continue;
|
|
20619
|
+
}
|
|
20620
|
+
if (pattern[i] === "\\") {
|
|
20621
|
+
out += pattern.slice(i, i + 2);
|
|
20622
|
+
i += 2;
|
|
20623
|
+
continue;
|
|
20624
|
+
}
|
|
20625
|
+
out += pattern[i];
|
|
20626
|
+
i++;
|
|
20627
|
+
}
|
|
20628
|
+
return out;
|
|
20629
|
+
}
|
|
20630
|
+
function isWideFile(match, rel) {
|
|
20631
|
+
return match.order_regex !== void 0 && match.wide_paths !== void 0 && match.wide_paths.some((p) => getRegex(p, "i").test(rel));
|
|
20632
|
+
}
|
|
20633
|
+
var MAX_ORDER_HITS = 5e3;
|
|
20634
|
+
function orderSpans(order, text) {
|
|
20635
|
+
const re2 = getRegex(order, "gi");
|
|
20636
|
+
const out = [];
|
|
20637
|
+
re2.lastIndex = 0;
|
|
20638
|
+
let m;
|
|
20639
|
+
while (out.length < MAX_ORDER_HITS && (m = re2.exec(text)) !== null) {
|
|
20640
|
+
if (m[0].length === 0) {
|
|
20641
|
+
re2.lastIndex++;
|
|
20642
|
+
continue;
|
|
20643
|
+
}
|
|
20644
|
+
out.push([m.index, m.index + m[0].length]);
|
|
20645
|
+
}
|
|
20646
|
+
return out;
|
|
20647
|
+
}
|
|
20562
20648
|
function escapeCodePoint(hit) {
|
|
20563
20649
|
const hex = hit.codePoint.toString(16).toUpperCase();
|
|
20564
20650
|
return hit.codePoint > 65535 ? `\\u{${hex}}` : `\\u${hex.padStart(4, "0")}`;
|
|
@@ -20770,12 +20856,19 @@ function runSignatures(file, norm3, defs, limitMs = REGEX_TIME_LIMIT_MS) {
|
|
|
20770
20856
|
fix: def.fix
|
|
20771
20857
|
};
|
|
20772
20858
|
const mine = [];
|
|
20859
|
+
const narrow = [];
|
|
20773
20860
|
if (match.regex) {
|
|
20774
|
-
const
|
|
20861
|
+
const wide = isWideFile(match, file.rel);
|
|
20862
|
+
const re2 = getRegex(wide ? stripLookbehinds(match.regex) : match.regex, "gi");
|
|
20775
20863
|
mine.push(addLogical(re2, norm3.plain));
|
|
20776
20864
|
if (vis) mine.push(addLogical(re2, vis.text));
|
|
20865
|
+
if (wide) {
|
|
20866
|
+
const own = getRegex(match.regex, "gi");
|
|
20867
|
+
narrow.push(addLogical(own, norm3.plain));
|
|
20868
|
+
if (vis) narrow.push(addLogical(own, vis.text));
|
|
20869
|
+
}
|
|
20777
20870
|
}
|
|
20778
|
-
active.push({ def, base, keep, jobs: mine });
|
|
20871
|
+
active.push({ def, base, keep, jobs: mine, narrow });
|
|
20779
20872
|
}
|
|
20780
20873
|
let results = jobs.length > 0 ? guarded(jobs, limitMs) : [];
|
|
20781
20874
|
const timedOut = /* @__PURE__ */ new Set();
|
|
@@ -20800,10 +20893,10 @@ function runSignatures(file, norm3, defs, limitMs = REGEX_TIME_LIMIT_MS) {
|
|
|
20800
20893
|
}
|
|
20801
20894
|
return out2;
|
|
20802
20895
|
};
|
|
20803
|
-
for (const { def, base, keep, jobs: mine } of active) {
|
|
20896
|
+
for (const { def, base, keep, jobs: mine, narrow } of active) {
|
|
20804
20897
|
const { match } = def;
|
|
20805
20898
|
if (match.regex) {
|
|
20806
|
-
if (mine.some(timedOutLogical)) {
|
|
20899
|
+
if ([...mine, ...narrow].some(timedOutLogical)) {
|
|
20807
20900
|
findings.push({
|
|
20808
20901
|
...base,
|
|
20809
20902
|
severity: agentFacing ? base.severity : "medium",
|
|
@@ -20818,8 +20911,11 @@ function runSignatures(file, norm3, defs, limitMs = REGEX_TIME_LIMIT_MS) {
|
|
|
20818
20911
|
mine.forEach((logicalId, k) => {
|
|
20819
20912
|
const src = k === 0 || !vis ? norm3.plain : vis.text;
|
|
20820
20913
|
const toPlain = k === 0 || !vis ? (i) => i : (i) => vis.map[i] ?? i;
|
|
20914
|
+
const orders = isWideFile(match, file.rel) ? orderSpans(match.order_regex, src) : null;
|
|
20915
|
+
const ownHits = narrow.length > 0 ? new Set(matchesOf(narrow[k] ?? -1).map(([i]) => i)) : null;
|
|
20821
20916
|
for (const [index2, text] of matchesOf(logicalId)) {
|
|
20822
20917
|
if (!keep(text)) continue;
|
|
20918
|
+
if (orders && !ownHits?.has(index2) && !orders.some(([s, e]) => e <= index2 || s >= index2 + text.length)) continue;
|
|
20823
20919
|
const at = toPlain(index2);
|
|
20824
20920
|
if (seen.has(at)) continue;
|
|
20825
20921
|
if (!ctx.allows(def, text, at, src, index2)) continue;
|
|
@@ -20950,7 +21046,7 @@ function runSignatures(file, norm3, defs, limitMs = REGEX_TIME_LIMIT_MS) {
|
|
|
20950
21046
|
const out = lowered.size === 0 ? findings : findings.map((f) => lowered.has(f.ruleId) ? { ...f, severity: "low" } : f);
|
|
20951
21047
|
return sameLineGroups(out, defs);
|
|
20952
21048
|
}
|
|
20953
|
-
var SEVERITY_RANK = { critical: 4, high: 3, medium: 2, low: 1 };
|
|
21049
|
+
var SEVERITY_RANK = { critical: 4, high: 3, medium: 2, low: 1, info: 0 };
|
|
20954
21050
|
function sameLineGroups(findings, defs) {
|
|
20955
21051
|
const groupOf = new Map(defs.filter((d) => d.same_line_group).map((d) => [d.id, d.same_line_group]));
|
|
20956
21052
|
if (groupOf.size === 0) return findings;
|
|
@@ -21400,11 +21496,68 @@ function extractPy(text, budget, out, dyn = []) {
|
|
|
21400
21496
|
if (r.dyn !== null) dyn.push(r.dyn);
|
|
21401
21497
|
if (r.after > 0) after = r.after;
|
|
21402
21498
|
}
|
|
21403
|
-
|
|
21499
|
+
const doc = docstringAfter(text, after, limit);
|
|
21500
|
+
if (lit === null) lit = doc;
|
|
21501
|
+
else if (doc !== null && PY_ARGS_SECTION.test(doc.value)) out.push(toFound(doc));
|
|
21404
21502
|
if (lit) out.push(toFound(lit));
|
|
21405
21503
|
}
|
|
21406
21504
|
}
|
|
21407
21505
|
}
|
|
21506
|
+
var PY_ARGS_SECTION = /^[ \t]*(?:Args|Arguments|Parameters|Params)[ \t]*:/m;
|
|
21507
|
+
var FIELD_KEYS = ["type", "enum", "items", "properties", "format", "default", "minimum", "maximum", "anyOf", "oneOf"];
|
|
21508
|
+
var SCHEMA_WORD = /properties|inputSchema|input_schema|parameters/;
|
|
21509
|
+
var MCP_TEXT = /modelcontextprotocol|FastMCP|McpServer|mcp\.server|inputSchema|input_schema|@mcp\.tool|\.tool\(|registerTool/;
|
|
21510
|
+
var nearSchema = (text, at) => SCHEMA_WORD.test(text.slice(Math.max(0, at - 3e3), at));
|
|
21511
|
+
function extractFieldsTs(text, out, dyn) {
|
|
21512
|
+
const keyBudget = { left: MAX_SITES };
|
|
21513
|
+
for (const at of indexesOf(text, "description", keyBudget)) {
|
|
21514
|
+
if (isIdent(text[at - 1])) continue;
|
|
21515
|
+
const limit = lim(text, at);
|
|
21516
|
+
let j = at + "description".length;
|
|
21517
|
+
if (text[j] === '"' || text[j] === "'") j++;
|
|
21518
|
+
j = skipTrivia(text, j, "ts", limit);
|
|
21519
|
+
if (text[j] !== ":") continue;
|
|
21520
|
+
const open4 = enclosingObject(text, at);
|
|
21521
|
+
if (open4 < 0 || !hasKeyAtTop(text, open4, FIELD_KEYS, limit)) continue;
|
|
21522
|
+
const p = skipTrivia(text, j + 1, "ts", limit);
|
|
21523
|
+
const l = isQuote(text[p]) ? readLiteral(text, p, "ts", limit) : null;
|
|
21524
|
+
if (l) {
|
|
21525
|
+
out.push(toFound(l));
|
|
21526
|
+
if (text[skipTrivia(text, l.next, "ts", limit)] === "+" && nearSchema(text, at)) dyn.push(p);
|
|
21527
|
+
} else if (nearSchema(text, at)) dyn.push(p);
|
|
21528
|
+
}
|
|
21529
|
+
const describeBudget = { left: MAX_SITES };
|
|
21530
|
+
for (const at of indexesOf(text, ".describe(", describeBudget)) {
|
|
21531
|
+
const limit = lim(text, at);
|
|
21532
|
+
const p = skipTrivia(text, at + ".describe(".length, "ts", limit);
|
|
21533
|
+
if (text[p] === ")") continue;
|
|
21534
|
+
const l = isQuote(text[p]) ? readLiteral(text, p, "ts", limit) : null;
|
|
21535
|
+
if (l) {
|
|
21536
|
+
out.push(toFound(l));
|
|
21537
|
+
if (text[skipTrivia(text, l.next, "ts", limit)] === "+") dyn.push(p);
|
|
21538
|
+
} else dyn.push(p);
|
|
21539
|
+
}
|
|
21540
|
+
}
|
|
21541
|
+
function extractFieldsPy(text, out, dyn) {
|
|
21542
|
+
const fieldBudget = { left: MAX_SITES };
|
|
21543
|
+
for (const at of indexesOf(text, "Field(", fieldBudget)) {
|
|
21544
|
+
if (isIdent(text[at - 1])) continue;
|
|
21545
|
+
const { lit, dyn: d } = findKeyString(text, at + 5, "py", lim(text, at), "=");
|
|
21546
|
+
if (lit) out.push(toFound(lit));
|
|
21547
|
+
if (d !== null) dyn.push(d);
|
|
21548
|
+
}
|
|
21549
|
+
const annBudget = { left: MAX_SITES };
|
|
21550
|
+
for (const at of indexesOf(text, "Annotated[", annBudget)) {
|
|
21551
|
+
if (isIdent(text[at - 1])) continue;
|
|
21552
|
+
const limit = lim(text, at);
|
|
21553
|
+
const first = skipTrivia(text, at + "Annotated[".length, "py", limit);
|
|
21554
|
+
const e = skipArgument(text, first, "py", limit);
|
|
21555
|
+
if (e < 0 || text[e] !== ",") continue;
|
|
21556
|
+
const p = skipTrivia(text, e + 1, "py", limit);
|
|
21557
|
+
const l = readPyString(text, p, limit);
|
|
21558
|
+
if (l) out.push(toFound(l));
|
|
21559
|
+
}
|
|
21560
|
+
}
|
|
21408
21561
|
function extractGo(text, budget, out) {
|
|
21409
21562
|
for (const at of indexesOf(text, "WithDescription(", budget)) {
|
|
21410
21563
|
if (isIdent(text[at - 1])) continue;
|
|
@@ -21414,9 +21567,10 @@ function extractGo(text, budget, out) {
|
|
|
21414
21567
|
if (l) out.push(toFound(l));
|
|
21415
21568
|
}
|
|
21416
21569
|
}
|
|
21417
|
-
function extractAll(text, lang) {
|
|
21570
|
+
function extractAll(text, lang, mcpPath = false) {
|
|
21418
21571
|
const out = [];
|
|
21419
21572
|
const dyn = [];
|
|
21573
|
+
const dynFields = [];
|
|
21420
21574
|
const budget = { left: MAX_SITES };
|
|
21421
21575
|
if (lang === "ts") {
|
|
21422
21576
|
extractTs(text, budget, out, dyn);
|
|
@@ -21427,11 +21581,20 @@ function extractAll(text, lang) {
|
|
|
21427
21581
|
extractPyConstructor(text, { left: MAX_SITES }, out, dyn);
|
|
21428
21582
|
} else if (lang === "go") extractGo(text, budget, out);
|
|
21429
21583
|
else extractOther(text, lang, budget, out);
|
|
21584
|
+
if ((lang === "ts" || lang === "py") && (mcpPath || out.length > 0 || dyn.length > 0 || MCP_TEXT.test(text))) {
|
|
21585
|
+
if (lang === "ts") extractFieldsTs(text, out, dynFields);
|
|
21586
|
+
else extractFieldsPy(text, out, dynFields);
|
|
21587
|
+
}
|
|
21430
21588
|
const seen = /* @__PURE__ */ new Set();
|
|
21431
|
-
|
|
21589
|
+
const taken = new Set(dyn);
|
|
21590
|
+
return {
|
|
21591
|
+
found: out.filter((f) => !seen.has(f.offset) && seen.add(f.offset)).sort((a, b) => a.offset - b.offset),
|
|
21592
|
+
dyn: [...taken].sort((a, b) => a - b),
|
|
21593
|
+
dynFields: [...new Set(dynFields)].filter((d) => !taken.has(d)).sort((a, b) => a - b)
|
|
21594
|
+
};
|
|
21432
21595
|
}
|
|
21433
|
-
function extract(text, lang) {
|
|
21434
|
-
return extractAll(text, lang).found;
|
|
21596
|
+
function extract(text, lang, mcpPath = false) {
|
|
21597
|
+
return extractAll(text, lang, mcpPath).found;
|
|
21435
21598
|
}
|
|
21436
21599
|
function enclosingObject(text, at) {
|
|
21437
21600
|
let depth = 0;
|
|
@@ -21552,17 +21715,22 @@ function scanDynamicToolDescriptions(file, text, defs) {
|
|
|
21552
21715
|
const lang = languageOf(file.rel);
|
|
21553
21716
|
if (!def || lang === null || typeof text !== "string" || lang !== "ts" && lang !== "py") return [];
|
|
21554
21717
|
if (!/mcp/i.test(file.rel) && !/modelcontextprotocol|FastMCP|McpServer|mcp\.server/.test(text)) return [];
|
|
21555
|
-
|
|
21718
|
+
const { dyn, dynFields } = extractAll(text, lang, true);
|
|
21719
|
+
const make = (at, span, what) => ({
|
|
21556
21720
|
source: "signature",
|
|
21557
21721
|
ruleId: def.id,
|
|
21558
21722
|
title: def.title,
|
|
21559
21723
|
severity: "medium",
|
|
21560
21724
|
file: file.rel,
|
|
21561
21725
|
...positionOf(text, at),
|
|
21562
|
-
span
|
|
21726
|
+
span,
|
|
21563
21727
|
owasp: def.owasp,
|
|
21564
|
-
fix:
|
|
21565
|
-
})
|
|
21728
|
+
fix: `This ${what} is computed (a variable, a constant from another file, a template or a concatenation), so the scan cannot read what an agent will be told. Write it as one plain string in the registration, or run the server behind the Shield: exorcist wrap <mcp config> (or exorcist init --shield) checks the real text the running server sends and withholds a poisoned tool.`
|
|
21729
|
+
});
|
|
21730
|
+
return [
|
|
21731
|
+
...dyn.map((at) => make(at, "tool description built at run time: not checked", "tool description")),
|
|
21732
|
+
...dynFields.map((at) => make(at, "tool field description built at run time: not checked", "field description of a tool parameter"))
|
|
21733
|
+
];
|
|
21566
21734
|
} catch {
|
|
21567
21735
|
return [];
|
|
21568
21736
|
}
|
|
@@ -21620,7 +21788,7 @@ function scanSourceTools(file, text, defs) {
|
|
|
21620
21788
|
const lang = languageOf(file.rel);
|
|
21621
21789
|
if (!def || lang === null || typeof text !== "string") return [];
|
|
21622
21790
|
const out = [];
|
|
21623
|
-
for (const s of extract(text, lang)) {
|
|
21791
|
+
for (const s of extract(text, lang, /mcp/i.test(file.rel))) {
|
|
21624
21792
|
for (const hit of scanText(s.text, "mcp-config", [def], file.rel)) {
|
|
21625
21793
|
const idx = Math.min(Math.max(indexOfLineCol(s.text, hit.line, hit.col), 0), s.text.length);
|
|
21626
21794
|
if (isQuietHint(hit.span, s.text, idx)) continue;
|
|
@@ -21664,8 +21832,8 @@ function sandboxFindings(text, rel) {
|
|
|
21664
21832
|
return [{
|
|
21665
21833
|
source: "signature",
|
|
21666
21834
|
ruleId: SANDBOX_RULE_ID,
|
|
21667
|
-
title: mcpOff ? "
|
|
21668
|
-
severity: "
|
|
21835
|
+
title: mcpOff ? "MCP sandboxing is off in this project" : "The command sandbox is off in this project",
|
|
21836
|
+
severity: "info",
|
|
21669
21837
|
file: rel,
|
|
21670
21838
|
line,
|
|
21671
21839
|
col,
|
|
@@ -22882,7 +23050,7 @@ function withinProject(raw, cwd) {
|
|
|
22882
23050
|
const rel = relative4(cwd, resolve3(cwd, raw));
|
|
22883
23051
|
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
22884
23052
|
}
|
|
22885
|
-
var anyInside = (
|
|
23053
|
+
var anyInside = (list3, cwd) => list3.split(/[:;]/).some((p) => insideProject(p, cwd));
|
|
22886
23054
|
var RISK_ENV = /^(?:AWS_.*_FILE|AWS_CONFIG_FILE|AWS_SHARED_CREDENTIALS_FILE|CLOUDSDK_CONFIG|AZURE_CONFIG_DIR|GIT_CONFIG.*)$/;
|
|
22887
23055
|
var ENV_FAMILIES = [
|
|
22888
23056
|
[/^KUBE/, ["kubectl", "helm", "kind", "minikube"]],
|
|
@@ -22928,8 +23096,8 @@ function envAssignRisk(name, value, cwd, dynamic = false, known, prog) {
|
|
|
22928
23096
|
const owners = envFamilyOwners(name);
|
|
22929
23097
|
if (owners !== null) {
|
|
22930
23098
|
if (name === "HELM_PLUGINS") return "HELM_PLUGINS names a folder of helm plugins, which are programs, and the guard always refuses it. The person can run it in their own terminal";
|
|
22931
|
-
const
|
|
22932
|
-
const unlocked = prog === void 0 ? owners.some((o) =>
|
|
23099
|
+
const list3 = known ?? userKnownPrograms();
|
|
23100
|
+
const unlocked = prog === void 0 ? owners.some((o) => list3.has(o)) : owners.includes(prog) && list3.has(prog);
|
|
22933
23101
|
if (unlocked) return unlockedValueRisk(name, value, cwd, dynamic);
|
|
22934
23102
|
return `${name} belongs to the environment of ${owners[0]}, and its variables change what the tool runs or trusts (config files, plugins, endpoints, certificates, helpers). The guard refuses them whatever the value. To allow it, add "${owners[0]}" to the list of programs in your own user config, ${KNOWN_PROGRAMS_HINT} (a list inside a repository is never read)`;
|
|
22935
23103
|
}
|
|
@@ -23335,8 +23503,8 @@ function devToolPlan(prog, args, ctx = {}) {
|
|
|
23335
23503
|
if (risk !== null) return blocked(prog, prog, `was given ${risk}`);
|
|
23336
23504
|
}
|
|
23337
23505
|
if (c.known.has(prog)) return plain;
|
|
23338
|
-
const
|
|
23339
|
-
if (
|
|
23506
|
+
const unreadable2 = args.find((w) => w.dynamic || w.glob);
|
|
23507
|
+
if (unreadable2 !== void 0) return blocked(prog, prog, "was given a word built at run time (a variable, a substitution or a pattern), and the guard cannot read what it will be");
|
|
23340
23508
|
switch (prog) {
|
|
23341
23509
|
case "docker":
|
|
23342
23510
|
case "podman":
|
|
@@ -23397,7 +23565,7 @@ var reject = (reason, fix = FIX_SIMPLE) => {
|
|
|
23397
23565
|
var SYSTEM_DIRS = ["/usr/bin/", "/bin/", "/usr/sbin/", "/sbin/", "/usr/local/bin/", "/usr/local/sbin/", "/opt/homebrew/bin/", "/opt/homebrew/sbin/", "/opt/local/bin/", "/usr/libexec/", "/usr/local/opt/"];
|
|
23398
23566
|
var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh", "ash", "csh", "tcsh", "fish"]);
|
|
23399
23567
|
var NODE_LIKE = /* @__PURE__ */ new Set(["node", "nodejs", "tsx", "ts-node", "bun", "deno"]);
|
|
23400
|
-
var
|
|
23568
|
+
var INTERPRETERS2 = /* @__PURE__ */ new Set(["node", "nodejs", "tsx", "ts-node", "bun", "deno", "python", "python3", "ruby", "perl", "php", "lua", "sh", "bash", "zsh", "dash", "ksh"]);
|
|
23401
23569
|
var KNOWN_PROGRAMS = /* @__PURE__ */ new Set([
|
|
23402
23570
|
// shell builtins and plain utilities
|
|
23403
23571
|
"cd",
|
|
@@ -23829,7 +23997,7 @@ function checkSpecial(prog, f, words2, ctx) {
|
|
|
23829
23997
|
if (prog === "less" || prog === "more" || prog === "man") {
|
|
23830
23998
|
if (args.some((a) => a.startsWith("--lesskey") || a === "+!" || a.startsWith("+!"))) reject("a pager was given commands to run", FIX_READ_TOOL);
|
|
23831
23999
|
}
|
|
23832
|
-
if (
|
|
24000
|
+
if (INTERPRETERS2.has(prog) || /^python[0-9.]*$/.test(prog)) {
|
|
23833
24001
|
const inlineFlag = (a) => {
|
|
23834
24002
|
if (NODE_LIKE.has(prog) || prog === "nodejs") return a === "-e" || a === "--eval" || a === "-p" || a === "--print" || a === "-pe" || a === "-ep";
|
|
23835
24003
|
if (/^python/.test(prog)) return a === "-c" || /^-[A-Za-z]*c$/.test(a) && a.length <= 4 && a.startsWith("-") && !a.startsWith("--");
|
|
@@ -24014,7 +24182,7 @@ function resolveWords(words2, f, ctx) {
|
|
|
24014
24182
|
}
|
|
24015
24183
|
pushExec(ctx, f, words2, raw);
|
|
24016
24184
|
const e = lastExec(ctx);
|
|
24017
|
-
if (ctx.mode === "script" && (
|
|
24185
|
+
if (ctx.mode === "script" && (INTERPRETERS2.has(prog) || /^python/.test(prog))) {
|
|
24018
24186
|
const flags2 = /* @__PURE__ */ new Set(["-e", "-c", "-p", "--eval", "--print", "-r", "-E"]);
|
|
24019
24187
|
const k = e.args.findIndex((a) => flags2.has(a.text));
|
|
24020
24188
|
const flag = e.args[k]?.text;
|
|
@@ -24442,14 +24610,14 @@ function scriptCandidates(rel) {
|
|
|
24442
24610
|
if (base.startsWith("..") || base.startsWith("/") || base === "." || base === "") return [];
|
|
24443
24611
|
return [.../* @__PURE__ */ new Set([base, ...JS_EXTS.map((e) => base + e), ...["index.js", "index.mjs", "index.cjs", "index.ts"].map((i) => posix.join(base, i))])];
|
|
24444
24612
|
}
|
|
24445
|
-
function followFiles(
|
|
24613
|
+
function followFiles(entries2, fs) {
|
|
24446
24614
|
const seen = /* @__PURE__ */ new Set();
|
|
24447
|
-
const queue =
|
|
24615
|
+
const queue = entries2.map((rel) => ({ rel, depth: 0 }));
|
|
24448
24616
|
const analysis = { secret: null, send: null };
|
|
24449
24617
|
const files = [];
|
|
24450
|
-
const
|
|
24618
|
+
const unreadable2 = [];
|
|
24451
24619
|
let exceeded = false;
|
|
24452
|
-
const first = new Set(
|
|
24620
|
+
const first = new Set(entries2);
|
|
24453
24621
|
while (queue.length > 0) {
|
|
24454
24622
|
const item = queue.shift();
|
|
24455
24623
|
if (seen.has(item.rel)) continue;
|
|
@@ -24460,7 +24628,7 @@ function followFiles(entries, fs) {
|
|
|
24460
24628
|
}
|
|
24461
24629
|
const text = fs.read(item.rel);
|
|
24462
24630
|
if (text === null) {
|
|
24463
|
-
|
|
24631
|
+
unreadable2.push(item.rel);
|
|
24464
24632
|
continue;
|
|
24465
24633
|
}
|
|
24466
24634
|
files.push(item.rel);
|
|
@@ -24477,7 +24645,7 @@ function followFiles(entries, fs) {
|
|
|
24477
24645
|
if (hit) queue.push({ rel: hit, depth: item.depth + 1 });
|
|
24478
24646
|
}
|
|
24479
24647
|
}
|
|
24480
|
-
return { analysis, files, exceeded, unreadable };
|
|
24648
|
+
return { analysis, files, exceeded, unreadable: unreadable2 };
|
|
24481
24649
|
}
|
|
24482
24650
|
|
|
24483
24651
|
// ../core/src/lifecycle-scripts.ts
|
|
@@ -24742,25 +24910,25 @@ function hitBase(pkgText, name, scripts) {
|
|
|
24742
24910
|
}
|
|
24743
24911
|
var INCOMPLETE = { line: 1, label: "more local files than can be followed" };
|
|
24744
24912
|
function evaluateTargets(targets, fs, failClosed) {
|
|
24745
|
-
const
|
|
24913
|
+
const entries2 = [];
|
|
24746
24914
|
let exceeded = false;
|
|
24747
24915
|
for (const rel of [...new Set(targets.files)]) {
|
|
24748
24916
|
const c = scriptCandidates(rel).find((x) => fs.read(x) !== null);
|
|
24749
|
-
if (c !== void 0)
|
|
24917
|
+
if (c !== void 0) entries2.push(c);
|
|
24750
24918
|
else if (fs.list?.(rel.replace(/\/$/, "")) != null) {
|
|
24751
24919
|
const w = [];
|
|
24752
24920
|
const b = { entries: 0, exceeded: false };
|
|
24753
24921
|
walk(fs, rel.replace(/\/$/, ""), (f) => SCRIPT_FILE.test(f), b, w);
|
|
24754
|
-
|
|
24922
|
+
entries2.push(...w);
|
|
24755
24923
|
exceeded = exceeded || b.exceeded;
|
|
24756
24924
|
}
|
|
24757
24925
|
}
|
|
24758
24926
|
for (const r of targets.runners) {
|
|
24759
24927
|
const rf = runnerFiles(r, fs);
|
|
24760
|
-
|
|
24928
|
+
entries2.push(...rf.files);
|
|
24761
24929
|
exceeded = exceeded || rf.exceeded;
|
|
24762
24930
|
}
|
|
24763
|
-
const followed = followFiles([...new Set(
|
|
24931
|
+
const followed = followFiles([...new Set(entries2)], fs);
|
|
24764
24932
|
exceeded = exceeded || followed.exceeded;
|
|
24765
24933
|
let secret = followed.analysis.secret;
|
|
24766
24934
|
const send = followed.analysis.send;
|
|
@@ -25311,29 +25479,29 @@ function parseMcpConfig(rel, role, text) {
|
|
|
25311
25479
|
const top = Obj.safeParse(parseJsonLoose2(text));
|
|
25312
25480
|
if (!top.success) return null;
|
|
25313
25481
|
const doc = top.data;
|
|
25314
|
-
const
|
|
25482
|
+
const entries2 = [];
|
|
25315
25483
|
let hasServersKey = false;
|
|
25316
25484
|
for (const key of role === "mcp-config" ? ["mcpServers", "servers"] : ["mcpServers"]) {
|
|
25317
25485
|
const s = Obj.safeParse(doc[key]);
|
|
25318
25486
|
if (!s.success) continue;
|
|
25319
25487
|
hasServersKey = true;
|
|
25320
|
-
|
|
25488
|
+
entries2.push(...serverEntries(s.data));
|
|
25321
25489
|
}
|
|
25322
|
-
if (role === "config" &&
|
|
25490
|
+
if (role === "config" && entries2.length === 0) return null;
|
|
25323
25491
|
const perms = Obj.safeParse(doc["permissions"]);
|
|
25324
25492
|
const allow = role === "mcp-config" && perms.success ? strings2(perms.data["allow"]) : [];
|
|
25325
25493
|
for (const a of allow) {
|
|
25326
25494
|
const m = /^mcp__([^_](?:[^_]|_(?!_))*)(?:__(.+))?$/.exec(a);
|
|
25327
25495
|
if (m) {
|
|
25328
|
-
const server =
|
|
25496
|
+
const server = entries2.find((e) => e.kind === "server" && e.name === m[1]);
|
|
25329
25497
|
server?.autoApprove.push(m[2] && m[2] !== "*" ? m[2] : "*");
|
|
25330
25498
|
continue;
|
|
25331
25499
|
}
|
|
25332
|
-
if (
|
|
25333
|
-
|
|
25500
|
+
if (entries2.some((e) => e.kind === "ability" && e.name === a)) continue;
|
|
25501
|
+
entries2.push({ name: a, kind: "ability", ability: a, disabled: false, autoApprove: ["*"] });
|
|
25334
25502
|
}
|
|
25335
|
-
if (!hasServersKey &&
|
|
25336
|
-
return { file: rel, entries, anchor: anchorFor(text, ["mcpServers", "servers", "allow", "permissions"]) };
|
|
25503
|
+
if (!hasServersKey && entries2.length === 0) return null;
|
|
25504
|
+
return { file: rel, entries: entries2, anchor: anchorFor(text, ["mcpServers", "servers", "allow", "permissions"]) };
|
|
25337
25505
|
}
|
|
25338
25506
|
var PinsSchema = external_exports.object({
|
|
25339
25507
|
servers: external_exports.record(external_exports.object({
|
|
@@ -25779,7 +25947,7 @@ async function* scanRepo(root, options) {
|
|
|
25779
25947
|
init_zod();
|
|
25780
25948
|
|
|
25781
25949
|
// ../core/src/version.ts
|
|
25782
|
-
var SCANNER_VERSION = "0.3.
|
|
25950
|
+
var SCANNER_VERSION = "0.3.8";
|
|
25783
25951
|
|
|
25784
25952
|
// ../core/src/reporters/json-reporter.ts
|
|
25785
25953
|
var ScanStatsSchema = external_exports.object({
|
|
@@ -25792,7 +25960,7 @@ var FindingSchema = external_exports.object({
|
|
|
25792
25960
|
source: external_exports.enum(["signature", "heuristic"]),
|
|
25793
25961
|
ruleId: external_exports.string(),
|
|
25794
25962
|
title: external_exports.string(),
|
|
25795
|
-
severity: external_exports.enum(["critical", "high", "medium", "low"]),
|
|
25963
|
+
severity: external_exports.enum(["critical", "high", "medium", "low", "info"]),
|
|
25796
25964
|
file: external_exports.string(),
|
|
25797
25965
|
// The file name with bidi, zero-width and control characters shown as [U+XXXX] (m18-scanner SC-19).
|
|
25798
25966
|
fileDisplay: external_exports.string().optional(),
|
|
@@ -26104,6 +26272,10 @@ var ENTRIES = {
|
|
|
26104
26272
|
"EX-074": {
|
|
26105
26273
|
headline: "This settings file makes Copilot approve every tool call",
|
|
26106
26274
|
attack: "A committed setting approves all tool calls of the chat agent, so it no longer asks before it runs commands, edits files or reaches the network."
|
|
26275
|
+
},
|
|
26276
|
+
"EX-075": {
|
|
26277
|
+
headline: "This instruction file tells your AI to do something that has nothing to do with the code",
|
|
26278
|
+
attack: "Agents follow their instruction files (steering files, AGENTS.md, CONTRIBUTING.md and the like) without asking. An order there to leave a marker file, skip or weaken a test or a check, run a command that is not a build, test or lint step, or fetch a web address is carried out quietly, even when nothing in the text hides it."
|
|
26107
26279
|
}
|
|
26108
26280
|
};
|
|
26109
26281
|
function plainFor(ruleId, fallbackTitle) {
|
|
@@ -26119,7 +26291,7 @@ function plural(n, one, many = `${one}s`) {
|
|
|
26119
26291
|
}
|
|
26120
26292
|
|
|
26121
26293
|
// ../core/src/verdict.ts
|
|
26122
|
-
var RANK = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
26294
|
+
var RANK = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
26123
26295
|
function verdictFor(level) {
|
|
26124
26296
|
if (level === "clean") return { word: "CLEAN", line: "Nothing here tries to give your AI agent orders." };
|
|
26125
26297
|
if (level === "critical" || level === "high") return { word: "POSSESSED", line: "Your AI agent would read these as orders. Fix them first." };
|
|
@@ -26137,7 +26309,7 @@ function verdictForFindings(findings) {
|
|
|
26137
26309
|
}
|
|
26138
26310
|
|
|
26139
26311
|
// ../core/src/reporters/markdown-reporter.ts
|
|
26140
|
-
var ORDER = ["critical", "high", "medium", "low"];
|
|
26312
|
+
var ORDER = ["critical", "high", "medium", "low", "info"];
|
|
26141
26313
|
function cell(s) {
|
|
26142
26314
|
return s.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
26143
26315
|
}
|
|
@@ -26172,13 +26344,14 @@ function toMarkdown(findings, stats, limit = 50) {
|
|
|
26172
26344
|
}
|
|
26173
26345
|
|
|
26174
26346
|
// ../core/src/reporters/badge.ts
|
|
26175
|
-
var ORDER2 = ["critical", "high", "medium", "low"];
|
|
26347
|
+
var ORDER2 = ["critical", "high", "medium", "low", "info"];
|
|
26176
26348
|
var COLORS = {
|
|
26177
26349
|
clean: "#2e9e5b",
|
|
26178
26350
|
critical: "#b0123b",
|
|
26179
26351
|
high: "#c2410c",
|
|
26180
26352
|
medium: "#8a6d00",
|
|
26181
|
-
low: "#2563a8"
|
|
26353
|
+
low: "#2563a8",
|
|
26354
|
+
info: "#5b6472"
|
|
26182
26355
|
};
|
|
26183
26356
|
function badgeStatus(findings) {
|
|
26184
26357
|
const worst = ORDER2.find((s) => findings.some((f) => f.severity === s)) ?? "clean";
|
|
@@ -26762,10 +26935,10 @@ function hiddenChanges(lines, removed) {
|
|
|
26762
26935
|
if (!first) return;
|
|
26763
26936
|
const { line, col } = lines.position(first.offset);
|
|
26764
26937
|
const names = [...new Set(run3.map((h) => cpName(h.codePoint)))];
|
|
26765
|
-
const
|
|
26938
|
+
const list3 = names.length > 4 ? `${names.slice(0, 4).join(" ")} ...` : names.join(" ");
|
|
26766
26939
|
const ruleId = ruleOfClass(first.class);
|
|
26767
26940
|
const what = ruleId === "EX-021" ? "variation selector" : "hidden character";
|
|
26768
|
-
out.push({ ruleId, line, col, summary: `removed ${run3.length} ${what}${run3.length === 1 ? "" : "s"} (${
|
|
26941
|
+
out.push({ ruleId, line, col, summary: `removed ${run3.length} ${what}${run3.length === 1 ? "" : "s"} (${list3})` });
|
|
26769
26942
|
run3 = [];
|
|
26770
26943
|
};
|
|
26771
26944
|
for (const h of removed) {
|
|
@@ -27058,13 +27231,13 @@ async function exorciseRepo(root, findings, opts = {}) {
|
|
|
27058
27231
|
const byFile = /* @__PURE__ */ new Map();
|
|
27059
27232
|
for (const f of findings) {
|
|
27060
27233
|
if (f.source !== "signature" || !isFixableRule(f.ruleId) || !only.has(f.ruleId)) continue;
|
|
27061
|
-
const
|
|
27062
|
-
|
|
27063
|
-
byFile.set(f.file,
|
|
27234
|
+
const list3 = byFile.get(f.file) ?? [];
|
|
27235
|
+
list3.push(f);
|
|
27236
|
+
byFile.set(f.file, list3);
|
|
27064
27237
|
}
|
|
27065
27238
|
const inputs = [];
|
|
27066
27239
|
const notUtf8 = [];
|
|
27067
|
-
for (const [file,
|
|
27240
|
+
for (const [file, list3] of [...byFile.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
27068
27241
|
let bytes;
|
|
27069
27242
|
try {
|
|
27070
27243
|
bytes = await readFile4(join10(root, file));
|
|
@@ -27073,13 +27246,13 @@ async function exorciseRepo(root, findings, opts = {}) {
|
|
|
27073
27246
|
}
|
|
27074
27247
|
const text = bytes.toString("utf8");
|
|
27075
27248
|
if (!Buffer.from(text, "utf8").equals(bytes)) {
|
|
27076
|
-
const first =
|
|
27249
|
+
const first = list3[0];
|
|
27077
27250
|
if (first && isFixableRule(first.ruleId)) {
|
|
27078
27251
|
notUtf8.push({ file, before: text, after: text, changes: [], changeCount: 0, notes: [{ ruleId: first.ruleId, line: first.line, col: first.col, message: "the file is not valid UTF-8, so it was not changed" }] });
|
|
27079
27252
|
}
|
|
27080
27253
|
continue;
|
|
27081
27254
|
}
|
|
27082
|
-
inputs.push({ file, text, findings:
|
|
27255
|
+
inputs.push({ file, text, findings: list3 });
|
|
27083
27256
|
}
|
|
27084
27257
|
return [...await exorciseTexts(inputs, opts), ...notUtf8].sort((a, b) => a.file.localeCompare(b.file));
|
|
27085
27258
|
}
|
|
@@ -27114,8 +27287,8 @@ ${body}`;
|
|
|
27114
27287
|
}
|
|
27115
27288
|
return { patch: parts2.join(""), files, fixes, omitted, unsafe };
|
|
27116
27289
|
}
|
|
27117
|
-
function rescanTexts(
|
|
27118
|
-
return deduplicate(
|
|
27290
|
+
function rescanTexts(entries2, defs) {
|
|
27291
|
+
return deduplicate(entries2.flatMap((e) => {
|
|
27119
27292
|
const role = classifyFile(e.file);
|
|
27120
27293
|
return runSignatures({ path: e.file, rel: e.file, role, sizeBytes: Buffer.byteLength(e.text, "utf8") }, normalize(e.text, role), defs);
|
|
27121
27294
|
}));
|
|
@@ -27165,7 +27338,7 @@ function stripComment(s) {
|
|
|
27165
27338
|
var SECTION = /^\[\s*([A-Za-z0-9.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?\s*\]/;
|
|
27166
27339
|
var KEY = /^([A-Za-z][A-Za-z0-9-]*)\s*(?:=(.*))?$/;
|
|
27167
27340
|
function parseGitConfig(text) {
|
|
27168
|
-
const
|
|
27341
|
+
const entries2 = [];
|
|
27169
27342
|
let section = "";
|
|
27170
27343
|
let subsection = null;
|
|
27171
27344
|
let current = null;
|
|
@@ -27205,10 +27378,10 @@ function parseGitConfig(text) {
|
|
|
27205
27378
|
const kv = KEY.exec(line);
|
|
27206
27379
|
if (!kv) return { ok: false, line: n + 1 };
|
|
27207
27380
|
current = { section, subsection, key: (kv[1] ?? "").toLowerCase(), value: kv[2] === void 0 ? "true" : kv[2].trim() };
|
|
27208
|
-
|
|
27381
|
+
entries2.push(current);
|
|
27209
27382
|
continuing = continues;
|
|
27210
27383
|
}
|
|
27211
|
-
return { ok: true, entries };
|
|
27384
|
+
return { ok: true, entries: entries2 };
|
|
27212
27385
|
}
|
|
27213
27386
|
var FALSE_VALUES = /* @__PURE__ */ new Set(["false", "no", "off", "0", ""]);
|
|
27214
27387
|
function dangerousKey(e) {
|
|
@@ -27601,7 +27774,7 @@ async function findOriginCommit(repoRoot, relFile, line, span, opts = {}) {
|
|
|
27601
27774
|
}
|
|
27602
27775
|
async function traceOrigins(repoRoot, queries, opts = {}) {
|
|
27603
27776
|
const deadline = Date.now() + (opts.totalMs ?? ORIGIN_TOTAL_TIMEOUT_MS);
|
|
27604
|
-
const
|
|
27777
|
+
const cache4 = /* @__PURE__ */ new Map();
|
|
27605
27778
|
const seen = /* @__PURE__ */ new Map();
|
|
27606
27779
|
const out = [];
|
|
27607
27780
|
for (const q of queries) {
|
|
@@ -27611,7 +27784,7 @@ async function traceOrigins(repoRoot, queries, opts = {}) {
|
|
|
27611
27784
|
hit = Date.now() >= deadline ? { status: "timeout", reason: "overall time limit reached before this finding was traced" } : await findOriginCommit(repoRoot, q.file, q.line, q.span, {
|
|
27612
27785
|
timeoutMs: opts.perFindingMs ?? ORIGIN_TIMEOUT_MS,
|
|
27613
27786
|
deadline,
|
|
27614
|
-
cache:
|
|
27787
|
+
cache: cache4,
|
|
27615
27788
|
...opts.boundaries ? { boundaries: opts.boundaries } : {}
|
|
27616
27789
|
});
|
|
27617
27790
|
seen.set(key, hit);
|
|
@@ -27623,7 +27796,7 @@ async function traceOrigins(repoRoot, queries, opts = {}) {
|
|
|
27623
27796
|
var OriginStatusSchema = external_exports.enum(["log-s", "blame", "uncommitted", "not-found", "timeout", "error"]);
|
|
27624
27797
|
var TimelineThreatSchema = external_exports.object({
|
|
27625
27798
|
ruleId: external_exports.string(),
|
|
27626
|
-
severity: external_exports.enum(["critical", "high", "medium", "low"]),
|
|
27799
|
+
severity: external_exports.enum(["critical", "high", "medium", "low", "info"]),
|
|
27627
27800
|
file: external_exports.string(),
|
|
27628
27801
|
line: external_exports.number().int().positive(),
|
|
27629
27802
|
title: external_exports.string(),
|
|
@@ -27900,21 +28073,21 @@ function addAllowedRead(cwd, file, env = process.env, expected) {
|
|
|
27900
28073
|
if (expected !== void 0 && hash !== expected) return { ok: false, error: "The file changed while you were confirming. Nothing was allowed; run allow-read again." };
|
|
27901
28074
|
const loc = allowedReadsLocation(cwd, env);
|
|
27902
28075
|
if (!loc.ok) return loc;
|
|
27903
|
-
let
|
|
28076
|
+
let entries2 = [];
|
|
27904
28077
|
if (existsSync4(loc.file)) {
|
|
27905
28078
|
try {
|
|
27906
28079
|
const parsed = AllowedReadsSchema.safeParse(JSON.parse(readFileSync7(loc.file, "utf8")));
|
|
27907
|
-
if (parsed.success && parsed.data.project === loc.project)
|
|
28080
|
+
if (parsed.success && parsed.data.project === loc.project) entries2 = parsed.data.entries;
|
|
27908
28081
|
} catch {
|
|
27909
28082
|
}
|
|
27910
28083
|
}
|
|
27911
|
-
|
|
28084
|
+
entries2 = [...entries2.filter((e) => e.path !== abs), { path: abs, sha256: hash }];
|
|
27912
28085
|
mkdirSync(dirname5(loc.file), { recursive: true });
|
|
27913
28086
|
const tmp = `${loc.file}.tmp-${process.pid}`;
|
|
27914
|
-
writeFileSync(tmp, `${JSON.stringify({ version: 2, project: loc.project, entries }, null, 2)}
|
|
28087
|
+
writeFileSync(tmp, `${JSON.stringify({ version: 2, project: loc.project, entries: entries2 }, null, 2)}
|
|
27915
28088
|
`, "utf8");
|
|
27916
28089
|
renameSync(tmp, loc.file);
|
|
27917
|
-
return { ok: true, hash, path: abs, store: loc.file, count:
|
|
28090
|
+
return { ok: true, hash, path: abs, store: loc.file, count: entries2.length };
|
|
27918
28091
|
}
|
|
27919
28092
|
|
|
27920
28093
|
// ../core/src/fs-expand.ts
|
|
@@ -27966,7 +28139,7 @@ function segmentRe(seg) {
|
|
|
27966
28139
|
}
|
|
27967
28140
|
function expandGlob(word, dir) {
|
|
27968
28141
|
const out = [];
|
|
27969
|
-
const
|
|
28142
|
+
const cap4 = MAX_TARGETS + 1;
|
|
27970
28143
|
for (const alt of braceExpand(word)) {
|
|
27971
28144
|
const abs = isAbsolute9(alt);
|
|
27972
28145
|
const segs = alt.split("/").filter((s, i) => s !== "" || i === 0);
|
|
@@ -27999,31 +28172,31 @@ function expandGlob(word, dir) {
|
|
|
27999
28172
|
for (const p of level) {
|
|
28000
28173
|
if (!existsSync5(p)) continue;
|
|
28001
28174
|
out.push(p);
|
|
28002
|
-
if (out.length >=
|
|
28175
|
+
if (out.length >= cap4) return out;
|
|
28003
28176
|
}
|
|
28004
28177
|
}
|
|
28005
28178
|
return out;
|
|
28006
28179
|
}
|
|
28007
28180
|
var SKIP_WALK = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
28008
|
-
function walkFiles(root,
|
|
28181
|
+
function walkFiles(root, cap4) {
|
|
28009
28182
|
const files = [];
|
|
28010
28183
|
const stack = [root];
|
|
28011
28184
|
let visited = 0;
|
|
28012
28185
|
while (stack.length > 0) {
|
|
28013
28186
|
const d = stack.pop();
|
|
28014
28187
|
if (visited++ > 5e3) return { files, exceeded: true };
|
|
28015
|
-
let
|
|
28188
|
+
let entries2;
|
|
28016
28189
|
try {
|
|
28017
|
-
|
|
28190
|
+
entries2 = readdirSync2(d, { withFileTypes: true });
|
|
28018
28191
|
} catch {
|
|
28019
28192
|
continue;
|
|
28020
28193
|
}
|
|
28021
|
-
for (const e of
|
|
28194
|
+
for (const e of entries2.sort((a, b) => a.name < b.name ? 1 : -1)) {
|
|
28022
28195
|
if (e.isDirectory()) {
|
|
28023
28196
|
if (!SKIP_WALK.has(e.name)) stack.push(resolve11(d, e.name));
|
|
28024
28197
|
} else if (e.isFile() || e.isSymbolicLink()) {
|
|
28025
28198
|
files.push(resolve11(d, e.name));
|
|
28026
|
-
if (files.length >
|
|
28199
|
+
if (files.length > cap4) return { files, exceeded: true };
|
|
28027
28200
|
}
|
|
28028
28201
|
}
|
|
28029
28202
|
}
|
|
@@ -28256,11 +28429,11 @@ var isLockfile = (label) => LOCKFILE_NAMES2.has(label.split(/[\\/]/).pop() ?? ""
|
|
|
28256
28429
|
function mustCheckFully(label, role) {
|
|
28257
28430
|
return AGENT_FACING.has(role) && !(role === "config" && isLockfile(label));
|
|
28258
28431
|
}
|
|
28259
|
-
function limitFor(remainingMs, jobs,
|
|
28432
|
+
function limitFor(remainingMs, jobs, cap4) {
|
|
28260
28433
|
const byThirds = remainingMs / (1 + jobs / 3);
|
|
28261
28434
|
const byFloor = remainingMs - 50 * jobs;
|
|
28262
28435
|
const bound = Math.floor(byThirds >= 150 ? byThirds : byFloor);
|
|
28263
|
-
return bound >= 50 ? Math.min(
|
|
28436
|
+
return bound >= 50 ? Math.min(cap4, bound) : null;
|
|
28264
28437
|
}
|
|
28265
28438
|
function regexJobs(defs, role) {
|
|
28266
28439
|
return 2 * defs.filter((d) => d.enabled !== false && d.applies_to.includes(role) && d.match.regex).length;
|
|
@@ -28404,7 +28577,7 @@ function timedOutSerious(f, defs) {
|
|
|
28404
28577
|
return sev === "critical" || sev === "high";
|
|
28405
28578
|
}
|
|
28406
28579
|
function severityRank(s) {
|
|
28407
|
-
return { critical: 0, high: 1, medium: 2, low: 3 }[s];
|
|
28580
|
+
return { critical: 0, high: 1, medium: 2, low: 3, info: 4 }[s];
|
|
28408
28581
|
}
|
|
28409
28582
|
function decideRead(event, defs, opts = {}) {
|
|
28410
28583
|
let parsed = event;
|
|
@@ -28446,7 +28619,7 @@ function decideRead(event, defs, opts = {}) {
|
|
|
28446
28619
|
const blocked2 = /* @__PURE__ */ new Map();
|
|
28447
28620
|
const warned2 = /* @__PURE__ */ new Map();
|
|
28448
28621
|
const notes = [];
|
|
28449
|
-
const
|
|
28622
|
+
const tooLarge2 = /* @__PURE__ */ new Set();
|
|
28450
28623
|
const unchecked = /* @__PURE__ */ new Map();
|
|
28451
28624
|
const deadline = Date.now() + (opts.budgetMs ?? DECIDE_BUDGET_MS);
|
|
28452
28625
|
const outOfTime = (label, role) => {
|
|
@@ -28463,13 +28636,13 @@ function decideRead(event, defs, opts = {}) {
|
|
|
28463
28636
|
if (stat4.size > MAX_SCAN_BYTES) {
|
|
28464
28637
|
const big = relLabel(abs, cwd);
|
|
28465
28638
|
if (rolesOf(abs, cwd).classes.some((r) => mustCheckFully(big, r))) {
|
|
28466
|
-
|
|
28639
|
+
tooLarge2.add(abs);
|
|
28467
28640
|
} else {
|
|
28468
28641
|
notes.push(`Exorcist 98 warning: ${shownName(big)} is larger than 10 MB, so it was not scanned. It was allowed.`);
|
|
28469
28642
|
continue;
|
|
28470
28643
|
}
|
|
28471
28644
|
}
|
|
28472
|
-
if (
|
|
28645
|
+
if (tooLarge2.has(abs)) {
|
|
28473
28646
|
if (opts.allowed && opts.allowed.has(allowKey(realPath(abs), sha256FileChunked(abs)))) continue;
|
|
28474
28647
|
unchecked.set(relLabel(abs, cwd), "it is larger than 10 MB, too large to check");
|
|
28475
28648
|
continue;
|
|
@@ -28483,9 +28656,9 @@ function decideRead(event, defs, opts = {}) {
|
|
|
28483
28656
|
const label = relLabel(abs, cwd);
|
|
28484
28657
|
const { classes, scan: scan2 } = rolesOf(abs, cwd);
|
|
28485
28658
|
const role = classes.find((r) => mustCheckFully(label, r)) ?? (classes[0] ?? "unknown");
|
|
28486
|
-
const
|
|
28659
|
+
const cap4 = opts.limitMs ?? REGEX_TIME_LIMIT_MS * Math.max(1, Math.ceil(text.length / 1048576));
|
|
28487
28660
|
const jobs = scan2.reduce((n, r) => n + regexJobs(defs, r), 0);
|
|
28488
|
-
const limit = limitFor(deadline - Date.now(), jobs,
|
|
28661
|
+
const limit = limitFor(deadline - Date.now(), jobs, cap4);
|
|
28489
28662
|
if (limit === null) {
|
|
28490
28663
|
outOfTime(label, role);
|
|
28491
28664
|
continue;
|
|
@@ -29565,13 +29738,13 @@ function envFiles(root) {
|
|
|
29565
29738
|
let visited = 0;
|
|
29566
29739
|
while (stack.length > 0 && visited < MAX_ENTRIES) {
|
|
29567
29740
|
const { dir, depth } = stack.pop();
|
|
29568
|
-
let
|
|
29741
|
+
let entries2;
|
|
29569
29742
|
try {
|
|
29570
|
-
|
|
29743
|
+
entries2 = readdirSync4(dir, { withFileTypes: true });
|
|
29571
29744
|
} catch {
|
|
29572
29745
|
continue;
|
|
29573
29746
|
}
|
|
29574
|
-
for (const e of
|
|
29747
|
+
for (const e of entries2.sort((a, b) => a.name < b.name ? -1 : 1)) {
|
|
29575
29748
|
if (visited++ >= MAX_ENTRIES) break;
|
|
29576
29749
|
const path = join17(dir, e.name);
|
|
29577
29750
|
if (e.isDirectory()) {
|
|
@@ -29622,7 +29795,7 @@ function loadEnvKeys(cwd) {
|
|
|
29622
29795
|
|
|
29623
29796
|
// ../core/src/gate.ts
|
|
29624
29797
|
init_walker();
|
|
29625
|
-
var RANK2 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
29798
|
+
var RANK2 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
29626
29799
|
var SCANNED_ROLES = /* @__PURE__ */ new Set(["instruction", "memory", "hook", "mcp-config", "power"]);
|
|
29627
29800
|
var norm2 = (rel) => rel.replace(/\\/g, "/");
|
|
29628
29801
|
var baseName2 = (rel) => norm2(rel).split("/").pop() ?? "";
|
|
@@ -29784,7 +29957,7 @@ function readBundleTar(tar) {
|
|
|
29784
29957
|
if (tar.length > DOWNLOAD_LIMIT_BYTES) return fail2(`The bundle is larger than the ${DOWNLOAD_LIMIT_BYTES / 1048576} MB limit.`);
|
|
29785
29958
|
if (tar.length === 0) return fail2("The bundle is empty.");
|
|
29786
29959
|
if (tar.length % BLOCK !== 0) return fail2("The bundle is not a tar archive (its size is not a whole number of 512-byte blocks).");
|
|
29787
|
-
const
|
|
29960
|
+
const entries2 = [];
|
|
29788
29961
|
const seen = /* @__PURE__ */ new Set();
|
|
29789
29962
|
for (let off = 0; ; ) {
|
|
29790
29963
|
if (off + BLOCK > tar.length) return fail2("The bundle is truncated (no end-of-archive marker).");
|
|
@@ -29816,11 +29989,11 @@ function readBundleTar(tar) {
|
|
|
29816
29989
|
if (size > MAX_FILE_BYTES2) return fail2(`The bundle entry ${printable(path)} is larger than ${MAX_FILE_BYTES2 / 1024} KB.`);
|
|
29817
29990
|
const start = off + BLOCK;
|
|
29818
29991
|
if (start + size > tar.length) return fail2("The bundle is truncated.");
|
|
29819
|
-
|
|
29820
|
-
if (
|
|
29992
|
+
entries2.push({ path, data: Buffer.from(tar.subarray(start, start + size)) });
|
|
29993
|
+
if (entries2.length > MAX_ENTRIES2 + 2) return fail2(`The bundle has more than ${MAX_ENTRIES2} definitions.`);
|
|
29821
29994
|
off = start + Math.ceil(size / BLOCK) * BLOCK;
|
|
29822
29995
|
}
|
|
29823
|
-
return { ok: true, entries };
|
|
29996
|
+
return { ok: true, entries: entries2 };
|
|
29824
29997
|
}
|
|
29825
29998
|
function verifySignature(manifestBytes, sig, publicKeyPem) {
|
|
29826
29999
|
const key = loadPublicKey(publicKeyPem);
|
|
@@ -30187,14 +30360,14 @@ function cmp(a, b) {
|
|
|
30187
30360
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
30188
30361
|
}
|
|
30189
30362
|
function buildBaseline(findings) {
|
|
30190
|
-
const
|
|
30363
|
+
const entries2 = findings.map((f) => ({
|
|
30191
30364
|
ruleId: f.ruleId,
|
|
30192
30365
|
file: f.file,
|
|
30193
30366
|
fingerprint: fingerprintOf(f),
|
|
30194
30367
|
line: f.line
|
|
30195
30368
|
}));
|
|
30196
|
-
|
|
30197
|
-
return { version: BASELINE_VERSION, entries };
|
|
30369
|
+
entries2.sort((a, b) => cmp(a.file, b.file) || cmp(a.ruleId, b.ruleId) || cmp(a.fingerprint, b.fingerprint) || a.line - b.line);
|
|
30370
|
+
return { version: BASELINE_VERSION, entries: entries2 };
|
|
30198
30371
|
}
|
|
30199
30372
|
function parseBaseline(text) {
|
|
30200
30373
|
let raw;
|
|
@@ -30345,14 +30518,229 @@ function repoHidingFindings(suppressed, def) {
|
|
|
30345
30518
|
}
|
|
30346
30519
|
return out;
|
|
30347
30520
|
}
|
|
30348
|
-
function ignoreFileFinding(file,
|
|
30349
|
-
return { ...hidingBase(def), file, line: 1, col: 1, span: `${file}: ${
|
|
30521
|
+
function ignoreFileFinding(file, entries2, def) {
|
|
30522
|
+
return { ...hidingBase(def), file, line: 1, col: 1, span: `${file}: ${entries2.length} ignored ${entries2.length === 1 ? "path" : "paths"}` };
|
|
30350
30523
|
}
|
|
30351
30524
|
|
|
30352
30525
|
// ../core/src/index.ts
|
|
30353
30526
|
init_text_decode();
|
|
30354
30527
|
init_image_text();
|
|
30355
30528
|
|
|
30529
|
+
// ../core/src/home-settings.ts
|
|
30530
|
+
init_zod();
|
|
30531
|
+
var UNKNOWN = "unknown format";
|
|
30532
|
+
var OWASP_RUN = ["ASI02 Inadequate Human-in-the-Loop Controls", "ASI05 Unexpected Code Execution", "LLM06:2025 Excessive Agency"];
|
|
30533
|
+
var OWASP_APPROVE = ["ASI02 Inadequate Human-in-the-Loop Controls", "MCP05 Excessive Tool Permissions"];
|
|
30534
|
+
var KIRO_FIX = 'This rule is in your home folder, so it applies to every project you open. Change "allow" to "ask" for broad capabilities, and allow only exact commands (for example "git status" or "npm test"). A wildcard on a shell, an interpreter or a program such as git, find or npm run lets the agent run any program without asking.';
|
|
30535
|
+
var KIRO_INFO_FIX = "A narrow allow rule in your home folder. Information only: check that you still want it in every project.";
|
|
30536
|
+
var CLINE_FIX = `Cline auto-approve is on in your home settings, for every project. Turn off "execute all commands" and file edits in Cline's auto-approve settings, or turn auto-approve off, so the agent asks before it acts.`;
|
|
30537
|
+
var CLINE_INFO_FIX = "Cline auto-approves only safe commands or reads. Information only: check that you still want it.";
|
|
30538
|
+
var cap2 = (s) => {
|
|
30539
|
+
const r = redactSecretText(s.replace(/\s+/g, " ").trim());
|
|
30540
|
+
return r.length > 120 ? `${r.slice(0, 119)}\u2026` : r;
|
|
30541
|
+
};
|
|
30542
|
+
function lineCol(text, at) {
|
|
30543
|
+
if (at < 0) return { line: 1, col: 1 };
|
|
30544
|
+
let line = 1;
|
|
30545
|
+
let start = 0;
|
|
30546
|
+
for (let i = text.indexOf("\n"); i !== -1 && i < at; i = text.indexOf("\n", i + 1)) {
|
|
30547
|
+
line++;
|
|
30548
|
+
start = i + 1;
|
|
30549
|
+
}
|
|
30550
|
+
return { line, col: at - start + 1 };
|
|
30551
|
+
}
|
|
30552
|
+
function toFinding(file, text, h) {
|
|
30553
|
+
return {
|
|
30554
|
+
source: "signature",
|
|
30555
|
+
ruleId: h.ruleId,
|
|
30556
|
+
title: h.title,
|
|
30557
|
+
severity: h.severity,
|
|
30558
|
+
file,
|
|
30559
|
+
...lineCol(text, h.at),
|
|
30560
|
+
span: cap2(h.span),
|
|
30561
|
+
owasp: h.ruleId === "EX-007" ? OWASP_APPROVE : OWASP_RUN,
|
|
30562
|
+
fix: h.fix
|
|
30563
|
+
};
|
|
30564
|
+
}
|
|
30565
|
+
var Globs = external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]);
|
|
30566
|
+
var RuleSchema2 = external_exports.object({ capability: external_exports.string(), match: Globs.optional().nullable(), exclude: Globs.optional().nullable(), effect: external_exports.string() }).passthrough();
|
|
30567
|
+
var KiroFileSchema = external_exports.object({ rules: external_exports.array(external_exports.unknown()).optional().nullable(), policies: external_exports.array(external_exports.unknown()).optional().nullable() }).passthrough();
|
|
30568
|
+
var list = (g) => g == null ? [] : Array.isArray(g) ? g : [g];
|
|
30569
|
+
var WILD_ONLY = /^(?:\*+|\*\*\/\*|\.\*|\.\+|\^?\.\*\$?)$/;
|
|
30570
|
+
var WIDE_RISK = /* @__PURE__ */ new Set(["fs_write", "filesystem", "mcp", "subagent", "skill", "power", "sandbox_network"]);
|
|
30571
|
+
function programOf(word) {
|
|
30572
|
+
const base = (word.split(/[\\/]/).pop() ?? word).toLowerCase();
|
|
30573
|
+
if (/^python3[0-9.]*$/.test(base)) return "python3";
|
|
30574
|
+
if (/^python[0-9.]*$/.test(base)) return "python";
|
|
30575
|
+
return base;
|
|
30576
|
+
}
|
|
30577
|
+
function judgeShellPattern(raw) {
|
|
30578
|
+
const pattern = raw.trim().replace(/\.\*/g, "*");
|
|
30579
|
+
if (pattern === "" || WILD_ONLY.test(pattern)) return { severity: "high", ruleId: "EX-033", why: "every shell command" };
|
|
30580
|
+
const words2 = pattern.split(/\s+/);
|
|
30581
|
+
const first = programOf((words2[0] ?? "").replace(/\*+$/, ""));
|
|
30582
|
+
const wild = /[*?[\]{}()|\\+^$;&<>`!]/.test(pattern) || /\.[*+?{]/.test(raw);
|
|
30583
|
+
if (["eval", "exec", "sudo", "cmd"].includes(first) || INTERPRETERS.has(first) && (words2.length === 1 || wild)) {
|
|
30584
|
+
return { severity: "high", ruleId: "EX-033", why: "an interpreter, which runs any code it is given" };
|
|
30585
|
+
}
|
|
30586
|
+
const two = `${first} ${programOf(words2[1] ?? "")}`;
|
|
30587
|
+
if (wild && (EXEC_COMMANDS.has(two) || EXEC_COMMANDS.has(first))) {
|
|
30588
|
+
return { severity: "high", ruleId: "EX-073", why: "a program that runs whatever it is given, with a wildcard" };
|
|
30589
|
+
}
|
|
30590
|
+
if (wild) return { severity: "medium", ruleId: "EX-033", why: "a wildcard, which can match more than one command" };
|
|
30591
|
+
return { severity: "info", ruleId: "EX-033", why: "one exact command" };
|
|
30592
|
+
}
|
|
30593
|
+
function seeker(text) {
|
|
30594
|
+
let pos = 0;
|
|
30595
|
+
return (needle, from) => {
|
|
30596
|
+
const start = from ?? pos;
|
|
30597
|
+
let i = needle === "" ? -1 : text.indexOf(needle, start);
|
|
30598
|
+
if (i === -1 && needle !== "") i = text.indexOf(needle);
|
|
30599
|
+
if (i !== -1) pos = i + needle.length;
|
|
30600
|
+
return i === -1 ? start : i;
|
|
30601
|
+
};
|
|
30602
|
+
}
|
|
30603
|
+
function unreadableHit(label, what, at) {
|
|
30604
|
+
return { ruleId: "EX-033", severity: "medium", title: `${label}: an entry could not be read, so it was not checked`, span: what, at, fix: KIRO_FIX };
|
|
30605
|
+
}
|
|
30606
|
+
function ruleHits(entries2, text, seek, label) {
|
|
30607
|
+
const hits = [];
|
|
30608
|
+
for (const [i, entry] of entries2.entries()) {
|
|
30609
|
+
const one = RuleSchema2.safeParse(entry);
|
|
30610
|
+
if (!one.success) {
|
|
30611
|
+
hits.push(unreadableHit(label, `rule ${i + 1} (unknown format)`, seek("rules", 0)));
|
|
30612
|
+
continue;
|
|
30613
|
+
}
|
|
30614
|
+
const r = one.data;
|
|
30615
|
+
const capability = r.capability.trim();
|
|
30616
|
+
const effect = r.effect.trim().toLowerCase();
|
|
30617
|
+
const at = seek(capability);
|
|
30618
|
+
const globs = list(r.match);
|
|
30619
|
+
if (effect === "deny" || effect === "ask") continue;
|
|
30620
|
+
if (effect === "evaluate") {
|
|
30621
|
+
hits.push({ ruleId: "EX-033", severity: "medium", title: `${label}: an AI decides which ${capability} actions run without asking`, span: `${capability} evaluate ${globs.join(", ")}`, at, fix: KIRO_FIX });
|
|
30622
|
+
continue;
|
|
30623
|
+
}
|
|
30624
|
+
if (effect !== "allow") continue;
|
|
30625
|
+
if (capability === "all" || capability === "builtin") {
|
|
30626
|
+
hits.push({ ruleId: "EX-033", severity: "high", title: `${label}: the agent may use every ${capability === "all" ? "" : "built-in "}tool without asking`, span: `${capability} allow ${globs.join(", ")}`, at, fix: KIRO_FIX });
|
|
30627
|
+
continue;
|
|
30628
|
+
}
|
|
30629
|
+
if (capability === "shell") {
|
|
30630
|
+
if (globs.length === 0) {
|
|
30631
|
+
hits.push({ ruleId: "EX-033", severity: "high", title: `${label}: the agent may run any shell command without asking`, span: "shell allow (no match list)", at, fix: KIRO_FIX });
|
|
30632
|
+
continue;
|
|
30633
|
+
}
|
|
30634
|
+
for (const g of globs) {
|
|
30635
|
+
const j = judgeShellPattern(g);
|
|
30636
|
+
const title = j.severity === "info" ? `${label}: one shell command runs without asking` : `${label}: a shell rule allows ${j.why}, without asking`;
|
|
30637
|
+
hits.push({ ruleId: j.ruleId, severity: j.severity, title, span: `shell allow ${g}`, at: seek(g, at), fix: j.severity === "info" ? KIRO_INFO_FIX : KIRO_FIX });
|
|
30638
|
+
}
|
|
30639
|
+
continue;
|
|
30640
|
+
}
|
|
30641
|
+
const wide = globs.length === 0 || globs.some((g) => WILD_ONLY.test(g.trim()));
|
|
30642
|
+
if (wide && WIDE_RISK.has(capability)) {
|
|
30643
|
+
hits.push({ ruleId: "EX-033", severity: "medium", title: `${label}: every ${capability} action runs without asking`, span: `${capability} allow ${globs.join(", ") || "(no match list)"}`, at, fix: KIRO_FIX });
|
|
30644
|
+
} else {
|
|
30645
|
+
hits.push({ ruleId: "EX-033", severity: "info", title: `${label}: a ${capability} rule runs without asking`, span: `${capability} allow ${globs.join(", ")}`, at, fix: KIRO_INFO_FIX });
|
|
30646
|
+
}
|
|
30647
|
+
}
|
|
30648
|
+
return hits;
|
|
30649
|
+
}
|
|
30650
|
+
function kiroPermissionsFindings(text, file) {
|
|
30651
|
+
let doc;
|
|
30652
|
+
try {
|
|
30653
|
+
doc = yaml.load(text, { schema: yaml.JSON_SCHEMA });
|
|
30654
|
+
} catch {
|
|
30655
|
+
return { ok: false, reason: UNKNOWN };
|
|
30656
|
+
}
|
|
30657
|
+
if (doc === void 0 || doc === null) return { ok: true, findings: [] };
|
|
30658
|
+
const parsed = KiroFileSchema.safeParse(doc);
|
|
30659
|
+
if (!parsed.success) return { ok: false, reason: UNKNOWN };
|
|
30660
|
+
const seek = seeker(text);
|
|
30661
|
+
const label = "Kiro permissions in your home folder";
|
|
30662
|
+
const hits = [];
|
|
30663
|
+
for (const p of parsed.data.policies ?? []) {
|
|
30664
|
+
if (typeof p !== "string") {
|
|
30665
|
+
hits.push(unreadableHit(label, "a policy (unknown format)", seek("policies", 0)));
|
|
30666
|
+
continue;
|
|
30667
|
+
}
|
|
30668
|
+
const name = p.trim().toLowerCase();
|
|
30669
|
+
if (name === "allow-all") hits.push({ ruleId: "EX-033", severity: "high", title: `${label}: every action runs without asking`, span: `policy ${p}`, at: seek(p), fix: KIRO_FIX });
|
|
30670
|
+
else if (name === "approve-for-me") hits.push({ ruleId: "EX-033", severity: "medium", title: `${label}: an AI approves actions for you`, span: `policy ${p}`, at: seek(p), fix: KIRO_FIX });
|
|
30671
|
+
}
|
|
30672
|
+
hits.push(...ruleHits(parsed.data.rules ?? [], text, seek, label));
|
|
30673
|
+
return { ok: true, findings: hits.map((h) => toFinding(file, text, h)) };
|
|
30674
|
+
}
|
|
30675
|
+
var AgentSchema = external_exports.object({
|
|
30676
|
+
permissions: external_exports.object({ rules: external_exports.array(external_exports.unknown()).optional().nullable() }).passthrough().optional().nullable(),
|
|
30677
|
+
toolsSettings: external_exports.record(external_exports.unknown()).optional().nullable()
|
|
30678
|
+
}).passthrough();
|
|
30679
|
+
function kiroAgentFindings(text, file) {
|
|
30680
|
+
const doc = parseJsonLoose(text);
|
|
30681
|
+
if (typeof doc !== "object" || doc === null || Array.isArray(doc)) return { ok: false, reason: UNKNOWN };
|
|
30682
|
+
const parsed = AgentSchema.safeParse(doc);
|
|
30683
|
+
if (!parsed.success) return { ok: false, reason: UNKNOWN };
|
|
30684
|
+
const seek = seeker(text);
|
|
30685
|
+
const label = "Kiro agent profile in your home folder";
|
|
30686
|
+
const hits = ruleHits(parsed.data.permissions?.rules ?? [], text, seek, label);
|
|
30687
|
+
for (const tool of ["execute_bash", "shell"]) {
|
|
30688
|
+
const t2 = parsed.data.toolsSettings?.[tool];
|
|
30689
|
+
if (typeof t2 !== "object" || t2 === null || !("allowedCommands" in t2)) continue;
|
|
30690
|
+
const cmds = t2.allowedCommands;
|
|
30691
|
+
const at = seek("allowedCommands", 0);
|
|
30692
|
+
if (!Array.isArray(cmds)) {
|
|
30693
|
+
hits.push(unreadableHit(label, `${tool}.allowedCommands (unknown format)`, at));
|
|
30694
|
+
continue;
|
|
30695
|
+
}
|
|
30696
|
+
for (const c of cmds) {
|
|
30697
|
+
if (typeof c !== "string") {
|
|
30698
|
+
hits.push(unreadableHit(label, `${tool}.allowedCommands entry (unknown format)`, at));
|
|
30699
|
+
continue;
|
|
30700
|
+
}
|
|
30701
|
+
const j = judgeShellPattern(c);
|
|
30702
|
+
const title = j.severity === "info" ? `${label}: one shell command runs without asking` : `${label}: an allowed command lets ${j.why} run without asking`;
|
|
30703
|
+
hits.push({ ruleId: j.ruleId, severity: j.severity, title, span: `${tool}.allowedCommands ${c}`, at: seek(JSON.stringify(c), at), fix: j.severity === "info" ? KIRO_INFO_FIX : KIRO_FIX });
|
|
30704
|
+
}
|
|
30705
|
+
}
|
|
30706
|
+
return { ok: true, findings: hits.map((h) => toFinding(file, text, h)) };
|
|
30707
|
+
}
|
|
30708
|
+
var HIGH_FLAGS = ["executeAllCommands"];
|
|
30709
|
+
var MEDIUM_FLAGS = ["editFiles", "editFilesExternally", "useMcp", "useBrowser"];
|
|
30710
|
+
var SAFE_FLAGS = ["executeSafeCommands", "readFiles", "readFilesExternally"];
|
|
30711
|
+
var ACTION_FLAGS = /* @__PURE__ */ new Set([...HIGH_FLAGS, ...MEDIUM_FLAGS, ...SAFE_FLAGS]);
|
|
30712
|
+
function clineFindings(text, file) {
|
|
30713
|
+
const doc = parseJsonLoose(text);
|
|
30714
|
+
if (typeof doc !== "object" || doc === null || Array.isArray(doc)) return { ok: false, reason: UNKNOWN };
|
|
30715
|
+
const s = doc["autoApprovalSettings"];
|
|
30716
|
+
if (typeof s !== "object" || s === null || Array.isArray(s)) return { ok: false, reason: UNKNOWN };
|
|
30717
|
+
const settings = s;
|
|
30718
|
+
if (typeof settings["enabled"] !== "boolean") return { ok: false, reason: UNKNOWN };
|
|
30719
|
+
const actions = settings["actions"];
|
|
30720
|
+
if (actions !== void 0 && (typeof actions !== "object" || actions === null || Array.isArray(actions))) return { ok: false, reason: UNKNOWN };
|
|
30721
|
+
if (settings["enabled"] !== true) return { ok: true, findings: [] };
|
|
30722
|
+
const flags2 = { ...settings, ...actions };
|
|
30723
|
+
const on = Object.entries(flags2).filter(([k, v]) => ACTION_FLAGS.has(k) && v === true).map(([k]) => k);
|
|
30724
|
+
if (on.length === 0) return { ok: true, findings: [] };
|
|
30725
|
+
const base = Math.max(0, text.indexOf('"autoApprovalSettings"'));
|
|
30726
|
+
const where2 = (key) => {
|
|
30727
|
+
const i = text.indexOf(`"${key}"`, base);
|
|
30728
|
+
return i === -1 ? base : i;
|
|
30729
|
+
};
|
|
30730
|
+
const label = "Cline auto-approve in your home settings";
|
|
30731
|
+
const high = on.filter((k) => HIGH_FLAGS.includes(k));
|
|
30732
|
+
const medium = on.filter((k) => MEDIUM_FLAGS.includes(k));
|
|
30733
|
+
let hit;
|
|
30734
|
+
if (high.length > 0) {
|
|
30735
|
+
hit = { ruleId: "EX-007", severity: "high", title: `${label}: every command runs without asking`, span: `autoApprovalSettings enabled, ${high.join(", ")}`, at: where2(high[0] ?? ""), fix: CLINE_FIX };
|
|
30736
|
+
} else if (medium.length > 0) {
|
|
30737
|
+
hit = { ruleId: "EX-007", severity: "medium", title: `${label}: file edits or tool use run without asking`, span: `autoApprovalSettings enabled, ${medium.join(", ")}`, at: where2(medium[0] ?? ""), fix: CLINE_FIX };
|
|
30738
|
+
} else {
|
|
30739
|
+
hit = { ruleId: "EX-007", severity: "info", title: `${label}: safe commands or reads run without asking`, span: `autoApprovalSettings enabled, ${on.join(", ")}`, at: where2(on[0] ?? ""), fix: CLINE_INFO_FIX };
|
|
30740
|
+
}
|
|
30741
|
+
return { ok: true, findings: [toFinding(file, text, hit)] };
|
|
30742
|
+
}
|
|
30743
|
+
|
|
30356
30744
|
// ../core/src/kiro-evidence.ts
|
|
30357
30745
|
init_zod();
|
|
30358
30746
|
var KiroEventSchema = external_exports.object({
|
|
@@ -31172,7 +31560,7 @@ function decideShellRead(event, defs, opts = {}, fallbackCwd = process.cwd()) {
|
|
|
31172
31560
|
}
|
|
31173
31561
|
|
|
31174
31562
|
// src/commands/approve.ts
|
|
31175
|
-
import { existsSync as
|
|
31563
|
+
import { existsSync as existsSync20, readFileSync as readFileSync27 } from "node:fs";
|
|
31176
31564
|
|
|
31177
31565
|
// ../shield/src/hash.ts
|
|
31178
31566
|
import { createHash as createHash7 } from "node:crypto";
|
|
@@ -31278,16 +31666,57 @@ var LineSplitter = class {
|
|
|
31278
31666
|
|
|
31279
31667
|
// ../shield/src/policy.ts
|
|
31280
31668
|
init_zod();
|
|
31281
|
-
import { existsSync as
|
|
31669
|
+
import { existsSync as existsSync10, lstatSync as lstatSync6, readFileSync as readFileSync15, writeFileSync as writeFileSync3 } from "node:fs";
|
|
31282
31670
|
import { join as join21 } from "node:path";
|
|
31283
31671
|
|
|
31284
31672
|
// ../shield/src/userkey.ts
|
|
31285
31673
|
import { createHmac, randomBytes as randomBytes3, timingSafeEqual } from "node:crypto";
|
|
31286
|
-
import { closeSync as closeSync4, constants as constants2, fstatSync as fstatSync2, lstatSync as lstatSync5, mkdirSync as mkdirSync3, openSync as openSync4, readFileSync as readFileSync14, writeSync } from "node:fs";
|
|
31674
|
+
import { closeSync as closeSync4, constants as constants2, existsSync as existsSync9, fstatSync as fstatSync2, lstatSync as lstatSync5, mkdirSync as mkdirSync3, openSync as openSync4, readFileSync as readFileSync14, realpathSync as realpathSync8, writeSync } from "node:fs";
|
|
31287
31675
|
import { homedir as homedir8 } from "node:os";
|
|
31288
|
-
import { isAbsolute as isAbsolute16, join as join20 } from "node:path";
|
|
31676
|
+
import { basename as basename8, dirname as dirname9, isAbsolute as isAbsolute16, join as join20, relative as relative13, resolve as resolve20 } from "node:path";
|
|
31289
31677
|
var KEY_FILE = "shield.key";
|
|
31290
31678
|
var IS_WINDOWS = process.platform === "win32";
|
|
31679
|
+
function userDirOverrideProblem(dir, cwd = process.cwd()) {
|
|
31680
|
+
const real = (p) => {
|
|
31681
|
+
let cur = resolve20(p);
|
|
31682
|
+
let rest = "";
|
|
31683
|
+
for (let i = 0; i < 64; i++) {
|
|
31684
|
+
try {
|
|
31685
|
+
return join20(realpathSync8.native(cur), rest);
|
|
31686
|
+
} catch {
|
|
31687
|
+
}
|
|
31688
|
+
const up = dirname9(cur);
|
|
31689
|
+
if (up === cur) break;
|
|
31690
|
+
rest = join20(basename8(cur), rest);
|
|
31691
|
+
cur = up;
|
|
31692
|
+
}
|
|
31693
|
+
return resolve20(p);
|
|
31694
|
+
};
|
|
31695
|
+
const fold2 = (p) => process.platform === "darwin" || IS_WINDOWS ? p.toLowerCase() : p;
|
|
31696
|
+
const d = fold2(real(dir));
|
|
31697
|
+
const c = fold2(real(cwd));
|
|
31698
|
+
if (d === fold2(real(join20(homedir8(), ".config", "exorcist-98")))) return null;
|
|
31699
|
+
const rel = relative13(c, d);
|
|
31700
|
+
if (rel === "" || !rel.startsWith("..") && !isAbsolute16(rel)) return "it is inside the current project folder";
|
|
31701
|
+
for (let cur = d, i = 0; i < 64; i++) {
|
|
31702
|
+
if (existsSync9(join20(cur, ".git"))) return `it is inside a git repository (${cur})`;
|
|
31703
|
+
const up = dirname9(cur);
|
|
31704
|
+
if (up === cur) break;
|
|
31705
|
+
cur = up;
|
|
31706
|
+
}
|
|
31707
|
+
let st;
|
|
31708
|
+
try {
|
|
31709
|
+
st = lstatSync5(dir);
|
|
31710
|
+
} catch {
|
|
31711
|
+
return null;
|
|
31712
|
+
}
|
|
31713
|
+
if (st.isSymbolicLink()) return "it is a symbolic link";
|
|
31714
|
+
if (!st.isDirectory()) return "it is not a folder";
|
|
31715
|
+
const me = uid();
|
|
31716
|
+
if (!IS_WINDOWS && me !== void 0 && st.uid !== me) return "it is not owned by you";
|
|
31717
|
+
if (!IS_WINDOWS && (st.mode & 63) !== 0) return "other users or your group can open it (a private folder is mode 0700)";
|
|
31718
|
+
return null;
|
|
31719
|
+
}
|
|
31291
31720
|
function userConfigDir(env = process.env) {
|
|
31292
31721
|
const o = env["EXORCIST_USER_DIR"];
|
|
31293
31722
|
if (o && isAbsolute16(o)) return o;
|
|
@@ -31295,6 +31724,14 @@ function userConfigDir(env = process.env) {
|
|
|
31295
31724
|
const base = xdg && isAbsolute16(xdg) ? xdg : join20(homedir8(), ".config");
|
|
31296
31725
|
return join20(base, "exorcist-98");
|
|
31297
31726
|
}
|
|
31727
|
+
function userDirRefusal(env = process.env, cwd = process.cwd()) {
|
|
31728
|
+
const o = env["EXORCIST_USER_DIR"];
|
|
31729
|
+
const xdg = env["XDG_CONFIG_HOME"];
|
|
31730
|
+
const overridden = o && isAbsolute16(o) || xdg && isAbsolute16(xdg);
|
|
31731
|
+
if (!overridden) return null;
|
|
31732
|
+
const problem = userDirOverrideProblem(userConfigDir(env), cwd);
|
|
31733
|
+
return problem === null ? null : `the user-level folder ${userConfigDir(env)} (set by EXORCIST_USER_DIR or XDG_CONFIG_HOME) was refused: ${problem}`;
|
|
31734
|
+
}
|
|
31298
31735
|
var uid = () => typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
31299
31736
|
function ensurePrivateDir(dir) {
|
|
31300
31737
|
try {
|
|
@@ -31337,6 +31774,10 @@ function readKeyFile(path) {
|
|
|
31337
31774
|
}
|
|
31338
31775
|
var cache2 = /* @__PURE__ */ new Map();
|
|
31339
31776
|
function getUserKey(o = {}) {
|
|
31777
|
+
if (o.dir === void 0) {
|
|
31778
|
+
const refused = userDirRefusal();
|
|
31779
|
+
if (refused !== null) return { ok: false, error: refused };
|
|
31780
|
+
}
|
|
31340
31781
|
const dir = o.dir ?? userConfigDir();
|
|
31341
31782
|
const cached2 = cache2.get(dir);
|
|
31342
31783
|
if (cached2) return { ok: true, key: cached2 };
|
|
@@ -31449,7 +31890,13 @@ var PolicySchema = external_exports.object({
|
|
|
31449
31890
|
* opt-in that only the USER-LEVEL policy can set. A project policy, signed or not,
|
|
31450
31891
|
* that asks for it is ignored with a note.
|
|
31451
31892
|
*/
|
|
31452
|
-
sessionRelease: external_exports.enum(["os", "terminal", "notification-code"]).optional()
|
|
31893
|
+
sessionRelease: external_exports.enum(["os", "terminal", "notification-code"]).optional(),
|
|
31894
|
+
/**
|
|
31895
|
+
* The event log (m19-log, LG-2). `off` stops the Shield writing events after one final event that says so.
|
|
31896
|
+
* Only the USER-LEVEL policy can set it: a project policy that sets `events` is ignored with a note, and the
|
|
31897
|
+
* environment variable EXORCIST_EVENTS is ignored (an MCP config can set a server's environment).
|
|
31898
|
+
*/
|
|
31899
|
+
events: external_exports.enum(["on", "off"]).optional()
|
|
31453
31900
|
}).strict();
|
|
31454
31901
|
var policySigPath = (policyFile) => policyFile.replace(/\.json$/, "") + ".sig";
|
|
31455
31902
|
var POLICY_DOMAIN = "exorcist-98:policy:v1";
|
|
@@ -31519,6 +31966,11 @@ function parsePolicyText(path, text) {
|
|
|
31519
31966
|
return { ok: true, raw: json2 };
|
|
31520
31967
|
}
|
|
31521
31968
|
function loadUserPolicy(notes) {
|
|
31969
|
+
const refused = userDirRefusal();
|
|
31970
|
+
if (refused !== null) {
|
|
31971
|
+
notes.push(`${refused}, so no user-level policy was read and the defaults apply.`);
|
|
31972
|
+
return { ok: true, raw: {} };
|
|
31973
|
+
}
|
|
31522
31974
|
const file = join21(userConfigDir(), "policy.json");
|
|
31523
31975
|
let st;
|
|
31524
31976
|
try {
|
|
@@ -31539,7 +31991,7 @@ function loadPolicy(path) {
|
|
|
31539
31991
|
const user = loadUserPolicy(notes);
|
|
31540
31992
|
if (!user.ok) return user;
|
|
31541
31993
|
let merged = { ...user.raw };
|
|
31542
|
-
if (
|
|
31994
|
+
if (existsSync10(path)) {
|
|
31543
31995
|
let text;
|
|
31544
31996
|
try {
|
|
31545
31997
|
text = readFileSync15(path, "utf8");
|
|
@@ -31552,6 +32004,10 @@ function loadPolicy(path) {
|
|
|
31552
32004
|
delete project.raw["sessionRelease"];
|
|
31553
32005
|
notes.push(`Ignored "sessionRelease": "notification-code" in ${path}: only your user-level policy can turn on release by a code in a desktop notification, because the notification database can be read by any program of your user.`);
|
|
31554
32006
|
}
|
|
32007
|
+
if (project.raw["events"] !== void 0) {
|
|
32008
|
+
delete project.raw["events"];
|
|
32009
|
+
notes.push(`Ignored "events" in ${path}: only your user-level policy can turn the event log off, so a repository cannot switch it off.`);
|
|
32010
|
+
}
|
|
31555
32011
|
if (isSigned(path, text)) {
|
|
31556
32012
|
merged = { ...merged, ...project.raw };
|
|
31557
32013
|
} else {
|
|
@@ -31779,12 +32235,13 @@ var ApprovalStore = class {
|
|
|
31779
32235
|
// ../shield/src/anchor.ts
|
|
31780
32236
|
import { createHash as createHash9 } from "node:crypto";
|
|
31781
32237
|
import { closeSync as closeSync6, constants as constants4, lstatSync as lstatSync8, openSync as openSync6, readFileSync as readFileSync17, renameSync as renameSync4, unlinkSync as unlinkSync2, writeSync as writeSync3 } from "node:fs";
|
|
31782
|
-
import { join as join23, resolve as
|
|
32238
|
+
import { join as join23, resolve as resolve21 } from "node:path";
|
|
31783
32239
|
var ANCHOR_DOMAIN = "exorcist-98:anchor:v1";
|
|
31784
|
-
var folderId = (dir) => createHash9("sha256").update(
|
|
32240
|
+
var folderId = (dir) => createHash9("sha256").update(resolve21(dir)).digest("hex").slice(0, 32);
|
|
31785
32241
|
var anchorPath = (dir, userDir = userConfigDir()) => join23(userDir, "anchors", `${folderId(dir)}.json`);
|
|
31786
|
-
var anchorText = (id, seq2, hash) => `${id}\0${seq2}\0${hash}`;
|
|
31787
|
-
|
|
32242
|
+
var anchorText = (id, seq2, hash, off) => `${id}\0${seq2}\0${hash}${off === void 0 ? "" : `\0off:${off}`}`;
|
|
32243
|
+
var isTime = (t2) => typeof t2 === "string" && t2.length <= 40 && !Number.isNaN(Date.parse(t2));
|
|
32244
|
+
function writeAnchor(dir, head, o = {}) {
|
|
31788
32245
|
const key = getUserKey({ create: true });
|
|
31789
32246
|
if (!key.ok) return `the log anchor could not be written (${key.error})`;
|
|
31790
32247
|
const userDir = userConfigDir();
|
|
@@ -31792,7 +32249,9 @@ function writeAnchor(dir, head) {
|
|
|
31792
32249
|
const problem = ensurePrivateDir(anchors);
|
|
31793
32250
|
if (problem !== null) return `the log anchor could not be written (${problem})`;
|
|
31794
32251
|
const id = folderId(dir);
|
|
31795
|
-
const
|
|
32252
|
+
const before = readAnchor(dir);
|
|
32253
|
+
const off = o.eventsOffSince ?? (before.ok ? before.anchor?.eventsOffSince : void 0);
|
|
32254
|
+
const rec = { v: 1, dir: id, seq: head.seq, hash: head.hash, mac: signText(key.key, ANCHOR_DOMAIN, anchorText(id, head.seq, head.hash, off)), ...off !== void 0 ? { eventsOffSince: off } : {} };
|
|
31796
32255
|
const path = join23(anchors, `${id}.json`);
|
|
31797
32256
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
31798
32257
|
let fd = null;
|
|
@@ -31838,11 +32297,16 @@ function readAnchor(dir) {
|
|
|
31838
32297
|
return { ok: false, error: "the anchor is damaged" };
|
|
31839
32298
|
}
|
|
31840
32299
|
const id = folderId(dir);
|
|
31841
|
-
|
|
32300
|
+
const off = raw.eventsOffSince;
|
|
32301
|
+
if (raw.v !== 1 || raw.dir !== id || typeof raw.seq !== "number" || typeof raw.hash !== "string" || off !== void 0 && !isTime(off) || !verifyText(key.key, ANCHOR_DOMAIN, anchorText(id, raw.seq, raw.hash, off), raw.mac)) {
|
|
31842
32302
|
return { ok: false, error: "the anchor was changed or was not written by this machine" };
|
|
31843
32303
|
}
|
|
31844
32304
|
return { ok: true, anchor: raw };
|
|
31845
32305
|
}
|
|
32306
|
+
function readEventsOffSince(dir) {
|
|
32307
|
+
const a = readAnchor(dir);
|
|
32308
|
+
return a.ok && a.anchor?.eventsOffSince !== void 0 ? a.anchor.eventsOffSince : null;
|
|
32309
|
+
}
|
|
31846
32310
|
function checkAnchor(dir, head, hashAt) {
|
|
31847
32311
|
const a = readAnchor(dir);
|
|
31848
32312
|
if (!a.ok) return { status: "tampered", detail: `The log anchor kept outside the state folder cannot be trusted: ${a.error}.` };
|
|
@@ -31856,17 +32320,250 @@ function checkAnchor(dir, head, hashAt) {
|
|
|
31856
32320
|
return { status: "ok", seq: seq2 };
|
|
31857
32321
|
}
|
|
31858
32322
|
|
|
32323
|
+
// ../shield/src/fs-kind.ts
|
|
32324
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
32325
|
+
import { statfsSync } from "node:fs";
|
|
32326
|
+
var NETWORK_FS_MAGIC = /* @__PURE__ */ new Set([
|
|
32327
|
+
26985,
|
|
32328
|
+
// NFS
|
|
32329
|
+
20859,
|
|
32330
|
+
// SMB
|
|
32331
|
+
4283649346,
|
|
32332
|
+
// CIFS
|
|
32333
|
+
4266872130,
|
|
32334
|
+
// SMB2
|
|
32335
|
+
1702057286,
|
|
32336
|
+
// FUSE (sshfs and others)
|
|
32337
|
+
12805120,
|
|
32338
|
+
// Ceph
|
|
32339
|
+
16914839,
|
|
32340
|
+
// 9p
|
|
32341
|
+
1397113167,
|
|
32342
|
+
// AFS
|
|
32343
|
+
1937076805,
|
|
32344
|
+
// Coda
|
|
32345
|
+
22092,
|
|
32346
|
+
// NCP
|
|
32347
|
+
198183888
|
|
32348
|
+
// Lustre
|
|
32349
|
+
]);
|
|
32350
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
32351
|
+
function isUncPath(p) {
|
|
32352
|
+
if (/^\\\\\?\\UNC\\/i.test(p)) return true;
|
|
32353
|
+
if (/^\\\\[?.]\\/.test(p)) return false;
|
|
32354
|
+
return /^\\\\[^\\]/.test(p);
|
|
32355
|
+
}
|
|
32356
|
+
function driveLetter(p) {
|
|
32357
|
+
const m = /^(?:\\\\[?.]\\)?([A-Za-z]):(?:[\\/]|$)/.exec(p);
|
|
32358
|
+
return m ? m[1].toUpperCase() : null;
|
|
32359
|
+
}
|
|
32360
|
+
function classifyDf(r) {
|
|
32361
|
+
if (r === null) return null;
|
|
32362
|
+
if (/No such file system/i.test(`${r.stdout}
|
|
32363
|
+
${r.stderr}`)) return true;
|
|
32364
|
+
if (r.status !== 0) return null;
|
|
32365
|
+
const lines = r.stdout.split("\n").filter((l) => l.trim() !== "");
|
|
32366
|
+
if (lines.length >= 2) return false;
|
|
32367
|
+
if (lines.length === 1 && /^Filesystem\b/.test(lines[0])) return true;
|
|
32368
|
+
return null;
|
|
32369
|
+
}
|
|
32370
|
+
function runDf(dir) {
|
|
32371
|
+
try {
|
|
32372
|
+
const stdout = execFileSync3("/bin/df", ["-l", dir], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
32373
|
+
return { status: 0, stdout, stderr: "" };
|
|
32374
|
+
} catch (e) {
|
|
32375
|
+
const x = e;
|
|
32376
|
+
if (typeof x.status === "number") return { status: x.status, stdout: String(x.stdout ?? ""), stderr: String(x.stderr ?? "") };
|
|
32377
|
+
return null;
|
|
32378
|
+
}
|
|
32379
|
+
}
|
|
32380
|
+
function runPowershell(letter) {
|
|
32381
|
+
try {
|
|
32382
|
+
return execFileSync3("powershell", ["-NoProfile", "-Command", `(Get-PSDrive -Name ${letter}).DisplayRoot`], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
32383
|
+
} catch {
|
|
32384
|
+
return null;
|
|
32385
|
+
}
|
|
32386
|
+
}
|
|
32387
|
+
function linux(dir, d) {
|
|
32388
|
+
try {
|
|
32389
|
+
const t2 = (d.statfs ?? ((p) => statfsSync(p)))(dir).type;
|
|
32390
|
+
const n = Number(BigInt(t2) & 0xffffffffn);
|
|
32391
|
+
return NETWORK_FS_MAGIC.has(n);
|
|
32392
|
+
} catch {
|
|
32393
|
+
return null;
|
|
32394
|
+
}
|
|
32395
|
+
}
|
|
32396
|
+
function windows(dir, d) {
|
|
32397
|
+
if (isUncPath(dir)) return true;
|
|
32398
|
+
const letter = driveLetter(dir);
|
|
32399
|
+
if (letter === null) return null;
|
|
32400
|
+
const out = (d.powershell ?? runPowershell)(letter);
|
|
32401
|
+
return out === null ? null : out.trim() !== "";
|
|
32402
|
+
}
|
|
32403
|
+
function isNetworkFs(dir, deps = {}) {
|
|
32404
|
+
const platform = deps.platform ?? process.platform;
|
|
32405
|
+
const key = `${platform}\0${dir}`;
|
|
32406
|
+
if (cache3.has(key)) return cache3.get(key) ?? null;
|
|
32407
|
+
let r;
|
|
32408
|
+
if (platform === "linux") r = linux(dir, deps);
|
|
32409
|
+
else if (platform === "darwin") r = classifyDf((deps.df ?? runDf)(dir));
|
|
32410
|
+
else if (platform === "win32") r = windows(dir, deps);
|
|
32411
|
+
else r = null;
|
|
32412
|
+
cache3.set(key, r);
|
|
32413
|
+
return r;
|
|
32414
|
+
}
|
|
32415
|
+
|
|
32416
|
+
// ../shield/src/log-location.ts
|
|
32417
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
32418
|
+
import { closeSync as closeSync7, constants as constants5, existsSync as existsSync11, lstatSync as lstatSync9, mkdirSync as mkdirSync4, openSync as openSync7, realpathSync as realpathSync9, writeSync as writeSync4 } from "node:fs";
|
|
32419
|
+
import { tmpdir as tmpdir2, userInfo } from "node:os";
|
|
32420
|
+
import { basename as basename9, dirname as dirname10, join as join24, resolve as resolve22 } from "node:path";
|
|
32421
|
+
var hook = null;
|
|
32422
|
+
var processUid = () => typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
32423
|
+
function existingAncestor(p) {
|
|
32424
|
+
let cur = resolve22(p);
|
|
32425
|
+
for (let i = 0; i < 64 && !existsSync11(cur); i++) {
|
|
32426
|
+
const up = dirname10(cur);
|
|
32427
|
+
if (up === cur) break;
|
|
32428
|
+
cur = up;
|
|
32429
|
+
}
|
|
32430
|
+
return cur;
|
|
32431
|
+
}
|
|
32432
|
+
function realPathOf(p) {
|
|
32433
|
+
const abs = resolve22(p);
|
|
32434
|
+
const anc = existingAncestor(abs);
|
|
32435
|
+
let real = anc;
|
|
32436
|
+
try {
|
|
32437
|
+
real = realpathSync9(anc);
|
|
32438
|
+
} catch {
|
|
32439
|
+
}
|
|
32440
|
+
return anc === abs ? real : join24(real, abs.slice(anc.length));
|
|
32441
|
+
}
|
|
32442
|
+
function basesFor(platform, d) {
|
|
32443
|
+
if (d.base !== void 0) return [d.base];
|
|
32444
|
+
const env = d.env ?? process.env;
|
|
32445
|
+
if (platform === "win32") {
|
|
32446
|
+
const la = env["LOCALAPPDATA"];
|
|
32447
|
+
return la !== void 0 && la !== "" ? [la] : [];
|
|
32448
|
+
}
|
|
32449
|
+
if (platform === "darwin") return [tmpdir2()];
|
|
32450
|
+
const run3 = env["XDG_RUNTIME_DIR"];
|
|
32451
|
+
const shared = d.sharedBase ?? "/var/tmp";
|
|
32452
|
+
return run3 !== void 0 && run3.startsWith("/") ? [shared, run3] : [shared];
|
|
32453
|
+
}
|
|
32454
|
+
function userLabel(uid2) {
|
|
32455
|
+
if (uid2 !== void 0) return String(uid2);
|
|
32456
|
+
let name = "user";
|
|
32457
|
+
try {
|
|
32458
|
+
name = userInfo().username;
|
|
32459
|
+
} catch {
|
|
32460
|
+
}
|
|
32461
|
+
return name.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 32) || "user";
|
|
32462
|
+
}
|
|
32463
|
+
function problemWith(dir, uid2, windows2) {
|
|
32464
|
+
let st;
|
|
32465
|
+
try {
|
|
32466
|
+
st = lstatSync9(dir);
|
|
32467
|
+
} catch {
|
|
32468
|
+
return `${dir} could not be inspected`;
|
|
32469
|
+
}
|
|
32470
|
+
if (st.isSymbolicLink()) return `${dir} is a symbolic link`;
|
|
32471
|
+
if (!st.isDirectory()) return `${dir} is not a folder`;
|
|
32472
|
+
if (!windows2 && uid2 !== void 0 && st.uid !== uid2) return `${dir} is not owned by this user`;
|
|
32473
|
+
if (!windows2 && (st.mode & 18) !== 0) return `${dir} can be changed by other users`;
|
|
32474
|
+
return null;
|
|
32475
|
+
}
|
|
32476
|
+
function resolveLogLocation(stateDir2, o = {}) {
|
|
32477
|
+
const d = { ...hook ?? {}, ...o };
|
|
32478
|
+
const platform = d.platform ?? process.platform;
|
|
32479
|
+
const probe = d.isNetworkFs ?? ((p) => isNetworkFs(p));
|
|
32480
|
+
const kind = probe(existingAncestor(stateDir2));
|
|
32481
|
+
if (kind === false) return { ok: true, dir: stateDir2, moved: false };
|
|
32482
|
+
const bases = basesFor(platform, d);
|
|
32483
|
+
if (bases.length === 0) return { ok: false, error: "the state folder is on a network drive (or its kind is unknown) and there is no local folder for the event log (LOCALAPPDATA is not set)" };
|
|
32484
|
+
const windows2 = platform === "win32";
|
|
32485
|
+
const uid2 = d.uid ?? processUid();
|
|
32486
|
+
const leaf = `events-${createHash10("sha256").update(realPathOf(stateDir2)).digest("hex").slice(0, 16)}`;
|
|
32487
|
+
let dir = null;
|
|
32488
|
+
let refused = "";
|
|
32489
|
+
for (const base of bases) {
|
|
32490
|
+
const parent = join24(base, `exorcist-98-${userLabel(uid2)}`);
|
|
32491
|
+
const candidate = join24(parent, leaf);
|
|
32492
|
+
if (lstatSyncOrNull(candidate) !== null && checkChain([parent, candidate], uid2, windows2, false) === null) {
|
|
32493
|
+
dir = candidate;
|
|
32494
|
+
break;
|
|
32495
|
+
}
|
|
32496
|
+
}
|
|
32497
|
+
if (dir === null) for (const base of bases) {
|
|
32498
|
+
const parent = join24(base, `exorcist-98-${userLabel(uid2)}`);
|
|
32499
|
+
const candidate = join24(parent, leaf);
|
|
32500
|
+
const bad = checkChain([parent, candidate], uid2, windows2, o.create === true);
|
|
32501
|
+
if (bad === null) {
|
|
32502
|
+
dir = candidate;
|
|
32503
|
+
break;
|
|
32504
|
+
}
|
|
32505
|
+
refused = bad;
|
|
32506
|
+
}
|
|
32507
|
+
if (dir === null) return { ok: false, error: `the local event log folder was refused: ${refused}` };
|
|
32508
|
+
const reason = kind === null ? "the kind of file system of the state folder could not be told, so it is treated as a network drive" : "the state folder is on a network drive, where appending to a file and lock files are not reliable";
|
|
32509
|
+
return { ok: true, dir, moved: true, reason };
|
|
32510
|
+
}
|
|
32511
|
+
function checkChain(paths2, uid2, windows2, create) {
|
|
32512
|
+
for (const p of paths2) {
|
|
32513
|
+
if (lstatSyncOrNull(p) === null) {
|
|
32514
|
+
if (!create) return null;
|
|
32515
|
+
try {
|
|
32516
|
+
mkdirSync4(p, { recursive: true, mode: 448 });
|
|
32517
|
+
} catch (e) {
|
|
32518
|
+
if (e.code !== "EEXIST") return `${p} could not be created`;
|
|
32519
|
+
}
|
|
32520
|
+
}
|
|
32521
|
+
const bad = problemWith(p, uid2, windows2);
|
|
32522
|
+
if (bad !== null) return bad;
|
|
32523
|
+
}
|
|
32524
|
+
return null;
|
|
32525
|
+
}
|
|
32526
|
+
function lstatSyncOrNull(p) {
|
|
32527
|
+
try {
|
|
32528
|
+
return lstatSync9(p);
|
|
32529
|
+
} catch {
|
|
32530
|
+
return null;
|
|
32531
|
+
}
|
|
32532
|
+
}
|
|
32533
|
+
function locationNote(loc) {
|
|
32534
|
+
return `Events are written in ${loc.dir}, not in the state folder: ${loc.reason ?? "the state folder is not local"}.`;
|
|
32535
|
+
}
|
|
32536
|
+
function writeLocationPointer(stateDir2, logDir) {
|
|
32537
|
+
const path = join24(stateDir2, "events.location");
|
|
32538
|
+
let fd = null;
|
|
32539
|
+
try {
|
|
32540
|
+
fd = openSync7(path, constants5.O_WRONLY | constants5.O_CREAT | constants5.O_TRUNC | (constants5.O_NOFOLLOW ?? 0), 384);
|
|
32541
|
+
writeSync4(fd, `${logDir}
|
|
32542
|
+
`);
|
|
32543
|
+
return null;
|
|
32544
|
+
} catch (e) {
|
|
32545
|
+
return `${basename9(path)} could not be written (${e.code ?? "error"})`;
|
|
32546
|
+
} finally {
|
|
32547
|
+
if (fd !== null) {
|
|
32548
|
+
try {
|
|
32549
|
+
closeSync7(fd);
|
|
32550
|
+
} catch {
|
|
32551
|
+
}
|
|
32552
|
+
}
|
|
32553
|
+
}
|
|
32554
|
+
}
|
|
32555
|
+
|
|
31859
32556
|
// ../shield/src/os-auth-platform.ts
|
|
31860
32557
|
import { spawn } from "node:child_process";
|
|
31861
|
-
import { accessSync, constants as
|
|
31862
|
-
import { delimiter, join as
|
|
32558
|
+
import { accessSync, constants as constants6 } from "node:fs";
|
|
32559
|
+
import { delimiter, join as join26 } from "node:path";
|
|
31863
32560
|
|
|
31864
32561
|
// ../shield/src/session.ts
|
|
31865
32562
|
init_zod();
|
|
31866
|
-
import { createHash as
|
|
32563
|
+
import { createHash as createHash11, randomBytes as randomBytes5 } from "node:crypto";
|
|
31867
32564
|
import { spawnSync } from "node:child_process";
|
|
31868
|
-
import { lstatSync as
|
|
31869
|
-
import { join as
|
|
32565
|
+
import { lstatSync as lstatSync10, mkdirSync as mkdirSync5, readFileSync as readFileSync18, readdirSync as readdirSync8, renameSync as renameSync5, rmSync as rmSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
32566
|
+
import { join as join25 } from "node:path";
|
|
31870
32567
|
var SESSION_RULE_ID = "EX-027";
|
|
31871
32568
|
var SESSION_TTL_MS = 2 * 60 * 60 * 1e3;
|
|
31872
32569
|
var MAX_FACTS = 32;
|
|
@@ -32049,14 +32746,14 @@ var TMP_RE = /\.tmp$/;
|
|
|
32049
32746
|
function code(err) {
|
|
32050
32747
|
return err && typeof err === "object" && "code" in err ? String(err.code) : "error";
|
|
32051
32748
|
}
|
|
32052
|
-
var sessionsPath = (stateDir2) =>
|
|
32749
|
+
var sessionsPath = (stateDir2) => join25(stateDir2, "sessions");
|
|
32053
32750
|
var FileSessionStore = class {
|
|
32054
32751
|
constructor(stateDir2, key, ttlMs = SESSION_TTL_MS) {
|
|
32055
32752
|
this.key = key;
|
|
32056
32753
|
this.ttlMs = ttlMs;
|
|
32057
32754
|
if (!isSessionKey(key)) throw new Error(`Invalid session key "${key}".`);
|
|
32058
32755
|
this.root = sessionsPath(stateDir2);
|
|
32059
|
-
this.dir =
|
|
32756
|
+
this.dir = join25(this.root, key);
|
|
32060
32757
|
}
|
|
32061
32758
|
dir;
|
|
32062
32759
|
root;
|
|
@@ -32078,10 +32775,10 @@ var FileSessionStore = class {
|
|
|
32078
32775
|
problems.push(`${name} in ${this.dir} is not a session record`);
|
|
32079
32776
|
continue;
|
|
32080
32777
|
}
|
|
32081
|
-
const path =
|
|
32778
|
+
const path = join25(this.dir, name);
|
|
32082
32779
|
let st;
|
|
32083
32780
|
try {
|
|
32084
|
-
st =
|
|
32781
|
+
st = lstatSync10(path);
|
|
32085
32782
|
} catch (err) {
|
|
32086
32783
|
if (code(err) !== "ENOENT") problems.push(`${name} could not be read (${code(err)})`);
|
|
32087
32784
|
continue;
|
|
@@ -32112,10 +32809,10 @@ var FileSessionStore = class {
|
|
|
32112
32809
|
return { records, problems };
|
|
32113
32810
|
}
|
|
32114
32811
|
write(record3) {
|
|
32115
|
-
const path =
|
|
32812
|
+
const path = join25(this.dir, `${record3.writer}.json`);
|
|
32116
32813
|
const tmp = `${path}.${process.pid}.${randomBytes5(4).toString("hex")}.tmp`;
|
|
32117
32814
|
try {
|
|
32118
|
-
|
|
32815
|
+
mkdirSync5(this.dir, { recursive: true, mode: 448 });
|
|
32119
32816
|
writeFileSync4(tmp, `${JSON.stringify(record3)}
|
|
32120
32817
|
`, { encoding: "utf8", mode: 384 });
|
|
32121
32818
|
renameSync5(tmp, path);
|
|
@@ -32138,8 +32835,8 @@ var FileSessionStore = class {
|
|
|
32138
32835
|
try {
|
|
32139
32836
|
for (const name of readdirSync8(this.dir)) {
|
|
32140
32837
|
if (name === `${own}.json`) continue;
|
|
32141
|
-
const p =
|
|
32142
|
-
const st =
|
|
32838
|
+
const p = join25(this.dir, name);
|
|
32839
|
+
const st = lstatSync10(p);
|
|
32143
32840
|
if (st.isFile() && old(st, TMP_RE.test(name) ? 6e4 : this.ttlMs)) unlinkSync3(p);
|
|
32144
32841
|
}
|
|
32145
32842
|
} catch {
|
|
@@ -32147,13 +32844,13 @@ var FileSessionStore = class {
|
|
|
32147
32844
|
try {
|
|
32148
32845
|
for (const name of readdirSync8(this.root).slice(0, MAX_SESSION_DIRS)) {
|
|
32149
32846
|
if (name === this.key || !KEY_RE.test(name)) continue;
|
|
32150
|
-
const p =
|
|
32151
|
-
const st =
|
|
32847
|
+
const p = join25(this.root, name);
|
|
32848
|
+
const st = lstatSync10(p);
|
|
32152
32849
|
if (!st.isDirectory()) continue;
|
|
32153
|
-
const
|
|
32154
|
-
const newest =
|
|
32850
|
+
const entries2 = readdirSync8(p);
|
|
32851
|
+
const newest = entries2.reduce((m, e) => {
|
|
32155
32852
|
try {
|
|
32156
|
-
return Math.max(m,
|
|
32853
|
+
return Math.max(m, lstatSync10(join25(p, e)).mtimeMs);
|
|
32157
32854
|
} catch {
|
|
32158
32855
|
return m;
|
|
32159
32856
|
}
|
|
@@ -32217,7 +32914,7 @@ function resolveSessionKey(o = {}) {
|
|
|
32217
32914
|
for (let hop = 0; hop < 8 && pid > 1; hop++) {
|
|
32218
32915
|
const info = lookup(pid);
|
|
32219
32916
|
if (!info) break;
|
|
32220
|
-
if (!isLauncher(info.command)) return `p${pid}-${
|
|
32917
|
+
if (!isLauncher(info.command)) return `p${pid}-${createHash11("sha256").update(info.started).digest("hex").slice(0, 8)}`;
|
|
32221
32918
|
if (info.ppid === pid) break;
|
|
32222
32919
|
pid = info.ppid;
|
|
32223
32920
|
}
|
|
@@ -32295,7 +32992,7 @@ function macOsAuth(o = {}) {
|
|
|
32295
32992
|
} catch {
|
|
32296
32993
|
return { kind: "fail" };
|
|
32297
32994
|
}
|
|
32298
|
-
return new Promise((
|
|
32995
|
+
return new Promise((resolve42) => {
|
|
32299
32996
|
let settled = false;
|
|
32300
32997
|
let timer;
|
|
32301
32998
|
let child;
|
|
@@ -32303,7 +33000,7 @@ function macOsAuth(o = {}) {
|
|
|
32303
33000
|
if (settled) return;
|
|
32304
33001
|
settled = true;
|
|
32305
33002
|
if (timer !== void 0) clearTimeout(timer);
|
|
32306
|
-
|
|
33003
|
+
resolve42(r);
|
|
32307
33004
|
};
|
|
32308
33005
|
try {
|
|
32309
33006
|
const base = o.env ?? process.env;
|
|
@@ -32432,7 +33129,7 @@ function commandOnPath(name, env = process.env) {
|
|
|
32432
33129
|
for (const dir of (env["PATH"] ?? env["Path"] ?? "").split(delimiter)) {
|
|
32433
33130
|
if (!dir) continue;
|
|
32434
33131
|
try {
|
|
32435
|
-
accessSync(
|
|
33132
|
+
accessSync(join26(dir, name), constants6.X_OK);
|
|
32436
33133
|
return true;
|
|
32437
33134
|
} catch {
|
|
32438
33135
|
}
|
|
@@ -32441,14 +33138,14 @@ function commandOnPath(name, env = process.env) {
|
|
|
32441
33138
|
}
|
|
32442
33139
|
var TIMEOUT_MS = 6e4;
|
|
32443
33140
|
function run(spawnFn, cmd, env, timeoutMs) {
|
|
32444
|
-
return new Promise((
|
|
33141
|
+
return new Promise((resolve42) => {
|
|
32445
33142
|
let done = false;
|
|
32446
33143
|
let timer;
|
|
32447
33144
|
const finish = (r) => {
|
|
32448
33145
|
if (done) return;
|
|
32449
33146
|
done = true;
|
|
32450
33147
|
if (timer !== void 0) clearTimeout(timer);
|
|
32451
|
-
|
|
33148
|
+
resolve42(r);
|
|
32452
33149
|
};
|
|
32453
33150
|
try {
|
|
32454
33151
|
const proc = spawnFn(cmd.file, cmd.args, { env, stdio: ["ignore", "pipe", "ignore"] });
|
|
@@ -32530,8 +33227,8 @@ function defaultOsAuth(o = {}) {
|
|
|
32530
33227
|
|
|
32531
33228
|
// ../shield/src/state.ts
|
|
32532
33229
|
init_zod();
|
|
32533
|
-
import { appendFileSync, existsSync as
|
|
32534
|
-
import { dirname as
|
|
33230
|
+
import { appendFileSync, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync19, renameSync as renameSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
33231
|
+
import { dirname as dirname11, join as join27 } from "node:path";
|
|
32535
33232
|
var Sha256 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
32536
33233
|
var PinSchema = external_exports.object({
|
|
32537
33234
|
hash: Sha256,
|
|
@@ -32580,16 +33277,16 @@ var StateSchema = external_exports.object({
|
|
|
32580
33277
|
servers: external_exports.record(ServerStateSchema).default({})
|
|
32581
33278
|
});
|
|
32582
33279
|
var emptyState = () => ({ version: 1, servers: {} });
|
|
32583
|
-
var statePath = (dir) =>
|
|
32584
|
-
var policyPath = (dir) =>
|
|
32585
|
-
var alertsPath = (dir) =>
|
|
32586
|
-
var vaultPath = (dir) =>
|
|
33280
|
+
var statePath = (dir) => join27(dir, "pins.json");
|
|
33281
|
+
var policyPath = (dir) => join27(dir, "policy.json");
|
|
33282
|
+
var alertsPath = (dir) => join27(dir, "alerts.jsonl");
|
|
33283
|
+
var vaultPath = (dir) => join27(dir, "vault");
|
|
32587
33284
|
var PINS_DOMAIN = "exorcist-98:pins:v1";
|
|
32588
33285
|
function pinsText(raw) {
|
|
32589
33286
|
return canonicalJson({ version: raw.version, servers: raw.servers });
|
|
32590
33287
|
}
|
|
32591
33288
|
function loadState(path) {
|
|
32592
|
-
if (!
|
|
33289
|
+
if (!existsSync12(path)) return { ok: true, state: emptyState() };
|
|
32593
33290
|
let json2;
|
|
32594
33291
|
try {
|
|
32595
33292
|
json2 = JSON.parse(readFileSync19(path, "utf8"));
|
|
@@ -32609,7 +33306,7 @@ function loadState(path) {
|
|
|
32609
33306
|
return { ok: true, state: parsed.data };
|
|
32610
33307
|
}
|
|
32611
33308
|
function saveState(path, state) {
|
|
32612
|
-
|
|
33309
|
+
mkdirSync6(dirname11(path), { recursive: true });
|
|
32613
33310
|
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
32614
33311
|
const body = JSON.parse(JSON.stringify({ version: state.version, servers: state.servers }));
|
|
32615
33312
|
const key = getUserKey({ create: true });
|
|
@@ -32627,7 +33324,7 @@ function serverState(state, name) {
|
|
|
32627
33324
|
return s;
|
|
32628
33325
|
}
|
|
32629
33326
|
function appendAlert(path, alert) {
|
|
32630
|
-
|
|
33327
|
+
mkdirSync6(dirname11(path), { recursive: true });
|
|
32631
33328
|
appendFileSync(path, `${JSON.stringify(alert)}
|
|
32632
33329
|
`, "utf8");
|
|
32633
33330
|
}
|
|
@@ -33274,8 +33971,8 @@ function throttle(o = {}) {
|
|
|
33274
33971
|
}
|
|
33275
33972
|
|
|
33276
33973
|
// ../shield/src/canary.ts
|
|
33277
|
-
import { existsSync as
|
|
33278
|
-
import { dirname as
|
|
33974
|
+
import { existsSync as existsSync13, lstatSync as lstatSync11, mkdirSync as mkdirSync7, readFileSync as readFileSync20, readdirSync as readdirSync9, realpathSync as realpathSync10, rmdirSync, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
33975
|
+
import { dirname as dirname12, isAbsolute as isAbsolute17, join as join28, resolve as resolve23 } from "node:path";
|
|
33279
33976
|
var TRAPS = [
|
|
33280
33977
|
{
|
|
33281
33978
|
name: ".env.canary",
|
|
@@ -33318,36 +34015,36 @@ function plantCanaries(root, o = {}) {
|
|
|
33318
34015
|
return { ok: false, error: `Canary traps are already planted in ${root}. To replace them, run "exorcist canary --remove" first.` };
|
|
33319
34016
|
}
|
|
33320
34017
|
for (const d of [".exorcist", CANARY_TRAP_DIR]) {
|
|
33321
|
-
const path =
|
|
33322
|
-
if (
|
|
34018
|
+
const path = join28(root, d);
|
|
34019
|
+
if (existsSync13(path) || isSymlink(path)) {
|
|
33323
34020
|
if (!isRealDir(path)) return { ok: false, error: `${path} is not a real folder (a symlink or a file); no traps were planted.` };
|
|
33324
34021
|
}
|
|
33325
34022
|
}
|
|
33326
34023
|
const traps = TRAPS.slice(0, count);
|
|
33327
34024
|
for (const t2 of traps) {
|
|
33328
|
-
const path =
|
|
33329
|
-
if (
|
|
34025
|
+
const path = join28(root, CANARY_TRAP_DIR, t2.name);
|
|
34026
|
+
if (existsSync13(path)) return { ok: false, error: `${path} already exists; it was not overwritten.` };
|
|
33330
34027
|
}
|
|
33331
34028
|
const created = (o.now ? o.now() : /* @__PURE__ */ new Date()).toISOString();
|
|
33332
34029
|
const records = [];
|
|
33333
|
-
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !
|
|
34030
|
+
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !existsSync13(join28(root, d)));
|
|
33334
34031
|
try {
|
|
33335
|
-
|
|
34032
|
+
mkdirSync7(join28(root, CANARY_TRAP_DIR), { recursive: true });
|
|
33336
34033
|
for (const t2 of traps) {
|
|
33337
34034
|
const token = newToken();
|
|
33338
34035
|
const file = `${CANARY_TRAP_DIR}/${t2.name}`;
|
|
33339
|
-
writeFileSync6(
|
|
34036
|
+
writeFileSync6(join28(root, file), t2.body(token), { flag: "wx" });
|
|
33340
34037
|
records.push({ token, file, created });
|
|
33341
34038
|
}
|
|
33342
34039
|
writeFileSync6(recordsFile, `${JSON.stringify({ version: 1, canaries: records, ...madeDirs.length > 0 ? { madeDirs } : {} }, null, 2)}
|
|
33343
34040
|
`);
|
|
33344
34041
|
} catch (err) {
|
|
33345
|
-
for (const r of records) rmSync3(
|
|
33346
|
-
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(
|
|
34042
|
+
for (const r of records) rmSync3(join28(root, r.file), { force: true });
|
|
34043
|
+
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(join28(root, d));
|
|
33347
34044
|
return { ok: false, error: `Could not plant the canary traps: ${firstLine(err)}` };
|
|
33348
34045
|
}
|
|
33349
34046
|
const result = { ok: true, records, recordsFile };
|
|
33350
|
-
if (o.stateDir &&
|
|
34047
|
+
if (o.stateDir && resolve23(o.stateDir) !== resolve23(root, ".exorcist")) {
|
|
33351
34048
|
const told = setPolicyCanaries(o.stateDir, recordsFile);
|
|
33352
34049
|
if (!told.ok) return { ok: false, error: `Planted the traps, but could not tell the Shield where they are: ${told.error}` };
|
|
33353
34050
|
result.policyUpdated = policyPath(o.stateDir);
|
|
@@ -33360,20 +34057,20 @@ function loadCanaries(root) {
|
|
|
33360
34057
|
}
|
|
33361
34058
|
function rmdirIfEmpty(path) {
|
|
33362
34059
|
try {
|
|
33363
|
-
if (
|
|
34060
|
+
if (lstatSync11(path).isDirectory() && readdirSync9(path).length === 0) rmdirSync(path);
|
|
33364
34061
|
} catch {
|
|
33365
34062
|
}
|
|
33366
34063
|
}
|
|
33367
34064
|
function isSymlink(path) {
|
|
33368
34065
|
try {
|
|
33369
|
-
return
|
|
34066
|
+
return lstatSync11(path).isSymbolicLink();
|
|
33370
34067
|
} catch {
|
|
33371
34068
|
return false;
|
|
33372
34069
|
}
|
|
33373
34070
|
}
|
|
33374
34071
|
function isRealDir(path) {
|
|
33375
34072
|
try {
|
|
33376
|
-
return
|
|
34073
|
+
return lstatSync11(path).isDirectory();
|
|
33377
34074
|
} catch {
|
|
33378
34075
|
return false;
|
|
33379
34076
|
}
|
|
@@ -33385,18 +34082,18 @@ function removeCanaries(root, o = {}) {
|
|
|
33385
34082
|
if (!existing.ok) return existing;
|
|
33386
34083
|
const removed = [];
|
|
33387
34084
|
const warnings = [];
|
|
33388
|
-
const stateFolder =
|
|
33389
|
-
const trapFolder =
|
|
34085
|
+
const stateFolder = join28(root, ".exorcist");
|
|
34086
|
+
const trapFolder = join28(root, CANARY_TRAP_DIR);
|
|
33390
34087
|
const foldersReal = isRealDir(stateFolder) && isRealDir(trapFolder);
|
|
33391
34088
|
let trapReal = null;
|
|
33392
34089
|
try {
|
|
33393
|
-
trapReal = foldersReal ?
|
|
34090
|
+
trapReal = foldersReal ? realpathSync10(trapFolder) : null;
|
|
33394
34091
|
} catch {
|
|
33395
34092
|
trapReal = null;
|
|
33396
34093
|
}
|
|
33397
34094
|
let left = 0;
|
|
33398
34095
|
for (const r of existing.canaries) {
|
|
33399
|
-
const full =
|
|
34096
|
+
const full = join28(root, r.file);
|
|
33400
34097
|
const name = r.file.slice(`${CANARY_TRAP_DIR}/`.length);
|
|
33401
34098
|
const leave = (why) => {
|
|
33402
34099
|
left++;
|
|
@@ -33404,7 +34101,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33404
34101
|
};
|
|
33405
34102
|
let st;
|
|
33406
34103
|
try {
|
|
33407
|
-
st =
|
|
34104
|
+
st = lstatSync11(full);
|
|
33408
34105
|
} catch {
|
|
33409
34106
|
continue;
|
|
33410
34107
|
}
|
|
@@ -33421,7 +34118,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33421
34118
|
continue;
|
|
33422
34119
|
}
|
|
33423
34120
|
try {
|
|
33424
|
-
if (
|
|
34121
|
+
if (realpathSync10(dirname12(full)) !== trapReal) {
|
|
33425
34122
|
leave("it is not inside the trap folder.");
|
|
33426
34123
|
continue;
|
|
33427
34124
|
}
|
|
@@ -33440,7 +34137,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33440
34137
|
return { ok: true, removed, warnings };
|
|
33441
34138
|
}
|
|
33442
34139
|
try {
|
|
33443
|
-
const st =
|
|
34140
|
+
const st = lstatSync11(recordsFile);
|
|
33444
34141
|
if (isRealDir(stateFolder) && st.isFile()) {
|
|
33445
34142
|
rmSync3(recordsFile);
|
|
33446
34143
|
removed.push(CANARY_RECORDS_FILE);
|
|
@@ -33452,12 +34149,12 @@ function removeCanaries(root, o = {}) {
|
|
|
33452
34149
|
}
|
|
33453
34150
|
if (existing.madeDirs.includes(CANARY_TRAP_DIR)) rmdirIfEmpty(trapFolder);
|
|
33454
34151
|
if (existing.madeDirs.includes(".exorcist")) rmdirIfEmpty(stateFolder);
|
|
33455
|
-
if (o.stateDir &&
|
|
34152
|
+
if (o.stateDir && resolve23(o.stateDir) !== resolve23(root, ".exorcist")) clearPolicyCanaries(o.stateDir, recordsFile);
|
|
33456
34153
|
return { ok: true, removed, warnings };
|
|
33457
34154
|
}
|
|
33458
34155
|
function readPolicyObject(stateDir2) {
|
|
33459
34156
|
const path = policyPath(stateDir2);
|
|
33460
|
-
if (!
|
|
34157
|
+
if (!existsSync13(path)) return { ok: true, obj: {} };
|
|
33461
34158
|
try {
|
|
33462
34159
|
const json2 = JSON.parse(readFileSync20(path, "utf8"));
|
|
33463
34160
|
if (!json2 || typeof json2 !== "object" || Array.isArray(json2)) return { ok: false, error: `${path} is not a JSON object.` };
|
|
@@ -33470,10 +34167,10 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33470
34167
|
const p = readPolicyObject(stateDir2);
|
|
33471
34168
|
if (!p.ok) return p;
|
|
33472
34169
|
try {
|
|
33473
|
-
|
|
34170
|
+
mkdirSync7(stateDir2, { recursive: true });
|
|
33474
34171
|
const file = policyPath(stateDir2);
|
|
33475
|
-
const sign = !
|
|
33476
|
-
writeFileSync6(file, `${JSON.stringify({ ...p.obj, canaries:
|
|
34172
|
+
const sign = !existsSync13(file) || policyIsSigned(file);
|
|
34173
|
+
writeFileSync6(file, `${JSON.stringify({ ...p.obj, canaries: resolve23(recordsFile) }, null, 2)}
|
|
33477
34174
|
`);
|
|
33478
34175
|
if (sign) signPolicyFile(file);
|
|
33479
34176
|
return { ok: true };
|
|
@@ -33483,7 +34180,7 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33483
34180
|
}
|
|
33484
34181
|
function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
33485
34182
|
const p = readPolicyObject(stateDir2);
|
|
33486
|
-
if (!p.ok || p.obj["canaries"] !==
|
|
34183
|
+
if (!p.ok || p.obj["canaries"] !== resolve23(recordsFile)) return;
|
|
33487
34184
|
const { canaries: _gone, ...rest } = p.obj;
|
|
33488
34185
|
try {
|
|
33489
34186
|
const file = policyPath(stateDir2);
|
|
@@ -33500,8 +34197,8 @@ function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33500
34197
|
}
|
|
33501
34198
|
}
|
|
33502
34199
|
function canariesFileFor(stateDir2, policyCanaries) {
|
|
33503
|
-
if (!policyCanaries) return
|
|
33504
|
-
return isAbsolute17(policyCanaries) ? policyCanaries :
|
|
34200
|
+
if (!policyCanaries) return join28(stateDir2, "canaries.json");
|
|
34201
|
+
return isAbsolute17(policyCanaries) ? policyCanaries : resolve23(stateDir2, policyCanaries);
|
|
33505
34202
|
}
|
|
33506
34203
|
function allStrings(value) {
|
|
33507
34204
|
const out = [];
|
|
@@ -33515,9 +34212,9 @@ function allStrings(value) {
|
|
|
33515
34212
|
seen.add(v);
|
|
33516
34213
|
if (Array.isArray(v)) for (let i = v.length - 1; i >= 0; i--) stack.push(v[i]);
|
|
33517
34214
|
else {
|
|
33518
|
-
const
|
|
33519
|
-
for (let i =
|
|
33520
|
-
const [k, x] =
|
|
34215
|
+
const entries2 = Object.entries(v);
|
|
34216
|
+
for (let i = entries2.length - 1; i >= 0; i--) {
|
|
34217
|
+
const [k, x] = entries2[i];
|
|
33521
34218
|
stack.push(x, k);
|
|
33522
34219
|
}
|
|
33523
34220
|
}
|
|
@@ -34029,7 +34726,7 @@ var ShieldEngine = class {
|
|
|
34029
34726
|
this.heldCalls.set(promptId, { call, id, tool, hosts, kind: "host", askedAt: this.now(), digest: this.digestOf(call, tool) });
|
|
34030
34727
|
this.callEvent(tool, "held", { ruleId: "EX-016", why: `It would send data to ${hosts.map((h) => cleanText(h, 80)).join(", ")}, which is not on the allowed list. Waiting for your answer in the agent's approval prompt.`, prompt: this.elicitSeq });
|
|
34031
34728
|
const shownTool = cleanText(tool, 80);
|
|
34032
|
-
const
|
|
34729
|
+
const list3 = hosts.map((h) => cleanText(h, 80)).join(", ");
|
|
34033
34730
|
return [{
|
|
34034
34731
|
type: "forward",
|
|
34035
34732
|
to: "client",
|
|
@@ -34038,11 +34735,11 @@ var ShieldEngine = class {
|
|
|
34038
34735
|
id: promptId,
|
|
34039
34736
|
method: "elicitation/create",
|
|
34040
34737
|
params: {
|
|
34041
|
-
message: `Exorcist 98: the tool "${shownTool}" on "${cleanText(this.o.server, 80)}" wants to send data to ${
|
|
34738
|
+
message: `Exorcist 98: the tool "${shownTool}" on "${cleanText(this.o.server, 80)}" wants to send data to ${list3}, which is not on your allowed list. Allow this call?`,
|
|
34042
34739
|
requestedSchema: {
|
|
34043
34740
|
type: "object",
|
|
34044
34741
|
properties: {
|
|
34045
|
-
remember: { type: "boolean", title: `Always allow ${
|
|
34742
|
+
remember: { type: "boolean", title: `Always allow ${list3} for ${cleanText(this.o.server, 80)}`, default: false }
|
|
34046
34743
|
}
|
|
34047
34744
|
}
|
|
34048
34745
|
}
|
|
@@ -34325,8 +35022,8 @@ var ShieldEngine = class {
|
|
|
34325
35022
|
const promptId = `${PROMPT_PREFIX}${++this.elicitSeq}`;
|
|
34326
35023
|
this.heldCalls.set(promptId, { call, id, tool, hosts, kind: "session", askedAt: this.now(), digest: this.digestOf(call, tool) });
|
|
34327
35024
|
this.callEvent(tool, "held", { ruleId: SESSION_RULE_ID, why: `Lethal trifecta in this session: ${out}. Waiting for your answer in the agent's approval prompt.`, prompt: this.elicitSeq });
|
|
34328
|
-
const
|
|
34329
|
-
const also = hosts.length > 0 ? ` It would also reach ${
|
|
35025
|
+
const list3 = hosts.map((h) => cleanText(h, 80)).join(", ");
|
|
35026
|
+
const also = hosts.length > 0 ? ` It would also reach ${list3}, which is not on your allowed list.` : "";
|
|
34330
35027
|
return [{
|
|
34331
35028
|
type: "forward",
|
|
34332
35029
|
to: "client",
|
|
@@ -34770,12 +35467,12 @@ var ShieldEngine = class {
|
|
|
34770
35467
|
|
|
34771
35468
|
// ../shield/src/proxy.ts
|
|
34772
35469
|
import { spawn as spawn3 } from "node:child_process";
|
|
34773
|
-
import { existsSync as
|
|
34774
|
-
import { dirname as
|
|
35470
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync10, readFileSync as readFileSync26, statSync as statSync15 } from "node:fs";
|
|
35471
|
+
import { dirname as dirname16 } from "node:path";
|
|
34775
35472
|
|
|
34776
35473
|
// ../shield/src/lockfile.ts
|
|
34777
|
-
import { existsSync as
|
|
34778
|
-
import { dirname as
|
|
35474
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
35475
|
+
import { dirname as dirname13, join as join29, parse as parsePath, resolve as resolve24 } from "node:path";
|
|
34779
35476
|
init_zod();
|
|
34780
35477
|
var Sha2562 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
34781
35478
|
var LockToolSchema = external_exports.object({
|
|
@@ -34811,7 +35508,7 @@ function lockUrl(url) {
|
|
|
34811
35508
|
return "(not a valid URL)";
|
|
34812
35509
|
}
|
|
34813
35510
|
}
|
|
34814
|
-
var record = (
|
|
35511
|
+
var record = (entries2) => Object.fromEntries(entries2);
|
|
34815
35512
|
function lockServer(l) {
|
|
34816
35513
|
const byName = /* @__PURE__ */ new Map();
|
|
34817
35514
|
for (const t2 of l.tools) {
|
|
@@ -34948,21 +35645,21 @@ function seedFromLock(s, ls, report, o) {
|
|
|
34948
35645
|
var PROJECT_MARKERS2 = [".git", ".kiro", ".exorcist"];
|
|
34949
35646
|
function findLockFile(starts) {
|
|
34950
35647
|
for (const start of starts) {
|
|
34951
|
-
const { root } = parsePath(
|
|
34952
|
-
for (let dir =
|
|
34953
|
-
const candidate =
|
|
34954
|
-
if (
|
|
34955
|
-
if (PROJECT_MARKERS2.some((m) =>
|
|
34956
|
-
if (dir === root ||
|
|
35648
|
+
const { root } = parsePath(resolve24(start));
|
|
35649
|
+
for (let dir = resolve24(start); ; dir = dirname13(dir)) {
|
|
35650
|
+
const candidate = join29(dir, LOCK_FILE);
|
|
35651
|
+
if (existsSync14(candidate)) return candidate;
|
|
35652
|
+
if (PROJECT_MARKERS2.some((m) => existsSync14(join29(dir, m)))) break;
|
|
35653
|
+
if (dir === root || dirname13(dir) === dir) break;
|
|
34957
35654
|
}
|
|
34958
35655
|
}
|
|
34959
35656
|
return null;
|
|
34960
35657
|
}
|
|
34961
35658
|
|
|
34962
35659
|
// ../shield/src/vault.ts
|
|
34963
|
-
import { createHash as
|
|
34964
|
-
import { closeSync as
|
|
34965
|
-
import { basename as
|
|
35660
|
+
import { createHash as createHash12, randomBytes as randomBytes7 } from "node:crypto";
|
|
35661
|
+
import { closeSync as closeSync8, constants as constants7, copyFileSync, existsSync as existsSync15, fstatSync as fstatSync3, lstatSync as lstatSync12, mkdirSync as mkdirSync8, openSync as openSync8, readFileSync as readFileSync21, readdirSync as readdirSync10, realpathSync as realpathSync11, rmSync as rmSync4, statSync as statSync13, writeFileSync as writeFileSync7, writeSync as writeSync5 } from "node:fs";
|
|
35662
|
+
import { basename as basename10, dirname as dirname14, isAbsolute as isAbsolute18, join as join30, resolve as resolve25, sep as sep6 } from "node:path";
|
|
34966
35663
|
init_zod();
|
|
34967
35664
|
var SafeRel = external_exports.string().min(1).max(1024).refine(
|
|
34968
35665
|
(p) => !isAbsolute18(p) && !p.includes("\\") && !p.includes("\0") && p.split("/").every((seg) => seg !== "" && seg !== "." && seg !== ".."),
|
|
@@ -34993,7 +35690,7 @@ var EntrySchema = external_exports.object({
|
|
|
34993
35690
|
/** HMAC with the user key over every other field (MS-5). Missing or wrong: the entry is not trusted. */
|
|
34994
35691
|
mac: external_exports.string().optional()
|
|
34995
35692
|
});
|
|
34996
|
-
var sha2562 = (data) =>
|
|
35693
|
+
var sha2562 = (data) => createHash12("sha256").update(data).digest("hex");
|
|
34997
35694
|
var fail3 = (error2) => ({ ok: false, error: error2 });
|
|
34998
35695
|
var VAULT_DOMAIN = "exorcist-98:vault:v1";
|
|
34999
35696
|
var entryText = (e) => {
|
|
@@ -35002,13 +35699,13 @@ var entryText = (e) => {
|
|
|
35002
35699
|
};
|
|
35003
35700
|
function ensureSafeVault(vaultDir) {
|
|
35004
35701
|
const me = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
35005
|
-
const state =
|
|
35702
|
+
const state = dirname14(vaultDir);
|
|
35006
35703
|
try {
|
|
35007
|
-
|
|
35704
|
+
mkdirSync8(dirname14(state), { recursive: true });
|
|
35008
35705
|
for (const d of [state, vaultDir]) {
|
|
35009
|
-
const st =
|
|
35706
|
+
const st = lstatSync12(d, { throwIfNoEntry: false });
|
|
35010
35707
|
if (st === void 0) {
|
|
35011
|
-
|
|
35708
|
+
mkdirSync8(d, { mode: 448 });
|
|
35012
35709
|
continue;
|
|
35013
35710
|
}
|
|
35014
35711
|
if (st.isSymbolicLink()) return `${d} is a symbolic link, so nothing was written there. Remove the link and try again.`;
|
|
@@ -35021,33 +35718,33 @@ function ensureSafeVault(vaultDir) {
|
|
|
35021
35718
|
}
|
|
35022
35719
|
}
|
|
35023
35720
|
function writeFileSafe(path, text) {
|
|
35024
|
-
const fd =
|
|
35721
|
+
const fd = openSync8(path, constants7.O_WRONLY | constants7.O_CREAT | constants7.O_TRUNC | (constants7.O_NOFOLLOW ?? 0), 384);
|
|
35025
35722
|
try {
|
|
35026
35723
|
if (!fstatSync3(fd).isFile()) throw new Error("not a regular file");
|
|
35027
|
-
|
|
35724
|
+
writeSync5(fd, text);
|
|
35028
35725
|
} finally {
|
|
35029
|
-
|
|
35726
|
+
closeSync8(fd);
|
|
35030
35727
|
}
|
|
35031
35728
|
}
|
|
35032
35729
|
var insideDir = (child, parent) => child === parent || child.startsWith(parent.endsWith(sep6) ? parent : parent + sep6);
|
|
35033
35730
|
function rootFor(vaultDir, target) {
|
|
35034
|
-
const state =
|
|
35035
|
-
if (
|
|
35036
|
-
const project =
|
|
35037
|
-
return insideDir(
|
|
35731
|
+
const state = dirname14(vaultDir);
|
|
35732
|
+
if (basename10(state) !== ".exorcist") return void 0;
|
|
35733
|
+
const project = dirname14(state);
|
|
35734
|
+
return insideDir(resolve25(target), resolve25(project)) ? resolve25(project) : void 0;
|
|
35038
35735
|
}
|
|
35039
35736
|
function realDirOf(target) {
|
|
35040
35737
|
try {
|
|
35041
|
-
return
|
|
35738
|
+
return realpathSync11(dirname14(target));
|
|
35042
35739
|
} catch {
|
|
35043
35740
|
return void 0;
|
|
35044
35741
|
}
|
|
35045
35742
|
}
|
|
35046
35743
|
function targetProblem(e) {
|
|
35047
|
-
const dir = e.kind === "exorcise" ? e.target :
|
|
35744
|
+
const dir = e.kind === "exorcise" ? e.target : dirname14(e.target);
|
|
35048
35745
|
let real;
|
|
35049
35746
|
try {
|
|
35050
|
-
real =
|
|
35747
|
+
real = realpathSync11(existsSync15(dir) ? dir : dirname14(dir));
|
|
35051
35748
|
} catch {
|
|
35052
35749
|
return `${e.target} cannot be resolved.`;
|
|
35053
35750
|
}
|
|
@@ -35055,7 +35752,7 @@ function targetProblem(e) {
|
|
|
35055
35752
|
if (e.root !== void 0) {
|
|
35056
35753
|
let root;
|
|
35057
35754
|
try {
|
|
35058
|
-
root =
|
|
35755
|
+
root = realpathSync11(e.root);
|
|
35059
35756
|
} catch {
|
|
35060
35757
|
return `The project folder ${e.root} cannot be resolved.`;
|
|
35061
35758
|
}
|
|
@@ -35069,24 +35766,24 @@ function newId(label, now) {
|
|
|
35069
35766
|
return `${stamp}-${slug}-${randomBytes7(2).toString("hex")}`;
|
|
35070
35767
|
}
|
|
35071
35768
|
function entryDir(vaultDir, id) {
|
|
35072
|
-
return
|
|
35769
|
+
return join30(vaultDir, id);
|
|
35073
35770
|
}
|
|
35074
35771
|
function writeManifest(vaultDir, e) {
|
|
35075
35772
|
const key = getUserKey({ create: true });
|
|
35076
35773
|
const { trusted: _t, ...plain4 } = e;
|
|
35077
35774
|
const body = key.ok ? { ...plain4, mac: signText(key.key, VAULT_DOMAIN, entryText(plain4)) } : plain4;
|
|
35078
|
-
writeFileSafe(
|
|
35775
|
+
writeFileSafe(join30(entryDir(vaultDir, e.id), "manifest.json"), `${JSON.stringify(body, null, 2)}
|
|
35079
35776
|
`);
|
|
35080
35777
|
}
|
|
35081
35778
|
function listEntries(vaultDir) {
|
|
35082
|
-
if (!
|
|
35779
|
+
if (!existsSync15(vaultDir)) return [];
|
|
35083
35780
|
const key = getUserKey();
|
|
35084
35781
|
const out = [];
|
|
35085
35782
|
for (const name of readdirSync10(vaultDir)) {
|
|
35086
|
-
const file =
|
|
35087
|
-
if (!
|
|
35783
|
+
const file = join30(vaultDir, name, "manifest.json");
|
|
35784
|
+
if (!existsSync15(file)) continue;
|
|
35088
35785
|
try {
|
|
35089
|
-
const st =
|
|
35786
|
+
const st = lstatSync12(file);
|
|
35090
35787
|
if (!st.isFile()) continue;
|
|
35091
35788
|
const parsed = EntrySchema.safeParse(JSON.parse(readFileSync21(file, "utf8")));
|
|
35092
35789
|
if (parsed.success) out.push({ ...parsed.data, trusted: key.ok && verifyText(key.key, VAULT_DOMAIN, entryText(parsed.data), parsed.data.mac) });
|
|
@@ -35121,7 +35818,7 @@ function readConfig(path) {
|
|
|
35121
35818
|
var writeConfig = (path, cfg) => writeFileSync7(path, `${JSON.stringify(cfg, null, 2)}
|
|
35122
35819
|
`, "utf8");
|
|
35123
35820
|
function quarantineServer(o) {
|
|
35124
|
-
const configPath =
|
|
35821
|
+
const configPath = resolve25(o.configPath);
|
|
35125
35822
|
const cfg = readConfig(configPath);
|
|
35126
35823
|
if (!cfg.ok) return cfg;
|
|
35127
35824
|
const entry = cfg.value.mcpServers?.[o.serverName];
|
|
@@ -35134,10 +35831,10 @@ function quarantineServer(o) {
|
|
|
35134
35831
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35135
35832
|
const id = newId(o.serverName, now);
|
|
35136
35833
|
const dir = entryDir(o.vaultDir, id);
|
|
35137
|
-
|
|
35834
|
+
mkdirSync8(dir, { recursive: true });
|
|
35138
35835
|
const backup = `${JSON.stringify(entry, null, 2)}
|
|
35139
35836
|
`;
|
|
35140
|
-
writeFileSafe(
|
|
35837
|
+
writeFileSafe(join30(dir, "entry.json"), backup);
|
|
35141
35838
|
const root = rootFor(o.vaultDir, configPath);
|
|
35142
35839
|
const realDir = realDirOf(configPath);
|
|
35143
35840
|
const e = {
|
|
@@ -35158,16 +35855,16 @@ function quarantineServer(o) {
|
|
|
35158
35855
|
return { ok: true, value: e };
|
|
35159
35856
|
}
|
|
35160
35857
|
function quarantineFile(o) {
|
|
35161
|
-
const target =
|
|
35162
|
-
if (!
|
|
35858
|
+
const target = resolve25(o.filePath);
|
|
35859
|
+
if (!existsSync15(target) || !statSync13(target).isFile()) return fail3(`${target} is not a file.`);
|
|
35163
35860
|
if (activeFor(o.vaultDir, target)) return fail3(`${target} is already in the vault.`);
|
|
35164
35861
|
const safe2 = ensureSafeVault(o.vaultDir);
|
|
35165
35862
|
if (safe2 !== null) return fail3(safe2);
|
|
35166
35863
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35167
|
-
const id = newId(
|
|
35864
|
+
const id = newId(basename10(target), now);
|
|
35168
35865
|
const dir = entryDir(o.vaultDir, id);
|
|
35169
|
-
|
|
35170
|
-
const stored =
|
|
35866
|
+
mkdirSync8(join30(dir, "files"), { recursive: true });
|
|
35867
|
+
const stored = join30(dir, "files", basename10(target));
|
|
35171
35868
|
copyFileSync(target, stored);
|
|
35172
35869
|
const digest = sha2562(readFileSync21(stored));
|
|
35173
35870
|
if (digest !== sha2562(readFileSync21(target))) {
|
|
@@ -35182,12 +35879,12 @@ function quarantineFile(o) {
|
|
|
35182
35879
|
return { ok: true, value: e };
|
|
35183
35880
|
}
|
|
35184
35881
|
function backupAndRewrite(o) {
|
|
35185
|
-
const root =
|
|
35882
|
+
const root = resolve25(o.root);
|
|
35186
35883
|
if (o.files.length === 0) return fail3("There are no files to change.");
|
|
35187
35884
|
for (const f of o.files) {
|
|
35188
35885
|
if (!SafeRel.safeParse(f.rel).success) return fail3(`Refusing to write outside ${root}: ${f.rel}`);
|
|
35189
|
-
const path =
|
|
35190
|
-
if (!
|
|
35886
|
+
const path = join30(root, f.rel);
|
|
35887
|
+
if (!existsSync15(path)) return fail3(`${f.rel} is gone; nothing was changed.`);
|
|
35191
35888
|
if (sha2562(readFileSync21(path)) !== sha2562(Buffer.from(f.before, "utf8"))) {
|
|
35192
35889
|
return fail3(`${f.rel} changed since it was scanned; nothing was changed. Run exorcise again.`);
|
|
35193
35890
|
}
|
|
@@ -35195,16 +35892,16 @@ function backupAndRewrite(o) {
|
|
|
35195
35892
|
const safe2 = ensureSafeVault(o.vaultDir);
|
|
35196
35893
|
if (safe2 !== null) return fail3(safe2);
|
|
35197
35894
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35198
|
-
const id = newId(`exorcise-${
|
|
35895
|
+
const id = newId(`exorcise-${basename10(root)}`, now);
|
|
35199
35896
|
const dir = entryDir(o.vaultDir, id);
|
|
35200
35897
|
const files = [];
|
|
35201
35898
|
try {
|
|
35202
35899
|
for (const f of o.files) {
|
|
35203
|
-
const stored =
|
|
35204
|
-
|
|
35205
|
-
copyFileSync(
|
|
35900
|
+
const stored = join30(dir, "files", f.rel);
|
|
35901
|
+
mkdirSync8(dirname14(stored), { recursive: true });
|
|
35902
|
+
copyFileSync(join30(root, f.rel), stored);
|
|
35206
35903
|
const digest = sha2562(readFileSync21(stored));
|
|
35207
|
-
if (digest !== sha2562(readFileSync21(
|
|
35904
|
+
if (digest !== sha2562(readFileSync21(join30(root, f.rel)))) throw new Error("mismatch");
|
|
35208
35905
|
files.push({ rel: f.rel, sha256: digest, after: sha2562(Buffer.from(f.after, "utf8")) });
|
|
35209
35906
|
}
|
|
35210
35907
|
} catch {
|
|
@@ -35224,14 +35921,14 @@ function backupAndRewrite(o) {
|
|
|
35224
35921
|
...exRoot ? { root: exRoot } : {}
|
|
35225
35922
|
};
|
|
35226
35923
|
writeManifest(o.vaultDir, e);
|
|
35227
|
-
for (const f of o.files) writeFileSync7(
|
|
35924
|
+
for (const f of o.files) writeFileSync7(join30(root, f.rel), f.after, "utf8");
|
|
35228
35925
|
return { ok: true, value: e };
|
|
35229
35926
|
}
|
|
35230
35927
|
function restoreExorcised(vaultDir, e, force) {
|
|
35231
35928
|
const files = e.files ?? [];
|
|
35232
35929
|
const blocked2 = files.filter((f) => {
|
|
35233
|
-
const path =
|
|
35234
|
-
if (!
|
|
35930
|
+
const path = join30(e.target, f.rel);
|
|
35931
|
+
if (!existsSync15(path)) return false;
|
|
35235
35932
|
const now = sha2562(readFileSync21(path));
|
|
35236
35933
|
return now !== f.after && now !== f.sha256;
|
|
35237
35934
|
});
|
|
@@ -35239,27 +35936,27 @@ function restoreExorcised(vaultDir, e, force) {
|
|
|
35239
35936
|
return fail3(`${blocked2.map((f) => f.rel).join(", ")} changed after the exorcism. Use --force to overwrite ${blocked2.length === 1 ? "it" : "them"} with the backup.`);
|
|
35240
35937
|
}
|
|
35241
35938
|
for (const f of files) {
|
|
35242
|
-
const stored =
|
|
35939
|
+
const stored = join30(entryDir(vaultDir, e.id), "files", f.rel);
|
|
35243
35940
|
if (sha2562(readFileSync21(stored)) !== f.sha256) return fail3(`The backup of ${f.rel} is damaged (sha256 does not match); nothing was restored.`);
|
|
35244
35941
|
}
|
|
35245
35942
|
for (const f of files) {
|
|
35246
|
-
const path =
|
|
35247
|
-
|
|
35248
|
-
copyFileSync(
|
|
35943
|
+
const path = join30(e.target, f.rel);
|
|
35944
|
+
mkdirSync8(dirname14(path), { recursive: true });
|
|
35945
|
+
copyFileSync(join30(entryDir(vaultDir, e.id), "files", f.rel), path);
|
|
35249
35946
|
}
|
|
35250
35947
|
return { ok: true, value: null };
|
|
35251
35948
|
}
|
|
35252
35949
|
function backupFile(vaultDir, e) {
|
|
35253
|
-
return e.kind === "mcp-server" ?
|
|
35950
|
+
return e.kind === "mcp-server" ? join30(entryDir(vaultDir, e.id), "entry.json") : join30(entryDir(vaultDir, e.id), "files", basename10(e.target));
|
|
35254
35951
|
}
|
|
35255
35952
|
function diffEntry(vaultDir, id) {
|
|
35256
35953
|
const e = getEntry(vaultDir, id);
|
|
35257
35954
|
if (!e) return fail3(`There is no vault entry "${id}".`);
|
|
35258
35955
|
if (e.kind === "exorcise") {
|
|
35259
35956
|
const parts2 = (e.files ?? []).map((f) => {
|
|
35260
|
-
const path =
|
|
35261
|
-
const before2 = readFileSync21(
|
|
35262
|
-
const after2 =
|
|
35957
|
+
const path = join30(e.target, f.rel);
|
|
35958
|
+
const before2 = readFileSync21(join30(entryDir(vaultDir, e.id), "files", f.rel), "utf8");
|
|
35959
|
+
const after2 = existsSync15(path) ? readFileSync21(path, "utf8") : "";
|
|
35263
35960
|
return createTwoFilesPatch(`${f.rel} (backup)`, `${f.rel} (now)`, before2, after2, "", "", { context: 3 });
|
|
35264
35961
|
});
|
|
35265
35962
|
return { ok: true, value: parts2.join("") };
|
|
@@ -35271,10 +35968,10 @@ function diffEntry(vaultDir, id) {
|
|
|
35271
35968
|
const now = cfg.ok ? cfg.value.mcpServers?.[e.serverName ?? ""] : void 0;
|
|
35272
35969
|
after = now ? `${JSON.stringify(now, null, 2)}
|
|
35273
35970
|
` : "";
|
|
35274
|
-
} else if (
|
|
35971
|
+
} else if (existsSync15(e.target)) {
|
|
35275
35972
|
after = readFileSync21(e.target, "utf8");
|
|
35276
35973
|
}
|
|
35277
|
-
const label = e.kind === "mcp-server" ? `${e.serverName} in ${
|
|
35974
|
+
const label = e.kind === "mcp-server" ? `${e.serverName} in ${basename10(e.target)}` : basename10(e.target);
|
|
35278
35975
|
return { ok: true, value: createTwoFilesPatch(`${label} (backup)`, `${label} (now)`, before, after, "", "", { context: 3 }) };
|
|
35279
35976
|
}
|
|
35280
35977
|
function restoreEntry(vaultDir, id, opts = {}) {
|
|
@@ -35308,10 +36005,10 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
35308
36005
|
writeConfig(e.target, cfg.value);
|
|
35309
36006
|
} else {
|
|
35310
36007
|
const stored = backupFile(vaultDir, e);
|
|
35311
|
-
if (
|
|
36008
|
+
if (existsSync15(e.target) && sha2562(readFileSync21(e.target)) !== e.sha256 && !opts.force) {
|
|
35312
36009
|
return fail3(`${e.target} exists and is different from the quarantined file. Use --force to overwrite it.`);
|
|
35313
36010
|
}
|
|
35314
|
-
|
|
36011
|
+
mkdirSync8(resolve25(e.target, ".."), { recursive: true });
|
|
35315
36012
|
copyFileSync(stored, e.target);
|
|
35316
36013
|
}
|
|
35317
36014
|
const done = { ...e, status: "restored" };
|
|
@@ -35321,14 +36018,14 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
35321
36018
|
|
|
35322
36019
|
// ../shield/src/events.ts
|
|
35323
36020
|
init_zod();
|
|
35324
|
-
import { closeSync as
|
|
35325
|
-
import { join as
|
|
36021
|
+
import { closeSync as closeSync10, constants as constants9, fstatSync as fstatSync5, lstatSync as lstatSync14, mkdirSync as mkdirSync9, openSync as openSync10, readFileSync as readFileSync24, readSync as readSync5, renameSync as renameSync8, rmdirSync as rmdirSync2, unlinkSync as unlinkSync5, writeSync as writeSync7 } from "node:fs";
|
|
36022
|
+
import { join as join32 } from "node:path";
|
|
35326
36023
|
|
|
35327
36024
|
// ../shield/src/chain.ts
|
|
35328
36025
|
init_zod();
|
|
35329
|
-
import { createHash as
|
|
35330
|
-
import { closeSync as
|
|
35331
|
-
import { join as
|
|
36026
|
+
import { createHash as createHash13, randomBytes as randomBytes8 } from "node:crypto";
|
|
36027
|
+
import { closeSync as closeSync9, constants as constants8, fstatSync as fstatSync4, lstatSync as lstatSync13, openSync as openSync9, readFileSync as readFileSync22, readSync as readSync4, renameSync as renameSync7, unlinkSync as unlinkSync4, writeSync as writeSync6 } from "node:fs";
|
|
36028
|
+
import { join as join31 } from "node:path";
|
|
35332
36029
|
|
|
35333
36030
|
// ../shield/src/chain-core.ts
|
|
35334
36031
|
init_zod();
|
|
@@ -35534,8 +36231,8 @@ function verifyChain(lines, head, genesis, opts) {
|
|
|
35534
36231
|
// ../shield/src/chain.ts
|
|
35535
36232
|
var ok = (value) => ({ ok: true, value });
|
|
35536
36233
|
var fail4 = (error2) => ({ ok: false, error: error2 });
|
|
35537
|
-
var headPath = (dir) =>
|
|
35538
|
-
var genesisPath = (dir) =>
|
|
36234
|
+
var headPath = (dir) => join31(dir, "events.head.json");
|
|
36235
|
+
var genesisPath = (dir) => join31(dir, "events.genesis.json");
|
|
35539
36236
|
var GenesisFileSchema = external_exports.object({ v: external_exports.literal(1), genesis: external_exports.string().regex(HEX64) }).strict();
|
|
35540
36237
|
var MAX_FILE_BYTES4 = 4096;
|
|
35541
36238
|
function errCode(e) {
|
|
@@ -35544,10 +36241,10 @@ function errCode(e) {
|
|
|
35544
36241
|
function readSmall(path) {
|
|
35545
36242
|
let fd = null;
|
|
35546
36243
|
try {
|
|
35547
|
-
const st =
|
|
36244
|
+
const st = lstatSync13(path, { throwIfNoEntry: false });
|
|
35548
36245
|
if (st === void 0) return ok(null);
|
|
35549
36246
|
if (!st.isFile()) return fail4("not a regular file");
|
|
35550
|
-
fd =
|
|
36247
|
+
fd = openSync9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
|
|
35551
36248
|
if (fstatSync4(fd).size > MAX_FILE_BYTES4) return fail4("file is too large");
|
|
35552
36249
|
return ok(readFileSync22(fd, "utf8"));
|
|
35553
36250
|
} catch (e) {
|
|
@@ -35555,7 +36252,7 @@ function readSmall(path) {
|
|
|
35555
36252
|
} finally {
|
|
35556
36253
|
if (fd !== null) {
|
|
35557
36254
|
try {
|
|
35558
|
-
|
|
36255
|
+
closeSync9(fd);
|
|
35559
36256
|
} catch {
|
|
35560
36257
|
}
|
|
35561
36258
|
}
|
|
@@ -35581,15 +36278,15 @@ function readGenesis(dir) {
|
|
|
35581
36278
|
function writeNew(path, text) {
|
|
35582
36279
|
let fd = null;
|
|
35583
36280
|
try {
|
|
35584
|
-
fd =
|
|
35585
|
-
|
|
36281
|
+
fd = openSync9(path, constants8.O_WRONLY | constants8.O_CREAT | constants8.O_EXCL | constants8.O_NOFOLLOW, 384);
|
|
36282
|
+
writeSync6(fd, text);
|
|
35586
36283
|
return ok(void 0);
|
|
35587
36284
|
} catch (e) {
|
|
35588
36285
|
return fail4(errCode(e));
|
|
35589
36286
|
} finally {
|
|
35590
36287
|
if (fd !== null) {
|
|
35591
36288
|
try {
|
|
35592
|
-
|
|
36289
|
+
closeSync9(fd);
|
|
35593
36290
|
} catch {
|
|
35594
36291
|
}
|
|
35595
36292
|
}
|
|
@@ -35599,7 +36296,7 @@ function loadOrCreateGenesis(dir, random = () => randomBytes8(32)) {
|
|
|
35599
36296
|
const existing = readGenesis(dir);
|
|
35600
36297
|
if (!existing.ok) return existing;
|
|
35601
36298
|
if (existing.value !== null) return ok(existing.value);
|
|
35602
|
-
const genesis =
|
|
36299
|
+
const genesis = createHash13("sha256").update(random()).digest("hex");
|
|
35603
36300
|
const w = writeNew(genesisPath(dir), `${JSON.stringify({ v: 1, genesis })}
|
|
35604
36301
|
`);
|
|
35605
36302
|
if (!w.ok) {
|
|
@@ -35620,7 +36317,7 @@ function readHead(dir) {
|
|
|
35620
36317
|
function writeHeadAtomic(dir, head) {
|
|
35621
36318
|
const parsed = HeadRecordSchema.safeParse(head);
|
|
35622
36319
|
if (!parsed.success) return fail4("head file: record is not valid");
|
|
35623
|
-
const tmp =
|
|
36320
|
+
const tmp = join31(dir, `events.head.json.${process.pid}.${randomBytes8(4).toString("hex")}.tmp`);
|
|
35624
36321
|
const w = writeNew(tmp, `${JSON.stringify(parsed.data)}
|
|
35625
36322
|
`);
|
|
35626
36323
|
if (!w.ok) return fail4(`head file: could not write (${w.error})`);
|
|
@@ -35639,10 +36336,10 @@ var CHUNK2 = 1 << 20;
|
|
|
35639
36336
|
function readEventsInto(path, out) {
|
|
35640
36337
|
let fd = null;
|
|
35641
36338
|
try {
|
|
35642
|
-
const st =
|
|
36339
|
+
const st = lstatSync13(path, { throwIfNoEntry: false });
|
|
35643
36340
|
if (st === void 0) return ok(null);
|
|
35644
36341
|
if (!st.isFile()) return fail4("not a regular file");
|
|
35645
|
-
fd =
|
|
36342
|
+
fd = openSync9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
|
|
35646
36343
|
const buf = Buffer.alloc(CHUNK2);
|
|
35647
36344
|
let carry = Buffer.alloc(0);
|
|
35648
36345
|
const take = (raw) => {
|
|
@@ -35681,33 +36378,36 @@ function readEventsInto(path, out) {
|
|
|
35681
36378
|
} finally {
|
|
35682
36379
|
if (fd !== null) {
|
|
35683
36380
|
try {
|
|
35684
|
-
|
|
36381
|
+
closeSync9(fd);
|
|
35685
36382
|
} catch {
|
|
35686
36383
|
}
|
|
35687
36384
|
}
|
|
35688
36385
|
}
|
|
35689
36386
|
}
|
|
35690
36387
|
function verifyLogDir(dir, opts) {
|
|
35691
|
-
const
|
|
35692
|
-
const
|
|
35693
|
-
if (!
|
|
35694
|
-
const
|
|
35695
|
-
|
|
36388
|
+
const unreadable2 = (what, error2) => ({ status: "broken", atSeq: 1, reason: "head-mismatch", detail: `${what} could not be read: ${error2}` });
|
|
36389
|
+
const loc = resolveLogLocation(dir, opts?.location ?? {});
|
|
36390
|
+
if (!loc.ok) return unreadable2("the event log folder", loc.error);
|
|
36391
|
+
const logDir = loc.dir;
|
|
36392
|
+
const head = readHead(logDir);
|
|
36393
|
+
if (!head.ok) return unreadable2("the head record", head.error);
|
|
36394
|
+
const genesis = readGenesis(logDir);
|
|
36395
|
+
if (!genesis.ok) return unreadable2("the genesis value", genesis.error);
|
|
35696
36396
|
const events = [];
|
|
35697
|
-
const old = oldEventsPath(
|
|
36397
|
+
const old = oldEventsPath(logDir);
|
|
35698
36398
|
let rotated = false;
|
|
35699
36399
|
try {
|
|
35700
|
-
rotated =
|
|
36400
|
+
rotated = lstatSync13(old, { throwIfNoEntry: false }) !== void 0;
|
|
35701
36401
|
} catch {
|
|
35702
|
-
return
|
|
36402
|
+
return unreadable2("events.1.jsonl", "not accessible");
|
|
35703
36403
|
}
|
|
35704
36404
|
if (rotated) {
|
|
35705
36405
|
const r = readEventsInto(old, events);
|
|
35706
|
-
if (!r.ok) return
|
|
36406
|
+
if (!r.ok) return unreadable2("events.1.jsonl", r.error);
|
|
35707
36407
|
}
|
|
35708
|
-
const cur = readEventsInto(eventsPath(
|
|
35709
|
-
if (!cur.ok) return
|
|
35710
|
-
const { anchor: useAnchor, ...verifyOpts } = opts ?? {};
|
|
36408
|
+
const cur = readEventsInto(eventsPath(logDir), events);
|
|
36409
|
+
if (!cur.ok) return unreadable2("events.jsonl", cur.error);
|
|
36410
|
+
const { anchor: useAnchor, location: _location, ...verifyOpts } = opts ?? {};
|
|
35711
36411
|
const status2 = verifyChain(events, head.value, genesis.value, { ...verifyOpts, allowRotatedStart: rotated });
|
|
35712
36412
|
if (useAnchor === false || status2.status === "broken") return status2;
|
|
35713
36413
|
const tip = status2.status === "intact" ? { seq: status2.head.seq, hash: status2.head.hash } : null;
|
|
@@ -35726,7 +36426,7 @@ function verifyLogDir(dir, opts) {
|
|
|
35726
36426
|
}
|
|
35727
36427
|
|
|
35728
36428
|
// ../shield/src/procstart.ts
|
|
35729
|
-
import { execFileSync as
|
|
36429
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
35730
36430
|
import { readFileSync as readFileSync23 } from "node:fs";
|
|
35731
36431
|
function processStart(pid, platform = process.platform) {
|
|
35732
36432
|
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
@@ -35738,7 +36438,7 @@ function processStart(pid, platform = process.platform) {
|
|
|
35738
36438
|
return ticks !== void 0 && /^\d+$/.test(ticks) ? `t${ticks}` : null;
|
|
35739
36439
|
}
|
|
35740
36440
|
if (platform === "win32") return null;
|
|
35741
|
-
const out =
|
|
36441
|
+
const out = execFileSync4("/bin/ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "ignore"], env: { PATH: "/usr/bin:/bin", LC_ALL: "C" } }).trim();
|
|
35742
36442
|
return out === "" ? null : `s${out.replace(/\s+/g, " ")}`;
|
|
35743
36443
|
} catch {
|
|
35744
36444
|
return null;
|
|
@@ -35770,9 +36470,9 @@ function holderAlive(pid, start, o = {}) {
|
|
|
35770
36470
|
}
|
|
35771
36471
|
|
|
35772
36472
|
// ../shield/src/events.ts
|
|
35773
|
-
var eventsPath = (dir) =>
|
|
35774
|
-
var oldEventsPath = (dir) =>
|
|
35775
|
-
var lockPath = (dir) =>
|
|
36473
|
+
var eventsPath = (dir) => join32(dir, "events.jsonl");
|
|
36474
|
+
var oldEventsPath = (dir) => join32(dir, "events.1.jsonl");
|
|
36475
|
+
var lockPath = (dir) => join32(dir, "events.lock");
|
|
35776
36476
|
var MAX_EVENT_BYTES = 1024 * 1024;
|
|
35777
36477
|
var MAX_LINE_BYTES = 8 * 1024;
|
|
35778
36478
|
var STALE_LOCK_MS = 1e4;
|
|
@@ -35877,7 +36577,7 @@ function myStart(startOf) {
|
|
|
35877
36577
|
function lockIsStale(lock, d) {
|
|
35878
36578
|
let st;
|
|
35879
36579
|
try {
|
|
35880
|
-
st =
|
|
36580
|
+
st = lstatSync14(lock);
|
|
35881
36581
|
} catch {
|
|
35882
36582
|
return { stale: false, seen: "" };
|
|
35883
36583
|
}
|
|
@@ -35898,7 +36598,7 @@ function lockIsStale(lock, d) {
|
|
|
35898
36598
|
}
|
|
35899
36599
|
function breakLock(lock, seen) {
|
|
35900
36600
|
try {
|
|
35901
|
-
const st =
|
|
36601
|
+
const st = lstatSync14(lock);
|
|
35902
36602
|
if (st.isDirectory()) {
|
|
35903
36603
|
rmdirSync2(lock);
|
|
35904
36604
|
return;
|
|
@@ -35914,8 +36614,8 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35914
36614
|
const take = () => {
|
|
35915
36615
|
let fd = null;
|
|
35916
36616
|
try {
|
|
35917
|
-
fd =
|
|
35918
|
-
|
|
36617
|
+
fd = openSync10(lock, constants9.O_WRONLY | constants9.O_CREAT | constants9.O_EXCL | (constants9.O_NOFOLLOW ?? 0), 384);
|
|
36618
|
+
writeSync7(fd, `${process.pid} ${myStart(d.startOf)}
|
|
35919
36619
|
`);
|
|
35920
36620
|
return true;
|
|
35921
36621
|
} catch (err) {
|
|
@@ -35924,7 +36624,7 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35924
36624
|
} finally {
|
|
35925
36625
|
if (fd !== null) {
|
|
35926
36626
|
try {
|
|
35927
|
-
|
|
36627
|
+
closeSync10(fd);
|
|
35928
36628
|
} catch {
|
|
35929
36629
|
}
|
|
35930
36630
|
}
|
|
@@ -35958,9 +36658,12 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35958
36658
|
var EventLog = class {
|
|
35959
36659
|
constructor(dir, o) {
|
|
35960
36660
|
this.dir = dir;
|
|
35961
|
-
this.
|
|
35962
|
-
this.
|
|
35963
|
-
this.
|
|
36661
|
+
this.locDeps = o.location ?? {};
|
|
36662
|
+
this.loc = resolveLogLocation(dir, this.locDeps);
|
|
36663
|
+
this.logDir = this.loc.ok ? this.loc.dir : dir;
|
|
36664
|
+
this.path = eventsPath(this.logDir);
|
|
36665
|
+
this.old = oldEventsPath(this.logDir);
|
|
36666
|
+
this.lock = lockPath(this.logDir);
|
|
35964
36667
|
this.maxBytes = o.maxBytes ?? MAX_EVENT_BYTES;
|
|
35965
36668
|
this.pid = o.pid ?? process.pid;
|
|
35966
36669
|
this.server = cleanText(o.server, NAME_CHARS2);
|
|
@@ -35972,6 +36675,11 @@ var EventLog = class {
|
|
|
35972
36675
|
this.session = o.session;
|
|
35973
36676
|
}
|
|
35974
36677
|
path;
|
|
36678
|
+
/** The folder that holds the log, its lock and its chain files: the state folder, or a local folder when that one is on a network drive (m19-log). */
|
|
36679
|
+
logDir;
|
|
36680
|
+
loc;
|
|
36681
|
+
prepared = false;
|
|
36682
|
+
locDeps;
|
|
35975
36683
|
old;
|
|
35976
36684
|
lock;
|
|
35977
36685
|
maxBytes;
|
|
@@ -35983,6 +36691,8 @@ var EventLog = class {
|
|
|
35983
36691
|
lockAttempts;
|
|
35984
36692
|
lockDeps;
|
|
35985
36693
|
sessionKey;
|
|
36694
|
+
/** Set while the final "logging is off" event is written: the anchor then carries the time. */
|
|
36695
|
+
offSince;
|
|
35986
36696
|
/** Events not written because the file was full and could not be rotated. */
|
|
35987
36697
|
dropped = 0;
|
|
35988
36698
|
problem = null;
|
|
@@ -36014,7 +36724,12 @@ var EventLog = class {
|
|
|
36014
36724
|
return false;
|
|
36015
36725
|
}
|
|
36016
36726
|
try {
|
|
36017
|
-
|
|
36727
|
+
mkdirSync9(this.dir, { recursive: true });
|
|
36728
|
+
const ready = this.prepare();
|
|
36729
|
+
if (ready !== null) {
|
|
36730
|
+
this.fail(ready);
|
|
36731
|
+
return false;
|
|
36732
|
+
}
|
|
36018
36733
|
if (this.chain) {
|
|
36019
36734
|
const r = withLock(this.lock, this.lockAttempts, () => this.writeChained(parsed.data), this.lockDeps);
|
|
36020
36735
|
if (r.held) return r.value;
|
|
@@ -36030,6 +36745,40 @@ var EventLog = class {
|
|
|
36030
36745
|
return false;
|
|
36031
36746
|
}
|
|
36032
36747
|
}
|
|
36748
|
+
/** Whether the log is in a local folder instead of the state folder, and why (m19-log). */
|
|
36749
|
+
get moved() {
|
|
36750
|
+
return this.loc.ok && this.loc.moved ? { reason: this.loc.reason ?? "" } : null;
|
|
36751
|
+
}
|
|
36752
|
+
/** The folder of the log as decided now, for the line the Shield logs (an error when the folder was refused). */
|
|
36753
|
+
get location() {
|
|
36754
|
+
return this.loc;
|
|
36755
|
+
}
|
|
36756
|
+
/** Make the local folder (mode 0700) and check it before the first write. A problem in words, or null. */
|
|
36757
|
+
prepare() {
|
|
36758
|
+
if (!this.loc.ok) return this.loc.error;
|
|
36759
|
+
if (!this.loc.moved || this.prepared) return null;
|
|
36760
|
+
const r = resolveLogLocation(this.dir, { ...this.locDeps, create: true });
|
|
36761
|
+
if (!r.ok) {
|
|
36762
|
+
this.loc = r;
|
|
36763
|
+
return r.error;
|
|
36764
|
+
}
|
|
36765
|
+
if (r.dir !== this.logDir) return "the event log folder changed since the Shield started";
|
|
36766
|
+
this.prepared = true;
|
|
36767
|
+
return null;
|
|
36768
|
+
}
|
|
36769
|
+
/**
|
|
36770
|
+
* The final event when the user-level setting turns logging off (LG-2.4): written chained, and the anchor
|
|
36771
|
+
* records the time. Written once: when the anchor already holds the time, nothing is added. Returns the time.
|
|
36772
|
+
*/
|
|
36773
|
+
writeOff() {
|
|
36774
|
+
const known = readAnchor(this.dir);
|
|
36775
|
+
if (known.ok && known.anchor?.eventsOffSince !== void 0) return { time: known.anchor.eventsOffSince, written: false };
|
|
36776
|
+
const time3 = this.now().toISOString();
|
|
36777
|
+
this.offSince = time3;
|
|
36778
|
+
const written = this.write({ kind: "alert", severity: "medium", ruleId: "SHIELD", message: `Event logging was turned off by your user-level config ("events": "off") at ${time3}. No later events are written by a Shield.` });
|
|
36779
|
+
this.offSince = void 0;
|
|
36780
|
+
return { time: time3, written };
|
|
36781
|
+
}
|
|
36033
36782
|
encode(e) {
|
|
36034
36783
|
const line = Buffer.from(`${JSON.stringify(e)}
|
|
36035
36784
|
`, "utf8");
|
|
@@ -36051,27 +36800,27 @@ var EventLog = class {
|
|
|
36051
36800
|
return false;
|
|
36052
36801
|
}
|
|
36053
36802
|
}
|
|
36054
|
-
const flags2 =
|
|
36055
|
-
const fd =
|
|
36803
|
+
const flags2 = constants9.O_WRONLY | constants9.O_APPEND | constants9.O_CREAT | (constants9.O_NOFOLLOW ?? 0);
|
|
36804
|
+
const fd = openSync10(this.path, flags2, 384);
|
|
36056
36805
|
try {
|
|
36057
36806
|
if (!fstatSync5(fd).isFile()) {
|
|
36058
36807
|
this.fail(`${this.path} is not a regular file`);
|
|
36059
36808
|
return false;
|
|
36060
36809
|
}
|
|
36061
|
-
|
|
36810
|
+
writeSync7(fd, line);
|
|
36062
36811
|
} finally {
|
|
36063
|
-
|
|
36812
|
+
closeSync10(fd);
|
|
36064
36813
|
}
|
|
36065
36814
|
return true;
|
|
36066
36815
|
}
|
|
36067
36816
|
/** The chained write, with the lock held. Falls back to an unchained line when the chain files are unusable. */
|
|
36068
36817
|
writeChained(event) {
|
|
36069
|
-
const g = loadOrCreateGenesis(this.
|
|
36818
|
+
const g = loadOrCreateGenesis(this.logDir, this.random);
|
|
36070
36819
|
if (!g.ok) {
|
|
36071
36820
|
this.fail(g.error);
|
|
36072
36821
|
return this.append(this.encode(event), true);
|
|
36073
36822
|
}
|
|
36074
|
-
const h = readHead(this.
|
|
36823
|
+
const h = readHead(this.logDir);
|
|
36075
36824
|
if (!h.ok) this.fail(h.error);
|
|
36076
36825
|
const head = h.ok ? h.value : null;
|
|
36077
36826
|
const anchor = readAnchor(this.dir);
|
|
@@ -36085,12 +36834,12 @@ var EventLog = class {
|
|
|
36085
36834
|
return false;
|
|
36086
36835
|
}
|
|
36087
36836
|
if (!this.append(this.encode(chained.data), true)) return false;
|
|
36088
|
-
const w = writeHeadAtomic(this.
|
|
36837
|
+
const w = writeHeadAtomic(this.logDir, { v: 1, genesis: g.value, seq: seq2, hash });
|
|
36089
36838
|
if (!w.ok) this.fail(w.error);
|
|
36090
36839
|
else if (drift) {
|
|
36091
36840
|
this.fail("the event log no longer matches the anchor kept outside the state folder (it was edited or replaced), so the anchor was not moved. Run: exorcist console --verify");
|
|
36092
36841
|
} else {
|
|
36093
|
-
const anchorProblem = writeAnchor(this.dir, { seq: seq2, hash });
|
|
36842
|
+
const anchorProblem = writeAnchor(this.dir, { seq: seq2, hash }, this.offSince !== void 0 ? { eventsOffSince: this.offSince } : {});
|
|
36094
36843
|
if (anchorProblem !== null) this.fail(anchorProblem);
|
|
36095
36844
|
}
|
|
36096
36845
|
return true;
|
|
@@ -36100,7 +36849,7 @@ var EventLog = class {
|
|
|
36100
36849
|
}
|
|
36101
36850
|
size() {
|
|
36102
36851
|
try {
|
|
36103
|
-
return
|
|
36852
|
+
return lstatSync14(this.path).size;
|
|
36104
36853
|
} catch {
|
|
36105
36854
|
return 0;
|
|
36106
36855
|
}
|
|
@@ -36142,7 +36891,7 @@ function parseEventLines(text) {
|
|
|
36142
36891
|
function readFrom(path, from) {
|
|
36143
36892
|
let fd;
|
|
36144
36893
|
try {
|
|
36145
|
-
fd =
|
|
36894
|
+
fd = openSync10(path, constants9.O_RDONLY | (constants9.O_NOFOLLOW ?? 0));
|
|
36146
36895
|
} catch {
|
|
36147
36896
|
return null;
|
|
36148
36897
|
}
|
|
@@ -36169,14 +36918,15 @@ function readFrom(path, from) {
|
|
|
36169
36918
|
if (dropFirst) text = text.slice(text.indexOf("\n") + 1);
|
|
36170
36919
|
return { text, end: start + lastNl + 1, st };
|
|
36171
36920
|
} finally {
|
|
36172
|
-
|
|
36921
|
+
closeSync10(fd);
|
|
36173
36922
|
}
|
|
36174
36923
|
}
|
|
36175
36924
|
var EventTail = class {
|
|
36176
|
-
constructor(dir) {
|
|
36925
|
+
constructor(dir, deps = {}) {
|
|
36177
36926
|
this.dir = dir;
|
|
36178
|
-
|
|
36179
|
-
this.
|
|
36927
|
+
const loc = resolveLogLocation(dir, deps);
|
|
36928
|
+
this.path = loc.ok ? eventsPath(loc.dir) : join32(dir, "events.refused");
|
|
36929
|
+
this.old = loc.ok ? oldEventsPath(loc.dir) : join32(dir, "events.1.refused");
|
|
36180
36930
|
}
|
|
36181
36931
|
cur = null;
|
|
36182
36932
|
skipped = 0;
|
|
@@ -36191,7 +36941,7 @@ var EventTail = class {
|
|
|
36191
36941
|
};
|
|
36192
36942
|
let st = null;
|
|
36193
36943
|
try {
|
|
36194
|
-
st =
|
|
36944
|
+
st = lstatSync14(this.path);
|
|
36195
36945
|
} catch {
|
|
36196
36946
|
st = null;
|
|
36197
36947
|
}
|
|
@@ -36229,10 +36979,10 @@ var EventTail = class {
|
|
|
36229
36979
|
};
|
|
36230
36980
|
|
|
36231
36981
|
// ../shield/src/launch.ts
|
|
36232
|
-
import { createHash as
|
|
36233
|
-
import { existsSync as
|
|
36234
|
-
import { dirname as
|
|
36235
|
-
var sha2563 = (b) =>
|
|
36982
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
36983
|
+
import { existsSync as existsSync16, readFileSync as readFileSync25, statSync as statSync14 } from "node:fs";
|
|
36984
|
+
import { dirname as dirname15, isAbsolute as isAbsolute19, join as join33, parse as parsePath2, relative as relative14, resolve as resolve26, sep as sep7 } from "node:path";
|
|
36985
|
+
var sha2563 = (b) => createHash14("sha256").update(b).digest("hex");
|
|
36236
36986
|
var MAX_HASHED_BYTES = 64 * 1024 * 1024;
|
|
36237
36987
|
var fsReader = (path) => {
|
|
36238
36988
|
try {
|
|
@@ -36254,7 +37004,7 @@ var RUNNERS2 = {
|
|
|
36254
37004
|
bun: ["x"],
|
|
36255
37005
|
pipx: ["run"]
|
|
36256
37006
|
};
|
|
36257
|
-
var
|
|
37007
|
+
var INTERPRETERS3 = /^(node|nodejs|deno|bun|python\d*(\.\d+)?|pythonw|uv|uvx|npx|pnpx|bunx|pnpm|npm|yarn|pipx|java|ruby|php|dotnet|docker|podman|sh|bash|zsh|cmd|powershell|pwsh)$/i;
|
|
36258
37008
|
var baseName3 = (c) => c.split(/[\\/]/).pop()?.replace(/\.(cmd|exe)$/i, "") ?? c;
|
|
36259
37009
|
function packageSpec(command, args) {
|
|
36260
37010
|
const sub = RUNNERS2[baseName3(command)];
|
|
@@ -36305,17 +37055,17 @@ function launchEntryOf(entry) {
|
|
|
36305
37055
|
}
|
|
36306
37056
|
var PROJECT_MARKERS3 = [".git", ".kiro"];
|
|
36307
37057
|
function configLabel(configPath) {
|
|
36308
|
-
const abs =
|
|
37058
|
+
const abs = resolve26(configPath);
|
|
36309
37059
|
const { root } = parsePath2(abs);
|
|
36310
|
-
for (let dir =
|
|
36311
|
-
if (PROJECT_MARKERS3.some((m) =>
|
|
36312
|
-
if (dir === root ||
|
|
37060
|
+
for (let dir = dirname15(abs); ; dir = dirname15(dir)) {
|
|
37061
|
+
if (PROJECT_MARKERS3.some((m) => existsSync16(join33(dir, m)))) return relative14(dir, abs).split(sep7).join("/");
|
|
37062
|
+
if (dir === root || dirname15(dir) === dir) return abs;
|
|
36313
37063
|
}
|
|
36314
37064
|
}
|
|
36315
37065
|
function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
36316
37066
|
const fileLine = (label, value) => {
|
|
36317
37067
|
if (value.length === 0 || value.length > 4096) return void 0;
|
|
36318
|
-
const path = isAbsolute19(value) ? value :
|
|
37068
|
+
const path = isAbsolute19(value) ? value : resolve26(cwd, value);
|
|
36319
37069
|
const f = reader(path);
|
|
36320
37070
|
if (f.kind !== "file") return void 0;
|
|
36321
37071
|
const content = f.size <= MAX_HASHED_BYTES ? `sha256:${sha2563(f.read())}` : `size:${f.size} mtime:${Math.round(f.mtimeMs)}`;
|
|
@@ -36323,7 +37073,7 @@ function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
|
36323
37073
|
};
|
|
36324
37074
|
const parts2 = [];
|
|
36325
37075
|
const commandIsPath = /[\\/]/.test(command);
|
|
36326
|
-
const own = commandIsPath && !
|
|
37076
|
+
const own = commandIsPath && !INTERPRETERS3.test(baseName3(command)) ? fileLine("command", command) : void 0;
|
|
36327
37077
|
parts2.push(own ?? `command ${command}`);
|
|
36328
37078
|
const spec2 = packageSpec(command, args);
|
|
36329
37079
|
if (spec2) parts2.push(`package ${spec2}`);
|
|
@@ -36365,11 +37115,11 @@ function checkLaunch(s, pin, now = /* @__PURE__ */ new Date()) {
|
|
|
36365
37115
|
// ../shield/src/ai-review.ts
|
|
36366
37116
|
var NONE = { block: [], warn: [] };
|
|
36367
37117
|
function withTimeout(p, ms) {
|
|
36368
|
-
return new Promise((
|
|
37118
|
+
return new Promise((resolve42, reject2) => {
|
|
36369
37119
|
const t2 = setTimeout(() => reject2(new Error(`no answer within ${ms} ms`)), ms);
|
|
36370
37120
|
p.then((v) => {
|
|
36371
37121
|
clearTimeout(t2);
|
|
36372
|
-
|
|
37122
|
+
resolve42(v);
|
|
36373
37123
|
}, (e) => {
|
|
36374
37124
|
clearTimeout(t2);
|
|
36375
37125
|
reject2(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -36447,14 +37197,35 @@ async function prepareShield(o) {
|
|
|
36447
37197
|
const stderr = o.stderr ?? process.stderr;
|
|
36448
37198
|
const log = (s) => void stderr.write(`[exorcist] ${s}
|
|
36449
37199
|
`);
|
|
36450
|
-
|
|
37200
|
+
mkdirSync10(o.dir, { recursive: true });
|
|
36451
37201
|
const policy = loadPolicy(policyPath(o.dir));
|
|
36452
37202
|
if (!policy.ok) {
|
|
36453
37203
|
log(policy.error);
|
|
36454
37204
|
return FAIL_CLOSED_EXIT;
|
|
36455
37205
|
}
|
|
36456
37206
|
for (const n of policy.notes) log(n);
|
|
36457
|
-
const
|
|
37207
|
+
const eventLog = new EventLog(o.dir, { server: o.server });
|
|
37208
|
+
const events = policy.policy.events === "off" ? null : eventLog;
|
|
37209
|
+
const envSwitch = process.env["EXORCIST_EVENTS"];
|
|
37210
|
+
if (events === null) {
|
|
37211
|
+
const off = eventLog.writeOff();
|
|
37212
|
+
log(`Event logging is turned off by your user-level config ("events": "off")${off.written ? `; a final event was written (${off.time})` : `, since ${off.time}`}.`);
|
|
37213
|
+
if (eventLog.problem) log(`The console event log: ${eventLog.problem}.`);
|
|
37214
|
+
if (envSwitch !== void 0 && envSwitch !== "") log("The environment variable EXORCIST_EVENTS is ignored.");
|
|
37215
|
+
} else {
|
|
37216
|
+
const where2 = eventLog.location;
|
|
37217
|
+
if (where2.ok && where2.moved) {
|
|
37218
|
+
log(locationNote(where2));
|
|
37219
|
+
const p = writeLocationPointer(o.dir, where2.dir);
|
|
37220
|
+
if (p !== null) log(`The note events.location could not be left in the state folder: ${p}.`);
|
|
37221
|
+
} else if (!where2.ok) {
|
|
37222
|
+
log(`The event log was not written: ${where2.error}. The Shield keeps protecting; only the live console misses events.`);
|
|
37223
|
+
}
|
|
37224
|
+
if (envSwitch !== void 0 && envSwitch !== "") {
|
|
37225
|
+
log('The environment variable EXORCIST_EVENTS was set and is ignored: only "events": "off" in your user-level policy turns logging off.');
|
|
37226
|
+
eventLog.write({ kind: "alert", severity: "medium", ruleId: "SHIELD", message: 'The environment variable EXORCIST_EVENTS was set and ignored. The user-level setting ("events": "off" in your user-level policy) is the way to turn logging off; a project or an MCP config cannot.' });
|
|
37227
|
+
}
|
|
37228
|
+
}
|
|
36458
37229
|
let eventProblemShown = false;
|
|
36459
37230
|
const eventProblem = () => {
|
|
36460
37231
|
if (events?.problem && !eventProblemShown) {
|
|
@@ -36489,13 +37260,13 @@ async function prepareShield(o) {
|
|
|
36489
37260
|
log(canariesFile.error);
|
|
36490
37261
|
return FAIL_CLOSED_EXIT;
|
|
36491
37262
|
}
|
|
36492
|
-
if (policy.policy.canaries && !
|
|
37263
|
+
if (policy.policy.canaries && !existsSync17(canariesAt)) log(`The policy names canary records at ${canariesAt}, but there is no such file; no canary traps are active.`);
|
|
36493
37264
|
const canaries = canariesFile.canaries.map((r) => ({ token: r.token, file: r.file }));
|
|
36494
37265
|
if (canaries.length > 0) log(`Watching for ${canaries.length} canary token${canaries.length === 1 ? "" : "s"} (EX-022).`);
|
|
36495
37266
|
let lockExpected;
|
|
36496
37267
|
let lockLaunch;
|
|
36497
|
-
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [
|
|
36498
|
-
if (lockFile &&
|
|
37268
|
+
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [dirname16(o.configPath)] : [], process.cwd()]) : o.lockPath;
|
|
37269
|
+
if (lockFile && existsSync17(lockFile)) {
|
|
36499
37270
|
let text;
|
|
36500
37271
|
try {
|
|
36501
37272
|
text = readFileSync26(lockFile, "utf8");
|
|
@@ -36828,16 +37599,16 @@ async function runProxy(o) {
|
|
|
36828
37599
|
});
|
|
36829
37600
|
prepared.attach(run3);
|
|
36830
37601
|
const stopWatch = prepared.watch(run3);
|
|
36831
|
-
return await new Promise((
|
|
37602
|
+
return await new Promise((resolve42) => {
|
|
36832
37603
|
child.on("error", (err) => {
|
|
36833
37604
|
stopWatch();
|
|
36834
37605
|
log(`Could not start "${o.command}": ${err.message}`);
|
|
36835
|
-
|
|
37606
|
+
resolve42(127);
|
|
36836
37607
|
});
|
|
36837
37608
|
child.on("close", (code3) => {
|
|
36838
37609
|
stopWatch();
|
|
36839
37610
|
for (const l of fromServer.flush()) fromServerLine(l);
|
|
36840
|
-
void serverQueue.then(() =>
|
|
37611
|
+
void serverQueue.then(() => resolve42(code3 ?? 1));
|
|
36841
37612
|
});
|
|
36842
37613
|
});
|
|
36843
37614
|
}
|
|
@@ -37042,7 +37813,7 @@ async function runRemoteProxy(o) {
|
|
|
37042
37813
|
const fromClient = new LineSplitter();
|
|
37043
37814
|
prepared.attach(deliver);
|
|
37044
37815
|
const stopWatch = prepared.watch(deliver);
|
|
37045
|
-
return await new Promise((
|
|
37816
|
+
return await new Promise((resolve42) => {
|
|
37046
37817
|
stdin.on("data", (chunk) => {
|
|
37047
37818
|
for (const l of fromClient.push(chunk)) deliver(engine.onClientLine(l));
|
|
37048
37819
|
});
|
|
@@ -37062,15 +37833,15 @@ async function runRemoteProxy(o) {
|
|
|
37062
37833
|
} catch {
|
|
37063
37834
|
}
|
|
37064
37835
|
}
|
|
37065
|
-
|
|
37836
|
+
resolve42(0);
|
|
37066
37837
|
})();
|
|
37067
37838
|
});
|
|
37068
37839
|
});
|
|
37069
37840
|
}
|
|
37070
37841
|
|
|
37071
37842
|
// ../shield/src/locate.ts
|
|
37072
|
-
import { existsSync as
|
|
37073
|
-
import { dirname as
|
|
37843
|
+
import { existsSync as existsSync18, readdirSync as readdirSync11, statSync as statSync16 } from "node:fs";
|
|
37844
|
+
import { dirname as dirname17, isAbsolute as isAbsolute20, join as join34, parse as parse2, resolve as resolve27 } from "node:path";
|
|
37074
37845
|
import { fileURLToPath } from "node:url";
|
|
37075
37846
|
function hasDefinitions(dir) {
|
|
37076
37847
|
try {
|
|
@@ -37082,28 +37853,28 @@ function hasDefinitions(dir) {
|
|
|
37082
37853
|
function findDefinitionsDir(o) {
|
|
37083
37854
|
const env = o.env ?? process.env;
|
|
37084
37855
|
const cwd = o.cwd ?? process.cwd();
|
|
37085
|
-
if (o.explicit) return
|
|
37856
|
+
if (o.explicit) return resolve27(cwd, o.explicit);
|
|
37086
37857
|
const fromEnv = env["EXORCIST_DEFINITIONS"];
|
|
37087
|
-
if (fromEnv) return
|
|
37858
|
+
if (fromEnv) return resolve27(cwd, fromEnv);
|
|
37088
37859
|
const installed = findActiveInstalledSet({ env, ...o.publicKeyPem ? { publicKeyPem: o.publicKeyPem } : {} });
|
|
37089
37860
|
if (installed && hasDefinitions(installed.definitionsDir)) return installed.definitionsDir;
|
|
37090
|
-
const here =
|
|
37091
|
-
const candidates = [
|
|
37861
|
+
const here = dirname17(fileURLToPath(o.callerUrl));
|
|
37862
|
+
const candidates = [join34(here, "..", "definitions"), join34(here, "..", "..", "..", "definitions"), join34(cwd, "definitions")];
|
|
37092
37863
|
return candidates.find(hasDefinitions) ?? null;
|
|
37093
37864
|
}
|
|
37094
37865
|
var PROJECT_MARKERS4 = [".exorcist", ".kiro", ".git"];
|
|
37095
37866
|
function findStateDir(o = {}) {
|
|
37096
37867
|
const env = o.env ?? process.env;
|
|
37097
|
-
const cwd =
|
|
37098
|
-
if (o.explicit) return
|
|
37868
|
+
const cwd = resolve27(o.cwd ?? process.cwd());
|
|
37869
|
+
if (o.explicit) return resolve27(cwd, o.explicit);
|
|
37099
37870
|
const fromEnv = env["EXORCIST_DIR"];
|
|
37100
|
-
if (fromEnv) return isAbsolute20(fromEnv) ? fromEnv :
|
|
37871
|
+
if (fromEnv) return isAbsolute20(fromEnv) ? fromEnv : resolve27(cwd, fromEnv);
|
|
37101
37872
|
const { root } = parse2(cwd);
|
|
37102
|
-
for (let dir = cwd; ; dir =
|
|
37103
|
-
if (PROJECT_MARKERS4.some((m) =>
|
|
37104
|
-
if (dir === root ||
|
|
37873
|
+
for (let dir = cwd; ; dir = dirname17(dir)) {
|
|
37874
|
+
if (PROJECT_MARKERS4.some((m) => existsSync18(join34(dir, m)))) return join34(dir, ".exorcist");
|
|
37875
|
+
if (dir === root || dirname17(dir) === dir) break;
|
|
37105
37876
|
}
|
|
37106
|
-
return
|
|
37877
|
+
return join34(cwd, ".exorcist");
|
|
37107
37878
|
}
|
|
37108
37879
|
|
|
37109
37880
|
// ../shield/src/wrap.ts
|
|
@@ -37286,8 +38057,8 @@ var DEFAULT_DIR = "the project's .exorcist folder (or EXORCIST_DIR)";
|
|
|
37286
38057
|
// src/commands/on-access.ts
|
|
37287
38058
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
37288
38059
|
import { execFile as execFile3 } from "node:child_process";
|
|
37289
|
-
import { existsSync as
|
|
37290
|
-
import { resolve as
|
|
38060
|
+
import { existsSync as existsSync19, statSync as statSync17 } from "node:fs";
|
|
38061
|
+
import { resolve as resolve28 } from "node:path";
|
|
37291
38062
|
import { createInterface } from "node:readline";
|
|
37292
38063
|
var ALLOW_READ_HELP = `Usage: exorcist allow-read <file>
|
|
37293
38064
|
|
|
@@ -37479,8 +38250,8 @@ ${ALLOW_READ_HELP}`);
|
|
|
37479
38250
|
io.err("exorcist allow-read only runs in an interactive terminal: the user must review the file and run it themselves. Nothing was allowed.");
|
|
37480
38251
|
return 1;
|
|
37481
38252
|
}
|
|
37482
|
-
const file =
|
|
37483
|
-
if (!
|
|
38253
|
+
const file = resolve28(target);
|
|
38254
|
+
if (!existsSync19(file) || !statSync17(file).isFile()) {
|
|
37484
38255
|
io.err(`Not a readable file: ${shownName(target)}`);
|
|
37485
38256
|
return 1;
|
|
37486
38257
|
}
|
|
@@ -37587,7 +38358,7 @@ ${APPROVE_HELP}`);
|
|
|
37587
38358
|
return 1;
|
|
37588
38359
|
}
|
|
37589
38360
|
const file = policyPath(stateDir(str4(p.values["dir"])));
|
|
37590
|
-
if (!
|
|
38361
|
+
if (!existsSync20(file)) {
|
|
37591
38362
|
io.err(`There is no policy file at ${file}.`);
|
|
37592
38363
|
return 1;
|
|
37593
38364
|
}
|
|
@@ -37648,7 +38419,7 @@ async function alertsCommand(argv, io) {
|
|
|
37648
38419
|
if (!h.ok) io.out(`Event log head: unreadable (${h.error.replace(/[^\x20-\x7e]/g, "?")}).`);
|
|
37649
38420
|
else io.out(h.value === null ? "Event log head: none yet (nothing has been logged in this folder)." : `Event log head: ${h.value.hash} (event ${h.value.seq})`);
|
|
37650
38421
|
};
|
|
37651
|
-
if (!
|
|
38422
|
+
if (!existsSync20(file)) {
|
|
37652
38423
|
io.out("No alerts.");
|
|
37653
38424
|
printHead();
|
|
37654
38425
|
return 0;
|
|
@@ -37668,16 +38439,16 @@ async function alertsCommand(argv, io) {
|
|
|
37668
38439
|
|
|
37669
38440
|
// src/commands/baseline.ts
|
|
37670
38441
|
import { statSync as statSync20, writeFileSync as writeFileSync9 } from "node:fs";
|
|
37671
|
-
import { join as
|
|
38442
|
+
import { join as join38, resolve as resolve31 } from "node:path";
|
|
37672
38443
|
|
|
37673
38444
|
// src/commands/scan.ts
|
|
37674
|
-
import { existsSync as
|
|
37675
|
-
import { basename as
|
|
38445
|
+
import { existsSync as existsSync22, readFileSync as readFileSync29, realpathSync as realpathSync12, statSync as statSync19, writeFileSync as writeFileSync8 } from "node:fs";
|
|
38446
|
+
import { basename as basename12, dirname as dirname18, isAbsolute as isAbsolute21, join as join37, relative as relative15, resolve as resolve30 } from "node:path";
|
|
37676
38447
|
init_bedrock();
|
|
37677
38448
|
|
|
37678
38449
|
// src/commands/detonate.ts
|
|
37679
|
-
import { existsSync as
|
|
37680
|
-
import { basename as
|
|
38450
|
+
import { existsSync as existsSync21, readFileSync as readFileSync28, statSync as statSync18 } from "node:fs";
|
|
38451
|
+
import { basename as basename11, join as join35, resolve as resolve29 } from "node:path";
|
|
37681
38452
|
init_bedrock();
|
|
37682
38453
|
var DEFAULT_DETONATE_MAX = 10;
|
|
37683
38454
|
var EX024 = "EX-024";
|
|
@@ -37715,7 +38486,7 @@ async function makeChamberClient(io, flag, real) {
|
|
|
37715
38486
|
return false;
|
|
37716
38487
|
}
|
|
37717
38488
|
}
|
|
37718
|
-
var RANK4 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
38489
|
+
var RANK4 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
37719
38490
|
function pickTargets(findings, max) {
|
|
37720
38491
|
const best = /* @__PURE__ */ new Map();
|
|
37721
38492
|
for (const f of findings) {
|
|
@@ -37756,12 +38527,12 @@ async function runDetonations(root, findings, client, max, def) {
|
|
|
37756
38527
|
for (const t2 of targets) {
|
|
37757
38528
|
let text;
|
|
37758
38529
|
try {
|
|
37759
|
-
text = readFileSync28(
|
|
38530
|
+
text = readFileSync28(join35(root, t2.file), "utf8");
|
|
37760
38531
|
} catch {
|
|
37761
38532
|
tally.inconclusive++;
|
|
37762
38533
|
continue;
|
|
37763
38534
|
}
|
|
37764
|
-
const r = await detonate(text, "file", client, { fileName:
|
|
38535
|
+
const r = await detonate(text, "file", client, { fileName: basename11(t2.file) });
|
|
37765
38536
|
calls += r.modelCalls;
|
|
37766
38537
|
tally[r.verdict]++;
|
|
37767
38538
|
reports.push({ file: t2.file, report: r });
|
|
@@ -37819,8 +38590,8 @@ ${DETONATE_HELP}`);
|
|
|
37819
38590
|
io.err(`Unknown format "${format}". Use text or json.`);
|
|
37820
38591
|
return 2;
|
|
37821
38592
|
}
|
|
37822
|
-
const abs =
|
|
37823
|
-
if (!
|
|
38593
|
+
const abs = resolve29(target);
|
|
38594
|
+
if (!existsSync21(abs) || !statSync18(abs).isFile()) {
|
|
37824
38595
|
io.err(`File not found: ${target}`);
|
|
37825
38596
|
return 2;
|
|
37826
38597
|
}
|
|
@@ -37830,7 +38601,7 @@ ${DETONATE_HELP}`);
|
|
|
37830
38601
|
}
|
|
37831
38602
|
const client = await makeChamberClient(io, "exorcist detonate", deps.client);
|
|
37832
38603
|
if (client === false) return 2;
|
|
37833
|
-
const report = await detonate(readFileSync28(abs, "utf8"), placement, client, { fileName:
|
|
38604
|
+
const report = await detonate(readFileSync28(abs, "utf8"), placement, client, { fileName: basename11(abs) });
|
|
37834
38605
|
if (format === "json") io.out(`${JSON.stringify({ file: target, model: modelIdFor("haiku"), ...report }, null, 2)}
|
|
37835
38606
|
`);
|
|
37836
38607
|
else io.out(renderTranscript(target, report));
|
|
@@ -37854,8 +38625,204 @@ function warnIfStale(io, o) {
|
|
|
37854
38625
|
);
|
|
37855
38626
|
}
|
|
37856
38627
|
|
|
38628
|
+
// src/home.ts
|
|
38629
|
+
import { closeSync as closeSync11, constants as constants10, fstatSync as fstatSync6, lstatSync as lstatSync15, openSync as openSync11, readdirSync as readdirSync12, readSync as readSync6 } from "node:fs";
|
|
38630
|
+
import { homedir as homedir9 } from "node:os";
|
|
38631
|
+
import { join as join36 } from "node:path";
|
|
38632
|
+
var HOME_MAX_BYTES = 1048576;
|
|
38633
|
+
var MAX_ENTRIES3 = 200;
|
|
38634
|
+
var CLINE_KEY = "saoudrizwan.claude-dev";
|
|
38635
|
+
var loadNodeSqlite = async () => {
|
|
38636
|
+
const spec2 = "node:sqlite";
|
|
38637
|
+
try {
|
|
38638
|
+
const mod = await import(spec2);
|
|
38639
|
+
const ctor = typeof mod === "object" && mod !== null ? mod.DatabaseSync : void 0;
|
|
38640
|
+
return typeof ctor === "function" ? mod : null;
|
|
38641
|
+
} catch {
|
|
38642
|
+
return null;
|
|
38643
|
+
}
|
|
38644
|
+
};
|
|
38645
|
+
function homeFolder(env = process.env) {
|
|
38646
|
+
const forced = env["EXORCIST_HOME"];
|
|
38647
|
+
return forced !== void 0 && forced !== "" ? forced : homedir9();
|
|
38648
|
+
}
|
|
38649
|
+
function readNoFollow(abs) {
|
|
38650
|
+
let st;
|
|
38651
|
+
try {
|
|
38652
|
+
st = lstatSync15(abs);
|
|
38653
|
+
} catch {
|
|
38654
|
+
return { kind: "missing" };
|
|
38655
|
+
}
|
|
38656
|
+
if (st.isSymbolicLink()) return { kind: "link" };
|
|
38657
|
+
if (!st.isFile()) return { kind: "not-file" };
|
|
38658
|
+
if (st.size > HOME_MAX_BYTES) return { kind: "too-large", size: st.size };
|
|
38659
|
+
let fd;
|
|
38660
|
+
try {
|
|
38661
|
+
fd = openSync11(abs, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0));
|
|
38662
|
+
} catch (e) {
|
|
38663
|
+
const code3 = e.code ?? "error";
|
|
38664
|
+
return code3 === "ELOOP" ? { kind: "link" } : { kind: "error", code: code3 };
|
|
38665
|
+
}
|
|
38666
|
+
try {
|
|
38667
|
+
const fst = fstatSync6(fd);
|
|
38668
|
+
if (!fst.isFile()) return { kind: "not-file" };
|
|
38669
|
+
if (fst.size > HOME_MAX_BYTES) return { kind: "too-large", size: fst.size };
|
|
38670
|
+
const buf = Buffer.alloc(HOME_MAX_BYTES + 1);
|
|
38671
|
+
let got = 0;
|
|
38672
|
+
for (; ; ) {
|
|
38673
|
+
const n = readSync6(fd, buf, got, buf.length - got, null);
|
|
38674
|
+
if (n === 0) break;
|
|
38675
|
+
got += n;
|
|
38676
|
+
if (got > HOME_MAX_BYTES) return { kind: "too-large", size: got };
|
|
38677
|
+
}
|
|
38678
|
+
return { kind: "ok", text: buf.subarray(0, got).toString("utf8") };
|
|
38679
|
+
} catch (e) {
|
|
38680
|
+
return { kind: "error", code: e.code ?? "error" };
|
|
38681
|
+
} finally {
|
|
38682
|
+
closeSync11(fd);
|
|
38683
|
+
}
|
|
38684
|
+
}
|
|
38685
|
+
function unreadable(file, kind) {
|
|
38686
|
+
return {
|
|
38687
|
+
source: "signature",
|
|
38688
|
+
ruleId: kind === "cline" ? "EX-007" : "EX-033",
|
|
38689
|
+
title: "Home settings file in an unknown format, not checked",
|
|
38690
|
+
severity: "medium",
|
|
38691
|
+
file,
|
|
38692
|
+
line: 1,
|
|
38693
|
+
col: 1,
|
|
38694
|
+
span: "unknown format, not checked",
|
|
38695
|
+
owasp: ["ASI02 Inadequate Human-in-the-Loop Controls", "LLM06:2025 Excessive Agency"],
|
|
38696
|
+
fix: "exorcist scan --home could not read this agent settings file, so its approval rules were not checked. Open it and check what it allows without asking."
|
|
38697
|
+
};
|
|
38698
|
+
}
|
|
38699
|
+
function tooLarge(file, size) {
|
|
38700
|
+
return {
|
|
38701
|
+
source: "signature",
|
|
38702
|
+
ruleId: "EX-026",
|
|
38703
|
+
title: "Home settings file too large to check",
|
|
38704
|
+
severity: "medium",
|
|
38705
|
+
file,
|
|
38706
|
+
line: 1,
|
|
38707
|
+
col: 1,
|
|
38708
|
+
span: `${(size / HOME_MAX_BYTES).toFixed(1)} MiB, not checked`,
|
|
38709
|
+
owasp: ["LLM01:2025 Prompt Injection", "ASI03 Prompt Injection via External Content"],
|
|
38710
|
+
fix: "This agent settings file is over 1 MiB, so exorcist scan --home did not read it. Settings files are far smaller: open it and check what it holds."
|
|
38711
|
+
};
|
|
38712
|
+
}
|
|
38713
|
+
var ANALYSE = { kiro: kiroPermissionsFindings, agent: kiroAgentFindings, cline: clineFindings };
|
|
38714
|
+
var UNREADABLE = { kiro: "Kiro's permissions", agent: "the Kiro agent profile", cline: "Cline's settings" };
|
|
38715
|
+
function entries(dir) {
|
|
38716
|
+
try {
|
|
38717
|
+
return readdirSync12(dir, { withFileTypes: true }).slice(0, MAX_ENTRIES3).map((d) => ({ name: d.name, dir: d.isDirectory(), file: d.isFile(), link: d.isSymbolicLink() })).sort((a, b) => a.name.localeCompare(b.name));
|
|
38718
|
+
} catch {
|
|
38719
|
+
return [];
|
|
38720
|
+
}
|
|
38721
|
+
}
|
|
38722
|
+
function vscdbPath(o) {
|
|
38723
|
+
const tail = ["Code", "User", "globalStorage", "state.vscdb"];
|
|
38724
|
+
const platform = o.platform ?? process.platform;
|
|
38725
|
+
if (platform === "darwin") return { abs: join36(o.home, "Library", "Application Support", ...tail), shown: `~/Library/Application Support/${tail.join("/")}` };
|
|
38726
|
+
if (platform === "win32") {
|
|
38727
|
+
const appData = o.appData ?? process.env["APPDATA"] ?? join36(o.home, "AppData", "Roaming");
|
|
38728
|
+
return { abs: join36(appData, ...tail), shown: `%APPDATA%/${tail.join("/")}` };
|
|
38729
|
+
}
|
|
38730
|
+
return { abs: join36(o.home, ".config", ...tail), shown: `~/.config/${tail.join("/")}` };
|
|
38731
|
+
}
|
|
38732
|
+
async function scanHome(o) {
|
|
38733
|
+
const out = { findings: [], notes: [], read: [] };
|
|
38734
|
+
const shown2 = (s) => displayFileName(s);
|
|
38735
|
+
const take = (abs, file, kind) => {
|
|
38736
|
+
const r = readNoFollow(abs);
|
|
38737
|
+
if (r.kind === "missing" || r.kind === "not-file") return;
|
|
38738
|
+
if (r.kind === "link") {
|
|
38739
|
+
out.notes.push(`${shown2(file)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38740
|
+
return;
|
|
38741
|
+
}
|
|
38742
|
+
if (r.kind === "too-large") {
|
|
38743
|
+
out.notes.push(`${shown2(file)} was not read: it is larger than 1 MiB.`);
|
|
38744
|
+
out.findings.push(tooLarge(file, r.size));
|
|
38745
|
+
return;
|
|
38746
|
+
}
|
|
38747
|
+
if (r.kind === "error") {
|
|
38748
|
+
out.notes.push(`Could not read ${shown2(file)} (${r.code}).`);
|
|
38749
|
+
return;
|
|
38750
|
+
}
|
|
38751
|
+
out.read.push(file);
|
|
38752
|
+
judge(r.text, file, kind);
|
|
38753
|
+
};
|
|
38754
|
+
const judge = (text, file, kind) => {
|
|
38755
|
+
const res = ANALYSE[kind](text, file);
|
|
38756
|
+
if (res.ok) out.findings.push(...res.findings);
|
|
38757
|
+
else {
|
|
38758
|
+
out.notes.push(`Could not read ${UNREADABLE[kind]} (${res.reason}): ${shown2(file)}.`);
|
|
38759
|
+
out.findings.push(unreadable(file, kind));
|
|
38760
|
+
}
|
|
38761
|
+
};
|
|
38762
|
+
take(join36(o.home, ".kiro", "settings", "permissions.yaml"), "~/.kiro/settings/permissions.yaml", "kiro");
|
|
38763
|
+
for (const e of entries(join36(o.home, ".kiro", "workspace-roots"))) {
|
|
38764
|
+
const file = `~/.kiro/workspace-roots/${e.name}/permissions.yaml`;
|
|
38765
|
+
if (e.link) out.notes.push(`${shown2(`~/.kiro/workspace-roots/${e.name}`)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38766
|
+
else if (e.dir) take(join36(o.home, ".kiro", "workspace-roots", e.name, "permissions.yaml"), file, "kiro");
|
|
38767
|
+
}
|
|
38768
|
+
for (const e of entries(join36(o.home, ".kiro", "agents"))) {
|
|
38769
|
+
if (!e.name.endsWith(".json")) continue;
|
|
38770
|
+
const file = `~/.kiro/agents/${e.name}`;
|
|
38771
|
+
if (e.link) out.notes.push(`${shown2(file)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38772
|
+
else if (e.file) take(join36(o.home, ".kiro", "agents", e.name), file, "agent");
|
|
38773
|
+
}
|
|
38774
|
+
take(join36(o.home, ".cline", "data", "globalState.json"), "~/.cline/data/globalState.json", "cline");
|
|
38775
|
+
await readVscdb(o, out, judge);
|
|
38776
|
+
return out;
|
|
38777
|
+
}
|
|
38778
|
+
async function readVscdb(o, out, judge) {
|
|
38779
|
+
const { abs, shown: shown2 } = vscdbPath(o);
|
|
38780
|
+
let st;
|
|
38781
|
+
try {
|
|
38782
|
+
st = lstatSync15(abs);
|
|
38783
|
+
} catch {
|
|
38784
|
+
return;
|
|
38785
|
+
}
|
|
38786
|
+
if (st.isSymbolicLink()) {
|
|
38787
|
+
out.notes.push(`${shown2} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38788
|
+
return;
|
|
38789
|
+
}
|
|
38790
|
+
if (!st.isFile()) return;
|
|
38791
|
+
const mod = await (o.loadSqlite ?? loadNodeSqlite)();
|
|
38792
|
+
if (!mod) {
|
|
38793
|
+
out.notes.push(`Could not read ${shown2}: this Node.js has no node:sqlite (Node 22.5 or later has it).`);
|
|
38794
|
+
return;
|
|
38795
|
+
}
|
|
38796
|
+
let value;
|
|
38797
|
+
try {
|
|
38798
|
+
const db = new mod.DatabaseSync(abs, { readOnly: true });
|
|
38799
|
+
try {
|
|
38800
|
+
const row = db.prepare("SELECT value FROM ItemTable WHERE key = ?").get(CLINE_KEY);
|
|
38801
|
+
value = typeof row === "object" && row !== null ? row.value : void 0;
|
|
38802
|
+
} finally {
|
|
38803
|
+
db.close();
|
|
38804
|
+
}
|
|
38805
|
+
} catch {
|
|
38806
|
+
out.notes.push(`Could not read ${shown2}: it is not a readable SQLite database.`);
|
|
38807
|
+
return;
|
|
38808
|
+
}
|
|
38809
|
+
if (value === void 0 || value === null) return;
|
|
38810
|
+
const text = typeof value === "string" ? value : value instanceof Uint8Array ? Buffer.from(value).toString("utf8") : null;
|
|
38811
|
+
if (text === null) {
|
|
38812
|
+
out.notes.push(`Could not read Cline's settings (unknown format): ${shown2}.`);
|
|
38813
|
+
return;
|
|
38814
|
+
}
|
|
38815
|
+
if (Buffer.byteLength(text, "utf8") > HOME_MAX_BYTES) {
|
|
38816
|
+
out.notes.push(`${shown2} was not read: Cline's settings in it are larger than 1 MiB.`);
|
|
38817
|
+
out.findings.push(tooLarge(shown2, Buffer.byteLength(text, "utf8")));
|
|
38818
|
+
return;
|
|
38819
|
+
}
|
|
38820
|
+
out.read.push(shown2);
|
|
38821
|
+
judge(text, shown2, "cline");
|
|
38822
|
+
}
|
|
38823
|
+
|
|
37857
38824
|
// src/commands/scan.ts
|
|
37858
|
-
var RANK5 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
38825
|
+
var RANK5 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
37859
38826
|
var SEVERITY_RANK2 = RANK5;
|
|
37860
38827
|
var FORMATS = ["text", "json", "sarif", "markdown", "badge"];
|
|
37861
38828
|
var MAX_AI_CALLS_PER_FILE = 2 * MAX_SPANS_PER_FILE;
|
|
@@ -37868,8 +38835,9 @@ Options:
|
|
|
37868
38835
|
--format <text|json|sarif|markdown|badge>
|
|
37869
38836
|
Output format (default: text). "badge" writes an
|
|
37870
38837
|
SVG README badge: "exorcised" or "possessed".
|
|
37871
|
-
--fail-on <critical|high|medium|low|none>
|
|
37872
|
-
Exit 1 if a finding is at least this bad (default: high)
|
|
38838
|
+
--fail-on <critical|high|medium|low|info|none>
|
|
38839
|
+
Exit 1 if a finding is at least this bad (default: high).
|
|
38840
|
+
Info findings never fail a scan unless --fail-on info is given.
|
|
37873
38841
|
--ignore <path> Skip a path prefix (repeatable).
|
|
37874
38842
|
--ignore-file <file> Skip the path prefixes listed in a file you name, one per
|
|
37875
38843
|
line. The file should live outside the scanned folder.
|
|
@@ -37894,6 +38862,8 @@ Options:
|
|
|
37894
38862
|
harmful. Nothing is executed. Needs AWS credentials and AWS_REGION;
|
|
37895
38863
|
at most 2 model calls per file. Off by default.
|
|
37896
38864
|
--detonate-max <n> Detonate at most n files (default ${DEFAULT_DETONATE_MAX})
|
|
38865
|
+
--home Opt-in, off by default: also read Kiro and Cline agent settings in your home folder.
|
|
38866
|
+
Only a fixed list of files is read (see REFERENCE, "--home").
|
|
37897
38867
|
Inline suppression (only with --trust-repo-ignores): a comment on the same line as a finding, or on the line
|
|
37898
38868
|
before it, silences one rule on that line, and the reason is listed in the report:
|
|
37899
38869
|
// exorcist-ignore EX-012: reviewed, this is documentation
|
|
@@ -37901,10 +38871,10 @@ Openers: // # <!-- /* -- ; A reason is required. Hidden characters (EX-00
|
|
|
37901
38871
|
secrets (EX-011) cannot be silenced this way. The comment's own text is still scanned.
|
|
37902
38872
|
`;
|
|
37903
38873
|
function readIgnoreFile(root) {
|
|
37904
|
-
return readIgnoreEntries(
|
|
38874
|
+
return readIgnoreEntries(join37(root, ".exorcistignore"));
|
|
37905
38875
|
}
|
|
37906
38876
|
function readIgnoreEntries(file) {
|
|
37907
|
-
if (!
|
|
38877
|
+
if (!existsSync22(file)) return [];
|
|
37908
38878
|
return readFileSync29(file, "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
|
|
37909
38879
|
}
|
|
37910
38880
|
function isIgnored(rel, prefixes) {
|
|
@@ -37952,7 +38922,7 @@ function renderText(findings, stats, suppressed, opts = { trust: false, repoIgno
|
|
|
37952
38922
|
if (f.source === "heuristic" && f.ruleId === EX024) lines.push(` chamber: ${displayMessage(f.rationale)}`);
|
|
37953
38923
|
lines.push(` fix: ${f.fix.replace(/\s+/g, " ").trim()}`);
|
|
37954
38924
|
}
|
|
37955
|
-
const counts = ["critical", "high", "medium", "low"].map((s) => ({ s, n: findings.filter((f) => f.severity === s).length })).filter((c) => c.n > 0).map((c) => `${c.n} ${c.s}`).join(", ");
|
|
38925
|
+
const counts = ["critical", "high", "medium", "low", "info"].map((s) => ({ s, n: findings.filter((f) => f.severity === s).length })).filter((c) => c.n > 0).map((c) => `${c.n} ${c.s}`).join(", ");
|
|
37956
38926
|
const withFindings = new Set(findings.map((f) => f.file)).size;
|
|
37957
38927
|
lines.push("", `${plural(findings.length, "threat")} in ${plural(withFindings, "file")} (${counts}). Scanned ${plural(stats.filesScanned, "file")}.`);
|
|
37958
38928
|
lines.push(...extra, verdict);
|
|
@@ -38009,14 +38979,14 @@ async function makeAiClient(rawMax, io, real) {
|
|
|
38009
38979
|
};
|
|
38010
38980
|
}
|
|
38011
38981
|
async function runScan(opts, io) {
|
|
38012
|
-
const abs =
|
|
38013
|
-
if (!
|
|
38982
|
+
const abs = resolve30(opts.target);
|
|
38983
|
+
if (!existsSync22(abs)) {
|
|
38014
38984
|
io.err(`Path not found: ${opts.target}`);
|
|
38015
38985
|
return { ok: false, code: 2 };
|
|
38016
38986
|
}
|
|
38017
38987
|
const isFile = statSync19(abs).isFile();
|
|
38018
|
-
const root = isFile ?
|
|
38019
|
-
const only = isFile ?
|
|
38988
|
+
const root = isFile ? dirname18(abs) : abs;
|
|
38989
|
+
const only = isFile ? basename12(abs) : null;
|
|
38020
38990
|
const defsDir = findDefinitionsDir2(opts.definitions);
|
|
38021
38991
|
if (!defsDir) {
|
|
38022
38992
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -38076,14 +39046,14 @@ async function runScan(opts, io) {
|
|
|
38076
39046
|
function makeRootReader(root) {
|
|
38077
39047
|
let realRoot;
|
|
38078
39048
|
try {
|
|
38079
|
-
realRoot =
|
|
39049
|
+
realRoot = realpathSync12(root);
|
|
38080
39050
|
} catch {
|
|
38081
39051
|
return () => null;
|
|
38082
39052
|
}
|
|
38083
39053
|
return (file) => {
|
|
38084
39054
|
try {
|
|
38085
|
-
const real =
|
|
38086
|
-
const rel =
|
|
39055
|
+
const real = realpathSync12(resolve30(realRoot, file));
|
|
39056
|
+
const rel = relative15(realRoot, real);
|
|
38087
39057
|
if (rel === "" || rel.startsWith("..") || isAbsolute21(rel)) return null;
|
|
38088
39058
|
if (statSync19(real).size > MAX_DIRECTIVE_FILE_BYTES) return null;
|
|
38089
39059
|
return readFileSync29(real, "utf8");
|
|
@@ -38112,7 +39082,8 @@ async function scanCommand(argv, io, deps = {}) {
|
|
|
38112
39082
|
ai: { type: "boolean" },
|
|
38113
39083
|
"ai-max-calls": { type: "string" },
|
|
38114
39084
|
detonate: { type: "boolean" },
|
|
38115
|
-
"detonate-max": { type: "string" }
|
|
39085
|
+
"detonate-max": { type: "string" },
|
|
39086
|
+
home: { type: "boolean" }
|
|
38116
39087
|
});
|
|
38117
39088
|
if (!p.ok) {
|
|
38118
39089
|
io.err(`${p.error}
|
|
@@ -38138,7 +39109,7 @@ ${SCAN_HELP}`);
|
|
|
38138
39109
|
}
|
|
38139
39110
|
const failOn = str4(p.values["fail-on"]) ?? "high";
|
|
38140
39111
|
if (failOn !== "none" && !(failOn in RANK5)) {
|
|
38141
|
-
io.err(`Unknown --fail-on "${failOn}". Use critical, high, medium, low or none.`);
|
|
39112
|
+
io.err(`Unknown --fail-on "${failOn}". Use critical, high, medium, low, info or none.`);
|
|
38142
39113
|
return 2;
|
|
38143
39114
|
}
|
|
38144
39115
|
const baselinePath = str4(p.values["baseline"]);
|
|
@@ -38146,7 +39117,7 @@ ${SCAN_HELP}`);
|
|
|
38146
39117
|
if (baselinePath !== void 0) {
|
|
38147
39118
|
let text;
|
|
38148
39119
|
try {
|
|
38149
|
-
text = readFileSync29(
|
|
39120
|
+
text = readFileSync29(resolve30(baselinePath), "utf8");
|
|
38150
39121
|
} catch {
|
|
38151
39122
|
io.err(`Could not read the baseline file ${baselinePath}. Check the path, or create one with: exorcist baseline <folder>`);
|
|
38152
39123
|
return 2;
|
|
@@ -38167,11 +39138,11 @@ ${SCAN_HELP}`);
|
|
|
38167
39138
|
const ignoreFilePath = str4(p.values["ignore-file"]);
|
|
38168
39139
|
let userIgnore = [];
|
|
38169
39140
|
if (ignoreFilePath !== void 0) {
|
|
38170
|
-
if (!
|
|
39141
|
+
if (!existsSync22(resolve30(ignoreFilePath))) {
|
|
38171
39142
|
io.err(`Could not read the ignore file ${ignoreFilePath}. Check the path.`);
|
|
38172
39143
|
return 2;
|
|
38173
39144
|
}
|
|
38174
|
-
userIgnore = readIgnoreEntries(
|
|
39145
|
+
userIgnore = readIgnoreEntries(resolve30(ignoreFilePath));
|
|
38175
39146
|
}
|
|
38176
39147
|
const held = { chamber: null, ai: null };
|
|
38177
39148
|
const result = await runScan({
|
|
@@ -38211,6 +39182,14 @@ ${SCAN_HELP}`);
|
|
|
38211
39182
|
}
|
|
38212
39183
|
stats = { ...stats, findingsTotal: findings.length };
|
|
38213
39184
|
const inline = applyInline(findings, makeRootReader(root));
|
|
39185
|
+
if (p.values["home"] === true) {
|
|
39186
|
+
const home = await (deps.homeScan ?? scanHome)({ home: homeFolder() });
|
|
39187
|
+
for (const n of home.notes) io.err(n);
|
|
39188
|
+
io.err(`Home settings (--home): read ${plural(home.read.length, "file")}.`);
|
|
39189
|
+
findings.push(...home.findings);
|
|
39190
|
+
inline.active.push(...home.findings);
|
|
39191
|
+
stats = { ...stats, findingsTotal: findings.length };
|
|
39192
|
+
}
|
|
38214
39193
|
let working = inline.active;
|
|
38215
39194
|
const honoured = trust ? inline.suppressed : [];
|
|
38216
39195
|
if (!trust) {
|
|
@@ -38278,7 +39257,7 @@ ${BASELINE_HELP}`);
|
|
|
38278
39257
|
}
|
|
38279
39258
|
const target = p.positionals[0] ?? ".";
|
|
38280
39259
|
try {
|
|
38281
|
-
if (!statSync20(
|
|
39260
|
+
if (!statSync20(resolve31(target)).isDirectory()) {
|
|
38282
39261
|
io.err(`${target} is a file. Give a folder to baseline.`);
|
|
38283
39262
|
return 2;
|
|
38284
39263
|
}
|
|
@@ -38291,7 +39270,7 @@ ${BASELINE_HELP}`);
|
|
|
38291
39270
|
const { findings, root } = result.run;
|
|
38292
39271
|
const { active } = applyInline(findings, makeRootReader(root));
|
|
38293
39272
|
const baseline = buildBaseline(active);
|
|
38294
|
-
const out = str4(p.values["output"]) ??
|
|
39273
|
+
const out = str4(p.values["output"]) ?? join38(root, BASELINE_FILE);
|
|
38295
39274
|
try {
|
|
38296
39275
|
writeFileSync9(out, `${JSON.stringify(baseline, null, 2)}
|
|
38297
39276
|
`, "utf8");
|
|
@@ -38304,7 +39283,7 @@ ${BASELINE_HELP}`);
|
|
|
38304
39283
|
}
|
|
38305
39284
|
|
|
38306
39285
|
// src/commands/canary.ts
|
|
38307
|
-
import { resolve as
|
|
39286
|
+
import { resolve as resolve32 } from "node:path";
|
|
38308
39287
|
var CANARY_HELP = `Usage: exorcist canary plant [dir] Plant canary traps in a project (3 by default)
|
|
38309
39288
|
exorcist canary --list [dir] Show the planted traps
|
|
38310
39289
|
exorcist canary --remove [dir] Remove the trap files and their records
|
|
@@ -38352,7 +39331,7 @@ ${CANARY_HELP}`);
|
|
|
38352
39331
|
${CANARY_HELP}`);
|
|
38353
39332
|
return 2;
|
|
38354
39333
|
}
|
|
38355
|
-
const dir =
|
|
39334
|
+
const dir = resolve32(positionals[0] ?? ".");
|
|
38356
39335
|
const wantList = p.values["list"] === true || sub === "list";
|
|
38357
39336
|
const wantRemove = p.values["remove"] === true || sub === "remove";
|
|
38358
39337
|
const wantPlant = sub === "plant";
|
|
@@ -38364,13 +39343,13 @@ ${CANARY_HELP}`);
|
|
|
38364
39343
|
}
|
|
38365
39344
|
const explicitDir = str4(p.values["dir"]);
|
|
38366
39345
|
const state = explicitDir !== void 0 || process.env["EXORCIST_DIR"] ? stateDir(explicitDir) : void 0;
|
|
38367
|
-
if (wantList) return
|
|
39346
|
+
if (wantList) return list2(io, dir);
|
|
38368
39347
|
if (wantRemove) return remove(io, dir, state);
|
|
38369
39348
|
const countRaw = str4(p.values["count"]);
|
|
38370
39349
|
const count = countRaw === void 0 ? 3 : Number(countRaw);
|
|
38371
39350
|
return plant(io, dir, state, count);
|
|
38372
39351
|
}
|
|
38373
|
-
function
|
|
39352
|
+
function list2(io, dir) {
|
|
38374
39353
|
const r = loadCanaries(dir);
|
|
38375
39354
|
if (!r.ok) {
|
|
38376
39355
|
io.err(`Exorcist 98: ${r.error}`);
|
|
@@ -38417,9 +39396,9 @@ function remove(io, dir, state) {
|
|
|
38417
39396
|
}
|
|
38418
39397
|
|
|
38419
39398
|
// src/commands/config.ts
|
|
38420
|
-
import { createHash as
|
|
38421
|
-
import { existsSync as
|
|
38422
|
-
import { join as
|
|
39399
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
39400
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync11, readFileSync as readFileSync30, rmSync as rmSync5, writeFileSync as writeFileSync10 } from "node:fs";
|
|
39401
|
+
import { join as join39, resolve as resolve33 } from "node:path";
|
|
38423
39402
|
var WRAP_HELP = `Usage: exorcist wrap <mcp.json> [options]
|
|
38424
39403
|
exorcist unwrap <mcp.json>
|
|
38425
39404
|
|
|
@@ -38430,12 +39409,12 @@ unwrap Put the original file back byte for byte, if it was not edited since
|
|
|
38430
39409
|
|
|
38431
39410
|
Options (wrap):
|
|
38432
39411
|
--bin <command> Command that runs the shield (default: exorcist)
|
|
38433
|
-
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.
|
|
39412
|
+
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.8
|
|
38434
39413
|
--dir <folder> State folder (default: ${DEFAULT_DIR})
|
|
38435
39414
|
--dry-run Show the result without writing the file
|
|
38436
39415
|
`;
|
|
38437
39416
|
function backupPath(dir, configPath) {
|
|
38438
|
-
return
|
|
39417
|
+
return join39(dir, "wrap-backups", `${createHash15("sha256").update(configPath).digest("hex").slice(0, 32)}.json`);
|
|
38439
39418
|
}
|
|
38440
39419
|
function readBackup(file) {
|
|
38441
39420
|
try {
|
|
@@ -38457,7 +39436,7 @@ function dirsInConfig(cfg) {
|
|
|
38457
39436
|
return out;
|
|
38458
39437
|
}
|
|
38459
39438
|
function readConfig2(path, io) {
|
|
38460
|
-
if (!
|
|
39439
|
+
if (!existsSync23(path)) {
|
|
38461
39440
|
io.err(`File not found: ${path}`);
|
|
38462
39441
|
return null;
|
|
38463
39442
|
}
|
|
@@ -38495,7 +39474,7 @@ ${WRAP_HELP}`);
|
|
|
38495
39474
|
${WRAP_HELP}`);
|
|
38496
39475
|
return 2;
|
|
38497
39476
|
}
|
|
38498
|
-
const path =
|
|
39477
|
+
const path = resolve33(file);
|
|
38499
39478
|
const cfg = readConfig2(path, io);
|
|
38500
39479
|
if (!cfg) return 2;
|
|
38501
39480
|
const text = readFileSync30(path, "utf8");
|
|
@@ -38524,7 +39503,7 @@ ${WRAP_HELP}`);
|
|
|
38524
39503
|
writeFileSync10(path, out, "utf8");
|
|
38525
39504
|
const b = backupPath(stateDir(str4(p.values["dir"])), path);
|
|
38526
39505
|
try {
|
|
38527
|
-
|
|
39506
|
+
mkdirSync11(join39(b, ".."), { recursive: true, mode: 448 });
|
|
38528
39507
|
writeFileSync10(b, JSON.stringify({ path, original: text, wrapped: out }), { mode: 384 });
|
|
38529
39508
|
} catch {
|
|
38530
39509
|
io.err("Could not save a copy of the original file; unwrap will still restore the original commands.");
|
|
@@ -38583,7 +39562,7 @@ import { randomBytes as randomBytes11, timingSafeEqual as timingSafeEqual2 } fro
|
|
|
38583
39562
|
import { createServer } from "node:http";
|
|
38584
39563
|
|
|
38585
39564
|
// src/console/model.ts
|
|
38586
|
-
import { lstatSync as
|
|
39565
|
+
import { lstatSync as lstatSync16, readdirSync as readdirSync13 } from "node:fs";
|
|
38587
39566
|
var BACKLOG = 400;
|
|
38588
39567
|
var MAX_SHIELDS = 64;
|
|
38589
39568
|
var MAX_SESSIONS = 16;
|
|
@@ -38625,9 +39604,15 @@ var ConsoleModel = class {
|
|
|
38625
39604
|
* (size, mtime, inode), so a quiet folder costs a few stat calls per poll. Read-only.
|
|
38626
39605
|
*/
|
|
38627
39606
|
chainState() {
|
|
38628
|
-
const
|
|
39607
|
+
const loc = resolveLogLocation(this.dir);
|
|
39608
|
+
if (!loc.ok) {
|
|
39609
|
+
this.chainCache = { chain: { status: "broken", atSeq: 1, reason: "head-mismatch", detail: `the event log folder was refused: ${loc.error}` }, chainHead: null };
|
|
39610
|
+
return this.chainCache;
|
|
39611
|
+
}
|
|
39612
|
+
const logDir = loc.dir;
|
|
39613
|
+
const sig = [eventsPath(logDir), oldEventsPath(logDir), headPath(logDir), genesisPath(logDir)].map((p) => {
|
|
38629
39614
|
try {
|
|
38630
|
-
const st =
|
|
39615
|
+
const st = lstatSync16(p);
|
|
38631
39616
|
return `${st.ino}:${st.size}:${st.mtimeMs}`;
|
|
38632
39617
|
} catch {
|
|
38633
39618
|
return "-";
|
|
@@ -38636,7 +39621,7 @@ var ConsoleModel = class {
|
|
|
38636
39621
|
if (sig === this.chainSig) return this.chainCache;
|
|
38637
39622
|
this.chainSig = sig;
|
|
38638
39623
|
const present = sig.split("|").some((x, i) => x !== "-" && i !== 3);
|
|
38639
|
-
const h = readHead(
|
|
39624
|
+
const h = readHead(logDir);
|
|
38640
39625
|
const chainHead = h.ok && h.value ? { seq: h.value.seq, hash: h.value.hash } : null;
|
|
38641
39626
|
this.chainCache = { chain: present ? verifyLogDir(this.dir) : null, chainHead };
|
|
38642
39627
|
return this.chainCache;
|
|
@@ -38710,7 +39695,7 @@ var ConsoleModel = class {
|
|
|
38710
39695
|
const root = sessionsPath(this.dir);
|
|
38711
39696
|
let names = [];
|
|
38712
39697
|
try {
|
|
38713
|
-
names =
|
|
39698
|
+
names = readdirSync13(root).filter((k) => isSessionKey(k));
|
|
38714
39699
|
} catch {
|
|
38715
39700
|
names = [];
|
|
38716
39701
|
}
|
|
@@ -38719,7 +39704,7 @@ var ConsoleModel = class {
|
|
|
38719
39704
|
for (const key of [...keys].slice(0, 256)) {
|
|
38720
39705
|
let isDir2 = false;
|
|
38721
39706
|
try {
|
|
38722
|
-
isDir2 =
|
|
39707
|
+
isDir2 = lstatSync16(`${root}/${key}`).isDirectory();
|
|
38723
39708
|
} catch {
|
|
38724
39709
|
isDir2 = false;
|
|
38725
39710
|
}
|
|
@@ -39500,11 +40485,11 @@ data: ${data}
|
|
|
39500
40485
|
});
|
|
39501
40486
|
server.headersTimeout = 1e4;
|
|
39502
40487
|
server.requestTimeout = 0;
|
|
39503
|
-
await new Promise((
|
|
40488
|
+
await new Promise((resolve42, reject2) => {
|
|
39504
40489
|
server.once("error", reject2);
|
|
39505
40490
|
server.listen(o.port ?? 0, "127.0.0.1", () => {
|
|
39506
40491
|
server.off("error", reject2);
|
|
39507
|
-
|
|
40492
|
+
resolve42();
|
|
39508
40493
|
});
|
|
39509
40494
|
});
|
|
39510
40495
|
port = server.address().port;
|
|
@@ -39550,8 +40535,9 @@ Exit codes: 0 the log is intact, or has no chain yet ("not chained", an old log)
|
|
|
39550
40535
|
2 usage error.
|
|
39551
40536
|
`;
|
|
39552
40537
|
var HEX643 = /^[0-9a-f]{64}$/;
|
|
39553
|
-
var
|
|
39554
|
-
var
|
|
40538
|
+
var eventsOffNote = (time3) => `Note: logging was turned off by your user-level config at ${plain3(time3)}: a Shield started under that setting writes no events, so an empty or short log after that time is not evidence that nothing happened.`;
|
|
40539
|
+
var eventsOffSince = (dir) => readEventsOffSince(dir);
|
|
40540
|
+
var envSwitchNote = (env = process.env) => env["EXORCIST_EVENTS"] === "0" ? 'Note: EXORCIST_EVENTS=0 is set in this environment, but it is ignored: it does not turn event logging off. Only "events": "off" in your user-level policy does.' : null;
|
|
39555
40541
|
function parseExpect(raw) {
|
|
39556
40542
|
const v = raw.trim().toLowerCase();
|
|
39557
40543
|
if (HEX643.test(v)) return { kind: "tip", hash: v };
|
|
@@ -39638,9 +40624,13 @@ ${VERIFY_LOG_HELP}`);
|
|
|
39638
40624
|
return 2;
|
|
39639
40625
|
}
|
|
39640
40626
|
}
|
|
39641
|
-
const
|
|
39642
|
-
|
|
39643
|
-
|
|
40627
|
+
const dir = stateDir(str4(p.values["dir"]));
|
|
40628
|
+
const status2 = run2(dir, expect);
|
|
40629
|
+
const offAt = eventsOffSince(dir);
|
|
40630
|
+
if (offAt !== null) io.err(eventsOffNote(offAt));
|
|
40631
|
+
const envNote = envSwitchNote();
|
|
40632
|
+
if (envNote !== null) io.err(envNote);
|
|
40633
|
+
io.out(p.values["json"] === true ? JSON.stringify(offAt !== null ? { ...status2, loggingTurnedOff: true, eventsOffSince: offAt } : status2) : describe(status2, expect !== null));
|
|
39644
40634
|
if (status2.status === "broken") return 1;
|
|
39645
40635
|
if (status2.status === "not-chained" && expect !== null) return 1;
|
|
39646
40636
|
return 0;
|
|
@@ -39676,11 +40666,11 @@ function openCommand(platform, url) {
|
|
|
39676
40666
|
if (platform === "win32") return { file: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
|
|
39677
40667
|
return { file: "xdg-open", args: [url] };
|
|
39678
40668
|
}
|
|
39679
|
-
var untilSignal = () => new Promise((
|
|
40669
|
+
var untilSignal = () => new Promise((resolve42) => {
|
|
39680
40670
|
const stop2 = () => {
|
|
39681
40671
|
process.off("SIGINT", stop2);
|
|
39682
40672
|
process.off("SIGTERM", stop2);
|
|
39683
|
-
|
|
40673
|
+
resolve42();
|
|
39684
40674
|
};
|
|
39685
40675
|
process.on("SIGINT", stop2);
|
|
39686
40676
|
process.on("SIGTERM", stop2);
|
|
@@ -39698,8 +40688,12 @@ ${CONSOLE_HELP}`);
|
|
|
39698
40688
|
return 0;
|
|
39699
40689
|
}
|
|
39700
40690
|
if (p.values["verify"] === true) {
|
|
39701
|
-
|
|
39702
|
-
const
|
|
40691
|
+
const verifyDir = stateDir(str4(p.values["dir"]));
|
|
40692
|
+
const offAt = eventsOffSince(verifyDir);
|
|
40693
|
+
if (offAt !== null) io.err(eventsOffNote(offAt));
|
|
40694
|
+
const envNote = envSwitchNote();
|
|
40695
|
+
if (envNote !== null) io.err(envNote);
|
|
40696
|
+
const status2 = verifyLogDir(verifyDir);
|
|
39703
40697
|
if (status2.status === "broken") {
|
|
39704
40698
|
io.out(`TAMPERED: the event log is broken at event ${status2.atSeq}. ${status2.detail.replace(/[^\x20-\x7e]/g, "?")}`);
|
|
39705
40699
|
return 1;
|
|
@@ -39728,7 +40722,10 @@ ${CONSOLE_HELP}`);
|
|
|
39728
40722
|
return 1;
|
|
39729
40723
|
}
|
|
39730
40724
|
io.out(`Exorcist 98 Shield console (read-only) for ${dir}`);
|
|
39731
|
-
|
|
40725
|
+
const offAtStart = eventsOffSince(dir);
|
|
40726
|
+
if (offAtStart !== null) io.out(eventsOffNote(offAtStart));
|
|
40727
|
+
const envNoteAtStart = envSwitchNote();
|
|
40728
|
+
if (envNoteAtStart !== null) io.out(envNoteAtStart);
|
|
39732
40729
|
if (p.values["no-open"] === true) {
|
|
39733
40730
|
io.out(` ${server.url}`);
|
|
39734
40731
|
io.out("Only this machine can open it, and only with the token in the URL. Press Ctrl+C to stop.");
|
|
@@ -39750,8 +40747,8 @@ ${CONSOLE_HELP}`);
|
|
|
39750
40747
|
}
|
|
39751
40748
|
|
|
39752
40749
|
// src/commands/exorcise.ts
|
|
39753
|
-
import { existsSync as
|
|
39754
|
-
import { basename as
|
|
40750
|
+
import { existsSync as existsSync24, readFileSync as readFileSync31, statSync as statSync21 } from "node:fs";
|
|
40751
|
+
import { basename as basename13, dirname as dirname19, isAbsolute as isAbsolute22, relative as relative16, resolve as resolve34 } from "node:path";
|
|
39755
40752
|
var EXORCISE_HELP = `Usage: exorcist exorcise [path] [options]
|
|
39756
40753
|
|
|
39757
40754
|
Disinfect: repair the threats that have one safe, mechanical fix, and report
|
|
@@ -39835,14 +40832,14 @@ ${EXORCISE_HELP}`);
|
|
|
39835
40832
|
return 2;
|
|
39836
40833
|
}
|
|
39837
40834
|
const target = p.positionals[0] ?? ".";
|
|
39838
|
-
const abs =
|
|
39839
|
-
if (!
|
|
40835
|
+
const abs = resolve34(target);
|
|
40836
|
+
if (!existsSync24(abs)) {
|
|
39840
40837
|
io.err(`Path not found: ${target}`);
|
|
39841
40838
|
return 2;
|
|
39842
40839
|
}
|
|
39843
40840
|
const isFile = statSync21(abs).isFile();
|
|
39844
|
-
const root = isFile ?
|
|
39845
|
-
const single = isFile ?
|
|
40841
|
+
const root = isFile ? dirname19(abs) : abs;
|
|
40842
|
+
const single = isFile ? basename13(abs) : null;
|
|
39846
40843
|
const defsDir = findDefinitionsDir2(str4(p.values["definitions"]));
|
|
39847
40844
|
if (!defsDir) {
|
|
39848
40845
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -39860,7 +40857,7 @@ ${EXORCISE_HELP}`);
|
|
|
39860
40857
|
return 2;
|
|
39861
40858
|
}
|
|
39862
40859
|
const vault = vaultPath(stateDir(str4(p.values["dir"])));
|
|
39863
|
-
const state =
|
|
40860
|
+
const state = relative16(root, resolve34(vault, ".."));
|
|
39864
40861
|
const ignore = [...strs(p.values["ignore"]), ...readIgnoreFile(root)];
|
|
39865
40862
|
if (state === "") ignore.push("vault");
|
|
39866
40863
|
else if (!state.startsWith("..") && !isAbsolute22(state)) ignore.push(state.replace(/\\/g, "/"));
|
|
@@ -39909,7 +40906,7 @@ ${EXORCISE_HELP}`);
|
|
|
39909
40906
|
return 1;
|
|
39910
40907
|
}
|
|
39911
40908
|
const changedSet = new Set(changed.map((r) => r.file));
|
|
39912
|
-
const now = changed.map((r) => ({ file: r.file, text: readFileSync31(
|
|
40909
|
+
const now = changed.map((r) => ({ file: r.file, text: readFileSync31(resolve34(root, r.file), "utf8") }));
|
|
39913
40910
|
const after = [...findings.filter((f) => !changedSet.has(f.file)), ...rescanTexts(now, defs).filter((f) => keep(f.file))];
|
|
39914
40911
|
const removed = Math.max(0, findings.length - after.length);
|
|
39915
40912
|
const dirFlag = str4(p.values["dir"]) ? ` --dir ${str4(p.values["dir"])}` : "";
|
|
@@ -39928,10 +40925,10 @@ ${EXORCISE_HELP}`);
|
|
|
39928
40925
|
}
|
|
39929
40926
|
|
|
39930
40927
|
// src/commands/gate.ts
|
|
39931
|
-
import { existsSync as
|
|
40928
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
39932
40929
|
import { lstat as lstat2, readFile as readFile6 } from "node:fs/promises";
|
|
39933
|
-
import { resolve as
|
|
39934
|
-
var GATE_HELP = `Usage: exorcist gate [dir] [--fail-on <critical|high|medium|low>] [--dir <state folder>]
|
|
40930
|
+
import { resolve as resolve35 } from "node:path";
|
|
40931
|
+
var GATE_HELP = `Usage: exorcist gate [dir] [--fail-on <critical|high|medium|low|info>] [--dir <state folder>]
|
|
39935
40932
|
The gate for the end of an agent's turn. It looks only at the files an AI agent
|
|
39936
40933
|
obeys (steering, specs, hooks, custom agents, MCP configs, AGENTS.md and the
|
|
39937
40934
|
other rule files, READMEs) that changed since the last commit, and exits 1 with
|
|
@@ -39944,7 +40941,7 @@ When the Shield's state folder has an event-log head file, its head hash is
|
|
|
39944
40941
|
printed too (see "exorcist verify-log").
|
|
39945
40942
|
The Kiro hook written by "exorcist init" runs it when the agent stops.
|
|
39946
40943
|
`;
|
|
39947
|
-
var THRESHOLDS = ["critical", "high", "medium", "low"];
|
|
40944
|
+
var THRESHOLDS = ["critical", "high", "medium", "low", "info"];
|
|
39948
40945
|
var GIT_MS = 1e4;
|
|
39949
40946
|
function headLine(explicit) {
|
|
39950
40947
|
const h = readHead(stateDir(explicit));
|
|
@@ -40014,8 +41011,8 @@ ${GATE_HELP}`);
|
|
|
40014
41011
|
${GATE_HELP}`);
|
|
40015
41012
|
return 2;
|
|
40016
41013
|
}
|
|
40017
|
-
const start =
|
|
40018
|
-
if (!
|
|
41014
|
+
const start = resolve35(p.positionals[0] ?? ".");
|
|
41015
|
+
if (!existsSync25(start)) return nothingChecked(io, "that folder does not exist");
|
|
40019
41016
|
const top = await gitRepoRoot(start);
|
|
40020
41017
|
if (!top) return nothingChecked(io, "this folder is not a git repository, or git is not available");
|
|
40021
41018
|
const repo = { root: top };
|
|
@@ -40032,7 +41029,7 @@ ${GATE_HELP}`);
|
|
|
40032
41029
|
const onDisk = [];
|
|
40033
41030
|
const sizes = /* @__PURE__ */ new Map();
|
|
40034
41031
|
for (const rel of changed.files) {
|
|
40035
|
-
const info = await lstat2(
|
|
41032
|
+
const info = await lstat2(resolve35(repo.root, rel)).catch(() => null);
|
|
40036
41033
|
if (!info || !info.isFile()) continue;
|
|
40037
41034
|
onDisk.push(rel);
|
|
40038
41035
|
sizes.set(rel, info.size);
|
|
@@ -40049,7 +41046,7 @@ ${GATE_HELP}`);
|
|
|
40049
41046
|
if (f) added.push(f);
|
|
40050
41047
|
continue;
|
|
40051
41048
|
}
|
|
40052
|
-
const after = await readFile6(
|
|
41049
|
+
const after = await readFile6(resolve35(repo.root, rel), "utf8").catch(() => null);
|
|
40053
41050
|
if (after === null) continue;
|
|
40054
41051
|
const before = then.has(rel) ? await committed(repo.root, rel) : null;
|
|
40055
41052
|
added.push(...gateFindings(rel, before, after, defs));
|
|
@@ -40067,8 +41064,8 @@ ${head}`);
|
|
|
40067
41064
|
|
|
40068
41065
|
// src/commands/guard-mcp-write.ts
|
|
40069
41066
|
import { randomBytes as randomBytes12 } from "node:crypto";
|
|
40070
|
-
import { createReadStream, createWriteStream, openSync as
|
|
40071
|
-
import { homedir as
|
|
41067
|
+
import { createReadStream, createWriteStream, openSync as openSync12, writeSync as writeSync8 } from "node:fs";
|
|
41068
|
+
import { homedir as homedir10 } from "node:os";
|
|
40072
41069
|
import { createInterface as createInterface2 } from "node:readline";
|
|
40073
41070
|
var GUARD_MCP_WRITE_HELP = `Usage: exorcist guard-mcp-write (Kiro hook helper)
|
|
40074
41071
|
Reads a Kiro PreToolUse hook event from stdin. When the tool would write to
|
|
@@ -40087,14 +41084,14 @@ var PROMPT_TIMEOUT_MS = 125e3;
|
|
|
40087
41084
|
function hookDeps() {
|
|
40088
41085
|
let fd = null;
|
|
40089
41086
|
try {
|
|
40090
|
-
fd =
|
|
41087
|
+
fd = openSync12("/dev/tty", "r+");
|
|
40091
41088
|
} catch {
|
|
40092
41089
|
fd = null;
|
|
40093
41090
|
}
|
|
40094
41091
|
const tty = fd;
|
|
40095
41092
|
const write = (s) => {
|
|
40096
41093
|
if (tty !== null) try {
|
|
40097
|
-
|
|
41094
|
+
writeSync8(tty, s.endsWith("\n") ? s : `${s}
|
|
40098
41095
|
`);
|
|
40099
41096
|
} catch {
|
|
40100
41097
|
}
|
|
@@ -40118,7 +41115,7 @@ function hookDeps() {
|
|
|
40118
41115
|
dialog: macDialog,
|
|
40119
41116
|
nonce: () => randomBytes12(4).toString("hex").slice(0, 6)
|
|
40120
41117
|
};
|
|
40121
|
-
return { term, promptIo: { out: write, err: write }, home:
|
|
41118
|
+
return { term, promptIo: { out: write, err: write }, home: homedir10(), timeoutMs: PROMPT_TIMEOUT_MS };
|
|
40122
41119
|
}
|
|
40123
41120
|
function dialogMessage(kind, path) {
|
|
40124
41121
|
if (kind === "trusted-commands") return `Your AI agent wants to change which commands it may run without asking you:
|
|
@@ -40216,10 +41213,10 @@ function guardEnvWriteCommand(stdin, io) {
|
|
|
40216
41213
|
}
|
|
40217
41214
|
|
|
40218
41215
|
// src/commands/guard-web-fetch.ts
|
|
40219
|
-
import { createHash as
|
|
41216
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
40220
41217
|
import { readFileSync as readFileSync32, writeFileSync as writeFileSync11 } from "node:fs";
|
|
40221
|
-
import { tmpdir as
|
|
40222
|
-
import { isAbsolute as isAbsolute24, join as
|
|
41218
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
41219
|
+
import { isAbsolute as isAbsolute24, join as join40 } from "node:path";
|
|
40223
41220
|
var GUARD_WEB_FETCH_HELP = `Usage: exorcist guard-web-fetch (Kiro hook helper)
|
|
40224
41221
|
Reads a Kiro PreToolUse hook event for the web_fetch tool from stdin. When the
|
|
40225
41222
|
address holds a secret (a key or token), a canary token, or a value from a .env
|
|
@@ -40255,8 +41252,8 @@ function guardWebFetchCommand(stdin, io) {
|
|
|
40255
41252
|
}
|
|
40256
41253
|
function sentStore(cwd, event) {
|
|
40257
41254
|
const sid = typeof event === "object" && event !== null && typeof event["session_id"] === "string" ? String(event["session_id"]) : "";
|
|
40258
|
-
const id =
|
|
40259
|
-
const file =
|
|
41255
|
+
const id = createHash16("sha256").update(`${cwd}\0${sid}`).digest("hex").slice(0, 24);
|
|
41256
|
+
const file = join40(tmpdir3(), `exorcist98-sent-${id}.json`);
|
|
40260
41257
|
return {
|
|
40261
41258
|
load: () => {
|
|
40262
41259
|
try {
|
|
@@ -40358,8 +41355,8 @@ async function guardShellReadCommand(stdin, io) {
|
|
|
40358
41355
|
}
|
|
40359
41356
|
|
|
40360
41357
|
// src/commands/hook-scan.ts
|
|
40361
|
-
import { existsSync as
|
|
40362
|
-
import { resolve as
|
|
41358
|
+
import { existsSync as existsSync26, statSync as statSync22 } from "node:fs";
|
|
41359
|
+
import { resolve as resolve36 } from "node:path";
|
|
40363
41360
|
async function hookScanCommand(stdin, io) {
|
|
40364
41361
|
let event;
|
|
40365
41362
|
try {
|
|
@@ -40369,14 +41366,14 @@ async function hookScanCommand(stdin, io) {
|
|
|
40369
41366
|
}
|
|
40370
41367
|
if (typeof event.file_path !== "string" || event.file_path === "") return 0;
|
|
40371
41368
|
const base = typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
|
|
40372
|
-
const file =
|
|
40373
|
-
if (!
|
|
41369
|
+
const file = resolve36(base, event.file_path);
|
|
41370
|
+
if (!existsSync26(file) || !statSync22(file).isFile()) return 0;
|
|
40374
41371
|
return await scanCommand([file, "--fail-on", "high"], { out: io.err, err: io.err });
|
|
40375
41372
|
}
|
|
40376
41373
|
|
|
40377
41374
|
// src/commands/init.ts
|
|
40378
|
-
import { chmodSync, existsSync as
|
|
40379
|
-
import { dirname as
|
|
41375
|
+
import { chmodSync, existsSync as existsSync27, lstatSync as lstatSync17, mkdirSync as mkdirSync12, readFileSync as readFileSync33, writeFileSync as writeFileSync12 } from "node:fs";
|
|
41376
|
+
import { dirname as dirname20, join as join41, resolve as resolve37 } from "node:path";
|
|
40380
41377
|
|
|
40381
41378
|
// src/kiro-hook-script.ts
|
|
40382
41379
|
var KIRO_HOOK_SCRIPT = [
|
|
@@ -40504,8 +41501,8 @@ function reviewerAgentForProject(mcpCommand) {
|
|
|
40504
41501
|
}
|
|
40505
41502
|
|
|
40506
41503
|
// src/commands/init.ts
|
|
40507
|
-
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.
|
|
40508
|
-
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.
|
|
41504
|
+
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.8";
|
|
41505
|
+
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.8";
|
|
40509
41506
|
var MISSING_FROM_DEFAULT_BIN = /* @__PURE__ */ new Set();
|
|
40510
41507
|
var INIT_HELP = `Usage: exorcist init [folder] [--kiro] [--shield] [--sandbox] [--no-agent] [--force]
|
|
40511
41508
|
[--bin <command>] [--mcp-bin <command>]
|
|
@@ -40544,15 +41541,15 @@ Existing files are never overwritten unless you pass --force.
|
|
|
40544
41541
|
var SANDBOX_REL = ".kiro/settings/sandbox.json";
|
|
40545
41542
|
var SANDBOX_SETTINGS = { enabled: true, networkAccess: "DEFAULT_BLOCKED", mcpSandboxing: true };
|
|
40546
41543
|
function writeSandboxFile(root, io) {
|
|
40547
|
-
const path =
|
|
41544
|
+
const path = join41(root, SANDBOX_REL);
|
|
40548
41545
|
let present = false;
|
|
40549
41546
|
try {
|
|
40550
|
-
|
|
41547
|
+
lstatSync17(path);
|
|
40551
41548
|
present = true;
|
|
40552
41549
|
} catch {
|
|
40553
41550
|
}
|
|
40554
41551
|
if (!present) {
|
|
40555
|
-
|
|
41552
|
+
mkdirSync12(dirname20(path), { recursive: true });
|
|
40556
41553
|
try {
|
|
40557
41554
|
writeFileSync12(path, `${JSON.stringify(SANDBOX_SETTINGS, null, 2)}
|
|
40558
41555
|
`, { encoding: "utf8", flag: "wx" });
|
|
@@ -40566,7 +41563,7 @@ function writeSandboxFile(root, io) {
|
|
|
40566
41563
|
io.out(`Left ${SANDBOX_REL} unchanged: it already exists. Delete it and rerun to get the Exorcist settings.`);
|
|
40567
41564
|
return false;
|
|
40568
41565
|
}
|
|
40569
|
-
var
|
|
41566
|
+
var hook2 = (name, description, body) => `${JSON.stringify({ version: "v1", hooks: [{ name, description, ...body }] }, null, 2)}
|
|
40570
41567
|
`;
|
|
40571
41568
|
var STEERING = `---
|
|
40572
41569
|
inclusion: always
|
|
@@ -40618,13 +41615,13 @@ function splitCommand(s) {
|
|
|
40618
41615
|
}
|
|
40619
41616
|
var MAX_NAME = 60;
|
|
40620
41617
|
function describeMcpConfig(path) {
|
|
40621
|
-
if (!
|
|
41618
|
+
if (!existsSync27(path)) return { exists: false, warnings: [], line: "no .kiro/settings/mcp.json yet (the mcp-scan hook scans it once you add one)" };
|
|
40622
41619
|
try {
|
|
40623
41620
|
const cfg = JSON.parse(readFileSync33(path, "utf8"));
|
|
40624
|
-
const
|
|
40625
|
-
const shielded =
|
|
40626
|
-
const warnings =
|
|
40627
|
-
return { exists: true, warnings, line: `.kiro/settings/mcp.json: ${
|
|
41621
|
+
const entries2 = Object.entries(cfg.mcpServers ?? {});
|
|
41622
|
+
const shielded = entries2.filter(([, e]) => isWrapped(e)).map(([n]) => n);
|
|
41623
|
+
const warnings = entries2.filter(([, e]) => Array.isArray(e.autoApprove) && e.autoApprove.includes("*")).map(([n]) => `WARNING: server "${displayMessage(n.slice(0, MAX_NAME).replace(/[\t\n\r]/g, " "))}${n.length > MAX_NAME ? "..." : ""}" has autoApprove "*": your agent can run every tool of it without asking you. List only the tools you trust, or remove autoApprove.`);
|
|
41624
|
+
return { exists: true, warnings, line: `.kiro/settings/mcp.json: ${entries2.length} server${entries2.length === 1 ? "" : "s"}, ${shielded.length} behind the Shield` };
|
|
40628
41625
|
} catch {
|
|
40629
41626
|
return { exists: true, warnings: [], line: ".kiro/settings/mcp.json is not valid JSON; fix it before using --shield" };
|
|
40630
41627
|
}
|
|
@@ -40656,7 +41653,7 @@ ${INIT_HELP}`);
|
|
|
40656
41653
|
${INIT_HELP}`);
|
|
40657
41654
|
return 2;
|
|
40658
41655
|
}
|
|
40659
|
-
const root =
|
|
41656
|
+
const root = resolve37(p.positionals[0] ?? ".");
|
|
40660
41657
|
const bin = str4(p.values["bin"]) ?? DEFAULT_BIN;
|
|
40661
41658
|
const mcpBin = str4(p.values["mcp-bin"]) ?? DEFAULT_MCP_BIN;
|
|
40662
41659
|
const force = p.values["force"] === true;
|
|
@@ -40694,7 +41691,7 @@ ${INIT_HELP}`);
|
|
|
40694
41691
|
{
|
|
40695
41692
|
rel: ".kiro/hooks/exorcist-secrets.json",
|
|
40696
41693
|
summary: "PreToolUse on shell tools: blocks git commit while staged files hold secrets",
|
|
40697
|
-
body:
|
|
41694
|
+
body: hook2("exorcist-secrets", "Block git commit while staged files contain secrets. Exit code 2 blocks the shell command.", {
|
|
40698
41695
|
trigger: "PreToolUse",
|
|
40699
41696
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40700
41697
|
action: { type: "command", command: `${HOOK_RUNNER} --guard ${bin} guard-commit` },
|
|
@@ -40704,7 +41701,7 @@ ${INIT_HELP}`);
|
|
|
40704
41701
|
{
|
|
40705
41702
|
rel: ".kiro/hooks/exorcist-mcp-scan.json",
|
|
40706
41703
|
summary: "PostFileSave on MCP configs: scans the saved file and reports high or critical findings",
|
|
40707
|
-
body:
|
|
41704
|
+
body: hook2("exorcist-mcp-scan", "Scan MCP configuration with Exorcist 98 whenever it is saved.", {
|
|
40708
41705
|
trigger: "PostFileSave",
|
|
40709
41706
|
matcher: "(\\.kiro/settings/mcp\\.json|\\.cursor/mcp\\.json|\\.vscode/mcp\\.json|claude_desktop_config\\.json)$",
|
|
40710
41707
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} hook-scan` },
|
|
@@ -40714,7 +41711,7 @@ ${INIT_HELP}`);
|
|
|
40714
41711
|
{
|
|
40715
41712
|
rel: ".kiro/hooks/exorcist-on-access.json",
|
|
40716
41713
|
summary: onAccessOff ? 'PreToolUse on read tools: WRITTEN DISABLED, because the published version in the default command has no on-access command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on read tools: blocks reading a file that hides instructions for the AI",
|
|
40717
|
-
body:
|
|
41714
|
+
body: hook2("exorcist-on-access", "Scan a file for instructions aimed at the AI before the agent reads it. Exit code 2 blocks the read.", {
|
|
40718
41715
|
trigger: "PreToolUse",
|
|
40719
41716
|
matcher: "read|readFile|read_file|readCode|fs_read|readMultipleFiles|grep|grep_search|grepSearch|file_search|fileSearch|glob|list_directory|listDirectory|code",
|
|
40720
41717
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} on-access` },
|
|
@@ -40725,7 +41722,7 @@ ${INIT_HELP}`);
|
|
|
40725
41722
|
{
|
|
40726
41723
|
rel: ".kiro/hooks/exorcist-gate.json",
|
|
40727
41724
|
summary: gateOff ? 'Stop: WRITTEN DISABLED, because the published version in the default command has no gate command (pass --bin with a newer build, then set "enabled": true)' : "Stop: when the agent finishes, fails if it added a high or critical finding to a file agents obey",
|
|
40728
|
-
body:
|
|
41725
|
+
body: hook2("exorcist-gate", "When the agent finishes its turn, check the agent files it changed against the last commit. Exit code 1 sends the list to the agent.", {
|
|
40729
41726
|
trigger: "Stop",
|
|
40730
41727
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} gate` },
|
|
40731
41728
|
timeout: 30,
|
|
@@ -40735,7 +41732,7 @@ ${INIT_HELP}`);
|
|
|
40735
41732
|
{
|
|
40736
41733
|
rel: ".kiro/hooks/exorcist-mcp-write-guard.json",
|
|
40737
41734
|
summary: mcpWriteOff ? 'PreToolUse on write and shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-mcp-write command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on write and shell tools: a person must confirm any agent write to an MCP config, trusted commands or hook/agent file",
|
|
40738
|
-
body:
|
|
41735
|
+
body: hook2("exorcist-mcp-write-guard", "A person must confirm any agent write to an MCP config, any change that adds a trusted command in .vscode/settings.json, and any change to a file in .kiro/hooks/ or .kiro/agents/. Exit code 2 blocks the write.", {
|
|
40739
41736
|
trigger: "PreToolUse",
|
|
40740
41737
|
matcher: "write|shell",
|
|
40741
41738
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-mcp-write` },
|
|
@@ -40746,7 +41743,7 @@ ${INIT_HELP}`);
|
|
|
40746
41743
|
{
|
|
40747
41744
|
rel: ".kiro/hooks/exorcist-guard-web-fetch.json",
|
|
40748
41745
|
summary: webFetchOff ? 'PreToolUse on web_fetch: WRITTEN DISABLED, because the published version in the default command has no guard-web-fetch command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on web_fetch: blocks a fetch whose address holds a secret, canary or .env value",
|
|
40749
|
-
body:
|
|
41746
|
+
body: hook2("exorcist-guard-web-fetch", "Blocks the web_fetch tool when the address holds a secret (key or token), a canary token, or a value from a .env file of this project. Exit code 2 blocks the fetch; the reason names the kind of value and the host, never the value.", {
|
|
40750
41747
|
trigger: "PreToolUse",
|
|
40751
41748
|
matcher: "web_fetch|webFetch|remote_web_search|web_search|webSearch|shell|execute_bash|executeBash|run_command|bash",
|
|
40752
41749
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-web-fetch` },
|
|
@@ -40757,7 +41754,7 @@ ${INIT_HELP}`);
|
|
|
40757
41754
|
{
|
|
40758
41755
|
rel: ".kiro/hooks/exorcist-guard-env-write.json",
|
|
40759
41756
|
summary: envWriteOff ? 'PreToolUse on write tools: WRITTEN DISABLED, because the published version in the default command has no guard-env-write command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on write tools: blocks writing a .env value into any other file",
|
|
40760
|
-
body:
|
|
41757
|
+
body: hook2("exorcist-guard-env-write", "Blocks the write tools (fs_write, str_replace) when the text to be written holds a value from a .env file of this project and the destination is not itself a .env file. Exit code 2 blocks the write; the reason names the file, never the value.", {
|
|
40761
41758
|
trigger: "PreToolUse",
|
|
40762
41759
|
matcher: "write|fs_write|str_replace|shell|execute_bash|executeBash|run_command|bash",
|
|
40763
41760
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-env-write` },
|
|
@@ -40768,7 +41765,7 @@ ${INIT_HELP}`);
|
|
|
40768
41765
|
{
|
|
40769
41766
|
rel: ".kiro/hooks/exorcist-guard-run-scripts.json",
|
|
40770
41767
|
summary: runScriptsOff ? 'PreToolUse on shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-run-scripts command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on shell tools: blocks npm test, npm install and similar when a script they run reads secrets and sends them out",
|
|
40771
|
-
body:
|
|
41768
|
+
body: hook2("exorcist-guard-run-scripts", "Blocks a shell command that would run a package script (npm, pnpm, yarn, npx of a local bin) whose file reads a secret and sends data out. Exit code 2 blocks the command; the reason names the script and the file, never file text. Nothing is run to find out.", {
|
|
40772
41769
|
trigger: "PreToolUse",
|
|
40773
41770
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40774
41771
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-run-scripts` },
|
|
@@ -40779,7 +41776,7 @@ ${INIT_HELP}`);
|
|
|
40779
41776
|
{
|
|
40780
41777
|
rel: ".kiro/hooks/exorcist-guard-shell-read.json",
|
|
40781
41778
|
summary: shellReadOff ? 'PreToolUse on shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-shell-read command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on shell tools: scans a file before cat, head, tail, grep, sed -n, awk, bat or nl reads it",
|
|
40782
|
-
body:
|
|
41779
|
+
body: hook2("exorcist-guard-shell-read", "Scans the files a shell command reads (cat, head, tail, less, more, sed -n, awk, bat, nl, grep) the way the on-access hook scans a read, and blocks the command when a high or critical rule fires. Exit code 2 blocks the command; the reason never quotes the file.", {
|
|
40783
41780
|
trigger: "PreToolUse",
|
|
40784
41781
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40785
41782
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-shell-read` },
|
|
@@ -40802,13 +41799,13 @@ ${INIT_HELP}`);
|
|
|
40802
41799
|
}
|
|
40803
41800
|
const done = [];
|
|
40804
41801
|
for (const f of files) {
|
|
40805
|
-
const path =
|
|
40806
|
-
if (
|
|
41802
|
+
const path = join41(root, f.rel);
|
|
41803
|
+
if (existsSync27(path) && !force) {
|
|
40807
41804
|
io.err(`Kept existing ${f.rel} (use --force to replace it).`);
|
|
40808
41805
|
done.push({ f, wrote: false });
|
|
40809
41806
|
continue;
|
|
40810
41807
|
}
|
|
40811
|
-
|
|
41808
|
+
mkdirSync12(dirname20(path), { recursive: true });
|
|
40812
41809
|
writeFileSync12(path, f.body, "utf8");
|
|
40813
41810
|
if (f.executable) chmodSync(path, 493);
|
|
40814
41811
|
if (!kiro) io.out(`Wrote ${f.rel}`);
|
|
@@ -40820,7 +41817,7 @@ ${INIT_HELP}`);
|
|
|
40820
41817
|
return wroteAny ? 0 : 1;
|
|
40821
41818
|
}
|
|
40822
41819
|
if (sandbox) writeSandboxFile(root, io);
|
|
40823
|
-
const mcpPath =
|
|
41820
|
+
const mcpPath = join41(root, ".kiro/settings/mcp.json");
|
|
40824
41821
|
let shieldOk = true;
|
|
40825
41822
|
let shieldLine = null;
|
|
40826
41823
|
if (shield) {
|
|
@@ -40830,7 +41827,7 @@ ${INIT_HELP}`);
|
|
|
40830
41827
|
shieldOk = false;
|
|
40831
41828
|
} else {
|
|
40832
41829
|
const [head, ...rest] = binWords;
|
|
40833
|
-
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${
|
|
41830
|
+
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${join41(root, ".exorcist")}`];
|
|
40834
41831
|
const notes = [];
|
|
40835
41832
|
const code3 = await wrapCommand(args, { out: io.out, err: (s) => notes.push(s) }, "wrap");
|
|
40836
41833
|
for (const n of notes) io.err(n);
|
|
@@ -40874,7 +41871,7 @@ ${INIT_HELP}`);
|
|
|
40874
41871
|
"then reconnect MCP servers in the MCP panel so they start through the Shield."
|
|
40875
41872
|
];
|
|
40876
41873
|
if (isDefaultBin) {
|
|
40877
|
-
lines.push("Commands run through npx (@exorcist-98/cli@0.3.
|
|
41874
|
+
lines.push("Commands run through npx (@exorcist-98/cli@0.3.8). If Kiro cannot start a wrapped server or a hook cannot find npx,");
|
|
40878
41875
|
lines.push('rerun with --bin "<absolute path to node> <absolute path to the exorcist CLI>" and --force.');
|
|
40879
41876
|
}
|
|
40880
41877
|
io.out(lines.join("\n"));
|
|
@@ -40883,8 +41880,8 @@ ${INIT_HELP}`);
|
|
|
40883
41880
|
}
|
|
40884
41881
|
|
|
40885
41882
|
// src/commands/lock.ts
|
|
40886
|
-
import { existsSync as
|
|
40887
|
-
import { isAbsolute as isAbsolute27, join as
|
|
41883
|
+
import { existsSync as existsSync28, readFileSync as readFileSync34, writeFileSync as writeFileSync13 } from "node:fs";
|
|
41884
|
+
import { isAbsolute as isAbsolute27, join as join42, resolve as resolve38 } from "node:path";
|
|
40888
41885
|
|
|
40889
41886
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js
|
|
40890
41887
|
var NEVER2 = Object.freeze({
|
|
@@ -41012,9 +42009,9 @@ function assertNever(_x) {
|
|
|
41012
42009
|
}
|
|
41013
42010
|
function assert(_) {
|
|
41014
42011
|
}
|
|
41015
|
-
function getEnumValues(
|
|
41016
|
-
const numericValues = Object.values(
|
|
41017
|
-
const values = Object.entries(
|
|
42012
|
+
function getEnumValues(entries2) {
|
|
42013
|
+
const numericValues = Object.values(entries2).filter((v) => typeof v === "number");
|
|
42014
|
+
const values = Object.entries(entries2).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
41018
42015
|
return values;
|
|
41019
42016
|
}
|
|
41020
42017
|
function joinValues(array2, separator = "|") {
|
|
@@ -44474,10 +45471,10 @@ var ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
44474
45471
|
};
|
|
44475
45472
|
});
|
|
44476
45473
|
function _enum(values, params) {
|
|
44477
|
-
const
|
|
45474
|
+
const entries2 = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
44478
45475
|
return new ZodEnum2({
|
|
44479
45476
|
type: "enum",
|
|
44480
|
-
entries,
|
|
45477
|
+
entries: entries2,
|
|
44481
45478
|
...util_exports.normalizeParams(params)
|
|
44482
45479
|
});
|
|
44483
45480
|
}
|
|
@@ -46754,7 +47751,7 @@ var Protocol = class {
|
|
|
46754
47751
|
return;
|
|
46755
47752
|
}
|
|
46756
47753
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
46757
|
-
await new Promise((
|
|
47754
|
+
await new Promise((resolve42) => setTimeout(resolve42, pollInterval));
|
|
46758
47755
|
options?.signal?.throwIfAborted();
|
|
46759
47756
|
}
|
|
46760
47757
|
} catch (error2) {
|
|
@@ -46771,7 +47768,7 @@ var Protocol = class {
|
|
|
46771
47768
|
*/
|
|
46772
47769
|
request(request, resultSchema, options) {
|
|
46773
47770
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
46774
|
-
return new Promise((
|
|
47771
|
+
return new Promise((resolve42, reject2) => {
|
|
46775
47772
|
const earlyReject = (error2) => {
|
|
46776
47773
|
reject2(error2);
|
|
46777
47774
|
};
|
|
@@ -46849,7 +47846,7 @@ var Protocol = class {
|
|
|
46849
47846
|
if (!parseResult.success) {
|
|
46850
47847
|
reject2(parseResult.error);
|
|
46851
47848
|
} else {
|
|
46852
|
-
|
|
47849
|
+
resolve42(parseResult.data);
|
|
46853
47850
|
}
|
|
46854
47851
|
} catch (error2) {
|
|
46855
47852
|
reject2(error2);
|
|
@@ -47111,12 +48108,12 @@ var Protocol = class {
|
|
|
47111
48108
|
}
|
|
47112
48109
|
} catch {
|
|
47113
48110
|
}
|
|
47114
|
-
return new Promise((
|
|
48111
|
+
return new Promise((resolve42, reject2) => {
|
|
47115
48112
|
if (signal.aborted) {
|
|
47116
48113
|
reject2(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
47117
48114
|
return;
|
|
47118
48115
|
}
|
|
47119
|
-
const timeoutId = setTimeout(
|
|
48116
|
+
const timeoutId = setTimeout(resolve42, interval);
|
|
47120
48117
|
signal.addEventListener("abort", () => {
|
|
47121
48118
|
clearTimeout(timeoutId);
|
|
47122
48119
|
reject2(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -48067,7 +49064,7 @@ var StdioClientTransport = class {
|
|
|
48067
49064
|
if (this._process) {
|
|
48068
49065
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
48069
49066
|
}
|
|
48070
|
-
return new Promise((
|
|
49067
|
+
return new Promise((resolve42, reject2) => {
|
|
48071
49068
|
this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
|
|
48072
49069
|
// merge default env with server env because mcp server needs some env vars
|
|
48073
49070
|
env: {
|
|
@@ -48084,7 +49081,7 @@ var StdioClientTransport = class {
|
|
|
48084
49081
|
this.onerror?.(error2);
|
|
48085
49082
|
});
|
|
48086
49083
|
this._process.on("spawn", () => {
|
|
48087
|
-
|
|
49084
|
+
resolve42();
|
|
48088
49085
|
});
|
|
48089
49086
|
this._process.on("close", (_code) => {
|
|
48090
49087
|
this._process = void 0;
|
|
@@ -48149,22 +49146,22 @@ var StdioClientTransport = class {
|
|
|
48149
49146
|
if (this._process) {
|
|
48150
49147
|
const processToClose = this._process;
|
|
48151
49148
|
this._process = void 0;
|
|
48152
|
-
const closePromise = new Promise((
|
|
49149
|
+
const closePromise = new Promise((resolve42) => {
|
|
48153
49150
|
processToClose.once("close", () => {
|
|
48154
|
-
|
|
49151
|
+
resolve42();
|
|
48155
49152
|
});
|
|
48156
49153
|
});
|
|
48157
49154
|
try {
|
|
48158
49155
|
processToClose.stdin?.end();
|
|
48159
49156
|
} catch {
|
|
48160
49157
|
}
|
|
48161
|
-
await Promise.race([closePromise, new Promise((
|
|
49158
|
+
await Promise.race([closePromise, new Promise((resolve42) => setTimeout(resolve42, 2e3).unref())]);
|
|
48162
49159
|
if (processToClose.exitCode === null) {
|
|
48163
49160
|
try {
|
|
48164
49161
|
processToClose.kill("SIGTERM");
|
|
48165
49162
|
} catch {
|
|
48166
49163
|
}
|
|
48167
|
-
await Promise.race([closePromise, new Promise((
|
|
49164
|
+
await Promise.race([closePromise, new Promise((resolve42) => setTimeout(resolve42, 2e3).unref())]);
|
|
48168
49165
|
}
|
|
48169
49166
|
if (processToClose.exitCode === null) {
|
|
48170
49167
|
try {
|
|
@@ -48176,15 +49173,15 @@ var StdioClientTransport = class {
|
|
|
48176
49173
|
this._readBuffer.clear();
|
|
48177
49174
|
}
|
|
48178
49175
|
send(message) {
|
|
48179
|
-
return new Promise((
|
|
49176
|
+
return new Promise((resolve42) => {
|
|
48180
49177
|
if (!this._process?.stdin) {
|
|
48181
49178
|
throw new Error("Not connected");
|
|
48182
49179
|
}
|
|
48183
49180
|
const json2 = serializeMessage(message);
|
|
48184
49181
|
if (this._process.stdin.write(json2)) {
|
|
48185
|
-
|
|
49182
|
+
resolve42();
|
|
48186
49183
|
} else {
|
|
48187
|
-
this._process.stdin.once("drain",
|
|
49184
|
+
this._process.stdin.once("drain", resolve42);
|
|
48188
49185
|
}
|
|
48189
49186
|
});
|
|
48190
49187
|
}
|
|
@@ -48193,7 +49190,7 @@ var StdioClientTransport = class {
|
|
|
48193
49190
|
// src/commands/lock.ts
|
|
48194
49191
|
init_zod();
|
|
48195
49192
|
var DEFAULT_LOCK_TIMEOUT_MS = 2e4;
|
|
48196
|
-
var DEFAULT_CONFIG =
|
|
49193
|
+
var DEFAULT_CONFIG = join42(".kiro", "settings", "mcp.json");
|
|
48197
49194
|
var MAX_PAGES = 100;
|
|
48198
49195
|
var LOCK_HELP = `Usage: exorcist lock [options]
|
|
48199
49196
|
exorcist lock --check [options]
|
|
@@ -48257,7 +49254,7 @@ var RawToolsPage = external_exports.object({ tools: external_exports.array(exter
|
|
|
48257
49254
|
var firstLine2 = (err) => (err instanceof Error ? err.message : String(err)).split("\n")[0]?.slice(0, 300) ?? "unknown error";
|
|
48258
49255
|
async function listTools(o) {
|
|
48259
49256
|
const transport = new StdioClientTransport({ command: o.command, args: o.args, env: o.env, cwd: o.cwd, stderr: "ignore" });
|
|
48260
|
-
const client = new Client({ name: "exorcist-lock", version: "0.3.
|
|
49257
|
+
const client = new Client({ name: "exorcist-lock", version: "0.3.8" }, { capabilities: {} });
|
|
48261
49258
|
let timer;
|
|
48262
49259
|
const timedOut = new Promise((res) => {
|
|
48263
49260
|
timer = setTimeout(() => res({ ok: false, error: `it did not list its tools within ${o.timeoutMs} ms.` }), o.timeoutMs);
|
|
@@ -48298,7 +49295,7 @@ function serverEnv(base, entryEnv = {}) {
|
|
|
48298
49295
|
return { ...Object.fromEntries(inherited), ...entryEnv };
|
|
48299
49296
|
}
|
|
48300
49297
|
async function collectListings(config2, o) {
|
|
48301
|
-
const
|
|
49298
|
+
const list3 = o.list ?? listTools;
|
|
48302
49299
|
const listings = [];
|
|
48303
49300
|
const kept = [];
|
|
48304
49301
|
const notes = [];
|
|
@@ -48340,14 +49337,14 @@ async function collectListings(config2, o) {
|
|
|
48340
49337
|
if (loaders.length > 0) {
|
|
48341
49338
|
warnings.push(`HIGH EX-025: "${name}" sets ${loaders.join(", ")} in its env, which changes how its program loads (for example NODE_OPTIONS=--require runs extra code first). Make sure you know why it is there.`);
|
|
48342
49339
|
}
|
|
48343
|
-
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute27(entry.cwd) ? entry.cwd :
|
|
49340
|
+
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute27(entry.cwd) ? entry.cwd : resolve38(o.cwd, entry.cwd);
|
|
48344
49341
|
if (o.static) {
|
|
48345
49342
|
const old = o.previous && Object.hasOwn(o.previous.servers, name) ? o.previous.servers[name] : void 0;
|
|
48346
49343
|
kept.push([name, { launch: launchFingerprint(command, entry.args, cwd, void 0, pinEntry).hash, tools: old?.tools ?? {} }]);
|
|
48347
49344
|
continue;
|
|
48348
49345
|
}
|
|
48349
49346
|
jobs.push((async () => {
|
|
48350
|
-
const r = await
|
|
49347
|
+
const r = await list3({ command, args: entry.args, env: serverEnv(process.env, entry.env), cwd, timeoutMs: o.timeoutMs });
|
|
48351
49348
|
if (!r.ok) {
|
|
48352
49349
|
errors.push(`Could not list the tools of "${name}": ${r.error}`);
|
|
48353
49350
|
return;
|
|
@@ -48409,7 +49406,7 @@ ${LOCK_HELP}`);
|
|
|
48409
49406
|
io.err("--timeout must be a positive whole number of milliseconds.");
|
|
48410
49407
|
return 2;
|
|
48411
49408
|
}
|
|
48412
|
-
const lockPath2 =
|
|
49409
|
+
const lockPath2 = resolve38(str4(p.values["lock"]) ?? LOCK_FILE);
|
|
48413
49410
|
const checking = p.values["check"] === true;
|
|
48414
49411
|
const fromShield = p.values["from-shield"] === true;
|
|
48415
49412
|
const isStatic = p.values["static"] === true;
|
|
@@ -48422,7 +49419,7 @@ ${LOCK_HELP}`);
|
|
|
48422
49419
|
return 2;
|
|
48423
49420
|
}
|
|
48424
49421
|
let previous;
|
|
48425
|
-
if (
|
|
49422
|
+
if (existsSync28(lockPath2)) {
|
|
48426
49423
|
let text2;
|
|
48427
49424
|
try {
|
|
48428
49425
|
text2 = readFileSync34(lockPath2, "utf8");
|
|
@@ -48450,8 +49447,8 @@ ${LOCK_HELP}`);
|
|
|
48450
49447
|
}
|
|
48451
49448
|
current = pinsToLock(st.state);
|
|
48452
49449
|
} else {
|
|
48453
|
-
const configPath =
|
|
48454
|
-
if (!
|
|
49450
|
+
const configPath = resolve38(str4(p.values["config"]) ?? DEFAULT_CONFIG);
|
|
49451
|
+
if (!existsSync28(configPath)) {
|
|
48455
49452
|
io.err(`MCP config not found: ${configPath}. Pass --config <file>, or --from-shield.`);
|
|
48456
49453
|
return 2;
|
|
48457
49454
|
}
|
|
@@ -48499,8 +49496,8 @@ ${LOCK_HELP}`);
|
|
|
48499
49496
|
}
|
|
48500
49497
|
|
|
48501
49498
|
// src/commands/map.ts
|
|
48502
|
-
import { existsSync as
|
|
48503
|
-
import { resolve as
|
|
49499
|
+
import { existsSync as existsSync29, statSync as statSync23 } from "node:fs";
|
|
49500
|
+
import { resolve as resolve39 } from "node:path";
|
|
48504
49501
|
var MAP_HELP = `Usage: exorcist map [dir] [options]
|
|
48505
49502
|
|
|
48506
49503
|
The Haunted House Map: for every MCP config in a folder (default: the current
|
|
@@ -48557,8 +49554,8 @@ function renderConfig(c, finding) {
|
|
|
48557
49554
|
lines.push(" One poisoned page, issue or message could make the agent read your secrets and send them out.");
|
|
48558
49555
|
} else {
|
|
48559
49556
|
const empty = ROOMS.filter((r) => c.legs[r.cap].length === 0).map((r) => r.room);
|
|
48560
|
-
const
|
|
48561
|
-
lines.push(` OK No trifecta: the ${
|
|
49557
|
+
const list3 = empty.length === 1 ? empty[0] : `${empty.slice(0, -1).join(", ")} and ${empty[empty.length - 1]}`;
|
|
49558
|
+
lines.push(` OK No trifecta: the ${list3} ${empty.length === 1 ? "room is" : "rooms are"} empty.`);
|
|
48562
49559
|
}
|
|
48563
49560
|
return [...lines, ""];
|
|
48564
49561
|
}
|
|
@@ -48595,8 +49592,8 @@ ${MAP_HELP}`);
|
|
|
48595
49592
|
return 2;
|
|
48596
49593
|
}
|
|
48597
49594
|
const target = p.positionals[0] ?? ".";
|
|
48598
|
-
const root =
|
|
48599
|
-
if (!
|
|
49595
|
+
const root = resolve39(target);
|
|
49596
|
+
if (!existsSync29(root) || !statSync23(root).isDirectory()) {
|
|
48600
49597
|
io.err(`Folder not found: ${target}`);
|
|
48601
49598
|
return 2;
|
|
48602
49599
|
}
|
|
@@ -48618,8 +49615,8 @@ ${MAP_HELP}`);
|
|
|
48618
49615
|
}
|
|
48619
49616
|
|
|
48620
49617
|
// src/commands/origin.ts
|
|
48621
|
-
import { existsSync as
|
|
48622
|
-
import { posix as posix3, relative as
|
|
49618
|
+
import { existsSync as existsSync30, realpathSync as realpathSync13, statSync as statSync24 } from "node:fs";
|
|
49619
|
+
import { posix as posix3, relative as relative17, resolve as resolve40, sep as sep8 } from "node:path";
|
|
48623
49620
|
var ORIGIN_HELP = `Usage: exorcist origin [dir] [options]
|
|
48624
49621
|
|
|
48625
49622
|
Scan a git repository, then walk its history to find the commit that
|
|
@@ -48741,8 +49738,8 @@ ${ORIGIN_HELP}`);
|
|
|
48741
49738
|
${ORIGIN_HELP}`);
|
|
48742
49739
|
return 2;
|
|
48743
49740
|
}
|
|
48744
|
-
const target =
|
|
48745
|
-
if (!
|
|
49741
|
+
const target = resolve40(p.positionals[0] ?? ".");
|
|
49742
|
+
if (!existsSync30(target) || !statSync24(target).isDirectory()) {
|
|
48746
49743
|
io.err(`Not a directory: ${target}`);
|
|
48747
49744
|
return 2;
|
|
48748
49745
|
}
|
|
@@ -48756,8 +49753,8 @@ ${ORIGIN_HELP}`);
|
|
|
48756
49753
|
return 2;
|
|
48757
49754
|
}
|
|
48758
49755
|
const { root: repoRoot, shallow, boundaries } = repo;
|
|
48759
|
-
const scanRoot =
|
|
48760
|
-
const prefix =
|
|
49756
|
+
const scanRoot = realpathSync13(target);
|
|
49757
|
+
const prefix = relative17(realpathSync13(repoRoot), scanRoot).split(sep8).join("/");
|
|
48761
49758
|
if (prefix.startsWith("..")) {
|
|
48762
49759
|
io.err(`The folder is outside the git repository git reported (${repoRoot}).`);
|
|
48763
49760
|
return 2;
|
|
@@ -48829,7 +49826,7 @@ ${ORIGIN_HELP}`);
|
|
|
48829
49826
|
}
|
|
48830
49827
|
|
|
48831
49828
|
// src/commands/shield.ts
|
|
48832
|
-
import { resolve as
|
|
49829
|
+
import { resolve as resolve41 } from "node:path";
|
|
48833
49830
|
var SHIELD_HELP = `Usage: exorcist shield --server <name> [options] -- <command> [args...]
|
|
48834
49831
|
exorcist shield --server <name> --url <https://...> [options]
|
|
48835
49832
|
|
|
@@ -48934,7 +49931,7 @@ ${SHIELD_HELP}`);
|
|
|
48934
49931
|
server,
|
|
48935
49932
|
dir: stateDir(str4(p.values["dir"])),
|
|
48936
49933
|
definitionsDir: defs,
|
|
48937
|
-
...config2 ? { configPath:
|
|
49934
|
+
...config2 ? { configPath: resolve41(config2) } : {},
|
|
48938
49935
|
// Desktop notifications for critical and high alerts; EXORCIST_NOTIFY=0 or policy notify:false turns them off.
|
|
48939
49936
|
...process.env["EXORCIST_NOTIFY"] === "0" ? {} : { notify: desktopNotifier() }
|
|
48940
49937
|
};
|
|
@@ -49090,12 +50087,12 @@ ${VAULT_HELP}`);
|
|
|
49090
50087
|
};
|
|
49091
50088
|
switch (sub) {
|
|
49092
50089
|
case "list": {
|
|
49093
|
-
const
|
|
49094
|
-
if (
|
|
50090
|
+
const entries2 = listEntries(vault);
|
|
50091
|
+
if (entries2.length === 0) {
|
|
49095
50092
|
io.out("The vault is empty.");
|
|
49096
50093
|
return 0;
|
|
49097
50094
|
}
|
|
49098
|
-
for (const e of
|
|
50095
|
+
for (const e of entries2) {
|
|
49099
50096
|
io.out(`${e.id} ${e.status.padEnd(11)} ${e.kind === "mcp-server" ? `server ${e.serverName}` : e.kind === "exorcise" ? `exorcism of ${e.files?.length ?? 0} file(s) in` : "file"} ${e.target} (${e.reason})${e.trusted === true ? "" : " [NOT SIGNED BY THIS MACHINE: it cannot be restored]"}`);
|
|
49100
50097
|
}
|
|
49101
50098
|
return 0;
|
|
@@ -49155,7 +50152,7 @@ ${VAULT_HELP}`);
|
|
|
49155
50152
|
}
|
|
49156
50153
|
|
|
49157
50154
|
// src/index.ts
|
|
49158
|
-
var VERSION = "0.3.
|
|
50155
|
+
var VERSION = "0.3.8";
|
|
49159
50156
|
var HELP = `Exorcist 98 ${VERSION}: antivirus for AI coding agents
|
|
49160
50157
|
|
|
49161
50158
|
Usage: exorcist <command> [options]
|