@exorcist-98/cli 0.3.7 → 0.3.9
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 +1597 -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.9";
|
|
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,54 @@ 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 (; ; ) {
|
|
31684
|
+
try {
|
|
31685
|
+
return join20(realpathSync8.native(cur), rest);
|
|
31686
|
+
} catch {
|
|
31687
|
+
}
|
|
31688
|
+
const up = dirname9(cur);
|
|
31689
|
+
if (up === cur) return resolve20(p);
|
|
31690
|
+
rest = join20(basename8(cur), rest);
|
|
31691
|
+
cur = up;
|
|
31692
|
+
}
|
|
31693
|
+
};
|
|
31694
|
+
const fold2 = (p) => process.platform === "darwin" || IS_WINDOWS ? p.toLowerCase() : p;
|
|
31695
|
+
const d = fold2(real(dir));
|
|
31696
|
+
const c = fold2(real(cwd));
|
|
31697
|
+
if (d === fold2(real(join20(homedir8(), ".config", "exorcist-98")))) return null;
|
|
31698
|
+
const rel = relative13(c, d);
|
|
31699
|
+
if (rel === "" || !rel.startsWith("..") && !isAbsolute16(rel)) return "it is inside the current project folder";
|
|
31700
|
+
for (let cur = d; ; cur = dirname9(cur)) {
|
|
31701
|
+
if (existsSync9(join20(cur, ".git"))) return `it is inside a git repository (${cur})`;
|
|
31702
|
+
if (dirname9(cur) === cur) break;
|
|
31703
|
+
}
|
|
31704
|
+
let st;
|
|
31705
|
+
try {
|
|
31706
|
+
st = lstatSync5(dir);
|
|
31707
|
+
} catch {
|
|
31708
|
+
return null;
|
|
31709
|
+
}
|
|
31710
|
+
if (st.isSymbolicLink()) return "it is a symbolic link";
|
|
31711
|
+
if (!st.isDirectory()) return "it is not a folder";
|
|
31712
|
+
const me = uid();
|
|
31713
|
+
if (!IS_WINDOWS && me !== void 0 && st.uid !== me) return "it is not owned by you";
|
|
31714
|
+
if (!IS_WINDOWS && (st.mode & 63) !== 0) return "other users or your group can open it (a private folder is mode 0700)";
|
|
31715
|
+
return null;
|
|
31716
|
+
}
|
|
31291
31717
|
function userConfigDir(env = process.env) {
|
|
31292
31718
|
const o = env["EXORCIST_USER_DIR"];
|
|
31293
31719
|
if (o && isAbsolute16(o)) return o;
|
|
@@ -31295,6 +31721,14 @@ function userConfigDir(env = process.env) {
|
|
|
31295
31721
|
const base = xdg && isAbsolute16(xdg) ? xdg : join20(homedir8(), ".config");
|
|
31296
31722
|
return join20(base, "exorcist-98");
|
|
31297
31723
|
}
|
|
31724
|
+
function userDirRefusal(env = process.env, cwd = process.cwd()) {
|
|
31725
|
+
const o = env["EXORCIST_USER_DIR"];
|
|
31726
|
+
const xdg = env["XDG_CONFIG_HOME"];
|
|
31727
|
+
const overridden = o && isAbsolute16(o) || xdg && isAbsolute16(xdg);
|
|
31728
|
+
if (!overridden) return null;
|
|
31729
|
+
const problem = userDirOverrideProblem(userConfigDir(env), cwd);
|
|
31730
|
+
return problem === null ? null : `the user-level folder ${userConfigDir(env)} (set by EXORCIST_USER_DIR or XDG_CONFIG_HOME) was refused: ${problem}`;
|
|
31731
|
+
}
|
|
31298
31732
|
var uid = () => typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
31299
31733
|
function ensurePrivateDir(dir) {
|
|
31300
31734
|
try {
|
|
@@ -31337,6 +31771,10 @@ function readKeyFile(path) {
|
|
|
31337
31771
|
}
|
|
31338
31772
|
var cache2 = /* @__PURE__ */ new Map();
|
|
31339
31773
|
function getUserKey(o = {}) {
|
|
31774
|
+
if (o.dir === void 0) {
|
|
31775
|
+
const refused = userDirRefusal();
|
|
31776
|
+
if (refused !== null) return { ok: false, error: refused };
|
|
31777
|
+
}
|
|
31340
31778
|
const dir = o.dir ?? userConfigDir();
|
|
31341
31779
|
const cached2 = cache2.get(dir);
|
|
31342
31780
|
if (cached2) return { ok: true, key: cached2 };
|
|
@@ -31449,7 +31887,13 @@ var PolicySchema = external_exports.object({
|
|
|
31449
31887
|
* opt-in that only the USER-LEVEL policy can set. A project policy, signed or not,
|
|
31450
31888
|
* that asks for it is ignored with a note.
|
|
31451
31889
|
*/
|
|
31452
|
-
sessionRelease: external_exports.enum(["os", "terminal", "notification-code"]).optional()
|
|
31890
|
+
sessionRelease: external_exports.enum(["os", "terminal", "notification-code"]).optional(),
|
|
31891
|
+
/**
|
|
31892
|
+
* The event log (m19-log, LG-2). `off` stops the Shield writing events after one final event that says so.
|
|
31893
|
+
* Only the USER-LEVEL policy can set it: a project policy that sets `events` is ignored with a note, and the
|
|
31894
|
+
* environment variable EXORCIST_EVENTS is ignored (an MCP config can set a server's environment).
|
|
31895
|
+
*/
|
|
31896
|
+
events: external_exports.enum(["on", "off"]).optional()
|
|
31453
31897
|
}).strict();
|
|
31454
31898
|
var policySigPath = (policyFile) => policyFile.replace(/\.json$/, "") + ".sig";
|
|
31455
31899
|
var POLICY_DOMAIN = "exorcist-98:policy:v1";
|
|
@@ -31519,6 +31963,11 @@ function parsePolicyText(path, text) {
|
|
|
31519
31963
|
return { ok: true, raw: json2 };
|
|
31520
31964
|
}
|
|
31521
31965
|
function loadUserPolicy(notes) {
|
|
31966
|
+
const refused = userDirRefusal();
|
|
31967
|
+
if (refused !== null) {
|
|
31968
|
+
notes.push(`${refused}, so no user-level policy was read and the defaults apply.`);
|
|
31969
|
+
return { ok: true, raw: {} };
|
|
31970
|
+
}
|
|
31522
31971
|
const file = join21(userConfigDir(), "policy.json");
|
|
31523
31972
|
let st;
|
|
31524
31973
|
try {
|
|
@@ -31539,7 +31988,7 @@ function loadPolicy(path) {
|
|
|
31539
31988
|
const user = loadUserPolicy(notes);
|
|
31540
31989
|
if (!user.ok) return user;
|
|
31541
31990
|
let merged = { ...user.raw };
|
|
31542
|
-
if (
|
|
31991
|
+
if (existsSync10(path)) {
|
|
31543
31992
|
let text;
|
|
31544
31993
|
try {
|
|
31545
31994
|
text = readFileSync15(path, "utf8");
|
|
@@ -31552,6 +32001,10 @@ function loadPolicy(path) {
|
|
|
31552
32001
|
delete project.raw["sessionRelease"];
|
|
31553
32002
|
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
32003
|
}
|
|
32004
|
+
if (project.raw["events"] !== void 0) {
|
|
32005
|
+
delete project.raw["events"];
|
|
32006
|
+
notes.push(`Ignored "events" in ${path}: only your user-level policy can turn the event log off, so a repository cannot switch it off.`);
|
|
32007
|
+
}
|
|
31555
32008
|
if (isSigned(path, text)) {
|
|
31556
32009
|
merged = { ...merged, ...project.raw };
|
|
31557
32010
|
} else {
|
|
@@ -31779,12 +32232,13 @@ var ApprovalStore = class {
|
|
|
31779
32232
|
// ../shield/src/anchor.ts
|
|
31780
32233
|
import { createHash as createHash9 } from "node:crypto";
|
|
31781
32234
|
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
|
|
32235
|
+
import { join as join23, resolve as resolve21 } from "node:path";
|
|
31783
32236
|
var ANCHOR_DOMAIN = "exorcist-98:anchor:v1";
|
|
31784
|
-
var folderId = (dir) => createHash9("sha256").update(
|
|
32237
|
+
var folderId = (dir) => createHash9("sha256").update(resolve21(dir)).digest("hex").slice(0, 32);
|
|
31785
32238
|
var anchorPath = (dir, userDir = userConfigDir()) => join23(userDir, "anchors", `${folderId(dir)}.json`);
|
|
31786
|
-
var anchorText = (id, seq2, hash) => `${id}\0${seq2}\0${hash}`;
|
|
31787
|
-
|
|
32239
|
+
var anchorText = (id, seq2, hash, off) => `${id}\0${seq2}\0${hash}${off === void 0 ? "" : `\0off:${off}`}`;
|
|
32240
|
+
var isTime = (t2) => typeof t2 === "string" && t2.length <= 40 && !Number.isNaN(Date.parse(t2));
|
|
32241
|
+
function writeAnchor(dir, head, o = {}) {
|
|
31788
32242
|
const key = getUserKey({ create: true });
|
|
31789
32243
|
if (!key.ok) return `the log anchor could not be written (${key.error})`;
|
|
31790
32244
|
const userDir = userConfigDir();
|
|
@@ -31792,7 +32246,9 @@ function writeAnchor(dir, head) {
|
|
|
31792
32246
|
const problem = ensurePrivateDir(anchors);
|
|
31793
32247
|
if (problem !== null) return `the log anchor could not be written (${problem})`;
|
|
31794
32248
|
const id = folderId(dir);
|
|
31795
|
-
const
|
|
32249
|
+
const before = readAnchor(dir);
|
|
32250
|
+
const off = o.eventsOffSince ?? (before.ok ? before.anchor?.eventsOffSince : void 0);
|
|
32251
|
+
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
32252
|
const path = join23(anchors, `${id}.json`);
|
|
31797
32253
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
31798
32254
|
let fd = null;
|
|
@@ -31838,11 +32294,16 @@ function readAnchor(dir) {
|
|
|
31838
32294
|
return { ok: false, error: "the anchor is damaged" };
|
|
31839
32295
|
}
|
|
31840
32296
|
const id = folderId(dir);
|
|
31841
|
-
|
|
32297
|
+
const off = raw.eventsOffSince;
|
|
32298
|
+
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
32299
|
return { ok: false, error: "the anchor was changed or was not written by this machine" };
|
|
31843
32300
|
}
|
|
31844
32301
|
return { ok: true, anchor: raw };
|
|
31845
32302
|
}
|
|
32303
|
+
function readEventsOffSince(dir) {
|
|
32304
|
+
const a = readAnchor(dir);
|
|
32305
|
+
return a.ok && a.anchor?.eventsOffSince !== void 0 ? a.anchor.eventsOffSince : null;
|
|
32306
|
+
}
|
|
31846
32307
|
function checkAnchor(dir, head, hashAt) {
|
|
31847
32308
|
const a = readAnchor(dir);
|
|
31848
32309
|
if (!a.ok) return { status: "tampered", detail: `The log anchor kept outside the state folder cannot be trusted: ${a.error}.` };
|
|
@@ -31856,17 +32317,250 @@ function checkAnchor(dir, head, hashAt) {
|
|
|
31856
32317
|
return { status: "ok", seq: seq2 };
|
|
31857
32318
|
}
|
|
31858
32319
|
|
|
32320
|
+
// ../shield/src/fs-kind.ts
|
|
32321
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
32322
|
+
import { statfsSync } from "node:fs";
|
|
32323
|
+
var NETWORK_FS_MAGIC = /* @__PURE__ */ new Set([
|
|
32324
|
+
26985,
|
|
32325
|
+
// NFS
|
|
32326
|
+
20859,
|
|
32327
|
+
// SMB
|
|
32328
|
+
4283649346,
|
|
32329
|
+
// CIFS
|
|
32330
|
+
4266872130,
|
|
32331
|
+
// SMB2
|
|
32332
|
+
1702057286,
|
|
32333
|
+
// FUSE (sshfs and others)
|
|
32334
|
+
12805120,
|
|
32335
|
+
// Ceph
|
|
32336
|
+
16914839,
|
|
32337
|
+
// 9p
|
|
32338
|
+
1397113167,
|
|
32339
|
+
// AFS
|
|
32340
|
+
1937076805,
|
|
32341
|
+
// Coda
|
|
32342
|
+
22092,
|
|
32343
|
+
// NCP
|
|
32344
|
+
198183888
|
|
32345
|
+
// Lustre
|
|
32346
|
+
]);
|
|
32347
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
32348
|
+
function isUncPath(p) {
|
|
32349
|
+
if (/^\\\\\?\\UNC\\/i.test(p)) return true;
|
|
32350
|
+
if (/^\\\\[?.]\\/.test(p)) return false;
|
|
32351
|
+
return /^\\\\[^\\]/.test(p);
|
|
32352
|
+
}
|
|
32353
|
+
function driveLetter(p) {
|
|
32354
|
+
const m = /^(?:\\\\[?.]\\)?([A-Za-z]):(?:[\\/]|$)/.exec(p);
|
|
32355
|
+
return m ? m[1].toUpperCase() : null;
|
|
32356
|
+
}
|
|
32357
|
+
function classifyDf(r) {
|
|
32358
|
+
if (r === null) return null;
|
|
32359
|
+
if (/No such file system/i.test(`${r.stdout}
|
|
32360
|
+
${r.stderr}`)) return true;
|
|
32361
|
+
if (r.status !== 0) return null;
|
|
32362
|
+
const lines = r.stdout.split("\n").filter((l) => l.trim() !== "");
|
|
32363
|
+
if (lines.length >= 2) return false;
|
|
32364
|
+
if (lines.length === 1 && /^Filesystem\b/.test(lines[0])) return true;
|
|
32365
|
+
return null;
|
|
32366
|
+
}
|
|
32367
|
+
function runDf(dir) {
|
|
32368
|
+
try {
|
|
32369
|
+
const stdout = execFileSync3("/bin/df", ["-l", dir], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
32370
|
+
return { status: 0, stdout, stderr: "" };
|
|
32371
|
+
} catch (e) {
|
|
32372
|
+
const x = e;
|
|
32373
|
+
if (typeof x.status === "number") return { status: x.status, stdout: String(x.stdout ?? ""), stderr: String(x.stderr ?? "") };
|
|
32374
|
+
return null;
|
|
32375
|
+
}
|
|
32376
|
+
}
|
|
32377
|
+
function runPowershell(letter) {
|
|
32378
|
+
try {
|
|
32379
|
+
return execFileSync3("powershell", ["-NoProfile", "-Command", `(Get-PSDrive -Name ${letter}).DisplayRoot`], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
32380
|
+
} catch {
|
|
32381
|
+
return null;
|
|
32382
|
+
}
|
|
32383
|
+
}
|
|
32384
|
+
function linux(dir, d) {
|
|
32385
|
+
try {
|
|
32386
|
+
const t2 = (d.statfs ?? ((p) => statfsSync(p)))(dir).type;
|
|
32387
|
+
const n = Number(BigInt(t2) & 0xffffffffn);
|
|
32388
|
+
return NETWORK_FS_MAGIC.has(n);
|
|
32389
|
+
} catch {
|
|
32390
|
+
return null;
|
|
32391
|
+
}
|
|
32392
|
+
}
|
|
32393
|
+
function windows(dir, d) {
|
|
32394
|
+
if (isUncPath(dir)) return true;
|
|
32395
|
+
const letter = driveLetter(dir);
|
|
32396
|
+
if (letter === null) return null;
|
|
32397
|
+
const out = (d.powershell ?? runPowershell)(letter);
|
|
32398
|
+
return out === null ? null : out.trim() !== "";
|
|
32399
|
+
}
|
|
32400
|
+
function isNetworkFs(dir, deps = {}) {
|
|
32401
|
+
const platform = deps.platform ?? process.platform;
|
|
32402
|
+
const key = `${platform}\0${dir}`;
|
|
32403
|
+
if (cache3.has(key)) return cache3.get(key) ?? null;
|
|
32404
|
+
let r;
|
|
32405
|
+
if (platform === "linux") r = linux(dir, deps);
|
|
32406
|
+
else if (platform === "darwin") r = classifyDf((deps.df ?? runDf)(dir));
|
|
32407
|
+
else if (platform === "win32") r = windows(dir, deps);
|
|
32408
|
+
else r = null;
|
|
32409
|
+
cache3.set(key, r);
|
|
32410
|
+
return r;
|
|
32411
|
+
}
|
|
32412
|
+
|
|
32413
|
+
// ../shield/src/log-location.ts
|
|
32414
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
32415
|
+
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";
|
|
32416
|
+
import { tmpdir as tmpdir2, userInfo } from "node:os";
|
|
32417
|
+
import { basename as basename9, dirname as dirname10, join as join24, resolve as resolve22 } from "node:path";
|
|
32418
|
+
var hook = null;
|
|
32419
|
+
var processUid = () => typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
32420
|
+
function existingAncestor(p) {
|
|
32421
|
+
let cur = resolve22(p);
|
|
32422
|
+
for (let i = 0; i < 64 && !existsSync11(cur); i++) {
|
|
32423
|
+
const up = dirname10(cur);
|
|
32424
|
+
if (up === cur) break;
|
|
32425
|
+
cur = up;
|
|
32426
|
+
}
|
|
32427
|
+
return cur;
|
|
32428
|
+
}
|
|
32429
|
+
function realPathOf(p) {
|
|
32430
|
+
const abs = resolve22(p);
|
|
32431
|
+
const anc = existingAncestor(abs);
|
|
32432
|
+
let real = anc;
|
|
32433
|
+
try {
|
|
32434
|
+
real = realpathSync9(anc);
|
|
32435
|
+
} catch {
|
|
32436
|
+
}
|
|
32437
|
+
return anc === abs ? real : join24(real, abs.slice(anc.length));
|
|
32438
|
+
}
|
|
32439
|
+
function basesFor(platform, d) {
|
|
32440
|
+
if (d.base !== void 0) return [d.base];
|
|
32441
|
+
const env = d.env ?? process.env;
|
|
32442
|
+
if (platform === "win32") {
|
|
32443
|
+
const la = env["LOCALAPPDATA"];
|
|
32444
|
+
return la !== void 0 && la !== "" ? [la] : [];
|
|
32445
|
+
}
|
|
32446
|
+
if (platform === "darwin") return [tmpdir2()];
|
|
32447
|
+
const run3 = env["XDG_RUNTIME_DIR"];
|
|
32448
|
+
const shared = d.sharedBase ?? "/var/tmp";
|
|
32449
|
+
return run3 !== void 0 && run3.startsWith("/") ? [shared, run3] : [shared];
|
|
32450
|
+
}
|
|
32451
|
+
function userLabel(uid2) {
|
|
32452
|
+
if (uid2 !== void 0) return String(uid2);
|
|
32453
|
+
let name = "user";
|
|
32454
|
+
try {
|
|
32455
|
+
name = userInfo().username;
|
|
32456
|
+
} catch {
|
|
32457
|
+
}
|
|
32458
|
+
return name.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 32) || "user";
|
|
32459
|
+
}
|
|
32460
|
+
function problemWith(dir, uid2, windows2) {
|
|
32461
|
+
let st;
|
|
32462
|
+
try {
|
|
32463
|
+
st = lstatSync9(dir);
|
|
32464
|
+
} catch {
|
|
32465
|
+
return `${dir} could not be inspected`;
|
|
32466
|
+
}
|
|
32467
|
+
if (st.isSymbolicLink()) return `${dir} is a symbolic link`;
|
|
32468
|
+
if (!st.isDirectory()) return `${dir} is not a folder`;
|
|
32469
|
+
if (!windows2 && uid2 !== void 0 && st.uid !== uid2) return `${dir} is not owned by this user`;
|
|
32470
|
+
if (!windows2 && (st.mode & 18) !== 0) return `${dir} can be changed by other users`;
|
|
32471
|
+
return null;
|
|
32472
|
+
}
|
|
32473
|
+
function resolveLogLocation(stateDir2, o = {}) {
|
|
32474
|
+
const d = { ...hook ?? {}, ...o };
|
|
32475
|
+
const platform = d.platform ?? process.platform;
|
|
32476
|
+
const probe = d.isNetworkFs ?? ((p) => isNetworkFs(p));
|
|
32477
|
+
const kind = probe(existingAncestor(stateDir2));
|
|
32478
|
+
if (kind === false) return { ok: true, dir: stateDir2, moved: false };
|
|
32479
|
+
const bases = basesFor(platform, d);
|
|
32480
|
+
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)" };
|
|
32481
|
+
const windows2 = platform === "win32";
|
|
32482
|
+
const uid2 = d.uid ?? processUid();
|
|
32483
|
+
const leaf = `events-${createHash10("sha256").update(realPathOf(stateDir2)).digest("hex").slice(0, 16)}`;
|
|
32484
|
+
let dir = null;
|
|
32485
|
+
let refused = "";
|
|
32486
|
+
for (const base of bases) {
|
|
32487
|
+
const parent = join24(base, `exorcist-98-${userLabel(uid2)}`);
|
|
32488
|
+
const candidate = join24(parent, leaf);
|
|
32489
|
+
if (lstatSyncOrNull(candidate) !== null && checkChain([parent, candidate], uid2, windows2, false) === null) {
|
|
32490
|
+
dir = candidate;
|
|
32491
|
+
break;
|
|
32492
|
+
}
|
|
32493
|
+
}
|
|
32494
|
+
if (dir === null) for (const base of bases) {
|
|
32495
|
+
const parent = join24(base, `exorcist-98-${userLabel(uid2)}`);
|
|
32496
|
+
const candidate = join24(parent, leaf);
|
|
32497
|
+
const bad = checkChain([parent, candidate], uid2, windows2, o.create === true);
|
|
32498
|
+
if (bad === null) {
|
|
32499
|
+
dir = candidate;
|
|
32500
|
+
break;
|
|
32501
|
+
}
|
|
32502
|
+
refused = bad;
|
|
32503
|
+
}
|
|
32504
|
+
if (dir === null) return { ok: false, error: `the local event log folder was refused: ${refused}` };
|
|
32505
|
+
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";
|
|
32506
|
+
return { ok: true, dir, moved: true, reason };
|
|
32507
|
+
}
|
|
32508
|
+
function checkChain(paths2, uid2, windows2, create) {
|
|
32509
|
+
for (const p of paths2) {
|
|
32510
|
+
if (lstatSyncOrNull(p) === null) {
|
|
32511
|
+
if (!create) return null;
|
|
32512
|
+
try {
|
|
32513
|
+
mkdirSync4(p, { recursive: true, mode: 448 });
|
|
32514
|
+
} catch (e) {
|
|
32515
|
+
if (e.code !== "EEXIST") return `${p} could not be created`;
|
|
32516
|
+
}
|
|
32517
|
+
}
|
|
32518
|
+
const bad = problemWith(p, uid2, windows2);
|
|
32519
|
+
if (bad !== null) return bad;
|
|
32520
|
+
}
|
|
32521
|
+
return null;
|
|
32522
|
+
}
|
|
32523
|
+
function lstatSyncOrNull(p) {
|
|
32524
|
+
try {
|
|
32525
|
+
return lstatSync9(p);
|
|
32526
|
+
} catch {
|
|
32527
|
+
return null;
|
|
32528
|
+
}
|
|
32529
|
+
}
|
|
32530
|
+
function locationNote(loc) {
|
|
32531
|
+
return `Events are written in ${loc.dir}, not in the state folder: ${loc.reason ?? "the state folder is not local"}.`;
|
|
32532
|
+
}
|
|
32533
|
+
function writeLocationPointer(stateDir2, logDir) {
|
|
32534
|
+
const path = join24(stateDir2, "events.location");
|
|
32535
|
+
let fd = null;
|
|
32536
|
+
try {
|
|
32537
|
+
fd = openSync7(path, constants5.O_WRONLY | constants5.O_CREAT | constants5.O_TRUNC | (constants5.O_NOFOLLOW ?? 0), 384);
|
|
32538
|
+
writeSync4(fd, `${logDir}
|
|
32539
|
+
`);
|
|
32540
|
+
return null;
|
|
32541
|
+
} catch (e) {
|
|
32542
|
+
return `${basename9(path)} could not be written (${e.code ?? "error"})`;
|
|
32543
|
+
} finally {
|
|
32544
|
+
if (fd !== null) {
|
|
32545
|
+
try {
|
|
32546
|
+
closeSync7(fd);
|
|
32547
|
+
} catch {
|
|
32548
|
+
}
|
|
32549
|
+
}
|
|
32550
|
+
}
|
|
32551
|
+
}
|
|
32552
|
+
|
|
31859
32553
|
// ../shield/src/os-auth-platform.ts
|
|
31860
32554
|
import { spawn } from "node:child_process";
|
|
31861
|
-
import { accessSync, constants as
|
|
31862
|
-
import { delimiter, join as
|
|
32555
|
+
import { accessSync, constants as constants6 } from "node:fs";
|
|
32556
|
+
import { delimiter, join as join26 } from "node:path";
|
|
31863
32557
|
|
|
31864
32558
|
// ../shield/src/session.ts
|
|
31865
32559
|
init_zod();
|
|
31866
|
-
import { createHash as
|
|
32560
|
+
import { createHash as createHash11, randomBytes as randomBytes5 } from "node:crypto";
|
|
31867
32561
|
import { spawnSync } from "node:child_process";
|
|
31868
|
-
import { lstatSync as
|
|
31869
|
-
import { join as
|
|
32562
|
+
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";
|
|
32563
|
+
import { join as join25 } from "node:path";
|
|
31870
32564
|
var SESSION_RULE_ID = "EX-027";
|
|
31871
32565
|
var SESSION_TTL_MS = 2 * 60 * 60 * 1e3;
|
|
31872
32566
|
var MAX_FACTS = 32;
|
|
@@ -32049,14 +32743,14 @@ var TMP_RE = /\.tmp$/;
|
|
|
32049
32743
|
function code(err) {
|
|
32050
32744
|
return err && typeof err === "object" && "code" in err ? String(err.code) : "error";
|
|
32051
32745
|
}
|
|
32052
|
-
var sessionsPath = (stateDir2) =>
|
|
32746
|
+
var sessionsPath = (stateDir2) => join25(stateDir2, "sessions");
|
|
32053
32747
|
var FileSessionStore = class {
|
|
32054
32748
|
constructor(stateDir2, key, ttlMs = SESSION_TTL_MS) {
|
|
32055
32749
|
this.key = key;
|
|
32056
32750
|
this.ttlMs = ttlMs;
|
|
32057
32751
|
if (!isSessionKey(key)) throw new Error(`Invalid session key "${key}".`);
|
|
32058
32752
|
this.root = sessionsPath(stateDir2);
|
|
32059
|
-
this.dir =
|
|
32753
|
+
this.dir = join25(this.root, key);
|
|
32060
32754
|
}
|
|
32061
32755
|
dir;
|
|
32062
32756
|
root;
|
|
@@ -32078,10 +32772,10 @@ var FileSessionStore = class {
|
|
|
32078
32772
|
problems.push(`${name} in ${this.dir} is not a session record`);
|
|
32079
32773
|
continue;
|
|
32080
32774
|
}
|
|
32081
|
-
const path =
|
|
32775
|
+
const path = join25(this.dir, name);
|
|
32082
32776
|
let st;
|
|
32083
32777
|
try {
|
|
32084
|
-
st =
|
|
32778
|
+
st = lstatSync10(path);
|
|
32085
32779
|
} catch (err) {
|
|
32086
32780
|
if (code(err) !== "ENOENT") problems.push(`${name} could not be read (${code(err)})`);
|
|
32087
32781
|
continue;
|
|
@@ -32112,10 +32806,10 @@ var FileSessionStore = class {
|
|
|
32112
32806
|
return { records, problems };
|
|
32113
32807
|
}
|
|
32114
32808
|
write(record3) {
|
|
32115
|
-
const path =
|
|
32809
|
+
const path = join25(this.dir, `${record3.writer}.json`);
|
|
32116
32810
|
const tmp = `${path}.${process.pid}.${randomBytes5(4).toString("hex")}.tmp`;
|
|
32117
32811
|
try {
|
|
32118
|
-
|
|
32812
|
+
mkdirSync5(this.dir, { recursive: true, mode: 448 });
|
|
32119
32813
|
writeFileSync4(tmp, `${JSON.stringify(record3)}
|
|
32120
32814
|
`, { encoding: "utf8", mode: 384 });
|
|
32121
32815
|
renameSync5(tmp, path);
|
|
@@ -32138,8 +32832,8 @@ var FileSessionStore = class {
|
|
|
32138
32832
|
try {
|
|
32139
32833
|
for (const name of readdirSync8(this.dir)) {
|
|
32140
32834
|
if (name === `${own}.json`) continue;
|
|
32141
|
-
const p =
|
|
32142
|
-
const st =
|
|
32835
|
+
const p = join25(this.dir, name);
|
|
32836
|
+
const st = lstatSync10(p);
|
|
32143
32837
|
if (st.isFile() && old(st, TMP_RE.test(name) ? 6e4 : this.ttlMs)) unlinkSync3(p);
|
|
32144
32838
|
}
|
|
32145
32839
|
} catch {
|
|
@@ -32147,13 +32841,13 @@ var FileSessionStore = class {
|
|
|
32147
32841
|
try {
|
|
32148
32842
|
for (const name of readdirSync8(this.root).slice(0, MAX_SESSION_DIRS)) {
|
|
32149
32843
|
if (name === this.key || !KEY_RE.test(name)) continue;
|
|
32150
|
-
const p =
|
|
32151
|
-
const st =
|
|
32844
|
+
const p = join25(this.root, name);
|
|
32845
|
+
const st = lstatSync10(p);
|
|
32152
32846
|
if (!st.isDirectory()) continue;
|
|
32153
|
-
const
|
|
32154
|
-
const newest =
|
|
32847
|
+
const entries2 = readdirSync8(p);
|
|
32848
|
+
const newest = entries2.reduce((m, e) => {
|
|
32155
32849
|
try {
|
|
32156
|
-
return Math.max(m,
|
|
32850
|
+
return Math.max(m, lstatSync10(join25(p, e)).mtimeMs);
|
|
32157
32851
|
} catch {
|
|
32158
32852
|
return m;
|
|
32159
32853
|
}
|
|
@@ -32217,7 +32911,7 @@ function resolveSessionKey(o = {}) {
|
|
|
32217
32911
|
for (let hop = 0; hop < 8 && pid > 1; hop++) {
|
|
32218
32912
|
const info = lookup(pid);
|
|
32219
32913
|
if (!info) break;
|
|
32220
|
-
if (!isLauncher(info.command)) return `p${pid}-${
|
|
32914
|
+
if (!isLauncher(info.command)) return `p${pid}-${createHash11("sha256").update(info.started).digest("hex").slice(0, 8)}`;
|
|
32221
32915
|
if (info.ppid === pid) break;
|
|
32222
32916
|
pid = info.ppid;
|
|
32223
32917
|
}
|
|
@@ -32295,7 +32989,7 @@ function macOsAuth(o = {}) {
|
|
|
32295
32989
|
} catch {
|
|
32296
32990
|
return { kind: "fail" };
|
|
32297
32991
|
}
|
|
32298
|
-
return new Promise((
|
|
32992
|
+
return new Promise((resolve42) => {
|
|
32299
32993
|
let settled = false;
|
|
32300
32994
|
let timer;
|
|
32301
32995
|
let child;
|
|
@@ -32303,7 +32997,7 @@ function macOsAuth(o = {}) {
|
|
|
32303
32997
|
if (settled) return;
|
|
32304
32998
|
settled = true;
|
|
32305
32999
|
if (timer !== void 0) clearTimeout(timer);
|
|
32306
|
-
|
|
33000
|
+
resolve42(r);
|
|
32307
33001
|
};
|
|
32308
33002
|
try {
|
|
32309
33003
|
const base = o.env ?? process.env;
|
|
@@ -32432,7 +33126,7 @@ function commandOnPath(name, env = process.env) {
|
|
|
32432
33126
|
for (const dir of (env["PATH"] ?? env["Path"] ?? "").split(delimiter)) {
|
|
32433
33127
|
if (!dir) continue;
|
|
32434
33128
|
try {
|
|
32435
|
-
accessSync(
|
|
33129
|
+
accessSync(join26(dir, name), constants6.X_OK);
|
|
32436
33130
|
return true;
|
|
32437
33131
|
} catch {
|
|
32438
33132
|
}
|
|
@@ -32441,14 +33135,14 @@ function commandOnPath(name, env = process.env) {
|
|
|
32441
33135
|
}
|
|
32442
33136
|
var TIMEOUT_MS = 6e4;
|
|
32443
33137
|
function run(spawnFn, cmd, env, timeoutMs) {
|
|
32444
|
-
return new Promise((
|
|
33138
|
+
return new Promise((resolve42) => {
|
|
32445
33139
|
let done = false;
|
|
32446
33140
|
let timer;
|
|
32447
33141
|
const finish = (r) => {
|
|
32448
33142
|
if (done) return;
|
|
32449
33143
|
done = true;
|
|
32450
33144
|
if (timer !== void 0) clearTimeout(timer);
|
|
32451
|
-
|
|
33145
|
+
resolve42(r);
|
|
32452
33146
|
};
|
|
32453
33147
|
try {
|
|
32454
33148
|
const proc = spawnFn(cmd.file, cmd.args, { env, stdio: ["ignore", "pipe", "ignore"] });
|
|
@@ -32530,8 +33224,8 @@ function defaultOsAuth(o = {}) {
|
|
|
32530
33224
|
|
|
32531
33225
|
// ../shield/src/state.ts
|
|
32532
33226
|
init_zod();
|
|
32533
|
-
import { appendFileSync, existsSync as
|
|
32534
|
-
import { dirname as
|
|
33227
|
+
import { appendFileSync, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync19, renameSync as renameSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
33228
|
+
import { dirname as dirname11, join as join27 } from "node:path";
|
|
32535
33229
|
var Sha256 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
32536
33230
|
var PinSchema = external_exports.object({
|
|
32537
33231
|
hash: Sha256,
|
|
@@ -32580,16 +33274,16 @@ var StateSchema = external_exports.object({
|
|
|
32580
33274
|
servers: external_exports.record(ServerStateSchema).default({})
|
|
32581
33275
|
});
|
|
32582
33276
|
var emptyState = () => ({ version: 1, servers: {} });
|
|
32583
|
-
var statePath = (dir) =>
|
|
32584
|
-
var policyPath = (dir) =>
|
|
32585
|
-
var alertsPath = (dir) =>
|
|
32586
|
-
var vaultPath = (dir) =>
|
|
33277
|
+
var statePath = (dir) => join27(dir, "pins.json");
|
|
33278
|
+
var policyPath = (dir) => join27(dir, "policy.json");
|
|
33279
|
+
var alertsPath = (dir) => join27(dir, "alerts.jsonl");
|
|
33280
|
+
var vaultPath = (dir) => join27(dir, "vault");
|
|
32587
33281
|
var PINS_DOMAIN = "exorcist-98:pins:v1";
|
|
32588
33282
|
function pinsText(raw) {
|
|
32589
33283
|
return canonicalJson({ version: raw.version, servers: raw.servers });
|
|
32590
33284
|
}
|
|
32591
33285
|
function loadState(path) {
|
|
32592
|
-
if (!
|
|
33286
|
+
if (!existsSync12(path)) return { ok: true, state: emptyState() };
|
|
32593
33287
|
let json2;
|
|
32594
33288
|
try {
|
|
32595
33289
|
json2 = JSON.parse(readFileSync19(path, "utf8"));
|
|
@@ -32609,7 +33303,7 @@ function loadState(path) {
|
|
|
32609
33303
|
return { ok: true, state: parsed.data };
|
|
32610
33304
|
}
|
|
32611
33305
|
function saveState(path, state) {
|
|
32612
|
-
|
|
33306
|
+
mkdirSync6(dirname11(path), { recursive: true });
|
|
32613
33307
|
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
32614
33308
|
const body = JSON.parse(JSON.stringify({ version: state.version, servers: state.servers }));
|
|
32615
33309
|
const key = getUserKey({ create: true });
|
|
@@ -32627,7 +33321,7 @@ function serverState(state, name) {
|
|
|
32627
33321
|
return s;
|
|
32628
33322
|
}
|
|
32629
33323
|
function appendAlert(path, alert) {
|
|
32630
|
-
|
|
33324
|
+
mkdirSync6(dirname11(path), { recursive: true });
|
|
32631
33325
|
appendFileSync(path, `${JSON.stringify(alert)}
|
|
32632
33326
|
`, "utf8");
|
|
32633
33327
|
}
|
|
@@ -33274,8 +33968,8 @@ function throttle(o = {}) {
|
|
|
33274
33968
|
}
|
|
33275
33969
|
|
|
33276
33970
|
// ../shield/src/canary.ts
|
|
33277
|
-
import { existsSync as
|
|
33278
|
-
import { dirname as
|
|
33971
|
+
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";
|
|
33972
|
+
import { dirname as dirname12, isAbsolute as isAbsolute17, join as join28, resolve as resolve23 } from "node:path";
|
|
33279
33973
|
var TRAPS = [
|
|
33280
33974
|
{
|
|
33281
33975
|
name: ".env.canary",
|
|
@@ -33318,36 +34012,36 @@ function plantCanaries(root, o = {}) {
|
|
|
33318
34012
|
return { ok: false, error: `Canary traps are already planted in ${root}. To replace them, run "exorcist canary --remove" first.` };
|
|
33319
34013
|
}
|
|
33320
34014
|
for (const d of [".exorcist", CANARY_TRAP_DIR]) {
|
|
33321
|
-
const path =
|
|
33322
|
-
if (
|
|
34015
|
+
const path = join28(root, d);
|
|
34016
|
+
if (existsSync13(path) || isSymlink(path)) {
|
|
33323
34017
|
if (!isRealDir(path)) return { ok: false, error: `${path} is not a real folder (a symlink or a file); no traps were planted.` };
|
|
33324
34018
|
}
|
|
33325
34019
|
}
|
|
33326
34020
|
const traps = TRAPS.slice(0, count);
|
|
33327
34021
|
for (const t2 of traps) {
|
|
33328
|
-
const path =
|
|
33329
|
-
if (
|
|
34022
|
+
const path = join28(root, CANARY_TRAP_DIR, t2.name);
|
|
34023
|
+
if (existsSync13(path)) return { ok: false, error: `${path} already exists; it was not overwritten.` };
|
|
33330
34024
|
}
|
|
33331
34025
|
const created = (o.now ? o.now() : /* @__PURE__ */ new Date()).toISOString();
|
|
33332
34026
|
const records = [];
|
|
33333
|
-
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !
|
|
34027
|
+
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !existsSync13(join28(root, d)));
|
|
33334
34028
|
try {
|
|
33335
|
-
|
|
34029
|
+
mkdirSync7(join28(root, CANARY_TRAP_DIR), { recursive: true });
|
|
33336
34030
|
for (const t2 of traps) {
|
|
33337
34031
|
const token = newToken();
|
|
33338
34032
|
const file = `${CANARY_TRAP_DIR}/${t2.name}`;
|
|
33339
|
-
writeFileSync6(
|
|
34033
|
+
writeFileSync6(join28(root, file), t2.body(token), { flag: "wx" });
|
|
33340
34034
|
records.push({ token, file, created });
|
|
33341
34035
|
}
|
|
33342
34036
|
writeFileSync6(recordsFile, `${JSON.stringify({ version: 1, canaries: records, ...madeDirs.length > 0 ? { madeDirs } : {} }, null, 2)}
|
|
33343
34037
|
`);
|
|
33344
34038
|
} catch (err) {
|
|
33345
|
-
for (const r of records) rmSync3(
|
|
33346
|
-
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(
|
|
34039
|
+
for (const r of records) rmSync3(join28(root, r.file), { force: true });
|
|
34040
|
+
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(join28(root, d));
|
|
33347
34041
|
return { ok: false, error: `Could not plant the canary traps: ${firstLine(err)}` };
|
|
33348
34042
|
}
|
|
33349
34043
|
const result = { ok: true, records, recordsFile };
|
|
33350
|
-
if (o.stateDir &&
|
|
34044
|
+
if (o.stateDir && resolve23(o.stateDir) !== resolve23(root, ".exorcist")) {
|
|
33351
34045
|
const told = setPolicyCanaries(o.stateDir, recordsFile);
|
|
33352
34046
|
if (!told.ok) return { ok: false, error: `Planted the traps, but could not tell the Shield where they are: ${told.error}` };
|
|
33353
34047
|
result.policyUpdated = policyPath(o.stateDir);
|
|
@@ -33360,20 +34054,20 @@ function loadCanaries(root) {
|
|
|
33360
34054
|
}
|
|
33361
34055
|
function rmdirIfEmpty(path) {
|
|
33362
34056
|
try {
|
|
33363
|
-
if (
|
|
34057
|
+
if (lstatSync11(path).isDirectory() && readdirSync9(path).length === 0) rmdirSync(path);
|
|
33364
34058
|
} catch {
|
|
33365
34059
|
}
|
|
33366
34060
|
}
|
|
33367
34061
|
function isSymlink(path) {
|
|
33368
34062
|
try {
|
|
33369
|
-
return
|
|
34063
|
+
return lstatSync11(path).isSymbolicLink();
|
|
33370
34064
|
} catch {
|
|
33371
34065
|
return false;
|
|
33372
34066
|
}
|
|
33373
34067
|
}
|
|
33374
34068
|
function isRealDir(path) {
|
|
33375
34069
|
try {
|
|
33376
|
-
return
|
|
34070
|
+
return lstatSync11(path).isDirectory();
|
|
33377
34071
|
} catch {
|
|
33378
34072
|
return false;
|
|
33379
34073
|
}
|
|
@@ -33385,18 +34079,18 @@ function removeCanaries(root, o = {}) {
|
|
|
33385
34079
|
if (!existing.ok) return existing;
|
|
33386
34080
|
const removed = [];
|
|
33387
34081
|
const warnings = [];
|
|
33388
|
-
const stateFolder =
|
|
33389
|
-
const trapFolder =
|
|
34082
|
+
const stateFolder = join28(root, ".exorcist");
|
|
34083
|
+
const trapFolder = join28(root, CANARY_TRAP_DIR);
|
|
33390
34084
|
const foldersReal = isRealDir(stateFolder) && isRealDir(trapFolder);
|
|
33391
34085
|
let trapReal = null;
|
|
33392
34086
|
try {
|
|
33393
|
-
trapReal = foldersReal ?
|
|
34087
|
+
trapReal = foldersReal ? realpathSync10(trapFolder) : null;
|
|
33394
34088
|
} catch {
|
|
33395
34089
|
trapReal = null;
|
|
33396
34090
|
}
|
|
33397
34091
|
let left = 0;
|
|
33398
34092
|
for (const r of existing.canaries) {
|
|
33399
|
-
const full =
|
|
34093
|
+
const full = join28(root, r.file);
|
|
33400
34094
|
const name = r.file.slice(`${CANARY_TRAP_DIR}/`.length);
|
|
33401
34095
|
const leave = (why) => {
|
|
33402
34096
|
left++;
|
|
@@ -33404,7 +34098,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33404
34098
|
};
|
|
33405
34099
|
let st;
|
|
33406
34100
|
try {
|
|
33407
|
-
st =
|
|
34101
|
+
st = lstatSync11(full);
|
|
33408
34102
|
} catch {
|
|
33409
34103
|
continue;
|
|
33410
34104
|
}
|
|
@@ -33421,7 +34115,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33421
34115
|
continue;
|
|
33422
34116
|
}
|
|
33423
34117
|
try {
|
|
33424
|
-
if (
|
|
34118
|
+
if (realpathSync10(dirname12(full)) !== trapReal) {
|
|
33425
34119
|
leave("it is not inside the trap folder.");
|
|
33426
34120
|
continue;
|
|
33427
34121
|
}
|
|
@@ -33440,7 +34134,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33440
34134
|
return { ok: true, removed, warnings };
|
|
33441
34135
|
}
|
|
33442
34136
|
try {
|
|
33443
|
-
const st =
|
|
34137
|
+
const st = lstatSync11(recordsFile);
|
|
33444
34138
|
if (isRealDir(stateFolder) && st.isFile()) {
|
|
33445
34139
|
rmSync3(recordsFile);
|
|
33446
34140
|
removed.push(CANARY_RECORDS_FILE);
|
|
@@ -33452,12 +34146,12 @@ function removeCanaries(root, o = {}) {
|
|
|
33452
34146
|
}
|
|
33453
34147
|
if (existing.madeDirs.includes(CANARY_TRAP_DIR)) rmdirIfEmpty(trapFolder);
|
|
33454
34148
|
if (existing.madeDirs.includes(".exorcist")) rmdirIfEmpty(stateFolder);
|
|
33455
|
-
if (o.stateDir &&
|
|
34149
|
+
if (o.stateDir && resolve23(o.stateDir) !== resolve23(root, ".exorcist")) clearPolicyCanaries(o.stateDir, recordsFile);
|
|
33456
34150
|
return { ok: true, removed, warnings };
|
|
33457
34151
|
}
|
|
33458
34152
|
function readPolicyObject(stateDir2) {
|
|
33459
34153
|
const path = policyPath(stateDir2);
|
|
33460
|
-
if (!
|
|
34154
|
+
if (!existsSync13(path)) return { ok: true, obj: {} };
|
|
33461
34155
|
try {
|
|
33462
34156
|
const json2 = JSON.parse(readFileSync20(path, "utf8"));
|
|
33463
34157
|
if (!json2 || typeof json2 !== "object" || Array.isArray(json2)) return { ok: false, error: `${path} is not a JSON object.` };
|
|
@@ -33470,10 +34164,10 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33470
34164
|
const p = readPolicyObject(stateDir2);
|
|
33471
34165
|
if (!p.ok) return p;
|
|
33472
34166
|
try {
|
|
33473
|
-
|
|
34167
|
+
mkdirSync7(stateDir2, { recursive: true });
|
|
33474
34168
|
const file = policyPath(stateDir2);
|
|
33475
|
-
const sign = !
|
|
33476
|
-
writeFileSync6(file, `${JSON.stringify({ ...p.obj, canaries:
|
|
34169
|
+
const sign = !existsSync13(file) || policyIsSigned(file);
|
|
34170
|
+
writeFileSync6(file, `${JSON.stringify({ ...p.obj, canaries: resolve23(recordsFile) }, null, 2)}
|
|
33477
34171
|
`);
|
|
33478
34172
|
if (sign) signPolicyFile(file);
|
|
33479
34173
|
return { ok: true };
|
|
@@ -33483,7 +34177,7 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33483
34177
|
}
|
|
33484
34178
|
function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
33485
34179
|
const p = readPolicyObject(stateDir2);
|
|
33486
|
-
if (!p.ok || p.obj["canaries"] !==
|
|
34180
|
+
if (!p.ok || p.obj["canaries"] !== resolve23(recordsFile)) return;
|
|
33487
34181
|
const { canaries: _gone, ...rest } = p.obj;
|
|
33488
34182
|
try {
|
|
33489
34183
|
const file = policyPath(stateDir2);
|
|
@@ -33500,8 +34194,8 @@ function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33500
34194
|
}
|
|
33501
34195
|
}
|
|
33502
34196
|
function canariesFileFor(stateDir2, policyCanaries) {
|
|
33503
|
-
if (!policyCanaries) return
|
|
33504
|
-
return isAbsolute17(policyCanaries) ? policyCanaries :
|
|
34197
|
+
if (!policyCanaries) return join28(stateDir2, "canaries.json");
|
|
34198
|
+
return isAbsolute17(policyCanaries) ? policyCanaries : resolve23(stateDir2, policyCanaries);
|
|
33505
34199
|
}
|
|
33506
34200
|
function allStrings(value) {
|
|
33507
34201
|
const out = [];
|
|
@@ -33515,9 +34209,9 @@ function allStrings(value) {
|
|
|
33515
34209
|
seen.add(v);
|
|
33516
34210
|
if (Array.isArray(v)) for (let i = v.length - 1; i >= 0; i--) stack.push(v[i]);
|
|
33517
34211
|
else {
|
|
33518
|
-
const
|
|
33519
|
-
for (let i =
|
|
33520
|
-
const [k, x] =
|
|
34212
|
+
const entries2 = Object.entries(v);
|
|
34213
|
+
for (let i = entries2.length - 1; i >= 0; i--) {
|
|
34214
|
+
const [k, x] = entries2[i];
|
|
33521
34215
|
stack.push(x, k);
|
|
33522
34216
|
}
|
|
33523
34217
|
}
|
|
@@ -34029,7 +34723,7 @@ var ShieldEngine = class {
|
|
|
34029
34723
|
this.heldCalls.set(promptId, { call, id, tool, hosts, kind: "host", askedAt: this.now(), digest: this.digestOf(call, tool) });
|
|
34030
34724
|
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
34725
|
const shownTool = cleanText(tool, 80);
|
|
34032
|
-
const
|
|
34726
|
+
const list3 = hosts.map((h) => cleanText(h, 80)).join(", ");
|
|
34033
34727
|
return [{
|
|
34034
34728
|
type: "forward",
|
|
34035
34729
|
to: "client",
|
|
@@ -34038,11 +34732,11 @@ var ShieldEngine = class {
|
|
|
34038
34732
|
id: promptId,
|
|
34039
34733
|
method: "elicitation/create",
|
|
34040
34734
|
params: {
|
|
34041
|
-
message: `Exorcist 98: the tool "${shownTool}" on "${cleanText(this.o.server, 80)}" wants to send data to ${
|
|
34735
|
+
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
34736
|
requestedSchema: {
|
|
34043
34737
|
type: "object",
|
|
34044
34738
|
properties: {
|
|
34045
|
-
remember: { type: "boolean", title: `Always allow ${
|
|
34739
|
+
remember: { type: "boolean", title: `Always allow ${list3} for ${cleanText(this.o.server, 80)}`, default: false }
|
|
34046
34740
|
}
|
|
34047
34741
|
}
|
|
34048
34742
|
}
|
|
@@ -34325,8 +35019,8 @@ var ShieldEngine = class {
|
|
|
34325
35019
|
const promptId = `${PROMPT_PREFIX}${++this.elicitSeq}`;
|
|
34326
35020
|
this.heldCalls.set(promptId, { call, id, tool, hosts, kind: "session", askedAt: this.now(), digest: this.digestOf(call, tool) });
|
|
34327
35021
|
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 ${
|
|
35022
|
+
const list3 = hosts.map((h) => cleanText(h, 80)).join(", ");
|
|
35023
|
+
const also = hosts.length > 0 ? ` It would also reach ${list3}, which is not on your allowed list.` : "";
|
|
34330
35024
|
return [{
|
|
34331
35025
|
type: "forward",
|
|
34332
35026
|
to: "client",
|
|
@@ -34770,12 +35464,12 @@ var ShieldEngine = class {
|
|
|
34770
35464
|
|
|
34771
35465
|
// ../shield/src/proxy.ts
|
|
34772
35466
|
import { spawn as spawn3 } from "node:child_process";
|
|
34773
|
-
import { existsSync as
|
|
34774
|
-
import { dirname as
|
|
35467
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync10, readFileSync as readFileSync26, statSync as statSync15 } from "node:fs";
|
|
35468
|
+
import { dirname as dirname16 } from "node:path";
|
|
34775
35469
|
|
|
34776
35470
|
// ../shield/src/lockfile.ts
|
|
34777
|
-
import { existsSync as
|
|
34778
|
-
import { dirname as
|
|
35471
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
35472
|
+
import { dirname as dirname13, join as join29, parse as parsePath, resolve as resolve24 } from "node:path";
|
|
34779
35473
|
init_zod();
|
|
34780
35474
|
var Sha2562 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
34781
35475
|
var LockToolSchema = external_exports.object({
|
|
@@ -34811,7 +35505,7 @@ function lockUrl(url) {
|
|
|
34811
35505
|
return "(not a valid URL)";
|
|
34812
35506
|
}
|
|
34813
35507
|
}
|
|
34814
|
-
var record = (
|
|
35508
|
+
var record = (entries2) => Object.fromEntries(entries2);
|
|
34815
35509
|
function lockServer(l) {
|
|
34816
35510
|
const byName = /* @__PURE__ */ new Map();
|
|
34817
35511
|
for (const t2 of l.tools) {
|
|
@@ -34948,21 +35642,21 @@ function seedFromLock(s, ls, report, o) {
|
|
|
34948
35642
|
var PROJECT_MARKERS2 = [".git", ".kiro", ".exorcist"];
|
|
34949
35643
|
function findLockFile(starts) {
|
|
34950
35644
|
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 ||
|
|
35645
|
+
const { root } = parsePath(resolve24(start));
|
|
35646
|
+
for (let dir = resolve24(start); ; dir = dirname13(dir)) {
|
|
35647
|
+
const candidate = join29(dir, LOCK_FILE);
|
|
35648
|
+
if (existsSync14(candidate)) return candidate;
|
|
35649
|
+
if (PROJECT_MARKERS2.some((m) => existsSync14(join29(dir, m)))) break;
|
|
35650
|
+
if (dir === root || dirname13(dir) === dir) break;
|
|
34957
35651
|
}
|
|
34958
35652
|
}
|
|
34959
35653
|
return null;
|
|
34960
35654
|
}
|
|
34961
35655
|
|
|
34962
35656
|
// ../shield/src/vault.ts
|
|
34963
|
-
import { createHash as
|
|
34964
|
-
import { closeSync as
|
|
34965
|
-
import { basename as
|
|
35657
|
+
import { createHash as createHash12, randomBytes as randomBytes7 } from "node:crypto";
|
|
35658
|
+
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";
|
|
35659
|
+
import { basename as basename10, dirname as dirname14, isAbsolute as isAbsolute18, join as join30, resolve as resolve25, sep as sep6 } from "node:path";
|
|
34966
35660
|
init_zod();
|
|
34967
35661
|
var SafeRel = external_exports.string().min(1).max(1024).refine(
|
|
34968
35662
|
(p) => !isAbsolute18(p) && !p.includes("\\") && !p.includes("\0") && p.split("/").every((seg) => seg !== "" && seg !== "." && seg !== ".."),
|
|
@@ -34993,7 +35687,7 @@ var EntrySchema = external_exports.object({
|
|
|
34993
35687
|
/** HMAC with the user key over every other field (MS-5). Missing or wrong: the entry is not trusted. */
|
|
34994
35688
|
mac: external_exports.string().optional()
|
|
34995
35689
|
});
|
|
34996
|
-
var sha2562 = (data) =>
|
|
35690
|
+
var sha2562 = (data) => createHash12("sha256").update(data).digest("hex");
|
|
34997
35691
|
var fail3 = (error2) => ({ ok: false, error: error2 });
|
|
34998
35692
|
var VAULT_DOMAIN = "exorcist-98:vault:v1";
|
|
34999
35693
|
var entryText = (e) => {
|
|
@@ -35002,13 +35696,13 @@ var entryText = (e) => {
|
|
|
35002
35696
|
};
|
|
35003
35697
|
function ensureSafeVault(vaultDir) {
|
|
35004
35698
|
const me = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
35005
|
-
const state =
|
|
35699
|
+
const state = dirname14(vaultDir);
|
|
35006
35700
|
try {
|
|
35007
|
-
|
|
35701
|
+
mkdirSync8(dirname14(state), { recursive: true });
|
|
35008
35702
|
for (const d of [state, vaultDir]) {
|
|
35009
|
-
const st =
|
|
35703
|
+
const st = lstatSync12(d, { throwIfNoEntry: false });
|
|
35010
35704
|
if (st === void 0) {
|
|
35011
|
-
|
|
35705
|
+
mkdirSync8(d, { mode: 448 });
|
|
35012
35706
|
continue;
|
|
35013
35707
|
}
|
|
35014
35708
|
if (st.isSymbolicLink()) return `${d} is a symbolic link, so nothing was written there. Remove the link and try again.`;
|
|
@@ -35021,33 +35715,33 @@ function ensureSafeVault(vaultDir) {
|
|
|
35021
35715
|
}
|
|
35022
35716
|
}
|
|
35023
35717
|
function writeFileSafe(path, text) {
|
|
35024
|
-
const fd =
|
|
35718
|
+
const fd = openSync8(path, constants7.O_WRONLY | constants7.O_CREAT | constants7.O_TRUNC | (constants7.O_NOFOLLOW ?? 0), 384);
|
|
35025
35719
|
try {
|
|
35026
35720
|
if (!fstatSync3(fd).isFile()) throw new Error("not a regular file");
|
|
35027
|
-
|
|
35721
|
+
writeSync5(fd, text);
|
|
35028
35722
|
} finally {
|
|
35029
|
-
|
|
35723
|
+
closeSync8(fd);
|
|
35030
35724
|
}
|
|
35031
35725
|
}
|
|
35032
35726
|
var insideDir = (child, parent) => child === parent || child.startsWith(parent.endsWith(sep6) ? parent : parent + sep6);
|
|
35033
35727
|
function rootFor(vaultDir, target) {
|
|
35034
|
-
const state =
|
|
35035
|
-
if (
|
|
35036
|
-
const project =
|
|
35037
|
-
return insideDir(
|
|
35728
|
+
const state = dirname14(vaultDir);
|
|
35729
|
+
if (basename10(state) !== ".exorcist") return void 0;
|
|
35730
|
+
const project = dirname14(state);
|
|
35731
|
+
return insideDir(resolve25(target), resolve25(project)) ? resolve25(project) : void 0;
|
|
35038
35732
|
}
|
|
35039
35733
|
function realDirOf(target) {
|
|
35040
35734
|
try {
|
|
35041
|
-
return
|
|
35735
|
+
return realpathSync11(dirname14(target));
|
|
35042
35736
|
} catch {
|
|
35043
35737
|
return void 0;
|
|
35044
35738
|
}
|
|
35045
35739
|
}
|
|
35046
35740
|
function targetProblem(e) {
|
|
35047
|
-
const dir = e.kind === "exorcise" ? e.target :
|
|
35741
|
+
const dir = e.kind === "exorcise" ? e.target : dirname14(e.target);
|
|
35048
35742
|
let real;
|
|
35049
35743
|
try {
|
|
35050
|
-
real =
|
|
35744
|
+
real = realpathSync11(existsSync15(dir) ? dir : dirname14(dir));
|
|
35051
35745
|
} catch {
|
|
35052
35746
|
return `${e.target} cannot be resolved.`;
|
|
35053
35747
|
}
|
|
@@ -35055,7 +35749,7 @@ function targetProblem(e) {
|
|
|
35055
35749
|
if (e.root !== void 0) {
|
|
35056
35750
|
let root;
|
|
35057
35751
|
try {
|
|
35058
|
-
root =
|
|
35752
|
+
root = realpathSync11(e.root);
|
|
35059
35753
|
} catch {
|
|
35060
35754
|
return `The project folder ${e.root} cannot be resolved.`;
|
|
35061
35755
|
}
|
|
@@ -35069,24 +35763,24 @@ function newId(label, now) {
|
|
|
35069
35763
|
return `${stamp}-${slug}-${randomBytes7(2).toString("hex")}`;
|
|
35070
35764
|
}
|
|
35071
35765
|
function entryDir(vaultDir, id) {
|
|
35072
|
-
return
|
|
35766
|
+
return join30(vaultDir, id);
|
|
35073
35767
|
}
|
|
35074
35768
|
function writeManifest(vaultDir, e) {
|
|
35075
35769
|
const key = getUserKey({ create: true });
|
|
35076
35770
|
const { trusted: _t, ...plain4 } = e;
|
|
35077
35771
|
const body = key.ok ? { ...plain4, mac: signText(key.key, VAULT_DOMAIN, entryText(plain4)) } : plain4;
|
|
35078
|
-
writeFileSafe(
|
|
35772
|
+
writeFileSafe(join30(entryDir(vaultDir, e.id), "manifest.json"), `${JSON.stringify(body, null, 2)}
|
|
35079
35773
|
`);
|
|
35080
35774
|
}
|
|
35081
35775
|
function listEntries(vaultDir) {
|
|
35082
|
-
if (!
|
|
35776
|
+
if (!existsSync15(vaultDir)) return [];
|
|
35083
35777
|
const key = getUserKey();
|
|
35084
35778
|
const out = [];
|
|
35085
35779
|
for (const name of readdirSync10(vaultDir)) {
|
|
35086
|
-
const file =
|
|
35087
|
-
if (!
|
|
35780
|
+
const file = join30(vaultDir, name, "manifest.json");
|
|
35781
|
+
if (!existsSync15(file)) continue;
|
|
35088
35782
|
try {
|
|
35089
|
-
const st =
|
|
35783
|
+
const st = lstatSync12(file);
|
|
35090
35784
|
if (!st.isFile()) continue;
|
|
35091
35785
|
const parsed = EntrySchema.safeParse(JSON.parse(readFileSync21(file, "utf8")));
|
|
35092
35786
|
if (parsed.success) out.push({ ...parsed.data, trusted: key.ok && verifyText(key.key, VAULT_DOMAIN, entryText(parsed.data), parsed.data.mac) });
|
|
@@ -35121,7 +35815,7 @@ function readConfig(path) {
|
|
|
35121
35815
|
var writeConfig = (path, cfg) => writeFileSync7(path, `${JSON.stringify(cfg, null, 2)}
|
|
35122
35816
|
`, "utf8");
|
|
35123
35817
|
function quarantineServer(o) {
|
|
35124
|
-
const configPath =
|
|
35818
|
+
const configPath = resolve25(o.configPath);
|
|
35125
35819
|
const cfg = readConfig(configPath);
|
|
35126
35820
|
if (!cfg.ok) return cfg;
|
|
35127
35821
|
const entry = cfg.value.mcpServers?.[o.serverName];
|
|
@@ -35134,10 +35828,10 @@ function quarantineServer(o) {
|
|
|
35134
35828
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35135
35829
|
const id = newId(o.serverName, now);
|
|
35136
35830
|
const dir = entryDir(o.vaultDir, id);
|
|
35137
|
-
|
|
35831
|
+
mkdirSync8(dir, { recursive: true });
|
|
35138
35832
|
const backup = `${JSON.stringify(entry, null, 2)}
|
|
35139
35833
|
`;
|
|
35140
|
-
writeFileSafe(
|
|
35834
|
+
writeFileSafe(join30(dir, "entry.json"), backup);
|
|
35141
35835
|
const root = rootFor(o.vaultDir, configPath);
|
|
35142
35836
|
const realDir = realDirOf(configPath);
|
|
35143
35837
|
const e = {
|
|
@@ -35158,16 +35852,16 @@ function quarantineServer(o) {
|
|
|
35158
35852
|
return { ok: true, value: e };
|
|
35159
35853
|
}
|
|
35160
35854
|
function quarantineFile(o) {
|
|
35161
|
-
const target =
|
|
35162
|
-
if (!
|
|
35855
|
+
const target = resolve25(o.filePath);
|
|
35856
|
+
if (!existsSync15(target) || !statSync13(target).isFile()) return fail3(`${target} is not a file.`);
|
|
35163
35857
|
if (activeFor(o.vaultDir, target)) return fail3(`${target} is already in the vault.`);
|
|
35164
35858
|
const safe2 = ensureSafeVault(o.vaultDir);
|
|
35165
35859
|
if (safe2 !== null) return fail3(safe2);
|
|
35166
35860
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35167
|
-
const id = newId(
|
|
35861
|
+
const id = newId(basename10(target), now);
|
|
35168
35862
|
const dir = entryDir(o.vaultDir, id);
|
|
35169
|
-
|
|
35170
|
-
const stored =
|
|
35863
|
+
mkdirSync8(join30(dir, "files"), { recursive: true });
|
|
35864
|
+
const stored = join30(dir, "files", basename10(target));
|
|
35171
35865
|
copyFileSync(target, stored);
|
|
35172
35866
|
const digest = sha2562(readFileSync21(stored));
|
|
35173
35867
|
if (digest !== sha2562(readFileSync21(target))) {
|
|
@@ -35182,12 +35876,12 @@ function quarantineFile(o) {
|
|
|
35182
35876
|
return { ok: true, value: e };
|
|
35183
35877
|
}
|
|
35184
35878
|
function backupAndRewrite(o) {
|
|
35185
|
-
const root =
|
|
35879
|
+
const root = resolve25(o.root);
|
|
35186
35880
|
if (o.files.length === 0) return fail3("There are no files to change.");
|
|
35187
35881
|
for (const f of o.files) {
|
|
35188
35882
|
if (!SafeRel.safeParse(f.rel).success) return fail3(`Refusing to write outside ${root}: ${f.rel}`);
|
|
35189
|
-
const path =
|
|
35190
|
-
if (!
|
|
35883
|
+
const path = join30(root, f.rel);
|
|
35884
|
+
if (!existsSync15(path)) return fail3(`${f.rel} is gone; nothing was changed.`);
|
|
35191
35885
|
if (sha2562(readFileSync21(path)) !== sha2562(Buffer.from(f.before, "utf8"))) {
|
|
35192
35886
|
return fail3(`${f.rel} changed since it was scanned; nothing was changed. Run exorcise again.`);
|
|
35193
35887
|
}
|
|
@@ -35195,16 +35889,16 @@ function backupAndRewrite(o) {
|
|
|
35195
35889
|
const safe2 = ensureSafeVault(o.vaultDir);
|
|
35196
35890
|
if (safe2 !== null) return fail3(safe2);
|
|
35197
35891
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35198
|
-
const id = newId(`exorcise-${
|
|
35892
|
+
const id = newId(`exorcise-${basename10(root)}`, now);
|
|
35199
35893
|
const dir = entryDir(o.vaultDir, id);
|
|
35200
35894
|
const files = [];
|
|
35201
35895
|
try {
|
|
35202
35896
|
for (const f of o.files) {
|
|
35203
|
-
const stored =
|
|
35204
|
-
|
|
35205
|
-
copyFileSync(
|
|
35897
|
+
const stored = join30(dir, "files", f.rel);
|
|
35898
|
+
mkdirSync8(dirname14(stored), { recursive: true });
|
|
35899
|
+
copyFileSync(join30(root, f.rel), stored);
|
|
35206
35900
|
const digest = sha2562(readFileSync21(stored));
|
|
35207
|
-
if (digest !== sha2562(readFileSync21(
|
|
35901
|
+
if (digest !== sha2562(readFileSync21(join30(root, f.rel)))) throw new Error("mismatch");
|
|
35208
35902
|
files.push({ rel: f.rel, sha256: digest, after: sha2562(Buffer.from(f.after, "utf8")) });
|
|
35209
35903
|
}
|
|
35210
35904
|
} catch {
|
|
@@ -35224,14 +35918,14 @@ function backupAndRewrite(o) {
|
|
|
35224
35918
|
...exRoot ? { root: exRoot } : {}
|
|
35225
35919
|
};
|
|
35226
35920
|
writeManifest(o.vaultDir, e);
|
|
35227
|
-
for (const f of o.files) writeFileSync7(
|
|
35921
|
+
for (const f of o.files) writeFileSync7(join30(root, f.rel), f.after, "utf8");
|
|
35228
35922
|
return { ok: true, value: e };
|
|
35229
35923
|
}
|
|
35230
35924
|
function restoreExorcised(vaultDir, e, force) {
|
|
35231
35925
|
const files = e.files ?? [];
|
|
35232
35926
|
const blocked2 = files.filter((f) => {
|
|
35233
|
-
const path =
|
|
35234
|
-
if (!
|
|
35927
|
+
const path = join30(e.target, f.rel);
|
|
35928
|
+
if (!existsSync15(path)) return false;
|
|
35235
35929
|
const now = sha2562(readFileSync21(path));
|
|
35236
35930
|
return now !== f.after && now !== f.sha256;
|
|
35237
35931
|
});
|
|
@@ -35239,27 +35933,27 @@ function restoreExorcised(vaultDir, e, force) {
|
|
|
35239
35933
|
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
35934
|
}
|
|
35241
35935
|
for (const f of files) {
|
|
35242
|
-
const stored =
|
|
35936
|
+
const stored = join30(entryDir(vaultDir, e.id), "files", f.rel);
|
|
35243
35937
|
if (sha2562(readFileSync21(stored)) !== f.sha256) return fail3(`The backup of ${f.rel} is damaged (sha256 does not match); nothing was restored.`);
|
|
35244
35938
|
}
|
|
35245
35939
|
for (const f of files) {
|
|
35246
|
-
const path =
|
|
35247
|
-
|
|
35248
|
-
copyFileSync(
|
|
35940
|
+
const path = join30(e.target, f.rel);
|
|
35941
|
+
mkdirSync8(dirname14(path), { recursive: true });
|
|
35942
|
+
copyFileSync(join30(entryDir(vaultDir, e.id), "files", f.rel), path);
|
|
35249
35943
|
}
|
|
35250
35944
|
return { ok: true, value: null };
|
|
35251
35945
|
}
|
|
35252
35946
|
function backupFile(vaultDir, e) {
|
|
35253
|
-
return e.kind === "mcp-server" ?
|
|
35947
|
+
return e.kind === "mcp-server" ? join30(entryDir(vaultDir, e.id), "entry.json") : join30(entryDir(vaultDir, e.id), "files", basename10(e.target));
|
|
35254
35948
|
}
|
|
35255
35949
|
function diffEntry(vaultDir, id) {
|
|
35256
35950
|
const e = getEntry(vaultDir, id);
|
|
35257
35951
|
if (!e) return fail3(`There is no vault entry "${id}".`);
|
|
35258
35952
|
if (e.kind === "exorcise") {
|
|
35259
35953
|
const parts2 = (e.files ?? []).map((f) => {
|
|
35260
|
-
const path =
|
|
35261
|
-
const before2 = readFileSync21(
|
|
35262
|
-
const after2 =
|
|
35954
|
+
const path = join30(e.target, f.rel);
|
|
35955
|
+
const before2 = readFileSync21(join30(entryDir(vaultDir, e.id), "files", f.rel), "utf8");
|
|
35956
|
+
const after2 = existsSync15(path) ? readFileSync21(path, "utf8") : "";
|
|
35263
35957
|
return createTwoFilesPatch(`${f.rel} (backup)`, `${f.rel} (now)`, before2, after2, "", "", { context: 3 });
|
|
35264
35958
|
});
|
|
35265
35959
|
return { ok: true, value: parts2.join("") };
|
|
@@ -35271,10 +35965,10 @@ function diffEntry(vaultDir, id) {
|
|
|
35271
35965
|
const now = cfg.ok ? cfg.value.mcpServers?.[e.serverName ?? ""] : void 0;
|
|
35272
35966
|
after = now ? `${JSON.stringify(now, null, 2)}
|
|
35273
35967
|
` : "";
|
|
35274
|
-
} else if (
|
|
35968
|
+
} else if (existsSync15(e.target)) {
|
|
35275
35969
|
after = readFileSync21(e.target, "utf8");
|
|
35276
35970
|
}
|
|
35277
|
-
const label = e.kind === "mcp-server" ? `${e.serverName} in ${
|
|
35971
|
+
const label = e.kind === "mcp-server" ? `${e.serverName} in ${basename10(e.target)}` : basename10(e.target);
|
|
35278
35972
|
return { ok: true, value: createTwoFilesPatch(`${label} (backup)`, `${label} (now)`, before, after, "", "", { context: 3 }) };
|
|
35279
35973
|
}
|
|
35280
35974
|
function restoreEntry(vaultDir, id, opts = {}) {
|
|
@@ -35308,10 +36002,10 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
35308
36002
|
writeConfig(e.target, cfg.value);
|
|
35309
36003
|
} else {
|
|
35310
36004
|
const stored = backupFile(vaultDir, e);
|
|
35311
|
-
if (
|
|
36005
|
+
if (existsSync15(e.target) && sha2562(readFileSync21(e.target)) !== e.sha256 && !opts.force) {
|
|
35312
36006
|
return fail3(`${e.target} exists and is different from the quarantined file. Use --force to overwrite it.`);
|
|
35313
36007
|
}
|
|
35314
|
-
|
|
36008
|
+
mkdirSync8(resolve25(e.target, ".."), { recursive: true });
|
|
35315
36009
|
copyFileSync(stored, e.target);
|
|
35316
36010
|
}
|
|
35317
36011
|
const done = { ...e, status: "restored" };
|
|
@@ -35321,14 +36015,14 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
35321
36015
|
|
|
35322
36016
|
// ../shield/src/events.ts
|
|
35323
36017
|
init_zod();
|
|
35324
|
-
import { closeSync as
|
|
35325
|
-
import { join as
|
|
36018
|
+
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";
|
|
36019
|
+
import { join as join32 } from "node:path";
|
|
35326
36020
|
|
|
35327
36021
|
// ../shield/src/chain.ts
|
|
35328
36022
|
init_zod();
|
|
35329
|
-
import { createHash as
|
|
35330
|
-
import { closeSync as
|
|
35331
|
-
import { join as
|
|
36023
|
+
import { createHash as createHash13, randomBytes as randomBytes8 } from "node:crypto";
|
|
36024
|
+
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";
|
|
36025
|
+
import { join as join31 } from "node:path";
|
|
35332
36026
|
|
|
35333
36027
|
// ../shield/src/chain-core.ts
|
|
35334
36028
|
init_zod();
|
|
@@ -35534,8 +36228,8 @@ function verifyChain(lines, head, genesis, opts) {
|
|
|
35534
36228
|
// ../shield/src/chain.ts
|
|
35535
36229
|
var ok = (value) => ({ ok: true, value });
|
|
35536
36230
|
var fail4 = (error2) => ({ ok: false, error: error2 });
|
|
35537
|
-
var headPath = (dir) =>
|
|
35538
|
-
var genesisPath = (dir) =>
|
|
36231
|
+
var headPath = (dir) => join31(dir, "events.head.json");
|
|
36232
|
+
var genesisPath = (dir) => join31(dir, "events.genesis.json");
|
|
35539
36233
|
var GenesisFileSchema = external_exports.object({ v: external_exports.literal(1), genesis: external_exports.string().regex(HEX64) }).strict();
|
|
35540
36234
|
var MAX_FILE_BYTES4 = 4096;
|
|
35541
36235
|
function errCode(e) {
|
|
@@ -35544,10 +36238,10 @@ function errCode(e) {
|
|
|
35544
36238
|
function readSmall(path) {
|
|
35545
36239
|
let fd = null;
|
|
35546
36240
|
try {
|
|
35547
|
-
const st =
|
|
36241
|
+
const st = lstatSync13(path, { throwIfNoEntry: false });
|
|
35548
36242
|
if (st === void 0) return ok(null);
|
|
35549
36243
|
if (!st.isFile()) return fail4("not a regular file");
|
|
35550
|
-
fd =
|
|
36244
|
+
fd = openSync9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
|
|
35551
36245
|
if (fstatSync4(fd).size > MAX_FILE_BYTES4) return fail4("file is too large");
|
|
35552
36246
|
return ok(readFileSync22(fd, "utf8"));
|
|
35553
36247
|
} catch (e) {
|
|
@@ -35555,7 +36249,7 @@ function readSmall(path) {
|
|
|
35555
36249
|
} finally {
|
|
35556
36250
|
if (fd !== null) {
|
|
35557
36251
|
try {
|
|
35558
|
-
|
|
36252
|
+
closeSync9(fd);
|
|
35559
36253
|
} catch {
|
|
35560
36254
|
}
|
|
35561
36255
|
}
|
|
@@ -35581,15 +36275,15 @@ function readGenesis(dir) {
|
|
|
35581
36275
|
function writeNew(path, text) {
|
|
35582
36276
|
let fd = null;
|
|
35583
36277
|
try {
|
|
35584
|
-
fd =
|
|
35585
|
-
|
|
36278
|
+
fd = openSync9(path, constants8.O_WRONLY | constants8.O_CREAT | constants8.O_EXCL | constants8.O_NOFOLLOW, 384);
|
|
36279
|
+
writeSync6(fd, text);
|
|
35586
36280
|
return ok(void 0);
|
|
35587
36281
|
} catch (e) {
|
|
35588
36282
|
return fail4(errCode(e));
|
|
35589
36283
|
} finally {
|
|
35590
36284
|
if (fd !== null) {
|
|
35591
36285
|
try {
|
|
35592
|
-
|
|
36286
|
+
closeSync9(fd);
|
|
35593
36287
|
} catch {
|
|
35594
36288
|
}
|
|
35595
36289
|
}
|
|
@@ -35599,7 +36293,7 @@ function loadOrCreateGenesis(dir, random = () => randomBytes8(32)) {
|
|
|
35599
36293
|
const existing = readGenesis(dir);
|
|
35600
36294
|
if (!existing.ok) return existing;
|
|
35601
36295
|
if (existing.value !== null) return ok(existing.value);
|
|
35602
|
-
const genesis =
|
|
36296
|
+
const genesis = createHash13("sha256").update(random()).digest("hex");
|
|
35603
36297
|
const w = writeNew(genesisPath(dir), `${JSON.stringify({ v: 1, genesis })}
|
|
35604
36298
|
`);
|
|
35605
36299
|
if (!w.ok) {
|
|
@@ -35620,7 +36314,7 @@ function readHead(dir) {
|
|
|
35620
36314
|
function writeHeadAtomic(dir, head) {
|
|
35621
36315
|
const parsed = HeadRecordSchema.safeParse(head);
|
|
35622
36316
|
if (!parsed.success) return fail4("head file: record is not valid");
|
|
35623
|
-
const tmp =
|
|
36317
|
+
const tmp = join31(dir, `events.head.json.${process.pid}.${randomBytes8(4).toString("hex")}.tmp`);
|
|
35624
36318
|
const w = writeNew(tmp, `${JSON.stringify(parsed.data)}
|
|
35625
36319
|
`);
|
|
35626
36320
|
if (!w.ok) return fail4(`head file: could not write (${w.error})`);
|
|
@@ -35639,10 +36333,10 @@ var CHUNK2 = 1 << 20;
|
|
|
35639
36333
|
function readEventsInto(path, out) {
|
|
35640
36334
|
let fd = null;
|
|
35641
36335
|
try {
|
|
35642
|
-
const st =
|
|
36336
|
+
const st = lstatSync13(path, { throwIfNoEntry: false });
|
|
35643
36337
|
if (st === void 0) return ok(null);
|
|
35644
36338
|
if (!st.isFile()) return fail4("not a regular file");
|
|
35645
|
-
fd =
|
|
36339
|
+
fd = openSync9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
|
|
35646
36340
|
const buf = Buffer.alloc(CHUNK2);
|
|
35647
36341
|
let carry = Buffer.alloc(0);
|
|
35648
36342
|
const take = (raw) => {
|
|
@@ -35681,33 +36375,36 @@ function readEventsInto(path, out) {
|
|
|
35681
36375
|
} finally {
|
|
35682
36376
|
if (fd !== null) {
|
|
35683
36377
|
try {
|
|
35684
|
-
|
|
36378
|
+
closeSync9(fd);
|
|
35685
36379
|
} catch {
|
|
35686
36380
|
}
|
|
35687
36381
|
}
|
|
35688
36382
|
}
|
|
35689
36383
|
}
|
|
35690
36384
|
function verifyLogDir(dir, opts) {
|
|
35691
|
-
const
|
|
35692
|
-
const
|
|
35693
|
-
if (!
|
|
35694
|
-
const
|
|
35695
|
-
|
|
36385
|
+
const unreadable2 = (what, error2) => ({ status: "broken", atSeq: 1, reason: "head-mismatch", detail: `${what} could not be read: ${error2}` });
|
|
36386
|
+
const loc = resolveLogLocation(dir, opts?.location ?? {});
|
|
36387
|
+
if (!loc.ok) return unreadable2("the event log folder", loc.error);
|
|
36388
|
+
const logDir = loc.dir;
|
|
36389
|
+
const head = readHead(logDir);
|
|
36390
|
+
if (!head.ok) return unreadable2("the head record", head.error);
|
|
36391
|
+
const genesis = readGenesis(logDir);
|
|
36392
|
+
if (!genesis.ok) return unreadable2("the genesis value", genesis.error);
|
|
35696
36393
|
const events = [];
|
|
35697
|
-
const old = oldEventsPath(
|
|
36394
|
+
const old = oldEventsPath(logDir);
|
|
35698
36395
|
let rotated = false;
|
|
35699
36396
|
try {
|
|
35700
|
-
rotated =
|
|
36397
|
+
rotated = lstatSync13(old, { throwIfNoEntry: false }) !== void 0;
|
|
35701
36398
|
} catch {
|
|
35702
|
-
return
|
|
36399
|
+
return unreadable2("events.1.jsonl", "not accessible");
|
|
35703
36400
|
}
|
|
35704
36401
|
if (rotated) {
|
|
35705
36402
|
const r = readEventsInto(old, events);
|
|
35706
|
-
if (!r.ok) return
|
|
36403
|
+
if (!r.ok) return unreadable2("events.1.jsonl", r.error);
|
|
35707
36404
|
}
|
|
35708
|
-
const cur = readEventsInto(eventsPath(
|
|
35709
|
-
if (!cur.ok) return
|
|
35710
|
-
const { anchor: useAnchor, ...verifyOpts } = opts ?? {};
|
|
36405
|
+
const cur = readEventsInto(eventsPath(logDir), events);
|
|
36406
|
+
if (!cur.ok) return unreadable2("events.jsonl", cur.error);
|
|
36407
|
+
const { anchor: useAnchor, location: _location, ...verifyOpts } = opts ?? {};
|
|
35711
36408
|
const status2 = verifyChain(events, head.value, genesis.value, { ...verifyOpts, allowRotatedStart: rotated });
|
|
35712
36409
|
if (useAnchor === false || status2.status === "broken") return status2;
|
|
35713
36410
|
const tip = status2.status === "intact" ? { seq: status2.head.seq, hash: status2.head.hash } : null;
|
|
@@ -35726,7 +36423,7 @@ function verifyLogDir(dir, opts) {
|
|
|
35726
36423
|
}
|
|
35727
36424
|
|
|
35728
36425
|
// ../shield/src/procstart.ts
|
|
35729
|
-
import { execFileSync as
|
|
36426
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
35730
36427
|
import { readFileSync as readFileSync23 } from "node:fs";
|
|
35731
36428
|
function processStart(pid, platform = process.platform) {
|
|
35732
36429
|
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
@@ -35738,7 +36435,7 @@ function processStart(pid, platform = process.platform) {
|
|
|
35738
36435
|
return ticks !== void 0 && /^\d+$/.test(ticks) ? `t${ticks}` : null;
|
|
35739
36436
|
}
|
|
35740
36437
|
if (platform === "win32") return null;
|
|
35741
|
-
const out =
|
|
36438
|
+
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
36439
|
return out === "" ? null : `s${out.replace(/\s+/g, " ")}`;
|
|
35743
36440
|
} catch {
|
|
35744
36441
|
return null;
|
|
@@ -35770,9 +36467,9 @@ function holderAlive(pid, start, o = {}) {
|
|
|
35770
36467
|
}
|
|
35771
36468
|
|
|
35772
36469
|
// ../shield/src/events.ts
|
|
35773
|
-
var eventsPath = (dir) =>
|
|
35774
|
-
var oldEventsPath = (dir) =>
|
|
35775
|
-
var lockPath = (dir) =>
|
|
36470
|
+
var eventsPath = (dir) => join32(dir, "events.jsonl");
|
|
36471
|
+
var oldEventsPath = (dir) => join32(dir, "events.1.jsonl");
|
|
36472
|
+
var lockPath = (dir) => join32(dir, "events.lock");
|
|
35776
36473
|
var MAX_EVENT_BYTES = 1024 * 1024;
|
|
35777
36474
|
var MAX_LINE_BYTES = 8 * 1024;
|
|
35778
36475
|
var STALE_LOCK_MS = 1e4;
|
|
@@ -35877,7 +36574,7 @@ function myStart(startOf) {
|
|
|
35877
36574
|
function lockIsStale(lock, d) {
|
|
35878
36575
|
let st;
|
|
35879
36576
|
try {
|
|
35880
|
-
st =
|
|
36577
|
+
st = lstatSync14(lock);
|
|
35881
36578
|
} catch {
|
|
35882
36579
|
return { stale: false, seen: "" };
|
|
35883
36580
|
}
|
|
@@ -35898,7 +36595,7 @@ function lockIsStale(lock, d) {
|
|
|
35898
36595
|
}
|
|
35899
36596
|
function breakLock(lock, seen) {
|
|
35900
36597
|
try {
|
|
35901
|
-
const st =
|
|
36598
|
+
const st = lstatSync14(lock);
|
|
35902
36599
|
if (st.isDirectory()) {
|
|
35903
36600
|
rmdirSync2(lock);
|
|
35904
36601
|
return;
|
|
@@ -35914,8 +36611,8 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35914
36611
|
const take = () => {
|
|
35915
36612
|
let fd = null;
|
|
35916
36613
|
try {
|
|
35917
|
-
fd =
|
|
35918
|
-
|
|
36614
|
+
fd = openSync10(lock, constants9.O_WRONLY | constants9.O_CREAT | constants9.O_EXCL | (constants9.O_NOFOLLOW ?? 0), 384);
|
|
36615
|
+
writeSync7(fd, `${process.pid} ${myStart(d.startOf)}
|
|
35919
36616
|
`);
|
|
35920
36617
|
return true;
|
|
35921
36618
|
} catch (err) {
|
|
@@ -35924,7 +36621,7 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35924
36621
|
} finally {
|
|
35925
36622
|
if (fd !== null) {
|
|
35926
36623
|
try {
|
|
35927
|
-
|
|
36624
|
+
closeSync10(fd);
|
|
35928
36625
|
} catch {
|
|
35929
36626
|
}
|
|
35930
36627
|
}
|
|
@@ -35958,9 +36655,12 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35958
36655
|
var EventLog = class {
|
|
35959
36656
|
constructor(dir, o) {
|
|
35960
36657
|
this.dir = dir;
|
|
35961
|
-
this.
|
|
35962
|
-
this.
|
|
35963
|
-
this.
|
|
36658
|
+
this.locDeps = o.location ?? {};
|
|
36659
|
+
this.loc = resolveLogLocation(dir, this.locDeps);
|
|
36660
|
+
this.logDir = this.loc.ok ? this.loc.dir : dir;
|
|
36661
|
+
this.path = eventsPath(this.logDir);
|
|
36662
|
+
this.old = oldEventsPath(this.logDir);
|
|
36663
|
+
this.lock = lockPath(this.logDir);
|
|
35964
36664
|
this.maxBytes = o.maxBytes ?? MAX_EVENT_BYTES;
|
|
35965
36665
|
this.pid = o.pid ?? process.pid;
|
|
35966
36666
|
this.server = cleanText(o.server, NAME_CHARS2);
|
|
@@ -35972,6 +36672,11 @@ var EventLog = class {
|
|
|
35972
36672
|
this.session = o.session;
|
|
35973
36673
|
}
|
|
35974
36674
|
path;
|
|
36675
|
+
/** 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). */
|
|
36676
|
+
logDir;
|
|
36677
|
+
loc;
|
|
36678
|
+
prepared = false;
|
|
36679
|
+
locDeps;
|
|
35975
36680
|
old;
|
|
35976
36681
|
lock;
|
|
35977
36682
|
maxBytes;
|
|
@@ -35983,6 +36688,8 @@ var EventLog = class {
|
|
|
35983
36688
|
lockAttempts;
|
|
35984
36689
|
lockDeps;
|
|
35985
36690
|
sessionKey;
|
|
36691
|
+
/** Set while the final "logging is off" event is written: the anchor then carries the time. */
|
|
36692
|
+
offSince;
|
|
35986
36693
|
/** Events not written because the file was full and could not be rotated. */
|
|
35987
36694
|
dropped = 0;
|
|
35988
36695
|
problem = null;
|
|
@@ -36014,7 +36721,12 @@ var EventLog = class {
|
|
|
36014
36721
|
return false;
|
|
36015
36722
|
}
|
|
36016
36723
|
try {
|
|
36017
|
-
|
|
36724
|
+
mkdirSync9(this.dir, { recursive: true });
|
|
36725
|
+
const ready = this.prepare();
|
|
36726
|
+
if (ready !== null) {
|
|
36727
|
+
this.fail(ready);
|
|
36728
|
+
return false;
|
|
36729
|
+
}
|
|
36018
36730
|
if (this.chain) {
|
|
36019
36731
|
const r = withLock(this.lock, this.lockAttempts, () => this.writeChained(parsed.data), this.lockDeps);
|
|
36020
36732
|
if (r.held) return r.value;
|
|
@@ -36030,6 +36742,40 @@ var EventLog = class {
|
|
|
36030
36742
|
return false;
|
|
36031
36743
|
}
|
|
36032
36744
|
}
|
|
36745
|
+
/** Whether the log is in a local folder instead of the state folder, and why (m19-log). */
|
|
36746
|
+
get moved() {
|
|
36747
|
+
return this.loc.ok && this.loc.moved ? { reason: this.loc.reason ?? "" } : null;
|
|
36748
|
+
}
|
|
36749
|
+
/** The folder of the log as decided now, for the line the Shield logs (an error when the folder was refused). */
|
|
36750
|
+
get location() {
|
|
36751
|
+
return this.loc;
|
|
36752
|
+
}
|
|
36753
|
+
/** Make the local folder (mode 0700) and check it before the first write. A problem in words, or null. */
|
|
36754
|
+
prepare() {
|
|
36755
|
+
if (!this.loc.ok) return this.loc.error;
|
|
36756
|
+
if (!this.loc.moved || this.prepared) return null;
|
|
36757
|
+
const r = resolveLogLocation(this.dir, { ...this.locDeps, create: true });
|
|
36758
|
+
if (!r.ok) {
|
|
36759
|
+
this.loc = r;
|
|
36760
|
+
return r.error;
|
|
36761
|
+
}
|
|
36762
|
+
if (r.dir !== this.logDir) return "the event log folder changed since the Shield started";
|
|
36763
|
+
this.prepared = true;
|
|
36764
|
+
return null;
|
|
36765
|
+
}
|
|
36766
|
+
/**
|
|
36767
|
+
* The final event when the user-level setting turns logging off (LG-2.4): written chained, and the anchor
|
|
36768
|
+
* records the time. Written once: when the anchor already holds the time, nothing is added. Returns the time.
|
|
36769
|
+
*/
|
|
36770
|
+
writeOff() {
|
|
36771
|
+
const known = readAnchor(this.dir);
|
|
36772
|
+
if (known.ok && known.anchor?.eventsOffSince !== void 0) return { time: known.anchor.eventsOffSince, written: false };
|
|
36773
|
+
const time3 = this.now().toISOString();
|
|
36774
|
+
this.offSince = time3;
|
|
36775
|
+
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.` });
|
|
36776
|
+
this.offSince = void 0;
|
|
36777
|
+
return { time: time3, written };
|
|
36778
|
+
}
|
|
36033
36779
|
encode(e) {
|
|
36034
36780
|
const line = Buffer.from(`${JSON.stringify(e)}
|
|
36035
36781
|
`, "utf8");
|
|
@@ -36051,27 +36797,27 @@ var EventLog = class {
|
|
|
36051
36797
|
return false;
|
|
36052
36798
|
}
|
|
36053
36799
|
}
|
|
36054
|
-
const flags2 =
|
|
36055
|
-
const fd =
|
|
36800
|
+
const flags2 = constants9.O_WRONLY | constants9.O_APPEND | constants9.O_CREAT | (constants9.O_NOFOLLOW ?? 0);
|
|
36801
|
+
const fd = openSync10(this.path, flags2, 384);
|
|
36056
36802
|
try {
|
|
36057
36803
|
if (!fstatSync5(fd).isFile()) {
|
|
36058
36804
|
this.fail(`${this.path} is not a regular file`);
|
|
36059
36805
|
return false;
|
|
36060
36806
|
}
|
|
36061
|
-
|
|
36807
|
+
writeSync7(fd, line);
|
|
36062
36808
|
} finally {
|
|
36063
|
-
|
|
36809
|
+
closeSync10(fd);
|
|
36064
36810
|
}
|
|
36065
36811
|
return true;
|
|
36066
36812
|
}
|
|
36067
36813
|
/** The chained write, with the lock held. Falls back to an unchained line when the chain files are unusable. */
|
|
36068
36814
|
writeChained(event) {
|
|
36069
|
-
const g = loadOrCreateGenesis(this.
|
|
36815
|
+
const g = loadOrCreateGenesis(this.logDir, this.random);
|
|
36070
36816
|
if (!g.ok) {
|
|
36071
36817
|
this.fail(g.error);
|
|
36072
36818
|
return this.append(this.encode(event), true);
|
|
36073
36819
|
}
|
|
36074
|
-
const h = readHead(this.
|
|
36820
|
+
const h = readHead(this.logDir);
|
|
36075
36821
|
if (!h.ok) this.fail(h.error);
|
|
36076
36822
|
const head = h.ok ? h.value : null;
|
|
36077
36823
|
const anchor = readAnchor(this.dir);
|
|
@@ -36085,12 +36831,12 @@ var EventLog = class {
|
|
|
36085
36831
|
return false;
|
|
36086
36832
|
}
|
|
36087
36833
|
if (!this.append(this.encode(chained.data), true)) return false;
|
|
36088
|
-
const w = writeHeadAtomic(this.
|
|
36834
|
+
const w = writeHeadAtomic(this.logDir, { v: 1, genesis: g.value, seq: seq2, hash });
|
|
36089
36835
|
if (!w.ok) this.fail(w.error);
|
|
36090
36836
|
else if (drift) {
|
|
36091
36837
|
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
36838
|
} else {
|
|
36093
|
-
const anchorProblem = writeAnchor(this.dir, { seq: seq2, hash });
|
|
36839
|
+
const anchorProblem = writeAnchor(this.dir, { seq: seq2, hash }, this.offSince !== void 0 ? { eventsOffSince: this.offSince } : {});
|
|
36094
36840
|
if (anchorProblem !== null) this.fail(anchorProblem);
|
|
36095
36841
|
}
|
|
36096
36842
|
return true;
|
|
@@ -36100,7 +36846,7 @@ var EventLog = class {
|
|
|
36100
36846
|
}
|
|
36101
36847
|
size() {
|
|
36102
36848
|
try {
|
|
36103
|
-
return
|
|
36849
|
+
return lstatSync14(this.path).size;
|
|
36104
36850
|
} catch {
|
|
36105
36851
|
return 0;
|
|
36106
36852
|
}
|
|
@@ -36142,7 +36888,7 @@ function parseEventLines(text) {
|
|
|
36142
36888
|
function readFrom(path, from) {
|
|
36143
36889
|
let fd;
|
|
36144
36890
|
try {
|
|
36145
|
-
fd =
|
|
36891
|
+
fd = openSync10(path, constants9.O_RDONLY | (constants9.O_NOFOLLOW ?? 0));
|
|
36146
36892
|
} catch {
|
|
36147
36893
|
return null;
|
|
36148
36894
|
}
|
|
@@ -36169,14 +36915,15 @@ function readFrom(path, from) {
|
|
|
36169
36915
|
if (dropFirst) text = text.slice(text.indexOf("\n") + 1);
|
|
36170
36916
|
return { text, end: start + lastNl + 1, st };
|
|
36171
36917
|
} finally {
|
|
36172
|
-
|
|
36918
|
+
closeSync10(fd);
|
|
36173
36919
|
}
|
|
36174
36920
|
}
|
|
36175
36921
|
var EventTail = class {
|
|
36176
|
-
constructor(dir) {
|
|
36922
|
+
constructor(dir, deps = {}) {
|
|
36177
36923
|
this.dir = dir;
|
|
36178
|
-
|
|
36179
|
-
this.
|
|
36924
|
+
const loc = resolveLogLocation(dir, deps);
|
|
36925
|
+
this.path = loc.ok ? eventsPath(loc.dir) : join32(dir, "events.refused");
|
|
36926
|
+
this.old = loc.ok ? oldEventsPath(loc.dir) : join32(dir, "events.1.refused");
|
|
36180
36927
|
}
|
|
36181
36928
|
cur = null;
|
|
36182
36929
|
skipped = 0;
|
|
@@ -36191,7 +36938,7 @@ var EventTail = class {
|
|
|
36191
36938
|
};
|
|
36192
36939
|
let st = null;
|
|
36193
36940
|
try {
|
|
36194
|
-
st =
|
|
36941
|
+
st = lstatSync14(this.path);
|
|
36195
36942
|
} catch {
|
|
36196
36943
|
st = null;
|
|
36197
36944
|
}
|
|
@@ -36229,10 +36976,10 @@ var EventTail = class {
|
|
|
36229
36976
|
};
|
|
36230
36977
|
|
|
36231
36978
|
// ../shield/src/launch.ts
|
|
36232
|
-
import { createHash as
|
|
36233
|
-
import { existsSync as
|
|
36234
|
-
import { dirname as
|
|
36235
|
-
var sha2563 = (b) =>
|
|
36979
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
36980
|
+
import { existsSync as existsSync16, readFileSync as readFileSync25, statSync as statSync14 } from "node:fs";
|
|
36981
|
+
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";
|
|
36982
|
+
var sha2563 = (b) => createHash14("sha256").update(b).digest("hex");
|
|
36236
36983
|
var MAX_HASHED_BYTES = 64 * 1024 * 1024;
|
|
36237
36984
|
var fsReader = (path) => {
|
|
36238
36985
|
try {
|
|
@@ -36254,7 +37001,7 @@ var RUNNERS2 = {
|
|
|
36254
37001
|
bun: ["x"],
|
|
36255
37002
|
pipx: ["run"]
|
|
36256
37003
|
};
|
|
36257
|
-
var
|
|
37004
|
+
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
37005
|
var baseName3 = (c) => c.split(/[\\/]/).pop()?.replace(/\.(cmd|exe)$/i, "") ?? c;
|
|
36259
37006
|
function packageSpec(command, args) {
|
|
36260
37007
|
const sub = RUNNERS2[baseName3(command)];
|
|
@@ -36305,17 +37052,17 @@ function launchEntryOf(entry) {
|
|
|
36305
37052
|
}
|
|
36306
37053
|
var PROJECT_MARKERS3 = [".git", ".kiro"];
|
|
36307
37054
|
function configLabel(configPath) {
|
|
36308
|
-
const abs =
|
|
37055
|
+
const abs = resolve26(configPath);
|
|
36309
37056
|
const { root } = parsePath2(abs);
|
|
36310
|
-
for (let dir =
|
|
36311
|
-
if (PROJECT_MARKERS3.some((m) =>
|
|
36312
|
-
if (dir === root ||
|
|
37057
|
+
for (let dir = dirname15(abs); ; dir = dirname15(dir)) {
|
|
37058
|
+
if (PROJECT_MARKERS3.some((m) => existsSync16(join33(dir, m)))) return relative14(dir, abs).split(sep7).join("/");
|
|
37059
|
+
if (dir === root || dirname15(dir) === dir) return abs;
|
|
36313
37060
|
}
|
|
36314
37061
|
}
|
|
36315
37062
|
function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
36316
37063
|
const fileLine = (label, value) => {
|
|
36317
37064
|
if (value.length === 0 || value.length > 4096) return void 0;
|
|
36318
|
-
const path = isAbsolute19(value) ? value :
|
|
37065
|
+
const path = isAbsolute19(value) ? value : resolve26(cwd, value);
|
|
36319
37066
|
const f = reader(path);
|
|
36320
37067
|
if (f.kind !== "file") return void 0;
|
|
36321
37068
|
const content = f.size <= MAX_HASHED_BYTES ? `sha256:${sha2563(f.read())}` : `size:${f.size} mtime:${Math.round(f.mtimeMs)}`;
|
|
@@ -36323,7 +37070,7 @@ function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
|
36323
37070
|
};
|
|
36324
37071
|
const parts2 = [];
|
|
36325
37072
|
const commandIsPath = /[\\/]/.test(command);
|
|
36326
|
-
const own = commandIsPath && !
|
|
37073
|
+
const own = commandIsPath && !INTERPRETERS3.test(baseName3(command)) ? fileLine("command", command) : void 0;
|
|
36327
37074
|
parts2.push(own ?? `command ${command}`);
|
|
36328
37075
|
const spec2 = packageSpec(command, args);
|
|
36329
37076
|
if (spec2) parts2.push(`package ${spec2}`);
|
|
@@ -36365,11 +37112,11 @@ function checkLaunch(s, pin, now = /* @__PURE__ */ new Date()) {
|
|
|
36365
37112
|
// ../shield/src/ai-review.ts
|
|
36366
37113
|
var NONE = { block: [], warn: [] };
|
|
36367
37114
|
function withTimeout(p, ms) {
|
|
36368
|
-
return new Promise((
|
|
37115
|
+
return new Promise((resolve42, reject2) => {
|
|
36369
37116
|
const t2 = setTimeout(() => reject2(new Error(`no answer within ${ms} ms`)), ms);
|
|
36370
37117
|
p.then((v) => {
|
|
36371
37118
|
clearTimeout(t2);
|
|
36372
|
-
|
|
37119
|
+
resolve42(v);
|
|
36373
37120
|
}, (e) => {
|
|
36374
37121
|
clearTimeout(t2);
|
|
36375
37122
|
reject2(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -36447,14 +37194,35 @@ async function prepareShield(o) {
|
|
|
36447
37194
|
const stderr = o.stderr ?? process.stderr;
|
|
36448
37195
|
const log = (s) => void stderr.write(`[exorcist] ${s}
|
|
36449
37196
|
`);
|
|
36450
|
-
|
|
37197
|
+
mkdirSync10(o.dir, { recursive: true });
|
|
36451
37198
|
const policy = loadPolicy(policyPath(o.dir));
|
|
36452
37199
|
if (!policy.ok) {
|
|
36453
37200
|
log(policy.error);
|
|
36454
37201
|
return FAIL_CLOSED_EXIT;
|
|
36455
37202
|
}
|
|
36456
37203
|
for (const n of policy.notes) log(n);
|
|
36457
|
-
const
|
|
37204
|
+
const eventLog = new EventLog(o.dir, { server: o.server });
|
|
37205
|
+
const events = policy.policy.events === "off" ? null : eventLog;
|
|
37206
|
+
const envSwitch = process.env["EXORCIST_EVENTS"];
|
|
37207
|
+
if (events === null) {
|
|
37208
|
+
const off = eventLog.writeOff();
|
|
37209
|
+
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}`}.`);
|
|
37210
|
+
if (eventLog.problem) log(`The console event log: ${eventLog.problem}.`);
|
|
37211
|
+
if (envSwitch !== void 0 && envSwitch !== "") log("The environment variable EXORCIST_EVENTS is ignored.");
|
|
37212
|
+
} else {
|
|
37213
|
+
const where2 = eventLog.location;
|
|
37214
|
+
if (where2.ok && where2.moved) {
|
|
37215
|
+
log(locationNote(where2));
|
|
37216
|
+
const p = writeLocationPointer(o.dir, where2.dir);
|
|
37217
|
+
if (p !== null) log(`The note events.location could not be left in the state folder: ${p}.`);
|
|
37218
|
+
} else if (!where2.ok) {
|
|
37219
|
+
log(`The event log was not written: ${where2.error}. The Shield keeps protecting; only the live console misses events.`);
|
|
37220
|
+
}
|
|
37221
|
+
if (envSwitch !== void 0 && envSwitch !== "") {
|
|
37222
|
+
log('The environment variable EXORCIST_EVENTS was set and is ignored: only "events": "off" in your user-level policy turns logging off.');
|
|
37223
|
+
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.' });
|
|
37224
|
+
}
|
|
37225
|
+
}
|
|
36458
37226
|
let eventProblemShown = false;
|
|
36459
37227
|
const eventProblem = () => {
|
|
36460
37228
|
if (events?.problem && !eventProblemShown) {
|
|
@@ -36489,13 +37257,13 @@ async function prepareShield(o) {
|
|
|
36489
37257
|
log(canariesFile.error);
|
|
36490
37258
|
return FAIL_CLOSED_EXIT;
|
|
36491
37259
|
}
|
|
36492
|
-
if (policy.policy.canaries && !
|
|
37260
|
+
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
37261
|
const canaries = canariesFile.canaries.map((r) => ({ token: r.token, file: r.file }));
|
|
36494
37262
|
if (canaries.length > 0) log(`Watching for ${canaries.length} canary token${canaries.length === 1 ? "" : "s"} (EX-022).`);
|
|
36495
37263
|
let lockExpected;
|
|
36496
37264
|
let lockLaunch;
|
|
36497
|
-
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [
|
|
36498
|
-
if (lockFile &&
|
|
37265
|
+
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [dirname16(o.configPath)] : [], process.cwd()]) : o.lockPath;
|
|
37266
|
+
if (lockFile && existsSync17(lockFile)) {
|
|
36499
37267
|
let text;
|
|
36500
37268
|
try {
|
|
36501
37269
|
text = readFileSync26(lockFile, "utf8");
|
|
@@ -36828,16 +37596,16 @@ async function runProxy(o) {
|
|
|
36828
37596
|
});
|
|
36829
37597
|
prepared.attach(run3);
|
|
36830
37598
|
const stopWatch = prepared.watch(run3);
|
|
36831
|
-
return await new Promise((
|
|
37599
|
+
return await new Promise((resolve42) => {
|
|
36832
37600
|
child.on("error", (err) => {
|
|
36833
37601
|
stopWatch();
|
|
36834
37602
|
log(`Could not start "${o.command}": ${err.message}`);
|
|
36835
|
-
|
|
37603
|
+
resolve42(127);
|
|
36836
37604
|
});
|
|
36837
37605
|
child.on("close", (code3) => {
|
|
36838
37606
|
stopWatch();
|
|
36839
37607
|
for (const l of fromServer.flush()) fromServerLine(l);
|
|
36840
|
-
void serverQueue.then(() =>
|
|
37608
|
+
void serverQueue.then(() => resolve42(code3 ?? 1));
|
|
36841
37609
|
});
|
|
36842
37610
|
});
|
|
36843
37611
|
}
|
|
@@ -37042,7 +37810,7 @@ async function runRemoteProxy(o) {
|
|
|
37042
37810
|
const fromClient = new LineSplitter();
|
|
37043
37811
|
prepared.attach(deliver);
|
|
37044
37812
|
const stopWatch = prepared.watch(deliver);
|
|
37045
|
-
return await new Promise((
|
|
37813
|
+
return await new Promise((resolve42) => {
|
|
37046
37814
|
stdin.on("data", (chunk) => {
|
|
37047
37815
|
for (const l of fromClient.push(chunk)) deliver(engine.onClientLine(l));
|
|
37048
37816
|
});
|
|
@@ -37062,15 +37830,15 @@ async function runRemoteProxy(o) {
|
|
|
37062
37830
|
} catch {
|
|
37063
37831
|
}
|
|
37064
37832
|
}
|
|
37065
|
-
|
|
37833
|
+
resolve42(0);
|
|
37066
37834
|
})();
|
|
37067
37835
|
});
|
|
37068
37836
|
});
|
|
37069
37837
|
}
|
|
37070
37838
|
|
|
37071
37839
|
// ../shield/src/locate.ts
|
|
37072
|
-
import { existsSync as
|
|
37073
|
-
import { dirname as
|
|
37840
|
+
import { existsSync as existsSync18, readdirSync as readdirSync11, statSync as statSync16 } from "node:fs";
|
|
37841
|
+
import { dirname as dirname17, isAbsolute as isAbsolute20, join as join34, parse as parse2, resolve as resolve27 } from "node:path";
|
|
37074
37842
|
import { fileURLToPath } from "node:url";
|
|
37075
37843
|
function hasDefinitions(dir) {
|
|
37076
37844
|
try {
|
|
@@ -37082,28 +37850,28 @@ function hasDefinitions(dir) {
|
|
|
37082
37850
|
function findDefinitionsDir(o) {
|
|
37083
37851
|
const env = o.env ?? process.env;
|
|
37084
37852
|
const cwd = o.cwd ?? process.cwd();
|
|
37085
|
-
if (o.explicit) return
|
|
37853
|
+
if (o.explicit) return resolve27(cwd, o.explicit);
|
|
37086
37854
|
const fromEnv = env["EXORCIST_DEFINITIONS"];
|
|
37087
|
-
if (fromEnv) return
|
|
37855
|
+
if (fromEnv) return resolve27(cwd, fromEnv);
|
|
37088
37856
|
const installed = findActiveInstalledSet({ env, ...o.publicKeyPem ? { publicKeyPem: o.publicKeyPem } : {} });
|
|
37089
37857
|
if (installed && hasDefinitions(installed.definitionsDir)) return installed.definitionsDir;
|
|
37090
|
-
const here =
|
|
37091
|
-
const candidates = [
|
|
37858
|
+
const here = dirname17(fileURLToPath(o.callerUrl));
|
|
37859
|
+
const candidates = [join34(here, "..", "definitions"), join34(here, "..", "..", "..", "definitions"), join34(cwd, "definitions")];
|
|
37092
37860
|
return candidates.find(hasDefinitions) ?? null;
|
|
37093
37861
|
}
|
|
37094
37862
|
var PROJECT_MARKERS4 = [".exorcist", ".kiro", ".git"];
|
|
37095
37863
|
function findStateDir(o = {}) {
|
|
37096
37864
|
const env = o.env ?? process.env;
|
|
37097
|
-
const cwd =
|
|
37098
|
-
if (o.explicit) return
|
|
37865
|
+
const cwd = resolve27(o.cwd ?? process.cwd());
|
|
37866
|
+
if (o.explicit) return resolve27(cwd, o.explicit);
|
|
37099
37867
|
const fromEnv = env["EXORCIST_DIR"];
|
|
37100
|
-
if (fromEnv) return isAbsolute20(fromEnv) ? fromEnv :
|
|
37868
|
+
if (fromEnv) return isAbsolute20(fromEnv) ? fromEnv : resolve27(cwd, fromEnv);
|
|
37101
37869
|
const { root } = parse2(cwd);
|
|
37102
|
-
for (let dir = cwd; ; dir =
|
|
37103
|
-
if (PROJECT_MARKERS4.some((m) =>
|
|
37104
|
-
if (dir === root ||
|
|
37870
|
+
for (let dir = cwd; ; dir = dirname17(dir)) {
|
|
37871
|
+
if (PROJECT_MARKERS4.some((m) => existsSync18(join34(dir, m)))) return join34(dir, ".exorcist");
|
|
37872
|
+
if (dir === root || dirname17(dir) === dir) break;
|
|
37105
37873
|
}
|
|
37106
|
-
return
|
|
37874
|
+
return join34(cwd, ".exorcist");
|
|
37107
37875
|
}
|
|
37108
37876
|
|
|
37109
37877
|
// ../shield/src/wrap.ts
|
|
@@ -37286,8 +38054,8 @@ var DEFAULT_DIR = "the project's .exorcist folder (or EXORCIST_DIR)";
|
|
|
37286
38054
|
// src/commands/on-access.ts
|
|
37287
38055
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
37288
38056
|
import { execFile as execFile3 } from "node:child_process";
|
|
37289
|
-
import { existsSync as
|
|
37290
|
-
import { resolve as
|
|
38057
|
+
import { existsSync as existsSync19, statSync as statSync17 } from "node:fs";
|
|
38058
|
+
import { resolve as resolve28 } from "node:path";
|
|
37291
38059
|
import { createInterface } from "node:readline";
|
|
37292
38060
|
var ALLOW_READ_HELP = `Usage: exorcist allow-read <file>
|
|
37293
38061
|
|
|
@@ -37479,8 +38247,8 @@ ${ALLOW_READ_HELP}`);
|
|
|
37479
38247
|
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
38248
|
return 1;
|
|
37481
38249
|
}
|
|
37482
|
-
const file =
|
|
37483
|
-
if (!
|
|
38250
|
+
const file = resolve28(target);
|
|
38251
|
+
if (!existsSync19(file) || !statSync17(file).isFile()) {
|
|
37484
38252
|
io.err(`Not a readable file: ${shownName(target)}`);
|
|
37485
38253
|
return 1;
|
|
37486
38254
|
}
|
|
@@ -37587,7 +38355,7 @@ ${APPROVE_HELP}`);
|
|
|
37587
38355
|
return 1;
|
|
37588
38356
|
}
|
|
37589
38357
|
const file = policyPath(stateDir(str4(p.values["dir"])));
|
|
37590
|
-
if (!
|
|
38358
|
+
if (!existsSync20(file)) {
|
|
37591
38359
|
io.err(`There is no policy file at ${file}.`);
|
|
37592
38360
|
return 1;
|
|
37593
38361
|
}
|
|
@@ -37648,7 +38416,7 @@ async function alertsCommand(argv, io) {
|
|
|
37648
38416
|
if (!h.ok) io.out(`Event log head: unreadable (${h.error.replace(/[^\x20-\x7e]/g, "?")}).`);
|
|
37649
38417
|
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
38418
|
};
|
|
37651
|
-
if (!
|
|
38419
|
+
if (!existsSync20(file)) {
|
|
37652
38420
|
io.out("No alerts.");
|
|
37653
38421
|
printHead();
|
|
37654
38422
|
return 0;
|
|
@@ -37668,16 +38436,16 @@ async function alertsCommand(argv, io) {
|
|
|
37668
38436
|
|
|
37669
38437
|
// src/commands/baseline.ts
|
|
37670
38438
|
import { statSync as statSync20, writeFileSync as writeFileSync9 } from "node:fs";
|
|
37671
|
-
import { join as
|
|
38439
|
+
import { join as join38, resolve as resolve31 } from "node:path";
|
|
37672
38440
|
|
|
37673
38441
|
// src/commands/scan.ts
|
|
37674
|
-
import { existsSync as
|
|
37675
|
-
import { basename as
|
|
38442
|
+
import { existsSync as existsSync22, readFileSync as readFileSync29, realpathSync as realpathSync12, statSync as statSync19, writeFileSync as writeFileSync8 } from "node:fs";
|
|
38443
|
+
import { basename as basename12, dirname as dirname18, isAbsolute as isAbsolute21, join as join37, relative as relative15, resolve as resolve30 } from "node:path";
|
|
37676
38444
|
init_bedrock();
|
|
37677
38445
|
|
|
37678
38446
|
// src/commands/detonate.ts
|
|
37679
|
-
import { existsSync as
|
|
37680
|
-
import { basename as
|
|
38447
|
+
import { existsSync as existsSync21, readFileSync as readFileSync28, statSync as statSync18 } from "node:fs";
|
|
38448
|
+
import { basename as basename11, join as join35, resolve as resolve29 } from "node:path";
|
|
37681
38449
|
init_bedrock();
|
|
37682
38450
|
var DEFAULT_DETONATE_MAX = 10;
|
|
37683
38451
|
var EX024 = "EX-024";
|
|
@@ -37715,7 +38483,7 @@ async function makeChamberClient(io, flag, real) {
|
|
|
37715
38483
|
return false;
|
|
37716
38484
|
}
|
|
37717
38485
|
}
|
|
37718
|
-
var RANK4 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
38486
|
+
var RANK4 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
37719
38487
|
function pickTargets(findings, max) {
|
|
37720
38488
|
const best = /* @__PURE__ */ new Map();
|
|
37721
38489
|
for (const f of findings) {
|
|
@@ -37756,12 +38524,12 @@ async function runDetonations(root, findings, client, max, def) {
|
|
|
37756
38524
|
for (const t2 of targets) {
|
|
37757
38525
|
let text;
|
|
37758
38526
|
try {
|
|
37759
|
-
text = readFileSync28(
|
|
38527
|
+
text = readFileSync28(join35(root, t2.file), "utf8");
|
|
37760
38528
|
} catch {
|
|
37761
38529
|
tally.inconclusive++;
|
|
37762
38530
|
continue;
|
|
37763
38531
|
}
|
|
37764
|
-
const r = await detonate(text, "file", client, { fileName:
|
|
38532
|
+
const r = await detonate(text, "file", client, { fileName: basename11(t2.file) });
|
|
37765
38533
|
calls += r.modelCalls;
|
|
37766
38534
|
tally[r.verdict]++;
|
|
37767
38535
|
reports.push({ file: t2.file, report: r });
|
|
@@ -37819,8 +38587,8 @@ ${DETONATE_HELP}`);
|
|
|
37819
38587
|
io.err(`Unknown format "${format}". Use text or json.`);
|
|
37820
38588
|
return 2;
|
|
37821
38589
|
}
|
|
37822
|
-
const abs =
|
|
37823
|
-
if (!
|
|
38590
|
+
const abs = resolve29(target);
|
|
38591
|
+
if (!existsSync21(abs) || !statSync18(abs).isFile()) {
|
|
37824
38592
|
io.err(`File not found: ${target}`);
|
|
37825
38593
|
return 2;
|
|
37826
38594
|
}
|
|
@@ -37830,7 +38598,7 @@ ${DETONATE_HELP}`);
|
|
|
37830
38598
|
}
|
|
37831
38599
|
const client = await makeChamberClient(io, "exorcist detonate", deps.client);
|
|
37832
38600
|
if (client === false) return 2;
|
|
37833
|
-
const report = await detonate(readFileSync28(abs, "utf8"), placement, client, { fileName:
|
|
38601
|
+
const report = await detonate(readFileSync28(abs, "utf8"), placement, client, { fileName: basename11(abs) });
|
|
37834
38602
|
if (format === "json") io.out(`${JSON.stringify({ file: target, model: modelIdFor("haiku"), ...report }, null, 2)}
|
|
37835
38603
|
`);
|
|
37836
38604
|
else io.out(renderTranscript(target, report));
|
|
@@ -37854,8 +38622,204 @@ function warnIfStale(io, o) {
|
|
|
37854
38622
|
);
|
|
37855
38623
|
}
|
|
37856
38624
|
|
|
38625
|
+
// src/home.ts
|
|
38626
|
+
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";
|
|
38627
|
+
import { homedir as homedir9 } from "node:os";
|
|
38628
|
+
import { join as join36 } from "node:path";
|
|
38629
|
+
var HOME_MAX_BYTES = 1048576;
|
|
38630
|
+
var MAX_ENTRIES3 = 200;
|
|
38631
|
+
var CLINE_KEY = "saoudrizwan.claude-dev";
|
|
38632
|
+
var loadNodeSqlite = async () => {
|
|
38633
|
+
const spec2 = "node:sqlite";
|
|
38634
|
+
try {
|
|
38635
|
+
const mod = await import(spec2);
|
|
38636
|
+
const ctor = typeof mod === "object" && mod !== null ? mod.DatabaseSync : void 0;
|
|
38637
|
+
return typeof ctor === "function" ? mod : null;
|
|
38638
|
+
} catch {
|
|
38639
|
+
return null;
|
|
38640
|
+
}
|
|
38641
|
+
};
|
|
38642
|
+
function homeFolder(env = process.env) {
|
|
38643
|
+
const forced = env["EXORCIST_HOME"];
|
|
38644
|
+
return forced !== void 0 && forced !== "" ? forced : homedir9();
|
|
38645
|
+
}
|
|
38646
|
+
function readNoFollow(abs) {
|
|
38647
|
+
let st;
|
|
38648
|
+
try {
|
|
38649
|
+
st = lstatSync15(abs);
|
|
38650
|
+
} catch {
|
|
38651
|
+
return { kind: "missing" };
|
|
38652
|
+
}
|
|
38653
|
+
if (st.isSymbolicLink()) return { kind: "link" };
|
|
38654
|
+
if (!st.isFile()) return { kind: "not-file" };
|
|
38655
|
+
if (st.size > HOME_MAX_BYTES) return { kind: "too-large", size: st.size };
|
|
38656
|
+
let fd;
|
|
38657
|
+
try {
|
|
38658
|
+
fd = openSync11(abs, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0));
|
|
38659
|
+
} catch (e) {
|
|
38660
|
+
const code3 = e.code ?? "error";
|
|
38661
|
+
return code3 === "ELOOP" ? { kind: "link" } : { kind: "error", code: code3 };
|
|
38662
|
+
}
|
|
38663
|
+
try {
|
|
38664
|
+
const fst = fstatSync6(fd);
|
|
38665
|
+
if (!fst.isFile()) return { kind: "not-file" };
|
|
38666
|
+
if (fst.size > HOME_MAX_BYTES) return { kind: "too-large", size: fst.size };
|
|
38667
|
+
const buf = Buffer.alloc(HOME_MAX_BYTES + 1);
|
|
38668
|
+
let got = 0;
|
|
38669
|
+
for (; ; ) {
|
|
38670
|
+
const n = readSync6(fd, buf, got, buf.length - got, null);
|
|
38671
|
+
if (n === 0) break;
|
|
38672
|
+
got += n;
|
|
38673
|
+
if (got > HOME_MAX_BYTES) return { kind: "too-large", size: got };
|
|
38674
|
+
}
|
|
38675
|
+
return { kind: "ok", text: buf.subarray(0, got).toString("utf8") };
|
|
38676
|
+
} catch (e) {
|
|
38677
|
+
return { kind: "error", code: e.code ?? "error" };
|
|
38678
|
+
} finally {
|
|
38679
|
+
closeSync11(fd);
|
|
38680
|
+
}
|
|
38681
|
+
}
|
|
38682
|
+
function unreadable(file, kind) {
|
|
38683
|
+
return {
|
|
38684
|
+
source: "signature",
|
|
38685
|
+
ruleId: kind === "cline" ? "EX-007" : "EX-033",
|
|
38686
|
+
title: "Home settings file in an unknown format, not checked",
|
|
38687
|
+
severity: "medium",
|
|
38688
|
+
file,
|
|
38689
|
+
line: 1,
|
|
38690
|
+
col: 1,
|
|
38691
|
+
span: "unknown format, not checked",
|
|
38692
|
+
owasp: ["ASI02 Inadequate Human-in-the-Loop Controls", "LLM06:2025 Excessive Agency"],
|
|
38693
|
+
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."
|
|
38694
|
+
};
|
|
38695
|
+
}
|
|
38696
|
+
function tooLarge(file, size) {
|
|
38697
|
+
return {
|
|
38698
|
+
source: "signature",
|
|
38699
|
+
ruleId: "EX-026",
|
|
38700
|
+
title: "Home settings file too large to check",
|
|
38701
|
+
severity: "medium",
|
|
38702
|
+
file,
|
|
38703
|
+
line: 1,
|
|
38704
|
+
col: 1,
|
|
38705
|
+
span: `${(size / HOME_MAX_BYTES).toFixed(1)} MiB, not checked`,
|
|
38706
|
+
owasp: ["LLM01:2025 Prompt Injection", "ASI03 Prompt Injection via External Content"],
|
|
38707
|
+
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."
|
|
38708
|
+
};
|
|
38709
|
+
}
|
|
38710
|
+
var ANALYSE = { kiro: kiroPermissionsFindings, agent: kiroAgentFindings, cline: clineFindings };
|
|
38711
|
+
var UNREADABLE = { kiro: "Kiro's permissions", agent: "the Kiro agent profile", cline: "Cline's settings" };
|
|
38712
|
+
function entries(dir) {
|
|
38713
|
+
try {
|
|
38714
|
+
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));
|
|
38715
|
+
} catch {
|
|
38716
|
+
return [];
|
|
38717
|
+
}
|
|
38718
|
+
}
|
|
38719
|
+
function vscdbPath(o) {
|
|
38720
|
+
const tail = ["Code", "User", "globalStorage", "state.vscdb"];
|
|
38721
|
+
const platform = o.platform ?? process.platform;
|
|
38722
|
+
if (platform === "darwin") return { abs: join36(o.home, "Library", "Application Support", ...tail), shown: `~/Library/Application Support/${tail.join("/")}` };
|
|
38723
|
+
if (platform === "win32") {
|
|
38724
|
+
const appData = o.appData ?? process.env["APPDATA"] ?? join36(o.home, "AppData", "Roaming");
|
|
38725
|
+
return { abs: join36(appData, ...tail), shown: `%APPDATA%/${tail.join("/")}` };
|
|
38726
|
+
}
|
|
38727
|
+
return { abs: join36(o.home, ".config", ...tail), shown: `~/.config/${tail.join("/")}` };
|
|
38728
|
+
}
|
|
38729
|
+
async function scanHome(o) {
|
|
38730
|
+
const out = { findings: [], notes: [], read: [] };
|
|
38731
|
+
const shown2 = (s) => displayFileName(s);
|
|
38732
|
+
const take = (abs, file, kind) => {
|
|
38733
|
+
const r = readNoFollow(abs);
|
|
38734
|
+
if (r.kind === "missing" || r.kind === "not-file") return;
|
|
38735
|
+
if (r.kind === "link") {
|
|
38736
|
+
out.notes.push(`${shown2(file)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38737
|
+
return;
|
|
38738
|
+
}
|
|
38739
|
+
if (r.kind === "too-large") {
|
|
38740
|
+
out.notes.push(`${shown2(file)} was not read: it is larger than 1 MiB.`);
|
|
38741
|
+
out.findings.push(tooLarge(file, r.size));
|
|
38742
|
+
return;
|
|
38743
|
+
}
|
|
38744
|
+
if (r.kind === "error") {
|
|
38745
|
+
out.notes.push(`Could not read ${shown2(file)} (${r.code}).`);
|
|
38746
|
+
return;
|
|
38747
|
+
}
|
|
38748
|
+
out.read.push(file);
|
|
38749
|
+
judge(r.text, file, kind);
|
|
38750
|
+
};
|
|
38751
|
+
const judge = (text, file, kind) => {
|
|
38752
|
+
const res = ANALYSE[kind](text, file);
|
|
38753
|
+
if (res.ok) out.findings.push(...res.findings);
|
|
38754
|
+
else {
|
|
38755
|
+
out.notes.push(`Could not read ${UNREADABLE[kind]} (${res.reason}): ${shown2(file)}.`);
|
|
38756
|
+
out.findings.push(unreadable(file, kind));
|
|
38757
|
+
}
|
|
38758
|
+
};
|
|
38759
|
+
take(join36(o.home, ".kiro", "settings", "permissions.yaml"), "~/.kiro/settings/permissions.yaml", "kiro");
|
|
38760
|
+
for (const e of entries(join36(o.home, ".kiro", "workspace-roots"))) {
|
|
38761
|
+
const file = `~/.kiro/workspace-roots/${e.name}/permissions.yaml`;
|
|
38762
|
+
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.`);
|
|
38763
|
+
else if (e.dir) take(join36(o.home, ".kiro", "workspace-roots", e.name, "permissions.yaml"), file, "kiro");
|
|
38764
|
+
}
|
|
38765
|
+
for (const e of entries(join36(o.home, ".kiro", "agents"))) {
|
|
38766
|
+
if (!e.name.endsWith(".json")) continue;
|
|
38767
|
+
const file = `~/.kiro/agents/${e.name}`;
|
|
38768
|
+
if (e.link) out.notes.push(`${shown2(file)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38769
|
+
else if (e.file) take(join36(o.home, ".kiro", "agents", e.name), file, "agent");
|
|
38770
|
+
}
|
|
38771
|
+
take(join36(o.home, ".cline", "data", "globalState.json"), "~/.cline/data/globalState.json", "cline");
|
|
38772
|
+
await readVscdb(o, out, judge);
|
|
38773
|
+
return out;
|
|
38774
|
+
}
|
|
38775
|
+
async function readVscdb(o, out, judge) {
|
|
38776
|
+
const { abs, shown: shown2 } = vscdbPath(o);
|
|
38777
|
+
let st;
|
|
38778
|
+
try {
|
|
38779
|
+
st = lstatSync15(abs);
|
|
38780
|
+
} catch {
|
|
38781
|
+
return;
|
|
38782
|
+
}
|
|
38783
|
+
if (st.isSymbolicLink()) {
|
|
38784
|
+
out.notes.push(`${shown2} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38785
|
+
return;
|
|
38786
|
+
}
|
|
38787
|
+
if (!st.isFile()) return;
|
|
38788
|
+
const mod = await (o.loadSqlite ?? loadNodeSqlite)();
|
|
38789
|
+
if (!mod) {
|
|
38790
|
+
out.notes.push(`Could not read ${shown2}: this Node.js has no node:sqlite (Node 22.5 or later has it).`);
|
|
38791
|
+
return;
|
|
38792
|
+
}
|
|
38793
|
+
let value;
|
|
38794
|
+
try {
|
|
38795
|
+
const db = new mod.DatabaseSync(abs, { readOnly: true });
|
|
38796
|
+
try {
|
|
38797
|
+
const row = db.prepare("SELECT value FROM ItemTable WHERE key = ?").get(CLINE_KEY);
|
|
38798
|
+
value = typeof row === "object" && row !== null ? row.value : void 0;
|
|
38799
|
+
} finally {
|
|
38800
|
+
db.close();
|
|
38801
|
+
}
|
|
38802
|
+
} catch {
|
|
38803
|
+
out.notes.push(`Could not read ${shown2}: it is not a readable SQLite database.`);
|
|
38804
|
+
return;
|
|
38805
|
+
}
|
|
38806
|
+
if (value === void 0 || value === null) return;
|
|
38807
|
+
const text = typeof value === "string" ? value : value instanceof Uint8Array ? Buffer.from(value).toString("utf8") : null;
|
|
38808
|
+
if (text === null) {
|
|
38809
|
+
out.notes.push(`Could not read Cline's settings (unknown format): ${shown2}.`);
|
|
38810
|
+
return;
|
|
38811
|
+
}
|
|
38812
|
+
if (Buffer.byteLength(text, "utf8") > HOME_MAX_BYTES) {
|
|
38813
|
+
out.notes.push(`${shown2} was not read: Cline's settings in it are larger than 1 MiB.`);
|
|
38814
|
+
out.findings.push(tooLarge(shown2, Buffer.byteLength(text, "utf8")));
|
|
38815
|
+
return;
|
|
38816
|
+
}
|
|
38817
|
+
out.read.push(shown2);
|
|
38818
|
+
judge(text, shown2, "cline");
|
|
38819
|
+
}
|
|
38820
|
+
|
|
37857
38821
|
// src/commands/scan.ts
|
|
37858
|
-
var RANK5 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
38822
|
+
var RANK5 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
37859
38823
|
var SEVERITY_RANK2 = RANK5;
|
|
37860
38824
|
var FORMATS = ["text", "json", "sarif", "markdown", "badge"];
|
|
37861
38825
|
var MAX_AI_CALLS_PER_FILE = 2 * MAX_SPANS_PER_FILE;
|
|
@@ -37868,8 +38832,9 @@ Options:
|
|
|
37868
38832
|
--format <text|json|sarif|markdown|badge>
|
|
37869
38833
|
Output format (default: text). "badge" writes an
|
|
37870
38834
|
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)
|
|
38835
|
+
--fail-on <critical|high|medium|low|info|none>
|
|
38836
|
+
Exit 1 if a finding is at least this bad (default: high).
|
|
38837
|
+
Info findings never fail a scan unless --fail-on info is given.
|
|
37873
38838
|
--ignore <path> Skip a path prefix (repeatable).
|
|
37874
38839
|
--ignore-file <file> Skip the path prefixes listed in a file you name, one per
|
|
37875
38840
|
line. The file should live outside the scanned folder.
|
|
@@ -37894,6 +38859,8 @@ Options:
|
|
|
37894
38859
|
harmful. Nothing is executed. Needs AWS credentials and AWS_REGION;
|
|
37895
38860
|
at most 2 model calls per file. Off by default.
|
|
37896
38861
|
--detonate-max <n> Detonate at most n files (default ${DEFAULT_DETONATE_MAX})
|
|
38862
|
+
--home Opt-in, off by default: also read Kiro and Cline agent settings in your home folder.
|
|
38863
|
+
Only a fixed list of files is read (see REFERENCE, "--home").
|
|
37897
38864
|
Inline suppression (only with --trust-repo-ignores): a comment on the same line as a finding, or on the line
|
|
37898
38865
|
before it, silences one rule on that line, and the reason is listed in the report:
|
|
37899
38866
|
// exorcist-ignore EX-012: reviewed, this is documentation
|
|
@@ -37901,10 +38868,10 @@ Openers: // # <!-- /* -- ; A reason is required. Hidden characters (EX-00
|
|
|
37901
38868
|
secrets (EX-011) cannot be silenced this way. The comment's own text is still scanned.
|
|
37902
38869
|
`;
|
|
37903
38870
|
function readIgnoreFile(root) {
|
|
37904
|
-
return readIgnoreEntries(
|
|
38871
|
+
return readIgnoreEntries(join37(root, ".exorcistignore"));
|
|
37905
38872
|
}
|
|
37906
38873
|
function readIgnoreEntries(file) {
|
|
37907
|
-
if (!
|
|
38874
|
+
if (!existsSync22(file)) return [];
|
|
37908
38875
|
return readFileSync29(file, "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
|
|
37909
38876
|
}
|
|
37910
38877
|
function isIgnored(rel, prefixes) {
|
|
@@ -37952,7 +38919,7 @@ function renderText(findings, stats, suppressed, opts = { trust: false, repoIgno
|
|
|
37952
38919
|
if (f.source === "heuristic" && f.ruleId === EX024) lines.push(` chamber: ${displayMessage(f.rationale)}`);
|
|
37953
38920
|
lines.push(` fix: ${f.fix.replace(/\s+/g, " ").trim()}`);
|
|
37954
38921
|
}
|
|
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(", ");
|
|
38922
|
+
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
38923
|
const withFindings = new Set(findings.map((f) => f.file)).size;
|
|
37957
38924
|
lines.push("", `${plural(findings.length, "threat")} in ${plural(withFindings, "file")} (${counts}). Scanned ${plural(stats.filesScanned, "file")}.`);
|
|
37958
38925
|
lines.push(...extra, verdict);
|
|
@@ -38009,14 +38976,14 @@ async function makeAiClient(rawMax, io, real) {
|
|
|
38009
38976
|
};
|
|
38010
38977
|
}
|
|
38011
38978
|
async function runScan(opts, io) {
|
|
38012
|
-
const abs =
|
|
38013
|
-
if (!
|
|
38979
|
+
const abs = resolve30(opts.target);
|
|
38980
|
+
if (!existsSync22(abs)) {
|
|
38014
38981
|
io.err(`Path not found: ${opts.target}`);
|
|
38015
38982
|
return { ok: false, code: 2 };
|
|
38016
38983
|
}
|
|
38017
38984
|
const isFile = statSync19(abs).isFile();
|
|
38018
|
-
const root = isFile ?
|
|
38019
|
-
const only = isFile ?
|
|
38985
|
+
const root = isFile ? dirname18(abs) : abs;
|
|
38986
|
+
const only = isFile ? basename12(abs) : null;
|
|
38020
38987
|
const defsDir = findDefinitionsDir2(opts.definitions);
|
|
38021
38988
|
if (!defsDir) {
|
|
38022
38989
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -38076,14 +39043,14 @@ async function runScan(opts, io) {
|
|
|
38076
39043
|
function makeRootReader(root) {
|
|
38077
39044
|
let realRoot;
|
|
38078
39045
|
try {
|
|
38079
|
-
realRoot =
|
|
39046
|
+
realRoot = realpathSync12(root);
|
|
38080
39047
|
} catch {
|
|
38081
39048
|
return () => null;
|
|
38082
39049
|
}
|
|
38083
39050
|
return (file) => {
|
|
38084
39051
|
try {
|
|
38085
|
-
const real =
|
|
38086
|
-
const rel =
|
|
39052
|
+
const real = realpathSync12(resolve30(realRoot, file));
|
|
39053
|
+
const rel = relative15(realRoot, real);
|
|
38087
39054
|
if (rel === "" || rel.startsWith("..") || isAbsolute21(rel)) return null;
|
|
38088
39055
|
if (statSync19(real).size > MAX_DIRECTIVE_FILE_BYTES) return null;
|
|
38089
39056
|
return readFileSync29(real, "utf8");
|
|
@@ -38112,7 +39079,8 @@ async function scanCommand(argv, io, deps = {}) {
|
|
|
38112
39079
|
ai: { type: "boolean" },
|
|
38113
39080
|
"ai-max-calls": { type: "string" },
|
|
38114
39081
|
detonate: { type: "boolean" },
|
|
38115
|
-
"detonate-max": { type: "string" }
|
|
39082
|
+
"detonate-max": { type: "string" },
|
|
39083
|
+
home: { type: "boolean" }
|
|
38116
39084
|
});
|
|
38117
39085
|
if (!p.ok) {
|
|
38118
39086
|
io.err(`${p.error}
|
|
@@ -38138,7 +39106,7 @@ ${SCAN_HELP}`);
|
|
|
38138
39106
|
}
|
|
38139
39107
|
const failOn = str4(p.values["fail-on"]) ?? "high";
|
|
38140
39108
|
if (failOn !== "none" && !(failOn in RANK5)) {
|
|
38141
|
-
io.err(`Unknown --fail-on "${failOn}". Use critical, high, medium, low or none.`);
|
|
39109
|
+
io.err(`Unknown --fail-on "${failOn}". Use critical, high, medium, low, info or none.`);
|
|
38142
39110
|
return 2;
|
|
38143
39111
|
}
|
|
38144
39112
|
const baselinePath = str4(p.values["baseline"]);
|
|
@@ -38146,7 +39114,7 @@ ${SCAN_HELP}`);
|
|
|
38146
39114
|
if (baselinePath !== void 0) {
|
|
38147
39115
|
let text;
|
|
38148
39116
|
try {
|
|
38149
|
-
text = readFileSync29(
|
|
39117
|
+
text = readFileSync29(resolve30(baselinePath), "utf8");
|
|
38150
39118
|
} catch {
|
|
38151
39119
|
io.err(`Could not read the baseline file ${baselinePath}. Check the path, or create one with: exorcist baseline <folder>`);
|
|
38152
39120
|
return 2;
|
|
@@ -38167,11 +39135,11 @@ ${SCAN_HELP}`);
|
|
|
38167
39135
|
const ignoreFilePath = str4(p.values["ignore-file"]);
|
|
38168
39136
|
let userIgnore = [];
|
|
38169
39137
|
if (ignoreFilePath !== void 0) {
|
|
38170
|
-
if (!
|
|
39138
|
+
if (!existsSync22(resolve30(ignoreFilePath))) {
|
|
38171
39139
|
io.err(`Could not read the ignore file ${ignoreFilePath}. Check the path.`);
|
|
38172
39140
|
return 2;
|
|
38173
39141
|
}
|
|
38174
|
-
userIgnore = readIgnoreEntries(
|
|
39142
|
+
userIgnore = readIgnoreEntries(resolve30(ignoreFilePath));
|
|
38175
39143
|
}
|
|
38176
39144
|
const held = { chamber: null, ai: null };
|
|
38177
39145
|
const result = await runScan({
|
|
@@ -38211,6 +39179,14 @@ ${SCAN_HELP}`);
|
|
|
38211
39179
|
}
|
|
38212
39180
|
stats = { ...stats, findingsTotal: findings.length };
|
|
38213
39181
|
const inline = applyInline(findings, makeRootReader(root));
|
|
39182
|
+
if (p.values["home"] === true) {
|
|
39183
|
+
const home = await (deps.homeScan ?? scanHome)({ home: homeFolder() });
|
|
39184
|
+
for (const n of home.notes) io.err(n);
|
|
39185
|
+
io.err(`Home settings (--home): read ${plural(home.read.length, "file")}.`);
|
|
39186
|
+
findings.push(...home.findings);
|
|
39187
|
+
inline.active.push(...home.findings);
|
|
39188
|
+
stats = { ...stats, findingsTotal: findings.length };
|
|
39189
|
+
}
|
|
38214
39190
|
let working = inline.active;
|
|
38215
39191
|
const honoured = trust ? inline.suppressed : [];
|
|
38216
39192
|
if (!trust) {
|
|
@@ -38278,7 +39254,7 @@ ${BASELINE_HELP}`);
|
|
|
38278
39254
|
}
|
|
38279
39255
|
const target = p.positionals[0] ?? ".";
|
|
38280
39256
|
try {
|
|
38281
|
-
if (!statSync20(
|
|
39257
|
+
if (!statSync20(resolve31(target)).isDirectory()) {
|
|
38282
39258
|
io.err(`${target} is a file. Give a folder to baseline.`);
|
|
38283
39259
|
return 2;
|
|
38284
39260
|
}
|
|
@@ -38291,7 +39267,7 @@ ${BASELINE_HELP}`);
|
|
|
38291
39267
|
const { findings, root } = result.run;
|
|
38292
39268
|
const { active } = applyInline(findings, makeRootReader(root));
|
|
38293
39269
|
const baseline = buildBaseline(active);
|
|
38294
|
-
const out = str4(p.values["output"]) ??
|
|
39270
|
+
const out = str4(p.values["output"]) ?? join38(root, BASELINE_FILE);
|
|
38295
39271
|
try {
|
|
38296
39272
|
writeFileSync9(out, `${JSON.stringify(baseline, null, 2)}
|
|
38297
39273
|
`, "utf8");
|
|
@@ -38304,7 +39280,7 @@ ${BASELINE_HELP}`);
|
|
|
38304
39280
|
}
|
|
38305
39281
|
|
|
38306
39282
|
// src/commands/canary.ts
|
|
38307
|
-
import { resolve as
|
|
39283
|
+
import { resolve as resolve32 } from "node:path";
|
|
38308
39284
|
var CANARY_HELP = `Usage: exorcist canary plant [dir] Plant canary traps in a project (3 by default)
|
|
38309
39285
|
exorcist canary --list [dir] Show the planted traps
|
|
38310
39286
|
exorcist canary --remove [dir] Remove the trap files and their records
|
|
@@ -38352,7 +39328,7 @@ ${CANARY_HELP}`);
|
|
|
38352
39328
|
${CANARY_HELP}`);
|
|
38353
39329
|
return 2;
|
|
38354
39330
|
}
|
|
38355
|
-
const dir =
|
|
39331
|
+
const dir = resolve32(positionals[0] ?? ".");
|
|
38356
39332
|
const wantList = p.values["list"] === true || sub === "list";
|
|
38357
39333
|
const wantRemove = p.values["remove"] === true || sub === "remove";
|
|
38358
39334
|
const wantPlant = sub === "plant";
|
|
@@ -38364,13 +39340,13 @@ ${CANARY_HELP}`);
|
|
|
38364
39340
|
}
|
|
38365
39341
|
const explicitDir = str4(p.values["dir"]);
|
|
38366
39342
|
const state = explicitDir !== void 0 || process.env["EXORCIST_DIR"] ? stateDir(explicitDir) : void 0;
|
|
38367
|
-
if (wantList) return
|
|
39343
|
+
if (wantList) return list2(io, dir);
|
|
38368
39344
|
if (wantRemove) return remove(io, dir, state);
|
|
38369
39345
|
const countRaw = str4(p.values["count"]);
|
|
38370
39346
|
const count = countRaw === void 0 ? 3 : Number(countRaw);
|
|
38371
39347
|
return plant(io, dir, state, count);
|
|
38372
39348
|
}
|
|
38373
|
-
function
|
|
39349
|
+
function list2(io, dir) {
|
|
38374
39350
|
const r = loadCanaries(dir);
|
|
38375
39351
|
if (!r.ok) {
|
|
38376
39352
|
io.err(`Exorcist 98: ${r.error}`);
|
|
@@ -38417,9 +39393,9 @@ function remove(io, dir, state) {
|
|
|
38417
39393
|
}
|
|
38418
39394
|
|
|
38419
39395
|
// src/commands/config.ts
|
|
38420
|
-
import { createHash as
|
|
38421
|
-
import { existsSync as
|
|
38422
|
-
import { join as
|
|
39396
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
39397
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync11, readFileSync as readFileSync30, rmSync as rmSync5, writeFileSync as writeFileSync10 } from "node:fs";
|
|
39398
|
+
import { join as join39, resolve as resolve33 } from "node:path";
|
|
38423
39399
|
var WRAP_HELP = `Usage: exorcist wrap <mcp.json> [options]
|
|
38424
39400
|
exorcist unwrap <mcp.json>
|
|
38425
39401
|
|
|
@@ -38430,12 +39406,12 @@ unwrap Put the original file back byte for byte, if it was not edited since
|
|
|
38430
39406
|
|
|
38431
39407
|
Options (wrap):
|
|
38432
39408
|
--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.
|
|
39409
|
+
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.9
|
|
38434
39410
|
--dir <folder> State folder (default: ${DEFAULT_DIR})
|
|
38435
39411
|
--dry-run Show the result without writing the file
|
|
38436
39412
|
`;
|
|
38437
39413
|
function backupPath(dir, configPath) {
|
|
38438
|
-
return
|
|
39414
|
+
return join39(dir, "wrap-backups", `${createHash15("sha256").update(configPath).digest("hex").slice(0, 32)}.json`);
|
|
38439
39415
|
}
|
|
38440
39416
|
function readBackup(file) {
|
|
38441
39417
|
try {
|
|
@@ -38457,7 +39433,7 @@ function dirsInConfig(cfg) {
|
|
|
38457
39433
|
return out;
|
|
38458
39434
|
}
|
|
38459
39435
|
function readConfig2(path, io) {
|
|
38460
|
-
if (!
|
|
39436
|
+
if (!existsSync23(path)) {
|
|
38461
39437
|
io.err(`File not found: ${path}`);
|
|
38462
39438
|
return null;
|
|
38463
39439
|
}
|
|
@@ -38495,7 +39471,7 @@ ${WRAP_HELP}`);
|
|
|
38495
39471
|
${WRAP_HELP}`);
|
|
38496
39472
|
return 2;
|
|
38497
39473
|
}
|
|
38498
|
-
const path =
|
|
39474
|
+
const path = resolve33(file);
|
|
38499
39475
|
const cfg = readConfig2(path, io);
|
|
38500
39476
|
if (!cfg) return 2;
|
|
38501
39477
|
const text = readFileSync30(path, "utf8");
|
|
@@ -38524,7 +39500,7 @@ ${WRAP_HELP}`);
|
|
|
38524
39500
|
writeFileSync10(path, out, "utf8");
|
|
38525
39501
|
const b = backupPath(stateDir(str4(p.values["dir"])), path);
|
|
38526
39502
|
try {
|
|
38527
|
-
|
|
39503
|
+
mkdirSync11(join39(b, ".."), { recursive: true, mode: 448 });
|
|
38528
39504
|
writeFileSync10(b, JSON.stringify({ path, original: text, wrapped: out }), { mode: 384 });
|
|
38529
39505
|
} catch {
|
|
38530
39506
|
io.err("Could not save a copy of the original file; unwrap will still restore the original commands.");
|
|
@@ -38583,7 +39559,7 @@ import { randomBytes as randomBytes11, timingSafeEqual as timingSafeEqual2 } fro
|
|
|
38583
39559
|
import { createServer } from "node:http";
|
|
38584
39560
|
|
|
38585
39561
|
// src/console/model.ts
|
|
38586
|
-
import { lstatSync as
|
|
39562
|
+
import { lstatSync as lstatSync16, readdirSync as readdirSync13 } from "node:fs";
|
|
38587
39563
|
var BACKLOG = 400;
|
|
38588
39564
|
var MAX_SHIELDS = 64;
|
|
38589
39565
|
var MAX_SESSIONS = 16;
|
|
@@ -38625,9 +39601,15 @@ var ConsoleModel = class {
|
|
|
38625
39601
|
* (size, mtime, inode), so a quiet folder costs a few stat calls per poll. Read-only.
|
|
38626
39602
|
*/
|
|
38627
39603
|
chainState() {
|
|
38628
|
-
const
|
|
39604
|
+
const loc = resolveLogLocation(this.dir);
|
|
39605
|
+
if (!loc.ok) {
|
|
39606
|
+
this.chainCache = { chain: { status: "broken", atSeq: 1, reason: "head-mismatch", detail: `the event log folder was refused: ${loc.error}` }, chainHead: null };
|
|
39607
|
+
return this.chainCache;
|
|
39608
|
+
}
|
|
39609
|
+
const logDir = loc.dir;
|
|
39610
|
+
const sig = [eventsPath(logDir), oldEventsPath(logDir), headPath(logDir), genesisPath(logDir)].map((p) => {
|
|
38629
39611
|
try {
|
|
38630
|
-
const st =
|
|
39612
|
+
const st = lstatSync16(p);
|
|
38631
39613
|
return `${st.ino}:${st.size}:${st.mtimeMs}`;
|
|
38632
39614
|
} catch {
|
|
38633
39615
|
return "-";
|
|
@@ -38636,7 +39618,7 @@ var ConsoleModel = class {
|
|
|
38636
39618
|
if (sig === this.chainSig) return this.chainCache;
|
|
38637
39619
|
this.chainSig = sig;
|
|
38638
39620
|
const present = sig.split("|").some((x, i) => x !== "-" && i !== 3);
|
|
38639
|
-
const h = readHead(
|
|
39621
|
+
const h = readHead(logDir);
|
|
38640
39622
|
const chainHead = h.ok && h.value ? { seq: h.value.seq, hash: h.value.hash } : null;
|
|
38641
39623
|
this.chainCache = { chain: present ? verifyLogDir(this.dir) : null, chainHead };
|
|
38642
39624
|
return this.chainCache;
|
|
@@ -38710,7 +39692,7 @@ var ConsoleModel = class {
|
|
|
38710
39692
|
const root = sessionsPath(this.dir);
|
|
38711
39693
|
let names = [];
|
|
38712
39694
|
try {
|
|
38713
|
-
names =
|
|
39695
|
+
names = readdirSync13(root).filter((k) => isSessionKey(k));
|
|
38714
39696
|
} catch {
|
|
38715
39697
|
names = [];
|
|
38716
39698
|
}
|
|
@@ -38719,7 +39701,7 @@ var ConsoleModel = class {
|
|
|
38719
39701
|
for (const key of [...keys].slice(0, 256)) {
|
|
38720
39702
|
let isDir2 = false;
|
|
38721
39703
|
try {
|
|
38722
|
-
isDir2 =
|
|
39704
|
+
isDir2 = lstatSync16(`${root}/${key}`).isDirectory();
|
|
38723
39705
|
} catch {
|
|
38724
39706
|
isDir2 = false;
|
|
38725
39707
|
}
|
|
@@ -39500,11 +40482,11 @@ data: ${data}
|
|
|
39500
40482
|
});
|
|
39501
40483
|
server.headersTimeout = 1e4;
|
|
39502
40484
|
server.requestTimeout = 0;
|
|
39503
|
-
await new Promise((
|
|
40485
|
+
await new Promise((resolve42, reject2) => {
|
|
39504
40486
|
server.once("error", reject2);
|
|
39505
40487
|
server.listen(o.port ?? 0, "127.0.0.1", () => {
|
|
39506
40488
|
server.off("error", reject2);
|
|
39507
|
-
|
|
40489
|
+
resolve42();
|
|
39508
40490
|
});
|
|
39509
40491
|
});
|
|
39510
40492
|
port = server.address().port;
|
|
@@ -39550,8 +40532,9 @@ Exit codes: 0 the log is intact, or has no chain yet ("not chained", an old log)
|
|
|
39550
40532
|
2 usage error.
|
|
39551
40533
|
`;
|
|
39552
40534
|
var HEX643 = /^[0-9a-f]{64}$/;
|
|
39553
|
-
var
|
|
39554
|
-
var
|
|
40535
|
+
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.`;
|
|
40536
|
+
var eventsOffSince = (dir) => readEventsOffSince(dir);
|
|
40537
|
+
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
40538
|
function parseExpect(raw) {
|
|
39556
40539
|
const v = raw.trim().toLowerCase();
|
|
39557
40540
|
if (HEX643.test(v)) return { kind: "tip", hash: v };
|
|
@@ -39638,9 +40621,13 @@ ${VERIFY_LOG_HELP}`);
|
|
|
39638
40621
|
return 2;
|
|
39639
40622
|
}
|
|
39640
40623
|
}
|
|
39641
|
-
const
|
|
39642
|
-
|
|
39643
|
-
|
|
40624
|
+
const dir = stateDir(str4(p.values["dir"]));
|
|
40625
|
+
const status2 = run2(dir, expect);
|
|
40626
|
+
const offAt = eventsOffSince(dir);
|
|
40627
|
+
if (offAt !== null) io.err(eventsOffNote(offAt));
|
|
40628
|
+
const envNote = envSwitchNote();
|
|
40629
|
+
if (envNote !== null) io.err(envNote);
|
|
40630
|
+
io.out(p.values["json"] === true ? JSON.stringify(offAt !== null ? { ...status2, loggingTurnedOff: true, eventsOffSince: offAt } : status2) : describe(status2, expect !== null));
|
|
39644
40631
|
if (status2.status === "broken") return 1;
|
|
39645
40632
|
if (status2.status === "not-chained" && expect !== null) return 1;
|
|
39646
40633
|
return 0;
|
|
@@ -39676,11 +40663,11 @@ function openCommand(platform, url) {
|
|
|
39676
40663
|
if (platform === "win32") return { file: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
|
|
39677
40664
|
return { file: "xdg-open", args: [url] };
|
|
39678
40665
|
}
|
|
39679
|
-
var untilSignal = () => new Promise((
|
|
40666
|
+
var untilSignal = () => new Promise((resolve42) => {
|
|
39680
40667
|
const stop2 = () => {
|
|
39681
40668
|
process.off("SIGINT", stop2);
|
|
39682
40669
|
process.off("SIGTERM", stop2);
|
|
39683
|
-
|
|
40670
|
+
resolve42();
|
|
39684
40671
|
};
|
|
39685
40672
|
process.on("SIGINT", stop2);
|
|
39686
40673
|
process.on("SIGTERM", stop2);
|
|
@@ -39698,8 +40685,12 @@ ${CONSOLE_HELP}`);
|
|
|
39698
40685
|
return 0;
|
|
39699
40686
|
}
|
|
39700
40687
|
if (p.values["verify"] === true) {
|
|
39701
|
-
|
|
39702
|
-
const
|
|
40688
|
+
const verifyDir = stateDir(str4(p.values["dir"]));
|
|
40689
|
+
const offAt = eventsOffSince(verifyDir);
|
|
40690
|
+
if (offAt !== null) io.err(eventsOffNote(offAt));
|
|
40691
|
+
const envNote = envSwitchNote();
|
|
40692
|
+
if (envNote !== null) io.err(envNote);
|
|
40693
|
+
const status2 = verifyLogDir(verifyDir);
|
|
39703
40694
|
if (status2.status === "broken") {
|
|
39704
40695
|
io.out(`TAMPERED: the event log is broken at event ${status2.atSeq}. ${status2.detail.replace(/[^\x20-\x7e]/g, "?")}`);
|
|
39705
40696
|
return 1;
|
|
@@ -39728,7 +40719,10 @@ ${CONSOLE_HELP}`);
|
|
|
39728
40719
|
return 1;
|
|
39729
40720
|
}
|
|
39730
40721
|
io.out(`Exorcist 98 Shield console (read-only) for ${dir}`);
|
|
39731
|
-
|
|
40722
|
+
const offAtStart = eventsOffSince(dir);
|
|
40723
|
+
if (offAtStart !== null) io.out(eventsOffNote(offAtStart));
|
|
40724
|
+
const envNoteAtStart = envSwitchNote();
|
|
40725
|
+
if (envNoteAtStart !== null) io.out(envNoteAtStart);
|
|
39732
40726
|
if (p.values["no-open"] === true) {
|
|
39733
40727
|
io.out(` ${server.url}`);
|
|
39734
40728
|
io.out("Only this machine can open it, and only with the token in the URL. Press Ctrl+C to stop.");
|
|
@@ -39750,8 +40744,8 @@ ${CONSOLE_HELP}`);
|
|
|
39750
40744
|
}
|
|
39751
40745
|
|
|
39752
40746
|
// src/commands/exorcise.ts
|
|
39753
|
-
import { existsSync as
|
|
39754
|
-
import { basename as
|
|
40747
|
+
import { existsSync as existsSync24, readFileSync as readFileSync31, statSync as statSync21 } from "node:fs";
|
|
40748
|
+
import { basename as basename13, dirname as dirname19, isAbsolute as isAbsolute22, relative as relative16, resolve as resolve34 } from "node:path";
|
|
39755
40749
|
var EXORCISE_HELP = `Usage: exorcist exorcise [path] [options]
|
|
39756
40750
|
|
|
39757
40751
|
Disinfect: repair the threats that have one safe, mechanical fix, and report
|
|
@@ -39835,14 +40829,14 @@ ${EXORCISE_HELP}`);
|
|
|
39835
40829
|
return 2;
|
|
39836
40830
|
}
|
|
39837
40831
|
const target = p.positionals[0] ?? ".";
|
|
39838
|
-
const abs =
|
|
39839
|
-
if (!
|
|
40832
|
+
const abs = resolve34(target);
|
|
40833
|
+
if (!existsSync24(abs)) {
|
|
39840
40834
|
io.err(`Path not found: ${target}`);
|
|
39841
40835
|
return 2;
|
|
39842
40836
|
}
|
|
39843
40837
|
const isFile = statSync21(abs).isFile();
|
|
39844
|
-
const root = isFile ?
|
|
39845
|
-
const single = isFile ?
|
|
40838
|
+
const root = isFile ? dirname19(abs) : abs;
|
|
40839
|
+
const single = isFile ? basename13(abs) : null;
|
|
39846
40840
|
const defsDir = findDefinitionsDir2(str4(p.values["definitions"]));
|
|
39847
40841
|
if (!defsDir) {
|
|
39848
40842
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -39860,7 +40854,7 @@ ${EXORCISE_HELP}`);
|
|
|
39860
40854
|
return 2;
|
|
39861
40855
|
}
|
|
39862
40856
|
const vault = vaultPath(stateDir(str4(p.values["dir"])));
|
|
39863
|
-
const state =
|
|
40857
|
+
const state = relative16(root, resolve34(vault, ".."));
|
|
39864
40858
|
const ignore = [...strs(p.values["ignore"]), ...readIgnoreFile(root)];
|
|
39865
40859
|
if (state === "") ignore.push("vault");
|
|
39866
40860
|
else if (!state.startsWith("..") && !isAbsolute22(state)) ignore.push(state.replace(/\\/g, "/"));
|
|
@@ -39909,7 +40903,7 @@ ${EXORCISE_HELP}`);
|
|
|
39909
40903
|
return 1;
|
|
39910
40904
|
}
|
|
39911
40905
|
const changedSet = new Set(changed.map((r) => r.file));
|
|
39912
|
-
const now = changed.map((r) => ({ file: r.file, text: readFileSync31(
|
|
40906
|
+
const now = changed.map((r) => ({ file: r.file, text: readFileSync31(resolve34(root, r.file), "utf8") }));
|
|
39913
40907
|
const after = [...findings.filter((f) => !changedSet.has(f.file)), ...rescanTexts(now, defs).filter((f) => keep(f.file))];
|
|
39914
40908
|
const removed = Math.max(0, findings.length - after.length);
|
|
39915
40909
|
const dirFlag = str4(p.values["dir"]) ? ` --dir ${str4(p.values["dir"])}` : "";
|
|
@@ -39928,10 +40922,10 @@ ${EXORCISE_HELP}`);
|
|
|
39928
40922
|
}
|
|
39929
40923
|
|
|
39930
40924
|
// src/commands/gate.ts
|
|
39931
|
-
import { existsSync as
|
|
40925
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
39932
40926
|
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>]
|
|
40927
|
+
import { resolve as resolve35 } from "node:path";
|
|
40928
|
+
var GATE_HELP = `Usage: exorcist gate [dir] [--fail-on <critical|high|medium|low|info>] [--dir <state folder>]
|
|
39935
40929
|
The gate for the end of an agent's turn. It looks only at the files an AI agent
|
|
39936
40930
|
obeys (steering, specs, hooks, custom agents, MCP configs, AGENTS.md and the
|
|
39937
40931
|
other rule files, READMEs) that changed since the last commit, and exits 1 with
|
|
@@ -39944,7 +40938,7 @@ When the Shield's state folder has an event-log head file, its head hash is
|
|
|
39944
40938
|
printed too (see "exorcist verify-log").
|
|
39945
40939
|
The Kiro hook written by "exorcist init" runs it when the agent stops.
|
|
39946
40940
|
`;
|
|
39947
|
-
var THRESHOLDS = ["critical", "high", "medium", "low"];
|
|
40941
|
+
var THRESHOLDS = ["critical", "high", "medium", "low", "info"];
|
|
39948
40942
|
var GIT_MS = 1e4;
|
|
39949
40943
|
function headLine(explicit) {
|
|
39950
40944
|
const h = readHead(stateDir(explicit));
|
|
@@ -40014,8 +41008,8 @@ ${GATE_HELP}`);
|
|
|
40014
41008
|
${GATE_HELP}`);
|
|
40015
41009
|
return 2;
|
|
40016
41010
|
}
|
|
40017
|
-
const start =
|
|
40018
|
-
if (!
|
|
41011
|
+
const start = resolve35(p.positionals[0] ?? ".");
|
|
41012
|
+
if (!existsSync25(start)) return nothingChecked(io, "that folder does not exist");
|
|
40019
41013
|
const top = await gitRepoRoot(start);
|
|
40020
41014
|
if (!top) return nothingChecked(io, "this folder is not a git repository, or git is not available");
|
|
40021
41015
|
const repo = { root: top };
|
|
@@ -40032,7 +41026,7 @@ ${GATE_HELP}`);
|
|
|
40032
41026
|
const onDisk = [];
|
|
40033
41027
|
const sizes = /* @__PURE__ */ new Map();
|
|
40034
41028
|
for (const rel of changed.files) {
|
|
40035
|
-
const info = await lstat2(
|
|
41029
|
+
const info = await lstat2(resolve35(repo.root, rel)).catch(() => null);
|
|
40036
41030
|
if (!info || !info.isFile()) continue;
|
|
40037
41031
|
onDisk.push(rel);
|
|
40038
41032
|
sizes.set(rel, info.size);
|
|
@@ -40049,7 +41043,7 @@ ${GATE_HELP}`);
|
|
|
40049
41043
|
if (f) added.push(f);
|
|
40050
41044
|
continue;
|
|
40051
41045
|
}
|
|
40052
|
-
const after = await readFile6(
|
|
41046
|
+
const after = await readFile6(resolve35(repo.root, rel), "utf8").catch(() => null);
|
|
40053
41047
|
if (after === null) continue;
|
|
40054
41048
|
const before = then.has(rel) ? await committed(repo.root, rel) : null;
|
|
40055
41049
|
added.push(...gateFindings(rel, before, after, defs));
|
|
@@ -40067,8 +41061,8 @@ ${head}`);
|
|
|
40067
41061
|
|
|
40068
41062
|
// src/commands/guard-mcp-write.ts
|
|
40069
41063
|
import { randomBytes as randomBytes12 } from "node:crypto";
|
|
40070
|
-
import { createReadStream, createWriteStream, openSync as
|
|
40071
|
-
import { homedir as
|
|
41064
|
+
import { createReadStream, createWriteStream, openSync as openSync12, writeSync as writeSync8 } from "node:fs";
|
|
41065
|
+
import { homedir as homedir10 } from "node:os";
|
|
40072
41066
|
import { createInterface as createInterface2 } from "node:readline";
|
|
40073
41067
|
var GUARD_MCP_WRITE_HELP = `Usage: exorcist guard-mcp-write (Kiro hook helper)
|
|
40074
41068
|
Reads a Kiro PreToolUse hook event from stdin. When the tool would write to
|
|
@@ -40087,14 +41081,14 @@ var PROMPT_TIMEOUT_MS = 125e3;
|
|
|
40087
41081
|
function hookDeps() {
|
|
40088
41082
|
let fd = null;
|
|
40089
41083
|
try {
|
|
40090
|
-
fd =
|
|
41084
|
+
fd = openSync12("/dev/tty", "r+");
|
|
40091
41085
|
} catch {
|
|
40092
41086
|
fd = null;
|
|
40093
41087
|
}
|
|
40094
41088
|
const tty = fd;
|
|
40095
41089
|
const write = (s) => {
|
|
40096
41090
|
if (tty !== null) try {
|
|
40097
|
-
|
|
41091
|
+
writeSync8(tty, s.endsWith("\n") ? s : `${s}
|
|
40098
41092
|
`);
|
|
40099
41093
|
} catch {
|
|
40100
41094
|
}
|
|
@@ -40118,7 +41112,7 @@ function hookDeps() {
|
|
|
40118
41112
|
dialog: macDialog,
|
|
40119
41113
|
nonce: () => randomBytes12(4).toString("hex").slice(0, 6)
|
|
40120
41114
|
};
|
|
40121
|
-
return { term, promptIo: { out: write, err: write }, home:
|
|
41115
|
+
return { term, promptIo: { out: write, err: write }, home: homedir10(), timeoutMs: PROMPT_TIMEOUT_MS };
|
|
40122
41116
|
}
|
|
40123
41117
|
function dialogMessage(kind, path) {
|
|
40124
41118
|
if (kind === "trusted-commands") return `Your AI agent wants to change which commands it may run without asking you:
|
|
@@ -40216,10 +41210,10 @@ function guardEnvWriteCommand(stdin, io) {
|
|
|
40216
41210
|
}
|
|
40217
41211
|
|
|
40218
41212
|
// src/commands/guard-web-fetch.ts
|
|
40219
|
-
import { createHash as
|
|
41213
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
40220
41214
|
import { readFileSync as readFileSync32, writeFileSync as writeFileSync11 } from "node:fs";
|
|
40221
|
-
import { tmpdir as
|
|
40222
|
-
import { isAbsolute as isAbsolute24, join as
|
|
41215
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
41216
|
+
import { isAbsolute as isAbsolute24, join as join40 } from "node:path";
|
|
40223
41217
|
var GUARD_WEB_FETCH_HELP = `Usage: exorcist guard-web-fetch (Kiro hook helper)
|
|
40224
41218
|
Reads a Kiro PreToolUse hook event for the web_fetch tool from stdin. When the
|
|
40225
41219
|
address holds a secret (a key or token), a canary token, or a value from a .env
|
|
@@ -40255,8 +41249,8 @@ function guardWebFetchCommand(stdin, io) {
|
|
|
40255
41249
|
}
|
|
40256
41250
|
function sentStore(cwd, event) {
|
|
40257
41251
|
const sid = typeof event === "object" && event !== null && typeof event["session_id"] === "string" ? String(event["session_id"]) : "";
|
|
40258
|
-
const id =
|
|
40259
|
-
const file =
|
|
41252
|
+
const id = createHash16("sha256").update(`${cwd}\0${sid}`).digest("hex").slice(0, 24);
|
|
41253
|
+
const file = join40(tmpdir3(), `exorcist98-sent-${id}.json`);
|
|
40260
41254
|
return {
|
|
40261
41255
|
load: () => {
|
|
40262
41256
|
try {
|
|
@@ -40358,8 +41352,8 @@ async function guardShellReadCommand(stdin, io) {
|
|
|
40358
41352
|
}
|
|
40359
41353
|
|
|
40360
41354
|
// src/commands/hook-scan.ts
|
|
40361
|
-
import { existsSync as
|
|
40362
|
-
import { resolve as
|
|
41355
|
+
import { existsSync as existsSync26, statSync as statSync22 } from "node:fs";
|
|
41356
|
+
import { resolve as resolve36 } from "node:path";
|
|
40363
41357
|
async function hookScanCommand(stdin, io) {
|
|
40364
41358
|
let event;
|
|
40365
41359
|
try {
|
|
@@ -40369,14 +41363,14 @@ async function hookScanCommand(stdin, io) {
|
|
|
40369
41363
|
}
|
|
40370
41364
|
if (typeof event.file_path !== "string" || event.file_path === "") return 0;
|
|
40371
41365
|
const base = typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
|
|
40372
|
-
const file =
|
|
40373
|
-
if (!
|
|
41366
|
+
const file = resolve36(base, event.file_path);
|
|
41367
|
+
if (!existsSync26(file) || !statSync22(file).isFile()) return 0;
|
|
40374
41368
|
return await scanCommand([file, "--fail-on", "high"], { out: io.err, err: io.err });
|
|
40375
41369
|
}
|
|
40376
41370
|
|
|
40377
41371
|
// src/commands/init.ts
|
|
40378
|
-
import { chmodSync, existsSync as
|
|
40379
|
-
import { dirname as
|
|
41372
|
+
import { chmodSync, existsSync as existsSync27, lstatSync as lstatSync17, mkdirSync as mkdirSync12, readFileSync as readFileSync33, writeFileSync as writeFileSync12 } from "node:fs";
|
|
41373
|
+
import { dirname as dirname20, join as join41, resolve as resolve37 } from "node:path";
|
|
40380
41374
|
|
|
40381
41375
|
// src/kiro-hook-script.ts
|
|
40382
41376
|
var KIRO_HOOK_SCRIPT = [
|
|
@@ -40504,8 +41498,8 @@ function reviewerAgentForProject(mcpCommand) {
|
|
|
40504
41498
|
}
|
|
40505
41499
|
|
|
40506
41500
|
// 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.
|
|
41501
|
+
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.9";
|
|
41502
|
+
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.9";
|
|
40509
41503
|
var MISSING_FROM_DEFAULT_BIN = /* @__PURE__ */ new Set();
|
|
40510
41504
|
var INIT_HELP = `Usage: exorcist init [folder] [--kiro] [--shield] [--sandbox] [--no-agent] [--force]
|
|
40511
41505
|
[--bin <command>] [--mcp-bin <command>]
|
|
@@ -40544,15 +41538,15 @@ Existing files are never overwritten unless you pass --force.
|
|
|
40544
41538
|
var SANDBOX_REL = ".kiro/settings/sandbox.json";
|
|
40545
41539
|
var SANDBOX_SETTINGS = { enabled: true, networkAccess: "DEFAULT_BLOCKED", mcpSandboxing: true };
|
|
40546
41540
|
function writeSandboxFile(root, io) {
|
|
40547
|
-
const path =
|
|
41541
|
+
const path = join41(root, SANDBOX_REL);
|
|
40548
41542
|
let present = false;
|
|
40549
41543
|
try {
|
|
40550
|
-
|
|
41544
|
+
lstatSync17(path);
|
|
40551
41545
|
present = true;
|
|
40552
41546
|
} catch {
|
|
40553
41547
|
}
|
|
40554
41548
|
if (!present) {
|
|
40555
|
-
|
|
41549
|
+
mkdirSync12(dirname20(path), { recursive: true });
|
|
40556
41550
|
try {
|
|
40557
41551
|
writeFileSync12(path, `${JSON.stringify(SANDBOX_SETTINGS, null, 2)}
|
|
40558
41552
|
`, { encoding: "utf8", flag: "wx" });
|
|
@@ -40566,7 +41560,7 @@ function writeSandboxFile(root, io) {
|
|
|
40566
41560
|
io.out(`Left ${SANDBOX_REL} unchanged: it already exists. Delete it and rerun to get the Exorcist settings.`);
|
|
40567
41561
|
return false;
|
|
40568
41562
|
}
|
|
40569
|
-
var
|
|
41563
|
+
var hook2 = (name, description, body) => `${JSON.stringify({ version: "v1", hooks: [{ name, description, ...body }] }, null, 2)}
|
|
40570
41564
|
`;
|
|
40571
41565
|
var STEERING = `---
|
|
40572
41566
|
inclusion: always
|
|
@@ -40618,13 +41612,13 @@ function splitCommand(s) {
|
|
|
40618
41612
|
}
|
|
40619
41613
|
var MAX_NAME = 60;
|
|
40620
41614
|
function describeMcpConfig(path) {
|
|
40621
|
-
if (!
|
|
41615
|
+
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
41616
|
try {
|
|
40623
41617
|
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: ${
|
|
41618
|
+
const entries2 = Object.entries(cfg.mcpServers ?? {});
|
|
41619
|
+
const shielded = entries2.filter(([, e]) => isWrapped(e)).map(([n]) => n);
|
|
41620
|
+
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.`);
|
|
41621
|
+
return { exists: true, warnings, line: `.kiro/settings/mcp.json: ${entries2.length} server${entries2.length === 1 ? "" : "s"}, ${shielded.length} behind the Shield` };
|
|
40628
41622
|
} catch {
|
|
40629
41623
|
return { exists: true, warnings: [], line: ".kiro/settings/mcp.json is not valid JSON; fix it before using --shield" };
|
|
40630
41624
|
}
|
|
@@ -40656,7 +41650,7 @@ ${INIT_HELP}`);
|
|
|
40656
41650
|
${INIT_HELP}`);
|
|
40657
41651
|
return 2;
|
|
40658
41652
|
}
|
|
40659
|
-
const root =
|
|
41653
|
+
const root = resolve37(p.positionals[0] ?? ".");
|
|
40660
41654
|
const bin = str4(p.values["bin"]) ?? DEFAULT_BIN;
|
|
40661
41655
|
const mcpBin = str4(p.values["mcp-bin"]) ?? DEFAULT_MCP_BIN;
|
|
40662
41656
|
const force = p.values["force"] === true;
|
|
@@ -40694,7 +41688,7 @@ ${INIT_HELP}`);
|
|
|
40694
41688
|
{
|
|
40695
41689
|
rel: ".kiro/hooks/exorcist-secrets.json",
|
|
40696
41690
|
summary: "PreToolUse on shell tools: blocks git commit while staged files hold secrets",
|
|
40697
|
-
body:
|
|
41691
|
+
body: hook2("exorcist-secrets", "Block git commit while staged files contain secrets. Exit code 2 blocks the shell command.", {
|
|
40698
41692
|
trigger: "PreToolUse",
|
|
40699
41693
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40700
41694
|
action: { type: "command", command: `${HOOK_RUNNER} --guard ${bin} guard-commit` },
|
|
@@ -40704,7 +41698,7 @@ ${INIT_HELP}`);
|
|
|
40704
41698
|
{
|
|
40705
41699
|
rel: ".kiro/hooks/exorcist-mcp-scan.json",
|
|
40706
41700
|
summary: "PostFileSave on MCP configs: scans the saved file and reports high or critical findings",
|
|
40707
|
-
body:
|
|
41701
|
+
body: hook2("exorcist-mcp-scan", "Scan MCP configuration with Exorcist 98 whenever it is saved.", {
|
|
40708
41702
|
trigger: "PostFileSave",
|
|
40709
41703
|
matcher: "(\\.kiro/settings/mcp\\.json|\\.cursor/mcp\\.json|\\.vscode/mcp\\.json|claude_desktop_config\\.json)$",
|
|
40710
41704
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} hook-scan` },
|
|
@@ -40714,7 +41708,7 @@ ${INIT_HELP}`);
|
|
|
40714
41708
|
{
|
|
40715
41709
|
rel: ".kiro/hooks/exorcist-on-access.json",
|
|
40716
41710
|
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:
|
|
41711
|
+
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
41712
|
trigger: "PreToolUse",
|
|
40719
41713
|
matcher: "read|readFile|read_file|readCode|fs_read|readMultipleFiles|grep|grep_search|grepSearch|file_search|fileSearch|glob|list_directory|listDirectory|code",
|
|
40720
41714
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} on-access` },
|
|
@@ -40725,7 +41719,7 @@ ${INIT_HELP}`);
|
|
|
40725
41719
|
{
|
|
40726
41720
|
rel: ".kiro/hooks/exorcist-gate.json",
|
|
40727
41721
|
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:
|
|
41722
|
+
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
41723
|
trigger: "Stop",
|
|
40730
41724
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} gate` },
|
|
40731
41725
|
timeout: 30,
|
|
@@ -40735,7 +41729,7 @@ ${INIT_HELP}`);
|
|
|
40735
41729
|
{
|
|
40736
41730
|
rel: ".kiro/hooks/exorcist-mcp-write-guard.json",
|
|
40737
41731
|
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:
|
|
41732
|
+
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
41733
|
trigger: "PreToolUse",
|
|
40740
41734
|
matcher: "write|shell",
|
|
40741
41735
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-mcp-write` },
|
|
@@ -40746,7 +41740,7 @@ ${INIT_HELP}`);
|
|
|
40746
41740
|
{
|
|
40747
41741
|
rel: ".kiro/hooks/exorcist-guard-web-fetch.json",
|
|
40748
41742
|
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:
|
|
41743
|
+
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
41744
|
trigger: "PreToolUse",
|
|
40751
41745
|
matcher: "web_fetch|webFetch|remote_web_search|web_search|webSearch|shell|execute_bash|executeBash|run_command|bash",
|
|
40752
41746
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-web-fetch` },
|
|
@@ -40757,7 +41751,7 @@ ${INIT_HELP}`);
|
|
|
40757
41751
|
{
|
|
40758
41752
|
rel: ".kiro/hooks/exorcist-guard-env-write.json",
|
|
40759
41753
|
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:
|
|
41754
|
+
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
41755
|
trigger: "PreToolUse",
|
|
40762
41756
|
matcher: "write|fs_write|str_replace|shell|execute_bash|executeBash|run_command|bash",
|
|
40763
41757
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-env-write` },
|
|
@@ -40768,7 +41762,7 @@ ${INIT_HELP}`);
|
|
|
40768
41762
|
{
|
|
40769
41763
|
rel: ".kiro/hooks/exorcist-guard-run-scripts.json",
|
|
40770
41764
|
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:
|
|
41765
|
+
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
41766
|
trigger: "PreToolUse",
|
|
40773
41767
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40774
41768
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-run-scripts` },
|
|
@@ -40779,7 +41773,7 @@ ${INIT_HELP}`);
|
|
|
40779
41773
|
{
|
|
40780
41774
|
rel: ".kiro/hooks/exorcist-guard-shell-read.json",
|
|
40781
41775
|
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:
|
|
41776
|
+
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
41777
|
trigger: "PreToolUse",
|
|
40784
41778
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40785
41779
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-shell-read` },
|
|
@@ -40802,13 +41796,13 @@ ${INIT_HELP}`);
|
|
|
40802
41796
|
}
|
|
40803
41797
|
const done = [];
|
|
40804
41798
|
for (const f of files) {
|
|
40805
|
-
const path =
|
|
40806
|
-
if (
|
|
41799
|
+
const path = join41(root, f.rel);
|
|
41800
|
+
if (existsSync27(path) && !force) {
|
|
40807
41801
|
io.err(`Kept existing ${f.rel} (use --force to replace it).`);
|
|
40808
41802
|
done.push({ f, wrote: false });
|
|
40809
41803
|
continue;
|
|
40810
41804
|
}
|
|
40811
|
-
|
|
41805
|
+
mkdirSync12(dirname20(path), { recursive: true });
|
|
40812
41806
|
writeFileSync12(path, f.body, "utf8");
|
|
40813
41807
|
if (f.executable) chmodSync(path, 493);
|
|
40814
41808
|
if (!kiro) io.out(`Wrote ${f.rel}`);
|
|
@@ -40820,7 +41814,7 @@ ${INIT_HELP}`);
|
|
|
40820
41814
|
return wroteAny ? 0 : 1;
|
|
40821
41815
|
}
|
|
40822
41816
|
if (sandbox) writeSandboxFile(root, io);
|
|
40823
|
-
const mcpPath =
|
|
41817
|
+
const mcpPath = join41(root, ".kiro/settings/mcp.json");
|
|
40824
41818
|
let shieldOk = true;
|
|
40825
41819
|
let shieldLine = null;
|
|
40826
41820
|
if (shield) {
|
|
@@ -40830,7 +41824,7 @@ ${INIT_HELP}`);
|
|
|
40830
41824
|
shieldOk = false;
|
|
40831
41825
|
} else {
|
|
40832
41826
|
const [head, ...rest] = binWords;
|
|
40833
|
-
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${
|
|
41827
|
+
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${join41(root, ".exorcist")}`];
|
|
40834
41828
|
const notes = [];
|
|
40835
41829
|
const code3 = await wrapCommand(args, { out: io.out, err: (s) => notes.push(s) }, "wrap");
|
|
40836
41830
|
for (const n of notes) io.err(n);
|
|
@@ -40874,7 +41868,7 @@ ${INIT_HELP}`);
|
|
|
40874
41868
|
"then reconnect MCP servers in the MCP panel so they start through the Shield."
|
|
40875
41869
|
];
|
|
40876
41870
|
if (isDefaultBin) {
|
|
40877
|
-
lines.push("Commands run through npx (@exorcist-98/cli@0.3.
|
|
41871
|
+
lines.push("Commands run through npx (@exorcist-98/cli@0.3.9). If Kiro cannot start a wrapped server or a hook cannot find npx,");
|
|
40878
41872
|
lines.push('rerun with --bin "<absolute path to node> <absolute path to the exorcist CLI>" and --force.');
|
|
40879
41873
|
}
|
|
40880
41874
|
io.out(lines.join("\n"));
|
|
@@ -40883,8 +41877,8 @@ ${INIT_HELP}`);
|
|
|
40883
41877
|
}
|
|
40884
41878
|
|
|
40885
41879
|
// src/commands/lock.ts
|
|
40886
|
-
import { existsSync as
|
|
40887
|
-
import { isAbsolute as isAbsolute27, join as
|
|
41880
|
+
import { existsSync as existsSync28, readFileSync as readFileSync34, writeFileSync as writeFileSync13 } from "node:fs";
|
|
41881
|
+
import { isAbsolute as isAbsolute27, join as join42, resolve as resolve38 } from "node:path";
|
|
40888
41882
|
|
|
40889
41883
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js
|
|
40890
41884
|
var NEVER2 = Object.freeze({
|
|
@@ -41012,9 +42006,9 @@ function assertNever(_x) {
|
|
|
41012
42006
|
}
|
|
41013
42007
|
function assert(_) {
|
|
41014
42008
|
}
|
|
41015
|
-
function getEnumValues(
|
|
41016
|
-
const numericValues = Object.values(
|
|
41017
|
-
const values = Object.entries(
|
|
42009
|
+
function getEnumValues(entries2) {
|
|
42010
|
+
const numericValues = Object.values(entries2).filter((v) => typeof v === "number");
|
|
42011
|
+
const values = Object.entries(entries2).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
41018
42012
|
return values;
|
|
41019
42013
|
}
|
|
41020
42014
|
function joinValues(array2, separator = "|") {
|
|
@@ -44474,10 +45468,10 @@ var ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
44474
45468
|
};
|
|
44475
45469
|
});
|
|
44476
45470
|
function _enum(values, params) {
|
|
44477
|
-
const
|
|
45471
|
+
const entries2 = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
44478
45472
|
return new ZodEnum2({
|
|
44479
45473
|
type: "enum",
|
|
44480
|
-
entries,
|
|
45474
|
+
entries: entries2,
|
|
44481
45475
|
...util_exports.normalizeParams(params)
|
|
44482
45476
|
});
|
|
44483
45477
|
}
|
|
@@ -46754,7 +47748,7 @@ var Protocol = class {
|
|
|
46754
47748
|
return;
|
|
46755
47749
|
}
|
|
46756
47750
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
46757
|
-
await new Promise((
|
|
47751
|
+
await new Promise((resolve42) => setTimeout(resolve42, pollInterval));
|
|
46758
47752
|
options?.signal?.throwIfAborted();
|
|
46759
47753
|
}
|
|
46760
47754
|
} catch (error2) {
|
|
@@ -46771,7 +47765,7 @@ var Protocol = class {
|
|
|
46771
47765
|
*/
|
|
46772
47766
|
request(request, resultSchema, options) {
|
|
46773
47767
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
46774
|
-
return new Promise((
|
|
47768
|
+
return new Promise((resolve42, reject2) => {
|
|
46775
47769
|
const earlyReject = (error2) => {
|
|
46776
47770
|
reject2(error2);
|
|
46777
47771
|
};
|
|
@@ -46849,7 +47843,7 @@ var Protocol = class {
|
|
|
46849
47843
|
if (!parseResult.success) {
|
|
46850
47844
|
reject2(parseResult.error);
|
|
46851
47845
|
} else {
|
|
46852
|
-
|
|
47846
|
+
resolve42(parseResult.data);
|
|
46853
47847
|
}
|
|
46854
47848
|
} catch (error2) {
|
|
46855
47849
|
reject2(error2);
|
|
@@ -47111,12 +48105,12 @@ var Protocol = class {
|
|
|
47111
48105
|
}
|
|
47112
48106
|
} catch {
|
|
47113
48107
|
}
|
|
47114
|
-
return new Promise((
|
|
48108
|
+
return new Promise((resolve42, reject2) => {
|
|
47115
48109
|
if (signal.aborted) {
|
|
47116
48110
|
reject2(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
47117
48111
|
return;
|
|
47118
48112
|
}
|
|
47119
|
-
const timeoutId = setTimeout(
|
|
48113
|
+
const timeoutId = setTimeout(resolve42, interval);
|
|
47120
48114
|
signal.addEventListener("abort", () => {
|
|
47121
48115
|
clearTimeout(timeoutId);
|
|
47122
48116
|
reject2(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -48067,7 +49061,7 @@ var StdioClientTransport = class {
|
|
|
48067
49061
|
if (this._process) {
|
|
48068
49062
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
48069
49063
|
}
|
|
48070
|
-
return new Promise((
|
|
49064
|
+
return new Promise((resolve42, reject2) => {
|
|
48071
49065
|
this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
|
|
48072
49066
|
// merge default env with server env because mcp server needs some env vars
|
|
48073
49067
|
env: {
|
|
@@ -48084,7 +49078,7 @@ var StdioClientTransport = class {
|
|
|
48084
49078
|
this.onerror?.(error2);
|
|
48085
49079
|
});
|
|
48086
49080
|
this._process.on("spawn", () => {
|
|
48087
|
-
|
|
49081
|
+
resolve42();
|
|
48088
49082
|
});
|
|
48089
49083
|
this._process.on("close", (_code) => {
|
|
48090
49084
|
this._process = void 0;
|
|
@@ -48149,22 +49143,22 @@ var StdioClientTransport = class {
|
|
|
48149
49143
|
if (this._process) {
|
|
48150
49144
|
const processToClose = this._process;
|
|
48151
49145
|
this._process = void 0;
|
|
48152
|
-
const closePromise = new Promise((
|
|
49146
|
+
const closePromise = new Promise((resolve42) => {
|
|
48153
49147
|
processToClose.once("close", () => {
|
|
48154
|
-
|
|
49148
|
+
resolve42();
|
|
48155
49149
|
});
|
|
48156
49150
|
});
|
|
48157
49151
|
try {
|
|
48158
49152
|
processToClose.stdin?.end();
|
|
48159
49153
|
} catch {
|
|
48160
49154
|
}
|
|
48161
|
-
await Promise.race([closePromise, new Promise((
|
|
49155
|
+
await Promise.race([closePromise, new Promise((resolve42) => setTimeout(resolve42, 2e3).unref())]);
|
|
48162
49156
|
if (processToClose.exitCode === null) {
|
|
48163
49157
|
try {
|
|
48164
49158
|
processToClose.kill("SIGTERM");
|
|
48165
49159
|
} catch {
|
|
48166
49160
|
}
|
|
48167
|
-
await Promise.race([closePromise, new Promise((
|
|
49161
|
+
await Promise.race([closePromise, new Promise((resolve42) => setTimeout(resolve42, 2e3).unref())]);
|
|
48168
49162
|
}
|
|
48169
49163
|
if (processToClose.exitCode === null) {
|
|
48170
49164
|
try {
|
|
@@ -48176,15 +49170,15 @@ var StdioClientTransport = class {
|
|
|
48176
49170
|
this._readBuffer.clear();
|
|
48177
49171
|
}
|
|
48178
49172
|
send(message) {
|
|
48179
|
-
return new Promise((
|
|
49173
|
+
return new Promise((resolve42) => {
|
|
48180
49174
|
if (!this._process?.stdin) {
|
|
48181
49175
|
throw new Error("Not connected");
|
|
48182
49176
|
}
|
|
48183
49177
|
const json2 = serializeMessage(message);
|
|
48184
49178
|
if (this._process.stdin.write(json2)) {
|
|
48185
|
-
|
|
49179
|
+
resolve42();
|
|
48186
49180
|
} else {
|
|
48187
|
-
this._process.stdin.once("drain",
|
|
49181
|
+
this._process.stdin.once("drain", resolve42);
|
|
48188
49182
|
}
|
|
48189
49183
|
});
|
|
48190
49184
|
}
|
|
@@ -48193,7 +49187,7 @@ var StdioClientTransport = class {
|
|
|
48193
49187
|
// src/commands/lock.ts
|
|
48194
49188
|
init_zod();
|
|
48195
49189
|
var DEFAULT_LOCK_TIMEOUT_MS = 2e4;
|
|
48196
|
-
var DEFAULT_CONFIG =
|
|
49190
|
+
var DEFAULT_CONFIG = join42(".kiro", "settings", "mcp.json");
|
|
48197
49191
|
var MAX_PAGES = 100;
|
|
48198
49192
|
var LOCK_HELP = `Usage: exorcist lock [options]
|
|
48199
49193
|
exorcist lock --check [options]
|
|
@@ -48257,7 +49251,7 @@ var RawToolsPage = external_exports.object({ tools: external_exports.array(exter
|
|
|
48257
49251
|
var firstLine2 = (err) => (err instanceof Error ? err.message : String(err)).split("\n")[0]?.slice(0, 300) ?? "unknown error";
|
|
48258
49252
|
async function listTools(o) {
|
|
48259
49253
|
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.
|
|
49254
|
+
const client = new Client({ name: "exorcist-lock", version: "0.3.9" }, { capabilities: {} });
|
|
48261
49255
|
let timer;
|
|
48262
49256
|
const timedOut = new Promise((res) => {
|
|
48263
49257
|
timer = setTimeout(() => res({ ok: false, error: `it did not list its tools within ${o.timeoutMs} ms.` }), o.timeoutMs);
|
|
@@ -48298,7 +49292,7 @@ function serverEnv(base, entryEnv = {}) {
|
|
|
48298
49292
|
return { ...Object.fromEntries(inherited), ...entryEnv };
|
|
48299
49293
|
}
|
|
48300
49294
|
async function collectListings(config2, o) {
|
|
48301
|
-
const
|
|
49295
|
+
const list3 = o.list ?? listTools;
|
|
48302
49296
|
const listings = [];
|
|
48303
49297
|
const kept = [];
|
|
48304
49298
|
const notes = [];
|
|
@@ -48340,14 +49334,14 @@ async function collectListings(config2, o) {
|
|
|
48340
49334
|
if (loaders.length > 0) {
|
|
48341
49335
|
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
49336
|
}
|
|
48343
|
-
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute27(entry.cwd) ? entry.cwd :
|
|
49337
|
+
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute27(entry.cwd) ? entry.cwd : resolve38(o.cwd, entry.cwd);
|
|
48344
49338
|
if (o.static) {
|
|
48345
49339
|
const old = o.previous && Object.hasOwn(o.previous.servers, name) ? o.previous.servers[name] : void 0;
|
|
48346
49340
|
kept.push([name, { launch: launchFingerprint(command, entry.args, cwd, void 0, pinEntry).hash, tools: old?.tools ?? {} }]);
|
|
48347
49341
|
continue;
|
|
48348
49342
|
}
|
|
48349
49343
|
jobs.push((async () => {
|
|
48350
|
-
const r = await
|
|
49344
|
+
const r = await list3({ command, args: entry.args, env: serverEnv(process.env, entry.env), cwd, timeoutMs: o.timeoutMs });
|
|
48351
49345
|
if (!r.ok) {
|
|
48352
49346
|
errors.push(`Could not list the tools of "${name}": ${r.error}`);
|
|
48353
49347
|
return;
|
|
@@ -48409,7 +49403,7 @@ ${LOCK_HELP}`);
|
|
|
48409
49403
|
io.err("--timeout must be a positive whole number of milliseconds.");
|
|
48410
49404
|
return 2;
|
|
48411
49405
|
}
|
|
48412
|
-
const lockPath2 =
|
|
49406
|
+
const lockPath2 = resolve38(str4(p.values["lock"]) ?? LOCK_FILE);
|
|
48413
49407
|
const checking = p.values["check"] === true;
|
|
48414
49408
|
const fromShield = p.values["from-shield"] === true;
|
|
48415
49409
|
const isStatic = p.values["static"] === true;
|
|
@@ -48422,7 +49416,7 @@ ${LOCK_HELP}`);
|
|
|
48422
49416
|
return 2;
|
|
48423
49417
|
}
|
|
48424
49418
|
let previous;
|
|
48425
|
-
if (
|
|
49419
|
+
if (existsSync28(lockPath2)) {
|
|
48426
49420
|
let text2;
|
|
48427
49421
|
try {
|
|
48428
49422
|
text2 = readFileSync34(lockPath2, "utf8");
|
|
@@ -48450,8 +49444,8 @@ ${LOCK_HELP}`);
|
|
|
48450
49444
|
}
|
|
48451
49445
|
current = pinsToLock(st.state);
|
|
48452
49446
|
} else {
|
|
48453
|
-
const configPath =
|
|
48454
|
-
if (!
|
|
49447
|
+
const configPath = resolve38(str4(p.values["config"]) ?? DEFAULT_CONFIG);
|
|
49448
|
+
if (!existsSync28(configPath)) {
|
|
48455
49449
|
io.err(`MCP config not found: ${configPath}. Pass --config <file>, or --from-shield.`);
|
|
48456
49450
|
return 2;
|
|
48457
49451
|
}
|
|
@@ -48499,8 +49493,8 @@ ${LOCK_HELP}`);
|
|
|
48499
49493
|
}
|
|
48500
49494
|
|
|
48501
49495
|
// src/commands/map.ts
|
|
48502
|
-
import { existsSync as
|
|
48503
|
-
import { resolve as
|
|
49496
|
+
import { existsSync as existsSync29, statSync as statSync23 } from "node:fs";
|
|
49497
|
+
import { resolve as resolve39 } from "node:path";
|
|
48504
49498
|
var MAP_HELP = `Usage: exorcist map [dir] [options]
|
|
48505
49499
|
|
|
48506
49500
|
The Haunted House Map: for every MCP config in a folder (default: the current
|
|
@@ -48557,8 +49551,8 @@ function renderConfig(c, finding) {
|
|
|
48557
49551
|
lines.push(" One poisoned page, issue or message could make the agent read your secrets and send them out.");
|
|
48558
49552
|
} else {
|
|
48559
49553
|
const empty = ROOMS.filter((r) => c.legs[r.cap].length === 0).map((r) => r.room);
|
|
48560
|
-
const
|
|
48561
|
-
lines.push(` OK No trifecta: the ${
|
|
49554
|
+
const list3 = empty.length === 1 ? empty[0] : `${empty.slice(0, -1).join(", ")} and ${empty[empty.length - 1]}`;
|
|
49555
|
+
lines.push(` OK No trifecta: the ${list3} ${empty.length === 1 ? "room is" : "rooms are"} empty.`);
|
|
48562
49556
|
}
|
|
48563
49557
|
return [...lines, ""];
|
|
48564
49558
|
}
|
|
@@ -48595,8 +49589,8 @@ ${MAP_HELP}`);
|
|
|
48595
49589
|
return 2;
|
|
48596
49590
|
}
|
|
48597
49591
|
const target = p.positionals[0] ?? ".";
|
|
48598
|
-
const root =
|
|
48599
|
-
if (!
|
|
49592
|
+
const root = resolve39(target);
|
|
49593
|
+
if (!existsSync29(root) || !statSync23(root).isDirectory()) {
|
|
48600
49594
|
io.err(`Folder not found: ${target}`);
|
|
48601
49595
|
return 2;
|
|
48602
49596
|
}
|
|
@@ -48618,8 +49612,8 @@ ${MAP_HELP}`);
|
|
|
48618
49612
|
}
|
|
48619
49613
|
|
|
48620
49614
|
// src/commands/origin.ts
|
|
48621
|
-
import { existsSync as
|
|
48622
|
-
import { posix as posix3, relative as
|
|
49615
|
+
import { existsSync as existsSync30, realpathSync as realpathSync13, statSync as statSync24 } from "node:fs";
|
|
49616
|
+
import { posix as posix3, relative as relative17, resolve as resolve40, sep as sep8 } from "node:path";
|
|
48623
49617
|
var ORIGIN_HELP = `Usage: exorcist origin [dir] [options]
|
|
48624
49618
|
|
|
48625
49619
|
Scan a git repository, then walk its history to find the commit that
|
|
@@ -48741,8 +49735,8 @@ ${ORIGIN_HELP}`);
|
|
|
48741
49735
|
${ORIGIN_HELP}`);
|
|
48742
49736
|
return 2;
|
|
48743
49737
|
}
|
|
48744
|
-
const target =
|
|
48745
|
-
if (!
|
|
49738
|
+
const target = resolve40(p.positionals[0] ?? ".");
|
|
49739
|
+
if (!existsSync30(target) || !statSync24(target).isDirectory()) {
|
|
48746
49740
|
io.err(`Not a directory: ${target}`);
|
|
48747
49741
|
return 2;
|
|
48748
49742
|
}
|
|
@@ -48756,8 +49750,8 @@ ${ORIGIN_HELP}`);
|
|
|
48756
49750
|
return 2;
|
|
48757
49751
|
}
|
|
48758
49752
|
const { root: repoRoot, shallow, boundaries } = repo;
|
|
48759
|
-
const scanRoot =
|
|
48760
|
-
const prefix =
|
|
49753
|
+
const scanRoot = realpathSync13(target);
|
|
49754
|
+
const prefix = relative17(realpathSync13(repoRoot), scanRoot).split(sep8).join("/");
|
|
48761
49755
|
if (prefix.startsWith("..")) {
|
|
48762
49756
|
io.err(`The folder is outside the git repository git reported (${repoRoot}).`);
|
|
48763
49757
|
return 2;
|
|
@@ -48829,7 +49823,7 @@ ${ORIGIN_HELP}`);
|
|
|
48829
49823
|
}
|
|
48830
49824
|
|
|
48831
49825
|
// src/commands/shield.ts
|
|
48832
|
-
import { resolve as
|
|
49826
|
+
import { resolve as resolve41 } from "node:path";
|
|
48833
49827
|
var SHIELD_HELP = `Usage: exorcist shield --server <name> [options] -- <command> [args...]
|
|
48834
49828
|
exorcist shield --server <name> --url <https://...> [options]
|
|
48835
49829
|
|
|
@@ -48934,7 +49928,7 @@ ${SHIELD_HELP}`);
|
|
|
48934
49928
|
server,
|
|
48935
49929
|
dir: stateDir(str4(p.values["dir"])),
|
|
48936
49930
|
definitionsDir: defs,
|
|
48937
|
-
...config2 ? { configPath:
|
|
49931
|
+
...config2 ? { configPath: resolve41(config2) } : {},
|
|
48938
49932
|
// Desktop notifications for critical and high alerts; EXORCIST_NOTIFY=0 or policy notify:false turns them off.
|
|
48939
49933
|
...process.env["EXORCIST_NOTIFY"] === "0" ? {} : { notify: desktopNotifier() }
|
|
48940
49934
|
};
|
|
@@ -49090,12 +50084,12 @@ ${VAULT_HELP}`);
|
|
|
49090
50084
|
};
|
|
49091
50085
|
switch (sub) {
|
|
49092
50086
|
case "list": {
|
|
49093
|
-
const
|
|
49094
|
-
if (
|
|
50087
|
+
const entries2 = listEntries(vault);
|
|
50088
|
+
if (entries2.length === 0) {
|
|
49095
50089
|
io.out("The vault is empty.");
|
|
49096
50090
|
return 0;
|
|
49097
50091
|
}
|
|
49098
|
-
for (const e of
|
|
50092
|
+
for (const e of entries2) {
|
|
49099
50093
|
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
50094
|
}
|
|
49101
50095
|
return 0;
|
|
@@ -49155,7 +50149,7 @@ ${VAULT_HELP}`);
|
|
|
49155
50149
|
}
|
|
49156
50150
|
|
|
49157
50151
|
// src/index.ts
|
|
49158
|
-
var VERSION = "0.3.
|
|
50152
|
+
var VERSION = "0.3.9";
|
|
49159
50153
|
var HELP = `Exorcist 98 ${VERSION}: antivirus for AI coding agents
|
|
49160
50154
|
|
|
49161
50155
|
Usage: exorcist <command> [options]
|