@exorcist-98/cli 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/definitions/EX-002-ai-instructions.yaml +1 -1
- package/definitions/EX-035-sandbox-mcp-off.yaml +1 -1
- package/definitions/EX-037-hide-action-from-user.yaml +8 -1
- package/definitions/EX-075-unrelated-order.yaml +37 -0
- package/dist/index.mjs +1603 -608
- 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"]],
|
|
@@ -22905,8 +23073,7 @@ function envFamilyOwners(name) {
|
|
|
22905
23073
|
for (const [re2, owners] of ENV_FAMILIES) if (re2.test(name)) return owners;
|
|
22906
23074
|
return null;
|
|
22907
23075
|
}
|
|
22908
|
-
var
|
|
22909
|
-
var PROGRAM_VAR = /(?:EDITOR|PAGER|BROWSER|_CMD|_COMMAND|_HELPER|_PROGRAM|_EXEC|_SHELL|_ARGS(?:_\w+)?)$/u;
|
|
23076
|
+
var PLAIN_VAR = /(?:_LOG|_LOG_LEVEL|_DEBUG|_VERBOSE|_COLOR|_NO_COLOR|_IN_AUTOMATION|_INPUT|_WORKSPACE|_NAMESPACE|_CONTEXT|_REGION|_VAR_[A-Za-z0-9_]+|EDITOR|PAGER|BROWSER|_CLI_ARGS(?:_[a-z]+)?)$/u;
|
|
22910
23077
|
var ENDPOINT_VAR = /(?:_HOST|_URL|_ENDPOINT|_SERVER)$/;
|
|
22911
23078
|
function unlockedValueRisk(name, value, cwd, dynamic) {
|
|
22912
23079
|
const runtime = dynamic || /[$`]/.test(value);
|
|
@@ -22919,19 +23086,18 @@ function unlockedValueRisk(name, value, cwd, dynamic) {
|
|
|
22919
23086
|
}
|
|
22920
23087
|
let v = value.trim();
|
|
22921
23088
|
if (v.startsWith("~")) v = expandTilde(v, cwd) ?? v;
|
|
22922
|
-
const one = `${name} takes one
|
|
23089
|
+
const one = `${name} takes one word here: an absolute path outside the project, or, for a variable that holds a plain value, a name with no dot, slash or tilde`;
|
|
22923
23090
|
if (v === "") return null;
|
|
22924
23091
|
if (/[\s:,;=]/u.test(v)) return one;
|
|
22925
23092
|
if (isAbsolute4(v)) return insideProject(v, cwd) ? say : null;
|
|
22926
|
-
|
|
22927
|
-
return /[./\\~]/u.test(v) ? one : null;
|
|
23093
|
+
return PLAIN_VAR.test(name) && !/[./\\~]/u.test(v) ? null : one;
|
|
22928
23094
|
}
|
|
22929
23095
|
function envAssignRisk(name, value, cwd, dynamic = false, known, prog) {
|
|
22930
23096
|
const owners = envFamilyOwners(name);
|
|
22931
23097
|
if (owners !== null) {
|
|
22932
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";
|
|
22933
|
-
const
|
|
22934
|
-
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);
|
|
22935
23101
|
if (unlocked) return unlockedValueRisk(name, value, cwd, dynamic);
|
|
22936
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)`;
|
|
22937
23103
|
}
|
|
@@ -23337,8 +23503,8 @@ function devToolPlan(prog, args, ctx = {}) {
|
|
|
23337
23503
|
if (risk !== null) return blocked(prog, prog, `was given ${risk}`);
|
|
23338
23504
|
}
|
|
23339
23505
|
if (c.known.has(prog)) return plain;
|
|
23340
|
-
const
|
|
23341
|
-
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");
|
|
23342
23508
|
switch (prog) {
|
|
23343
23509
|
case "docker":
|
|
23344
23510
|
case "podman":
|
|
@@ -23399,7 +23565,7 @@ var reject = (reason, fix = FIX_SIMPLE) => {
|
|
|
23399
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/"];
|
|
23400
23566
|
var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh", "ash", "csh", "tcsh", "fish"]);
|
|
23401
23567
|
var NODE_LIKE = /* @__PURE__ */ new Set(["node", "nodejs", "tsx", "ts-node", "bun", "deno"]);
|
|
23402
|
-
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"]);
|
|
23403
23569
|
var KNOWN_PROGRAMS = /* @__PURE__ */ new Set([
|
|
23404
23570
|
// shell builtins and plain utilities
|
|
23405
23571
|
"cd",
|
|
@@ -23831,7 +23997,7 @@ function checkSpecial(prog, f, words2, ctx) {
|
|
|
23831
23997
|
if (prog === "less" || prog === "more" || prog === "man") {
|
|
23832
23998
|
if (args.some((a) => a.startsWith("--lesskey") || a === "+!" || a.startsWith("+!"))) reject("a pager was given commands to run", FIX_READ_TOOL);
|
|
23833
23999
|
}
|
|
23834
|
-
if (
|
|
24000
|
+
if (INTERPRETERS2.has(prog) || /^python[0-9.]*$/.test(prog)) {
|
|
23835
24001
|
const inlineFlag = (a) => {
|
|
23836
24002
|
if (NODE_LIKE.has(prog) || prog === "nodejs") return a === "-e" || a === "--eval" || a === "-p" || a === "--print" || a === "-pe" || a === "-ep";
|
|
23837
24003
|
if (/^python/.test(prog)) return a === "-c" || /^-[A-Za-z]*c$/.test(a) && a.length <= 4 && a.startsWith("-") && !a.startsWith("--");
|
|
@@ -24016,7 +24182,7 @@ function resolveWords(words2, f, ctx) {
|
|
|
24016
24182
|
}
|
|
24017
24183
|
pushExec(ctx, f, words2, raw);
|
|
24018
24184
|
const e = lastExec(ctx);
|
|
24019
|
-
if (ctx.mode === "script" && (
|
|
24185
|
+
if (ctx.mode === "script" && (INTERPRETERS2.has(prog) || /^python/.test(prog))) {
|
|
24020
24186
|
const flags2 = /* @__PURE__ */ new Set(["-e", "-c", "-p", "--eval", "--print", "-r", "-E"]);
|
|
24021
24187
|
const k = e.args.findIndex((a) => flags2.has(a.text));
|
|
24022
24188
|
const flag = e.args[k]?.text;
|
|
@@ -24444,14 +24610,14 @@ function scriptCandidates(rel) {
|
|
|
24444
24610
|
if (base.startsWith("..") || base.startsWith("/") || base === "." || base === "") return [];
|
|
24445
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))])];
|
|
24446
24612
|
}
|
|
24447
|
-
function followFiles(
|
|
24613
|
+
function followFiles(entries2, fs) {
|
|
24448
24614
|
const seen = /* @__PURE__ */ new Set();
|
|
24449
|
-
const queue =
|
|
24615
|
+
const queue = entries2.map((rel) => ({ rel, depth: 0 }));
|
|
24450
24616
|
const analysis = { secret: null, send: null };
|
|
24451
24617
|
const files = [];
|
|
24452
|
-
const
|
|
24618
|
+
const unreadable2 = [];
|
|
24453
24619
|
let exceeded = false;
|
|
24454
|
-
const first = new Set(
|
|
24620
|
+
const first = new Set(entries2);
|
|
24455
24621
|
while (queue.length > 0) {
|
|
24456
24622
|
const item = queue.shift();
|
|
24457
24623
|
if (seen.has(item.rel)) continue;
|
|
@@ -24462,7 +24628,7 @@ function followFiles(entries, fs) {
|
|
|
24462
24628
|
}
|
|
24463
24629
|
const text = fs.read(item.rel);
|
|
24464
24630
|
if (text === null) {
|
|
24465
|
-
|
|
24631
|
+
unreadable2.push(item.rel);
|
|
24466
24632
|
continue;
|
|
24467
24633
|
}
|
|
24468
24634
|
files.push(item.rel);
|
|
@@ -24479,7 +24645,7 @@ function followFiles(entries, fs) {
|
|
|
24479
24645
|
if (hit) queue.push({ rel: hit, depth: item.depth + 1 });
|
|
24480
24646
|
}
|
|
24481
24647
|
}
|
|
24482
|
-
return { analysis, files, exceeded, unreadable };
|
|
24648
|
+
return { analysis, files, exceeded, unreadable: unreadable2 };
|
|
24483
24649
|
}
|
|
24484
24650
|
|
|
24485
24651
|
// ../core/src/lifecycle-scripts.ts
|
|
@@ -24744,25 +24910,25 @@ function hitBase(pkgText, name, scripts) {
|
|
|
24744
24910
|
}
|
|
24745
24911
|
var INCOMPLETE = { line: 1, label: "more local files than can be followed" };
|
|
24746
24912
|
function evaluateTargets(targets, fs, failClosed) {
|
|
24747
|
-
const
|
|
24913
|
+
const entries2 = [];
|
|
24748
24914
|
let exceeded = false;
|
|
24749
24915
|
for (const rel of [...new Set(targets.files)]) {
|
|
24750
24916
|
const c = scriptCandidates(rel).find((x) => fs.read(x) !== null);
|
|
24751
|
-
if (c !== void 0)
|
|
24917
|
+
if (c !== void 0) entries2.push(c);
|
|
24752
24918
|
else if (fs.list?.(rel.replace(/\/$/, "")) != null) {
|
|
24753
24919
|
const w = [];
|
|
24754
24920
|
const b = { entries: 0, exceeded: false };
|
|
24755
24921
|
walk(fs, rel.replace(/\/$/, ""), (f) => SCRIPT_FILE.test(f), b, w);
|
|
24756
|
-
|
|
24922
|
+
entries2.push(...w);
|
|
24757
24923
|
exceeded = exceeded || b.exceeded;
|
|
24758
24924
|
}
|
|
24759
24925
|
}
|
|
24760
24926
|
for (const r of targets.runners) {
|
|
24761
24927
|
const rf = runnerFiles(r, fs);
|
|
24762
|
-
|
|
24928
|
+
entries2.push(...rf.files);
|
|
24763
24929
|
exceeded = exceeded || rf.exceeded;
|
|
24764
24930
|
}
|
|
24765
|
-
const followed = followFiles([...new Set(
|
|
24931
|
+
const followed = followFiles([...new Set(entries2)], fs);
|
|
24766
24932
|
exceeded = exceeded || followed.exceeded;
|
|
24767
24933
|
let secret = followed.analysis.secret;
|
|
24768
24934
|
const send = followed.analysis.send;
|
|
@@ -25313,29 +25479,29 @@ function parseMcpConfig(rel, role, text) {
|
|
|
25313
25479
|
const top = Obj.safeParse(parseJsonLoose2(text));
|
|
25314
25480
|
if (!top.success) return null;
|
|
25315
25481
|
const doc = top.data;
|
|
25316
|
-
const
|
|
25482
|
+
const entries2 = [];
|
|
25317
25483
|
let hasServersKey = false;
|
|
25318
25484
|
for (const key of role === "mcp-config" ? ["mcpServers", "servers"] : ["mcpServers"]) {
|
|
25319
25485
|
const s = Obj.safeParse(doc[key]);
|
|
25320
25486
|
if (!s.success) continue;
|
|
25321
25487
|
hasServersKey = true;
|
|
25322
|
-
|
|
25488
|
+
entries2.push(...serverEntries(s.data));
|
|
25323
25489
|
}
|
|
25324
|
-
if (role === "config" &&
|
|
25490
|
+
if (role === "config" && entries2.length === 0) return null;
|
|
25325
25491
|
const perms = Obj.safeParse(doc["permissions"]);
|
|
25326
25492
|
const allow = role === "mcp-config" && perms.success ? strings2(perms.data["allow"]) : [];
|
|
25327
25493
|
for (const a of allow) {
|
|
25328
25494
|
const m = /^mcp__([^_](?:[^_]|_(?!_))*)(?:__(.+))?$/.exec(a);
|
|
25329
25495
|
if (m) {
|
|
25330
|
-
const server =
|
|
25496
|
+
const server = entries2.find((e) => e.kind === "server" && e.name === m[1]);
|
|
25331
25497
|
server?.autoApprove.push(m[2] && m[2] !== "*" ? m[2] : "*");
|
|
25332
25498
|
continue;
|
|
25333
25499
|
}
|
|
25334
|
-
if (
|
|
25335
|
-
|
|
25500
|
+
if (entries2.some((e) => e.kind === "ability" && e.name === a)) continue;
|
|
25501
|
+
entries2.push({ name: a, kind: "ability", ability: a, disabled: false, autoApprove: ["*"] });
|
|
25336
25502
|
}
|
|
25337
|
-
if (!hasServersKey &&
|
|
25338
|
-
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"]) };
|
|
25339
25505
|
}
|
|
25340
25506
|
var PinsSchema = external_exports.object({
|
|
25341
25507
|
servers: external_exports.record(external_exports.object({
|
|
@@ -25781,7 +25947,7 @@ async function* scanRepo(root, options) {
|
|
|
25781
25947
|
init_zod();
|
|
25782
25948
|
|
|
25783
25949
|
// ../core/src/version.ts
|
|
25784
|
-
var SCANNER_VERSION = "0.3.
|
|
25950
|
+
var SCANNER_VERSION = "0.3.8";
|
|
25785
25951
|
|
|
25786
25952
|
// ../core/src/reporters/json-reporter.ts
|
|
25787
25953
|
var ScanStatsSchema = external_exports.object({
|
|
@@ -25794,7 +25960,7 @@ var FindingSchema = external_exports.object({
|
|
|
25794
25960
|
source: external_exports.enum(["signature", "heuristic"]),
|
|
25795
25961
|
ruleId: external_exports.string(),
|
|
25796
25962
|
title: external_exports.string(),
|
|
25797
|
-
severity: external_exports.enum(["critical", "high", "medium", "low"]),
|
|
25963
|
+
severity: external_exports.enum(["critical", "high", "medium", "low", "info"]),
|
|
25798
25964
|
file: external_exports.string(),
|
|
25799
25965
|
// The file name with bidi, zero-width and control characters shown as [U+XXXX] (m18-scanner SC-19).
|
|
25800
25966
|
fileDisplay: external_exports.string().optional(),
|
|
@@ -26106,6 +26272,10 @@ var ENTRIES = {
|
|
|
26106
26272
|
"EX-074": {
|
|
26107
26273
|
headline: "This settings file makes Copilot approve every tool call",
|
|
26108
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."
|
|
26109
26279
|
}
|
|
26110
26280
|
};
|
|
26111
26281
|
function plainFor(ruleId, fallbackTitle) {
|
|
@@ -26121,7 +26291,7 @@ function plural(n, one, many = `${one}s`) {
|
|
|
26121
26291
|
}
|
|
26122
26292
|
|
|
26123
26293
|
// ../core/src/verdict.ts
|
|
26124
|
-
var RANK = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
26294
|
+
var RANK = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
26125
26295
|
function verdictFor(level) {
|
|
26126
26296
|
if (level === "clean") return { word: "CLEAN", line: "Nothing here tries to give your AI agent orders." };
|
|
26127
26297
|
if (level === "critical" || level === "high") return { word: "POSSESSED", line: "Your AI agent would read these as orders. Fix them first." };
|
|
@@ -26139,7 +26309,7 @@ function verdictForFindings(findings) {
|
|
|
26139
26309
|
}
|
|
26140
26310
|
|
|
26141
26311
|
// ../core/src/reporters/markdown-reporter.ts
|
|
26142
|
-
var ORDER = ["critical", "high", "medium", "low"];
|
|
26312
|
+
var ORDER = ["critical", "high", "medium", "low", "info"];
|
|
26143
26313
|
function cell(s) {
|
|
26144
26314
|
return s.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
26145
26315
|
}
|
|
@@ -26174,13 +26344,14 @@ function toMarkdown(findings, stats, limit = 50) {
|
|
|
26174
26344
|
}
|
|
26175
26345
|
|
|
26176
26346
|
// ../core/src/reporters/badge.ts
|
|
26177
|
-
var ORDER2 = ["critical", "high", "medium", "low"];
|
|
26347
|
+
var ORDER2 = ["critical", "high", "medium", "low", "info"];
|
|
26178
26348
|
var COLORS = {
|
|
26179
26349
|
clean: "#2e9e5b",
|
|
26180
26350
|
critical: "#b0123b",
|
|
26181
26351
|
high: "#c2410c",
|
|
26182
26352
|
medium: "#8a6d00",
|
|
26183
|
-
low: "#2563a8"
|
|
26353
|
+
low: "#2563a8",
|
|
26354
|
+
info: "#5b6472"
|
|
26184
26355
|
};
|
|
26185
26356
|
function badgeStatus(findings) {
|
|
26186
26357
|
const worst = ORDER2.find((s) => findings.some((f) => f.severity === s)) ?? "clean";
|
|
@@ -26764,10 +26935,10 @@ function hiddenChanges(lines, removed) {
|
|
|
26764
26935
|
if (!first) return;
|
|
26765
26936
|
const { line, col } = lines.position(first.offset);
|
|
26766
26937
|
const names = [...new Set(run3.map((h) => cpName(h.codePoint)))];
|
|
26767
|
-
const
|
|
26938
|
+
const list3 = names.length > 4 ? `${names.slice(0, 4).join(" ")} ...` : names.join(" ");
|
|
26768
26939
|
const ruleId = ruleOfClass(first.class);
|
|
26769
26940
|
const what = ruleId === "EX-021" ? "variation selector" : "hidden character";
|
|
26770
|
-
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})` });
|
|
26771
26942
|
run3 = [];
|
|
26772
26943
|
};
|
|
26773
26944
|
for (const h of removed) {
|
|
@@ -27060,13 +27231,13 @@ async function exorciseRepo(root, findings, opts = {}) {
|
|
|
27060
27231
|
const byFile = /* @__PURE__ */ new Map();
|
|
27061
27232
|
for (const f of findings) {
|
|
27062
27233
|
if (f.source !== "signature" || !isFixableRule(f.ruleId) || !only.has(f.ruleId)) continue;
|
|
27063
|
-
const
|
|
27064
|
-
|
|
27065
|
-
byFile.set(f.file,
|
|
27234
|
+
const list3 = byFile.get(f.file) ?? [];
|
|
27235
|
+
list3.push(f);
|
|
27236
|
+
byFile.set(f.file, list3);
|
|
27066
27237
|
}
|
|
27067
27238
|
const inputs = [];
|
|
27068
27239
|
const notUtf8 = [];
|
|
27069
|
-
for (const [file,
|
|
27240
|
+
for (const [file, list3] of [...byFile.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
27070
27241
|
let bytes;
|
|
27071
27242
|
try {
|
|
27072
27243
|
bytes = await readFile4(join10(root, file));
|
|
@@ -27075,13 +27246,13 @@ async function exorciseRepo(root, findings, opts = {}) {
|
|
|
27075
27246
|
}
|
|
27076
27247
|
const text = bytes.toString("utf8");
|
|
27077
27248
|
if (!Buffer.from(text, "utf8").equals(bytes)) {
|
|
27078
|
-
const first =
|
|
27249
|
+
const first = list3[0];
|
|
27079
27250
|
if (first && isFixableRule(first.ruleId)) {
|
|
27080
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" }] });
|
|
27081
27252
|
}
|
|
27082
27253
|
continue;
|
|
27083
27254
|
}
|
|
27084
|
-
inputs.push({ file, text, findings:
|
|
27255
|
+
inputs.push({ file, text, findings: list3 });
|
|
27085
27256
|
}
|
|
27086
27257
|
return [...await exorciseTexts(inputs, opts), ...notUtf8].sort((a, b) => a.file.localeCompare(b.file));
|
|
27087
27258
|
}
|
|
@@ -27116,8 +27287,8 @@ ${body}`;
|
|
|
27116
27287
|
}
|
|
27117
27288
|
return { patch: parts2.join(""), files, fixes, omitted, unsafe };
|
|
27118
27289
|
}
|
|
27119
|
-
function rescanTexts(
|
|
27120
|
-
return deduplicate(
|
|
27290
|
+
function rescanTexts(entries2, defs) {
|
|
27291
|
+
return deduplicate(entries2.flatMap((e) => {
|
|
27121
27292
|
const role = classifyFile(e.file);
|
|
27122
27293
|
return runSignatures({ path: e.file, rel: e.file, role, sizeBytes: Buffer.byteLength(e.text, "utf8") }, normalize(e.text, role), defs);
|
|
27123
27294
|
}));
|
|
@@ -27167,7 +27338,7 @@ function stripComment(s) {
|
|
|
27167
27338
|
var SECTION = /^\[\s*([A-Za-z0-9.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?\s*\]/;
|
|
27168
27339
|
var KEY = /^([A-Za-z][A-Za-z0-9-]*)\s*(?:=(.*))?$/;
|
|
27169
27340
|
function parseGitConfig(text) {
|
|
27170
|
-
const
|
|
27341
|
+
const entries2 = [];
|
|
27171
27342
|
let section = "";
|
|
27172
27343
|
let subsection = null;
|
|
27173
27344
|
let current = null;
|
|
@@ -27207,10 +27378,10 @@ function parseGitConfig(text) {
|
|
|
27207
27378
|
const kv = KEY.exec(line);
|
|
27208
27379
|
if (!kv) return { ok: false, line: n + 1 };
|
|
27209
27380
|
current = { section, subsection, key: (kv[1] ?? "").toLowerCase(), value: kv[2] === void 0 ? "true" : kv[2].trim() };
|
|
27210
|
-
|
|
27381
|
+
entries2.push(current);
|
|
27211
27382
|
continuing = continues;
|
|
27212
27383
|
}
|
|
27213
|
-
return { ok: true, entries };
|
|
27384
|
+
return { ok: true, entries: entries2 };
|
|
27214
27385
|
}
|
|
27215
27386
|
var FALSE_VALUES = /* @__PURE__ */ new Set(["false", "no", "off", "0", ""]);
|
|
27216
27387
|
function dangerousKey(e) {
|
|
@@ -27603,7 +27774,7 @@ async function findOriginCommit(repoRoot, relFile, line, span, opts = {}) {
|
|
|
27603
27774
|
}
|
|
27604
27775
|
async function traceOrigins(repoRoot, queries, opts = {}) {
|
|
27605
27776
|
const deadline = Date.now() + (opts.totalMs ?? ORIGIN_TOTAL_TIMEOUT_MS);
|
|
27606
|
-
const
|
|
27777
|
+
const cache4 = /* @__PURE__ */ new Map();
|
|
27607
27778
|
const seen = /* @__PURE__ */ new Map();
|
|
27608
27779
|
const out = [];
|
|
27609
27780
|
for (const q of queries) {
|
|
@@ -27613,7 +27784,7 @@ async function traceOrigins(repoRoot, queries, opts = {}) {
|
|
|
27613
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, {
|
|
27614
27785
|
timeoutMs: opts.perFindingMs ?? ORIGIN_TIMEOUT_MS,
|
|
27615
27786
|
deadline,
|
|
27616
|
-
cache:
|
|
27787
|
+
cache: cache4,
|
|
27617
27788
|
...opts.boundaries ? { boundaries: opts.boundaries } : {}
|
|
27618
27789
|
});
|
|
27619
27790
|
seen.set(key, hit);
|
|
@@ -27625,7 +27796,7 @@ async function traceOrigins(repoRoot, queries, opts = {}) {
|
|
|
27625
27796
|
var OriginStatusSchema = external_exports.enum(["log-s", "blame", "uncommitted", "not-found", "timeout", "error"]);
|
|
27626
27797
|
var TimelineThreatSchema = external_exports.object({
|
|
27627
27798
|
ruleId: external_exports.string(),
|
|
27628
|
-
severity: external_exports.enum(["critical", "high", "medium", "low"]),
|
|
27799
|
+
severity: external_exports.enum(["critical", "high", "medium", "low", "info"]),
|
|
27629
27800
|
file: external_exports.string(),
|
|
27630
27801
|
line: external_exports.number().int().positive(),
|
|
27631
27802
|
title: external_exports.string(),
|
|
@@ -27902,21 +28073,21 @@ function addAllowedRead(cwd, file, env = process.env, expected) {
|
|
|
27902
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." };
|
|
27903
28074
|
const loc = allowedReadsLocation(cwd, env);
|
|
27904
28075
|
if (!loc.ok) return loc;
|
|
27905
|
-
let
|
|
28076
|
+
let entries2 = [];
|
|
27906
28077
|
if (existsSync4(loc.file)) {
|
|
27907
28078
|
try {
|
|
27908
28079
|
const parsed = AllowedReadsSchema.safeParse(JSON.parse(readFileSync7(loc.file, "utf8")));
|
|
27909
|
-
if (parsed.success && parsed.data.project === loc.project)
|
|
28080
|
+
if (parsed.success && parsed.data.project === loc.project) entries2 = parsed.data.entries;
|
|
27910
28081
|
} catch {
|
|
27911
28082
|
}
|
|
27912
28083
|
}
|
|
27913
|
-
|
|
28084
|
+
entries2 = [...entries2.filter((e) => e.path !== abs), { path: abs, sha256: hash }];
|
|
27914
28085
|
mkdirSync(dirname5(loc.file), { recursive: true });
|
|
27915
28086
|
const tmp = `${loc.file}.tmp-${process.pid}`;
|
|
27916
|
-
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)}
|
|
27917
28088
|
`, "utf8");
|
|
27918
28089
|
renameSync(tmp, loc.file);
|
|
27919
|
-
return { ok: true, hash, path: abs, store: loc.file, count:
|
|
28090
|
+
return { ok: true, hash, path: abs, store: loc.file, count: entries2.length };
|
|
27920
28091
|
}
|
|
27921
28092
|
|
|
27922
28093
|
// ../core/src/fs-expand.ts
|
|
@@ -27968,7 +28139,7 @@ function segmentRe(seg) {
|
|
|
27968
28139
|
}
|
|
27969
28140
|
function expandGlob(word, dir) {
|
|
27970
28141
|
const out = [];
|
|
27971
|
-
const
|
|
28142
|
+
const cap4 = MAX_TARGETS + 1;
|
|
27972
28143
|
for (const alt of braceExpand(word)) {
|
|
27973
28144
|
const abs = isAbsolute9(alt);
|
|
27974
28145
|
const segs = alt.split("/").filter((s, i) => s !== "" || i === 0);
|
|
@@ -28001,31 +28172,31 @@ function expandGlob(word, dir) {
|
|
|
28001
28172
|
for (const p of level) {
|
|
28002
28173
|
if (!existsSync5(p)) continue;
|
|
28003
28174
|
out.push(p);
|
|
28004
|
-
if (out.length >=
|
|
28175
|
+
if (out.length >= cap4) return out;
|
|
28005
28176
|
}
|
|
28006
28177
|
}
|
|
28007
28178
|
return out;
|
|
28008
28179
|
}
|
|
28009
28180
|
var SKIP_WALK = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
28010
|
-
function walkFiles(root,
|
|
28181
|
+
function walkFiles(root, cap4) {
|
|
28011
28182
|
const files = [];
|
|
28012
28183
|
const stack = [root];
|
|
28013
28184
|
let visited = 0;
|
|
28014
28185
|
while (stack.length > 0) {
|
|
28015
28186
|
const d = stack.pop();
|
|
28016
28187
|
if (visited++ > 5e3) return { files, exceeded: true };
|
|
28017
|
-
let
|
|
28188
|
+
let entries2;
|
|
28018
28189
|
try {
|
|
28019
|
-
|
|
28190
|
+
entries2 = readdirSync2(d, { withFileTypes: true });
|
|
28020
28191
|
} catch {
|
|
28021
28192
|
continue;
|
|
28022
28193
|
}
|
|
28023
|
-
for (const e of
|
|
28194
|
+
for (const e of entries2.sort((a, b) => a.name < b.name ? 1 : -1)) {
|
|
28024
28195
|
if (e.isDirectory()) {
|
|
28025
28196
|
if (!SKIP_WALK.has(e.name)) stack.push(resolve11(d, e.name));
|
|
28026
28197
|
} else if (e.isFile() || e.isSymbolicLink()) {
|
|
28027
28198
|
files.push(resolve11(d, e.name));
|
|
28028
|
-
if (files.length >
|
|
28199
|
+
if (files.length > cap4) return { files, exceeded: true };
|
|
28029
28200
|
}
|
|
28030
28201
|
}
|
|
28031
28202
|
}
|
|
@@ -28258,11 +28429,11 @@ var isLockfile = (label) => LOCKFILE_NAMES2.has(label.split(/[\\/]/).pop() ?? ""
|
|
|
28258
28429
|
function mustCheckFully(label, role) {
|
|
28259
28430
|
return AGENT_FACING.has(role) && !(role === "config" && isLockfile(label));
|
|
28260
28431
|
}
|
|
28261
|
-
function limitFor(remainingMs, jobs,
|
|
28432
|
+
function limitFor(remainingMs, jobs, cap4) {
|
|
28262
28433
|
const byThirds = remainingMs / (1 + jobs / 3);
|
|
28263
28434
|
const byFloor = remainingMs - 50 * jobs;
|
|
28264
28435
|
const bound = Math.floor(byThirds >= 150 ? byThirds : byFloor);
|
|
28265
|
-
return bound >= 50 ? Math.min(
|
|
28436
|
+
return bound >= 50 ? Math.min(cap4, bound) : null;
|
|
28266
28437
|
}
|
|
28267
28438
|
function regexJobs(defs, role) {
|
|
28268
28439
|
return 2 * defs.filter((d) => d.enabled !== false && d.applies_to.includes(role) && d.match.regex).length;
|
|
@@ -28406,7 +28577,7 @@ function timedOutSerious(f, defs) {
|
|
|
28406
28577
|
return sev === "critical" || sev === "high";
|
|
28407
28578
|
}
|
|
28408
28579
|
function severityRank(s) {
|
|
28409
|
-
return { critical: 0, high: 1, medium: 2, low: 3 }[s];
|
|
28580
|
+
return { critical: 0, high: 1, medium: 2, low: 3, info: 4 }[s];
|
|
28410
28581
|
}
|
|
28411
28582
|
function decideRead(event, defs, opts = {}) {
|
|
28412
28583
|
let parsed = event;
|
|
@@ -28448,7 +28619,7 @@ function decideRead(event, defs, opts = {}) {
|
|
|
28448
28619
|
const blocked2 = /* @__PURE__ */ new Map();
|
|
28449
28620
|
const warned2 = /* @__PURE__ */ new Map();
|
|
28450
28621
|
const notes = [];
|
|
28451
|
-
const
|
|
28622
|
+
const tooLarge2 = /* @__PURE__ */ new Set();
|
|
28452
28623
|
const unchecked = /* @__PURE__ */ new Map();
|
|
28453
28624
|
const deadline = Date.now() + (opts.budgetMs ?? DECIDE_BUDGET_MS);
|
|
28454
28625
|
const outOfTime = (label, role) => {
|
|
@@ -28465,13 +28636,13 @@ function decideRead(event, defs, opts = {}) {
|
|
|
28465
28636
|
if (stat4.size > MAX_SCAN_BYTES) {
|
|
28466
28637
|
const big = relLabel(abs, cwd);
|
|
28467
28638
|
if (rolesOf(abs, cwd).classes.some((r) => mustCheckFully(big, r))) {
|
|
28468
|
-
|
|
28639
|
+
tooLarge2.add(abs);
|
|
28469
28640
|
} else {
|
|
28470
28641
|
notes.push(`Exorcist 98 warning: ${shownName(big)} is larger than 10 MB, so it was not scanned. It was allowed.`);
|
|
28471
28642
|
continue;
|
|
28472
28643
|
}
|
|
28473
28644
|
}
|
|
28474
|
-
if (
|
|
28645
|
+
if (tooLarge2.has(abs)) {
|
|
28475
28646
|
if (opts.allowed && opts.allowed.has(allowKey(realPath(abs), sha256FileChunked(abs)))) continue;
|
|
28476
28647
|
unchecked.set(relLabel(abs, cwd), "it is larger than 10 MB, too large to check");
|
|
28477
28648
|
continue;
|
|
@@ -28485,9 +28656,9 @@ function decideRead(event, defs, opts = {}) {
|
|
|
28485
28656
|
const label = relLabel(abs, cwd);
|
|
28486
28657
|
const { classes, scan: scan2 } = rolesOf(abs, cwd);
|
|
28487
28658
|
const role = classes.find((r) => mustCheckFully(label, r)) ?? (classes[0] ?? "unknown");
|
|
28488
|
-
const
|
|
28659
|
+
const cap4 = opts.limitMs ?? REGEX_TIME_LIMIT_MS * Math.max(1, Math.ceil(text.length / 1048576));
|
|
28489
28660
|
const jobs = scan2.reduce((n, r) => n + regexJobs(defs, r), 0);
|
|
28490
|
-
const limit = limitFor(deadline - Date.now(), jobs,
|
|
28661
|
+
const limit = limitFor(deadline - Date.now(), jobs, cap4);
|
|
28491
28662
|
if (limit === null) {
|
|
28492
28663
|
outOfTime(label, role);
|
|
28493
28664
|
continue;
|
|
@@ -29567,13 +29738,13 @@ function envFiles(root) {
|
|
|
29567
29738
|
let visited = 0;
|
|
29568
29739
|
while (stack.length > 0 && visited < MAX_ENTRIES) {
|
|
29569
29740
|
const { dir, depth } = stack.pop();
|
|
29570
|
-
let
|
|
29741
|
+
let entries2;
|
|
29571
29742
|
try {
|
|
29572
|
-
|
|
29743
|
+
entries2 = readdirSync4(dir, { withFileTypes: true });
|
|
29573
29744
|
} catch {
|
|
29574
29745
|
continue;
|
|
29575
29746
|
}
|
|
29576
|
-
for (const e of
|
|
29747
|
+
for (const e of entries2.sort((a, b) => a.name < b.name ? -1 : 1)) {
|
|
29577
29748
|
if (visited++ >= MAX_ENTRIES) break;
|
|
29578
29749
|
const path = join17(dir, e.name);
|
|
29579
29750
|
if (e.isDirectory()) {
|
|
@@ -29624,7 +29795,7 @@ function loadEnvKeys(cwd) {
|
|
|
29624
29795
|
|
|
29625
29796
|
// ../core/src/gate.ts
|
|
29626
29797
|
init_walker();
|
|
29627
|
-
var RANK2 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
29798
|
+
var RANK2 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
29628
29799
|
var SCANNED_ROLES = /* @__PURE__ */ new Set(["instruction", "memory", "hook", "mcp-config", "power"]);
|
|
29629
29800
|
var norm2 = (rel) => rel.replace(/\\/g, "/");
|
|
29630
29801
|
var baseName2 = (rel) => norm2(rel).split("/").pop() ?? "";
|
|
@@ -29786,7 +29957,7 @@ function readBundleTar(tar) {
|
|
|
29786
29957
|
if (tar.length > DOWNLOAD_LIMIT_BYTES) return fail2(`The bundle is larger than the ${DOWNLOAD_LIMIT_BYTES / 1048576} MB limit.`);
|
|
29787
29958
|
if (tar.length === 0) return fail2("The bundle is empty.");
|
|
29788
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).");
|
|
29789
|
-
const
|
|
29960
|
+
const entries2 = [];
|
|
29790
29961
|
const seen = /* @__PURE__ */ new Set();
|
|
29791
29962
|
for (let off = 0; ; ) {
|
|
29792
29963
|
if (off + BLOCK > tar.length) return fail2("The bundle is truncated (no end-of-archive marker).");
|
|
@@ -29818,11 +29989,11 @@ function readBundleTar(tar) {
|
|
|
29818
29989
|
if (size > MAX_FILE_BYTES2) return fail2(`The bundle entry ${printable(path)} is larger than ${MAX_FILE_BYTES2 / 1024} KB.`);
|
|
29819
29990
|
const start = off + BLOCK;
|
|
29820
29991
|
if (start + size > tar.length) return fail2("The bundle is truncated.");
|
|
29821
|
-
|
|
29822
|
-
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.`);
|
|
29823
29994
|
off = start + Math.ceil(size / BLOCK) * BLOCK;
|
|
29824
29995
|
}
|
|
29825
|
-
return { ok: true, entries };
|
|
29996
|
+
return { ok: true, entries: entries2 };
|
|
29826
29997
|
}
|
|
29827
29998
|
function verifySignature(manifestBytes, sig, publicKeyPem) {
|
|
29828
29999
|
const key = loadPublicKey(publicKeyPem);
|
|
@@ -30189,14 +30360,14 @@ function cmp(a, b) {
|
|
|
30189
30360
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
30190
30361
|
}
|
|
30191
30362
|
function buildBaseline(findings) {
|
|
30192
|
-
const
|
|
30363
|
+
const entries2 = findings.map((f) => ({
|
|
30193
30364
|
ruleId: f.ruleId,
|
|
30194
30365
|
file: f.file,
|
|
30195
30366
|
fingerprint: fingerprintOf(f),
|
|
30196
30367
|
line: f.line
|
|
30197
30368
|
}));
|
|
30198
|
-
|
|
30199
|
-
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 };
|
|
30200
30371
|
}
|
|
30201
30372
|
function parseBaseline(text) {
|
|
30202
30373
|
let raw;
|
|
@@ -30347,14 +30518,229 @@ function repoHidingFindings(suppressed, def) {
|
|
|
30347
30518
|
}
|
|
30348
30519
|
return out;
|
|
30349
30520
|
}
|
|
30350
|
-
function ignoreFileFinding(file,
|
|
30351
|
-
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"}` };
|
|
30352
30523
|
}
|
|
30353
30524
|
|
|
30354
30525
|
// ../core/src/index.ts
|
|
30355
30526
|
init_text_decode();
|
|
30356
30527
|
init_image_text();
|
|
30357
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
|
+
|
|
30358
30744
|
// ../core/src/kiro-evidence.ts
|
|
30359
30745
|
init_zod();
|
|
30360
30746
|
var KiroEventSchema = external_exports.object({
|
|
@@ -31174,7 +31560,7 @@ function decideShellRead(event, defs, opts = {}, fallbackCwd = process.cwd()) {
|
|
|
31174
31560
|
}
|
|
31175
31561
|
|
|
31176
31562
|
// src/commands/approve.ts
|
|
31177
|
-
import { existsSync as
|
|
31563
|
+
import { existsSync as existsSync20, readFileSync as readFileSync27 } from "node:fs";
|
|
31178
31564
|
|
|
31179
31565
|
// ../shield/src/hash.ts
|
|
31180
31566
|
import { createHash as createHash7 } from "node:crypto";
|
|
@@ -31280,16 +31666,57 @@ var LineSplitter = class {
|
|
|
31280
31666
|
|
|
31281
31667
|
// ../shield/src/policy.ts
|
|
31282
31668
|
init_zod();
|
|
31283
|
-
import { existsSync as
|
|
31669
|
+
import { existsSync as existsSync10, lstatSync as lstatSync6, readFileSync as readFileSync15, writeFileSync as writeFileSync3 } from "node:fs";
|
|
31284
31670
|
import { join as join21 } from "node:path";
|
|
31285
31671
|
|
|
31286
31672
|
// ../shield/src/userkey.ts
|
|
31287
31673
|
import { createHmac, randomBytes as randomBytes3, timingSafeEqual } from "node:crypto";
|
|
31288
|
-
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";
|
|
31289
31675
|
import { homedir as homedir8 } from "node:os";
|
|
31290
|
-
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";
|
|
31291
31677
|
var KEY_FILE = "shield.key";
|
|
31292
31678
|
var IS_WINDOWS = process.platform === "win32";
|
|
31679
|
+
function userDirOverrideProblem(dir, cwd = process.cwd()) {
|
|
31680
|
+
const real = (p) => {
|
|
31681
|
+
let cur = resolve20(p);
|
|
31682
|
+
let rest = "";
|
|
31683
|
+
for (let i = 0; i < 64; i++) {
|
|
31684
|
+
try {
|
|
31685
|
+
return join20(realpathSync8.native(cur), rest);
|
|
31686
|
+
} catch {
|
|
31687
|
+
}
|
|
31688
|
+
const up = dirname9(cur);
|
|
31689
|
+
if (up === cur) break;
|
|
31690
|
+
rest = join20(basename8(cur), rest);
|
|
31691
|
+
cur = up;
|
|
31692
|
+
}
|
|
31693
|
+
return resolve20(p);
|
|
31694
|
+
};
|
|
31695
|
+
const fold2 = (p) => process.platform === "darwin" || IS_WINDOWS ? p.toLowerCase() : p;
|
|
31696
|
+
const d = fold2(real(dir));
|
|
31697
|
+
const c = fold2(real(cwd));
|
|
31698
|
+
if (d === fold2(real(join20(homedir8(), ".config", "exorcist-98")))) return null;
|
|
31699
|
+
const rel = relative13(c, d);
|
|
31700
|
+
if (rel === "" || !rel.startsWith("..") && !isAbsolute16(rel)) return "it is inside the current project folder";
|
|
31701
|
+
for (let cur = d, i = 0; i < 64; i++) {
|
|
31702
|
+
if (existsSync9(join20(cur, ".git"))) return `it is inside a git repository (${cur})`;
|
|
31703
|
+
const up = dirname9(cur);
|
|
31704
|
+
if (up === cur) break;
|
|
31705
|
+
cur = up;
|
|
31706
|
+
}
|
|
31707
|
+
let st;
|
|
31708
|
+
try {
|
|
31709
|
+
st = lstatSync5(dir);
|
|
31710
|
+
} catch {
|
|
31711
|
+
return null;
|
|
31712
|
+
}
|
|
31713
|
+
if (st.isSymbolicLink()) return "it is a symbolic link";
|
|
31714
|
+
if (!st.isDirectory()) return "it is not a folder";
|
|
31715
|
+
const me = uid();
|
|
31716
|
+
if (!IS_WINDOWS && me !== void 0 && st.uid !== me) return "it is not owned by you";
|
|
31717
|
+
if (!IS_WINDOWS && (st.mode & 63) !== 0) return "other users or your group can open it (a private folder is mode 0700)";
|
|
31718
|
+
return null;
|
|
31719
|
+
}
|
|
31293
31720
|
function userConfigDir(env = process.env) {
|
|
31294
31721
|
const o = env["EXORCIST_USER_DIR"];
|
|
31295
31722
|
if (o && isAbsolute16(o)) return o;
|
|
@@ -31297,6 +31724,14 @@ function userConfigDir(env = process.env) {
|
|
|
31297
31724
|
const base = xdg && isAbsolute16(xdg) ? xdg : join20(homedir8(), ".config");
|
|
31298
31725
|
return join20(base, "exorcist-98");
|
|
31299
31726
|
}
|
|
31727
|
+
function userDirRefusal(env = process.env, cwd = process.cwd()) {
|
|
31728
|
+
const o = env["EXORCIST_USER_DIR"];
|
|
31729
|
+
const xdg = env["XDG_CONFIG_HOME"];
|
|
31730
|
+
const overridden = o && isAbsolute16(o) || xdg && isAbsolute16(xdg);
|
|
31731
|
+
if (!overridden) return null;
|
|
31732
|
+
const problem = userDirOverrideProblem(userConfigDir(env), cwd);
|
|
31733
|
+
return problem === null ? null : `the user-level folder ${userConfigDir(env)} (set by EXORCIST_USER_DIR or XDG_CONFIG_HOME) was refused: ${problem}`;
|
|
31734
|
+
}
|
|
31300
31735
|
var uid = () => typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
31301
31736
|
function ensurePrivateDir(dir) {
|
|
31302
31737
|
try {
|
|
@@ -31339,6 +31774,10 @@ function readKeyFile(path) {
|
|
|
31339
31774
|
}
|
|
31340
31775
|
var cache2 = /* @__PURE__ */ new Map();
|
|
31341
31776
|
function getUserKey(o = {}) {
|
|
31777
|
+
if (o.dir === void 0) {
|
|
31778
|
+
const refused = userDirRefusal();
|
|
31779
|
+
if (refused !== null) return { ok: false, error: refused };
|
|
31780
|
+
}
|
|
31342
31781
|
const dir = o.dir ?? userConfigDir();
|
|
31343
31782
|
const cached2 = cache2.get(dir);
|
|
31344
31783
|
if (cached2) return { ok: true, key: cached2 };
|
|
@@ -31451,7 +31890,13 @@ var PolicySchema = external_exports.object({
|
|
|
31451
31890
|
* opt-in that only the USER-LEVEL policy can set. A project policy, signed or not,
|
|
31452
31891
|
* that asks for it is ignored with a note.
|
|
31453
31892
|
*/
|
|
31454
|
-
sessionRelease: external_exports.enum(["os", "terminal", "notification-code"]).optional()
|
|
31893
|
+
sessionRelease: external_exports.enum(["os", "terminal", "notification-code"]).optional(),
|
|
31894
|
+
/**
|
|
31895
|
+
* The event log (m19-log, LG-2). `off` stops the Shield writing events after one final event that says so.
|
|
31896
|
+
* Only the USER-LEVEL policy can set it: a project policy that sets `events` is ignored with a note, and the
|
|
31897
|
+
* environment variable EXORCIST_EVENTS is ignored (an MCP config can set a server's environment).
|
|
31898
|
+
*/
|
|
31899
|
+
events: external_exports.enum(["on", "off"]).optional()
|
|
31455
31900
|
}).strict();
|
|
31456
31901
|
var policySigPath = (policyFile) => policyFile.replace(/\.json$/, "") + ".sig";
|
|
31457
31902
|
var POLICY_DOMAIN = "exorcist-98:policy:v1";
|
|
@@ -31521,6 +31966,11 @@ function parsePolicyText(path, text) {
|
|
|
31521
31966
|
return { ok: true, raw: json2 };
|
|
31522
31967
|
}
|
|
31523
31968
|
function loadUserPolicy(notes) {
|
|
31969
|
+
const refused = userDirRefusal();
|
|
31970
|
+
if (refused !== null) {
|
|
31971
|
+
notes.push(`${refused}, so no user-level policy was read and the defaults apply.`);
|
|
31972
|
+
return { ok: true, raw: {} };
|
|
31973
|
+
}
|
|
31524
31974
|
const file = join21(userConfigDir(), "policy.json");
|
|
31525
31975
|
let st;
|
|
31526
31976
|
try {
|
|
@@ -31541,7 +31991,7 @@ function loadPolicy(path) {
|
|
|
31541
31991
|
const user = loadUserPolicy(notes);
|
|
31542
31992
|
if (!user.ok) return user;
|
|
31543
31993
|
let merged = { ...user.raw };
|
|
31544
|
-
if (
|
|
31994
|
+
if (existsSync10(path)) {
|
|
31545
31995
|
let text;
|
|
31546
31996
|
try {
|
|
31547
31997
|
text = readFileSync15(path, "utf8");
|
|
@@ -31554,6 +32004,10 @@ function loadPolicy(path) {
|
|
|
31554
32004
|
delete project.raw["sessionRelease"];
|
|
31555
32005
|
notes.push(`Ignored "sessionRelease": "notification-code" in ${path}: only your user-level policy can turn on release by a code in a desktop notification, because the notification database can be read by any program of your user.`);
|
|
31556
32006
|
}
|
|
32007
|
+
if (project.raw["events"] !== void 0) {
|
|
32008
|
+
delete project.raw["events"];
|
|
32009
|
+
notes.push(`Ignored "events" in ${path}: only your user-level policy can turn the event log off, so a repository cannot switch it off.`);
|
|
32010
|
+
}
|
|
31557
32011
|
if (isSigned(path, text)) {
|
|
31558
32012
|
merged = { ...merged, ...project.raw };
|
|
31559
32013
|
} else {
|
|
@@ -31781,12 +32235,13 @@ var ApprovalStore = class {
|
|
|
31781
32235
|
// ../shield/src/anchor.ts
|
|
31782
32236
|
import { createHash as createHash9 } from "node:crypto";
|
|
31783
32237
|
import { closeSync as closeSync6, constants as constants4, lstatSync as lstatSync8, openSync as openSync6, readFileSync as readFileSync17, renameSync as renameSync4, unlinkSync as unlinkSync2, writeSync as writeSync3 } from "node:fs";
|
|
31784
|
-
import { join as join23, resolve as
|
|
32238
|
+
import { join as join23, resolve as resolve21 } from "node:path";
|
|
31785
32239
|
var ANCHOR_DOMAIN = "exorcist-98:anchor:v1";
|
|
31786
|
-
var folderId = (dir) => createHash9("sha256").update(
|
|
32240
|
+
var folderId = (dir) => createHash9("sha256").update(resolve21(dir)).digest("hex").slice(0, 32);
|
|
31787
32241
|
var anchorPath = (dir, userDir = userConfigDir()) => join23(userDir, "anchors", `${folderId(dir)}.json`);
|
|
31788
|
-
var anchorText = (id, seq2, hash) => `${id}\0${seq2}\0${hash}`;
|
|
31789
|
-
|
|
32242
|
+
var anchorText = (id, seq2, hash, off) => `${id}\0${seq2}\0${hash}${off === void 0 ? "" : `\0off:${off}`}`;
|
|
32243
|
+
var isTime = (t2) => typeof t2 === "string" && t2.length <= 40 && !Number.isNaN(Date.parse(t2));
|
|
32244
|
+
function writeAnchor(dir, head, o = {}) {
|
|
31790
32245
|
const key = getUserKey({ create: true });
|
|
31791
32246
|
if (!key.ok) return `the log anchor could not be written (${key.error})`;
|
|
31792
32247
|
const userDir = userConfigDir();
|
|
@@ -31794,7 +32249,9 @@ function writeAnchor(dir, head) {
|
|
|
31794
32249
|
const problem = ensurePrivateDir(anchors);
|
|
31795
32250
|
if (problem !== null) return `the log anchor could not be written (${problem})`;
|
|
31796
32251
|
const id = folderId(dir);
|
|
31797
|
-
const
|
|
32252
|
+
const before = readAnchor(dir);
|
|
32253
|
+
const off = o.eventsOffSince ?? (before.ok ? before.anchor?.eventsOffSince : void 0);
|
|
32254
|
+
const rec = { v: 1, dir: id, seq: head.seq, hash: head.hash, mac: signText(key.key, ANCHOR_DOMAIN, anchorText(id, head.seq, head.hash, off)), ...off !== void 0 ? { eventsOffSince: off } : {} };
|
|
31798
32255
|
const path = join23(anchors, `${id}.json`);
|
|
31799
32256
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
31800
32257
|
let fd = null;
|
|
@@ -31840,11 +32297,16 @@ function readAnchor(dir) {
|
|
|
31840
32297
|
return { ok: false, error: "the anchor is damaged" };
|
|
31841
32298
|
}
|
|
31842
32299
|
const id = folderId(dir);
|
|
31843
|
-
|
|
32300
|
+
const off = raw.eventsOffSince;
|
|
32301
|
+
if (raw.v !== 1 || raw.dir !== id || typeof raw.seq !== "number" || typeof raw.hash !== "string" || off !== void 0 && !isTime(off) || !verifyText(key.key, ANCHOR_DOMAIN, anchorText(id, raw.seq, raw.hash, off), raw.mac)) {
|
|
31844
32302
|
return { ok: false, error: "the anchor was changed or was not written by this machine" };
|
|
31845
32303
|
}
|
|
31846
32304
|
return { ok: true, anchor: raw };
|
|
31847
32305
|
}
|
|
32306
|
+
function readEventsOffSince(dir) {
|
|
32307
|
+
const a = readAnchor(dir);
|
|
32308
|
+
return a.ok && a.anchor?.eventsOffSince !== void 0 ? a.anchor.eventsOffSince : null;
|
|
32309
|
+
}
|
|
31848
32310
|
function checkAnchor(dir, head, hashAt) {
|
|
31849
32311
|
const a = readAnchor(dir);
|
|
31850
32312
|
if (!a.ok) return { status: "tampered", detail: `The log anchor kept outside the state folder cannot be trusted: ${a.error}.` };
|
|
@@ -31858,17 +32320,250 @@ function checkAnchor(dir, head, hashAt) {
|
|
|
31858
32320
|
return { status: "ok", seq: seq2 };
|
|
31859
32321
|
}
|
|
31860
32322
|
|
|
32323
|
+
// ../shield/src/fs-kind.ts
|
|
32324
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
32325
|
+
import { statfsSync } from "node:fs";
|
|
32326
|
+
var NETWORK_FS_MAGIC = /* @__PURE__ */ new Set([
|
|
32327
|
+
26985,
|
|
32328
|
+
// NFS
|
|
32329
|
+
20859,
|
|
32330
|
+
// SMB
|
|
32331
|
+
4283649346,
|
|
32332
|
+
// CIFS
|
|
32333
|
+
4266872130,
|
|
32334
|
+
// SMB2
|
|
32335
|
+
1702057286,
|
|
32336
|
+
// FUSE (sshfs and others)
|
|
32337
|
+
12805120,
|
|
32338
|
+
// Ceph
|
|
32339
|
+
16914839,
|
|
32340
|
+
// 9p
|
|
32341
|
+
1397113167,
|
|
32342
|
+
// AFS
|
|
32343
|
+
1937076805,
|
|
32344
|
+
// Coda
|
|
32345
|
+
22092,
|
|
32346
|
+
// NCP
|
|
32347
|
+
198183888
|
|
32348
|
+
// Lustre
|
|
32349
|
+
]);
|
|
32350
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
32351
|
+
function isUncPath(p) {
|
|
32352
|
+
if (/^\\\\\?\\UNC\\/i.test(p)) return true;
|
|
32353
|
+
if (/^\\\\[?.]\\/.test(p)) return false;
|
|
32354
|
+
return /^\\\\[^\\]/.test(p);
|
|
32355
|
+
}
|
|
32356
|
+
function driveLetter(p) {
|
|
32357
|
+
const m = /^(?:\\\\[?.]\\)?([A-Za-z]):(?:[\\/]|$)/.exec(p);
|
|
32358
|
+
return m ? m[1].toUpperCase() : null;
|
|
32359
|
+
}
|
|
32360
|
+
function classifyDf(r) {
|
|
32361
|
+
if (r === null) return null;
|
|
32362
|
+
if (/No such file system/i.test(`${r.stdout}
|
|
32363
|
+
${r.stderr}`)) return true;
|
|
32364
|
+
if (r.status !== 0) return null;
|
|
32365
|
+
const lines = r.stdout.split("\n").filter((l) => l.trim() !== "");
|
|
32366
|
+
if (lines.length >= 2) return false;
|
|
32367
|
+
if (lines.length === 1 && /^Filesystem\b/.test(lines[0])) return true;
|
|
32368
|
+
return null;
|
|
32369
|
+
}
|
|
32370
|
+
function runDf(dir) {
|
|
32371
|
+
try {
|
|
32372
|
+
const stdout = execFileSync3("/bin/df", ["-l", dir], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
32373
|
+
return { status: 0, stdout, stderr: "" };
|
|
32374
|
+
} catch (e) {
|
|
32375
|
+
const x = e;
|
|
32376
|
+
if (typeof x.status === "number") return { status: x.status, stdout: String(x.stdout ?? ""), stderr: String(x.stderr ?? "") };
|
|
32377
|
+
return null;
|
|
32378
|
+
}
|
|
32379
|
+
}
|
|
32380
|
+
function runPowershell(letter) {
|
|
32381
|
+
try {
|
|
32382
|
+
return execFileSync3("powershell", ["-NoProfile", "-Command", `(Get-PSDrive -Name ${letter}).DisplayRoot`], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
32383
|
+
} catch {
|
|
32384
|
+
return null;
|
|
32385
|
+
}
|
|
32386
|
+
}
|
|
32387
|
+
function linux(dir, d) {
|
|
32388
|
+
try {
|
|
32389
|
+
const t2 = (d.statfs ?? ((p) => statfsSync(p)))(dir).type;
|
|
32390
|
+
const n = Number(BigInt(t2) & 0xffffffffn);
|
|
32391
|
+
return NETWORK_FS_MAGIC.has(n);
|
|
32392
|
+
} catch {
|
|
32393
|
+
return null;
|
|
32394
|
+
}
|
|
32395
|
+
}
|
|
32396
|
+
function windows(dir, d) {
|
|
32397
|
+
if (isUncPath(dir)) return true;
|
|
32398
|
+
const letter = driveLetter(dir);
|
|
32399
|
+
if (letter === null) return null;
|
|
32400
|
+
const out = (d.powershell ?? runPowershell)(letter);
|
|
32401
|
+
return out === null ? null : out.trim() !== "";
|
|
32402
|
+
}
|
|
32403
|
+
function isNetworkFs(dir, deps = {}) {
|
|
32404
|
+
const platform = deps.platform ?? process.platform;
|
|
32405
|
+
const key = `${platform}\0${dir}`;
|
|
32406
|
+
if (cache3.has(key)) return cache3.get(key) ?? null;
|
|
32407
|
+
let r;
|
|
32408
|
+
if (platform === "linux") r = linux(dir, deps);
|
|
32409
|
+
else if (platform === "darwin") r = classifyDf((deps.df ?? runDf)(dir));
|
|
32410
|
+
else if (platform === "win32") r = windows(dir, deps);
|
|
32411
|
+
else r = null;
|
|
32412
|
+
cache3.set(key, r);
|
|
32413
|
+
return r;
|
|
32414
|
+
}
|
|
32415
|
+
|
|
32416
|
+
// ../shield/src/log-location.ts
|
|
32417
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
32418
|
+
import { closeSync as closeSync7, constants as constants5, existsSync as existsSync11, lstatSync as lstatSync9, mkdirSync as mkdirSync4, openSync as openSync7, realpathSync as realpathSync9, writeSync as writeSync4 } from "node:fs";
|
|
32419
|
+
import { tmpdir as tmpdir2, userInfo } from "node:os";
|
|
32420
|
+
import { basename as basename9, dirname as dirname10, join as join24, resolve as resolve22 } from "node:path";
|
|
32421
|
+
var hook = null;
|
|
32422
|
+
var processUid = () => typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
32423
|
+
function existingAncestor(p) {
|
|
32424
|
+
let cur = resolve22(p);
|
|
32425
|
+
for (let i = 0; i < 64 && !existsSync11(cur); i++) {
|
|
32426
|
+
const up = dirname10(cur);
|
|
32427
|
+
if (up === cur) break;
|
|
32428
|
+
cur = up;
|
|
32429
|
+
}
|
|
32430
|
+
return cur;
|
|
32431
|
+
}
|
|
32432
|
+
function realPathOf(p) {
|
|
32433
|
+
const abs = resolve22(p);
|
|
32434
|
+
const anc = existingAncestor(abs);
|
|
32435
|
+
let real = anc;
|
|
32436
|
+
try {
|
|
32437
|
+
real = realpathSync9(anc);
|
|
32438
|
+
} catch {
|
|
32439
|
+
}
|
|
32440
|
+
return anc === abs ? real : join24(real, abs.slice(anc.length));
|
|
32441
|
+
}
|
|
32442
|
+
function basesFor(platform, d) {
|
|
32443
|
+
if (d.base !== void 0) return [d.base];
|
|
32444
|
+
const env = d.env ?? process.env;
|
|
32445
|
+
if (platform === "win32") {
|
|
32446
|
+
const la = env["LOCALAPPDATA"];
|
|
32447
|
+
return la !== void 0 && la !== "" ? [la] : [];
|
|
32448
|
+
}
|
|
32449
|
+
if (platform === "darwin") return [tmpdir2()];
|
|
32450
|
+
const run3 = env["XDG_RUNTIME_DIR"];
|
|
32451
|
+
const shared = d.sharedBase ?? "/var/tmp";
|
|
32452
|
+
return run3 !== void 0 && run3.startsWith("/") ? [shared, run3] : [shared];
|
|
32453
|
+
}
|
|
32454
|
+
function userLabel(uid2) {
|
|
32455
|
+
if (uid2 !== void 0) return String(uid2);
|
|
32456
|
+
let name = "user";
|
|
32457
|
+
try {
|
|
32458
|
+
name = userInfo().username;
|
|
32459
|
+
} catch {
|
|
32460
|
+
}
|
|
32461
|
+
return name.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 32) || "user";
|
|
32462
|
+
}
|
|
32463
|
+
function problemWith(dir, uid2, windows2) {
|
|
32464
|
+
let st;
|
|
32465
|
+
try {
|
|
32466
|
+
st = lstatSync9(dir);
|
|
32467
|
+
} catch {
|
|
32468
|
+
return `${dir} could not be inspected`;
|
|
32469
|
+
}
|
|
32470
|
+
if (st.isSymbolicLink()) return `${dir} is a symbolic link`;
|
|
32471
|
+
if (!st.isDirectory()) return `${dir} is not a folder`;
|
|
32472
|
+
if (!windows2 && uid2 !== void 0 && st.uid !== uid2) return `${dir} is not owned by this user`;
|
|
32473
|
+
if (!windows2 && (st.mode & 18) !== 0) return `${dir} can be changed by other users`;
|
|
32474
|
+
return null;
|
|
32475
|
+
}
|
|
32476
|
+
function resolveLogLocation(stateDir2, o = {}) {
|
|
32477
|
+
const d = { ...hook ?? {}, ...o };
|
|
32478
|
+
const platform = d.platform ?? process.platform;
|
|
32479
|
+
const probe = d.isNetworkFs ?? ((p) => isNetworkFs(p));
|
|
32480
|
+
const kind = probe(existingAncestor(stateDir2));
|
|
32481
|
+
if (kind === false) return { ok: true, dir: stateDir2, moved: false };
|
|
32482
|
+
const bases = basesFor(platform, d);
|
|
32483
|
+
if (bases.length === 0) return { ok: false, error: "the state folder is on a network drive (or its kind is unknown) and there is no local folder for the event log (LOCALAPPDATA is not set)" };
|
|
32484
|
+
const windows2 = platform === "win32";
|
|
32485
|
+
const uid2 = d.uid ?? processUid();
|
|
32486
|
+
const leaf = `events-${createHash10("sha256").update(realPathOf(stateDir2)).digest("hex").slice(0, 16)}`;
|
|
32487
|
+
let dir = null;
|
|
32488
|
+
let refused = "";
|
|
32489
|
+
for (const base of bases) {
|
|
32490
|
+
const parent = join24(base, `exorcist-98-${userLabel(uid2)}`);
|
|
32491
|
+
const candidate = join24(parent, leaf);
|
|
32492
|
+
if (lstatSyncOrNull(candidate) !== null && checkChain([parent, candidate], uid2, windows2, false) === null) {
|
|
32493
|
+
dir = candidate;
|
|
32494
|
+
break;
|
|
32495
|
+
}
|
|
32496
|
+
}
|
|
32497
|
+
if (dir === null) for (const base of bases) {
|
|
32498
|
+
const parent = join24(base, `exorcist-98-${userLabel(uid2)}`);
|
|
32499
|
+
const candidate = join24(parent, leaf);
|
|
32500
|
+
const bad = checkChain([parent, candidate], uid2, windows2, o.create === true);
|
|
32501
|
+
if (bad === null) {
|
|
32502
|
+
dir = candidate;
|
|
32503
|
+
break;
|
|
32504
|
+
}
|
|
32505
|
+
refused = bad;
|
|
32506
|
+
}
|
|
32507
|
+
if (dir === null) return { ok: false, error: `the local event log folder was refused: ${refused}` };
|
|
32508
|
+
const reason = kind === null ? "the kind of file system of the state folder could not be told, so it is treated as a network drive" : "the state folder is on a network drive, where appending to a file and lock files are not reliable";
|
|
32509
|
+
return { ok: true, dir, moved: true, reason };
|
|
32510
|
+
}
|
|
32511
|
+
function checkChain(paths2, uid2, windows2, create) {
|
|
32512
|
+
for (const p of paths2) {
|
|
32513
|
+
if (lstatSyncOrNull(p) === null) {
|
|
32514
|
+
if (!create) return null;
|
|
32515
|
+
try {
|
|
32516
|
+
mkdirSync4(p, { recursive: true, mode: 448 });
|
|
32517
|
+
} catch (e) {
|
|
32518
|
+
if (e.code !== "EEXIST") return `${p} could not be created`;
|
|
32519
|
+
}
|
|
32520
|
+
}
|
|
32521
|
+
const bad = problemWith(p, uid2, windows2);
|
|
32522
|
+
if (bad !== null) return bad;
|
|
32523
|
+
}
|
|
32524
|
+
return null;
|
|
32525
|
+
}
|
|
32526
|
+
function lstatSyncOrNull(p) {
|
|
32527
|
+
try {
|
|
32528
|
+
return lstatSync9(p);
|
|
32529
|
+
} catch {
|
|
32530
|
+
return null;
|
|
32531
|
+
}
|
|
32532
|
+
}
|
|
32533
|
+
function locationNote(loc) {
|
|
32534
|
+
return `Events are written in ${loc.dir}, not in the state folder: ${loc.reason ?? "the state folder is not local"}.`;
|
|
32535
|
+
}
|
|
32536
|
+
function writeLocationPointer(stateDir2, logDir) {
|
|
32537
|
+
const path = join24(stateDir2, "events.location");
|
|
32538
|
+
let fd = null;
|
|
32539
|
+
try {
|
|
32540
|
+
fd = openSync7(path, constants5.O_WRONLY | constants5.O_CREAT | constants5.O_TRUNC | (constants5.O_NOFOLLOW ?? 0), 384);
|
|
32541
|
+
writeSync4(fd, `${logDir}
|
|
32542
|
+
`);
|
|
32543
|
+
return null;
|
|
32544
|
+
} catch (e) {
|
|
32545
|
+
return `${basename9(path)} could not be written (${e.code ?? "error"})`;
|
|
32546
|
+
} finally {
|
|
32547
|
+
if (fd !== null) {
|
|
32548
|
+
try {
|
|
32549
|
+
closeSync7(fd);
|
|
32550
|
+
} catch {
|
|
32551
|
+
}
|
|
32552
|
+
}
|
|
32553
|
+
}
|
|
32554
|
+
}
|
|
32555
|
+
|
|
31861
32556
|
// ../shield/src/os-auth-platform.ts
|
|
31862
32557
|
import { spawn } from "node:child_process";
|
|
31863
|
-
import { accessSync, constants as
|
|
31864
|
-
import { delimiter, join as
|
|
32558
|
+
import { accessSync, constants as constants6 } from "node:fs";
|
|
32559
|
+
import { delimiter, join as join26 } from "node:path";
|
|
31865
32560
|
|
|
31866
32561
|
// ../shield/src/session.ts
|
|
31867
32562
|
init_zod();
|
|
31868
|
-
import { createHash as
|
|
32563
|
+
import { createHash as createHash11, randomBytes as randomBytes5 } from "node:crypto";
|
|
31869
32564
|
import { spawnSync } from "node:child_process";
|
|
31870
|
-
import { lstatSync as
|
|
31871
|
-
import { join as
|
|
32565
|
+
import { lstatSync as lstatSync10, mkdirSync as mkdirSync5, readFileSync as readFileSync18, readdirSync as readdirSync8, renameSync as renameSync5, rmSync as rmSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
32566
|
+
import { join as join25 } from "node:path";
|
|
31872
32567
|
var SESSION_RULE_ID = "EX-027";
|
|
31873
32568
|
var SESSION_TTL_MS = 2 * 60 * 60 * 1e3;
|
|
31874
32569
|
var MAX_FACTS = 32;
|
|
@@ -32051,14 +32746,14 @@ var TMP_RE = /\.tmp$/;
|
|
|
32051
32746
|
function code(err) {
|
|
32052
32747
|
return err && typeof err === "object" && "code" in err ? String(err.code) : "error";
|
|
32053
32748
|
}
|
|
32054
|
-
var sessionsPath = (stateDir2) =>
|
|
32749
|
+
var sessionsPath = (stateDir2) => join25(stateDir2, "sessions");
|
|
32055
32750
|
var FileSessionStore = class {
|
|
32056
32751
|
constructor(stateDir2, key, ttlMs = SESSION_TTL_MS) {
|
|
32057
32752
|
this.key = key;
|
|
32058
32753
|
this.ttlMs = ttlMs;
|
|
32059
32754
|
if (!isSessionKey(key)) throw new Error(`Invalid session key "${key}".`);
|
|
32060
32755
|
this.root = sessionsPath(stateDir2);
|
|
32061
|
-
this.dir =
|
|
32756
|
+
this.dir = join25(this.root, key);
|
|
32062
32757
|
}
|
|
32063
32758
|
dir;
|
|
32064
32759
|
root;
|
|
@@ -32080,10 +32775,10 @@ var FileSessionStore = class {
|
|
|
32080
32775
|
problems.push(`${name} in ${this.dir} is not a session record`);
|
|
32081
32776
|
continue;
|
|
32082
32777
|
}
|
|
32083
|
-
const path =
|
|
32778
|
+
const path = join25(this.dir, name);
|
|
32084
32779
|
let st;
|
|
32085
32780
|
try {
|
|
32086
|
-
st =
|
|
32781
|
+
st = lstatSync10(path);
|
|
32087
32782
|
} catch (err) {
|
|
32088
32783
|
if (code(err) !== "ENOENT") problems.push(`${name} could not be read (${code(err)})`);
|
|
32089
32784
|
continue;
|
|
@@ -32114,10 +32809,10 @@ var FileSessionStore = class {
|
|
|
32114
32809
|
return { records, problems };
|
|
32115
32810
|
}
|
|
32116
32811
|
write(record3) {
|
|
32117
|
-
const path =
|
|
32812
|
+
const path = join25(this.dir, `${record3.writer}.json`);
|
|
32118
32813
|
const tmp = `${path}.${process.pid}.${randomBytes5(4).toString("hex")}.tmp`;
|
|
32119
32814
|
try {
|
|
32120
|
-
|
|
32815
|
+
mkdirSync5(this.dir, { recursive: true, mode: 448 });
|
|
32121
32816
|
writeFileSync4(tmp, `${JSON.stringify(record3)}
|
|
32122
32817
|
`, { encoding: "utf8", mode: 384 });
|
|
32123
32818
|
renameSync5(tmp, path);
|
|
@@ -32140,8 +32835,8 @@ var FileSessionStore = class {
|
|
|
32140
32835
|
try {
|
|
32141
32836
|
for (const name of readdirSync8(this.dir)) {
|
|
32142
32837
|
if (name === `${own}.json`) continue;
|
|
32143
|
-
const p =
|
|
32144
|
-
const st =
|
|
32838
|
+
const p = join25(this.dir, name);
|
|
32839
|
+
const st = lstatSync10(p);
|
|
32145
32840
|
if (st.isFile() && old(st, TMP_RE.test(name) ? 6e4 : this.ttlMs)) unlinkSync3(p);
|
|
32146
32841
|
}
|
|
32147
32842
|
} catch {
|
|
@@ -32149,13 +32844,13 @@ var FileSessionStore = class {
|
|
|
32149
32844
|
try {
|
|
32150
32845
|
for (const name of readdirSync8(this.root).slice(0, MAX_SESSION_DIRS)) {
|
|
32151
32846
|
if (name === this.key || !KEY_RE.test(name)) continue;
|
|
32152
|
-
const p =
|
|
32153
|
-
const st =
|
|
32847
|
+
const p = join25(this.root, name);
|
|
32848
|
+
const st = lstatSync10(p);
|
|
32154
32849
|
if (!st.isDirectory()) continue;
|
|
32155
|
-
const
|
|
32156
|
-
const newest =
|
|
32850
|
+
const entries2 = readdirSync8(p);
|
|
32851
|
+
const newest = entries2.reduce((m, e) => {
|
|
32157
32852
|
try {
|
|
32158
|
-
return Math.max(m,
|
|
32853
|
+
return Math.max(m, lstatSync10(join25(p, e)).mtimeMs);
|
|
32159
32854
|
} catch {
|
|
32160
32855
|
return m;
|
|
32161
32856
|
}
|
|
@@ -32219,7 +32914,7 @@ function resolveSessionKey(o = {}) {
|
|
|
32219
32914
|
for (let hop = 0; hop < 8 && pid > 1; hop++) {
|
|
32220
32915
|
const info = lookup(pid);
|
|
32221
32916
|
if (!info) break;
|
|
32222
|
-
if (!isLauncher(info.command)) return `p${pid}-${
|
|
32917
|
+
if (!isLauncher(info.command)) return `p${pid}-${createHash11("sha256").update(info.started).digest("hex").slice(0, 8)}`;
|
|
32223
32918
|
if (info.ppid === pid) break;
|
|
32224
32919
|
pid = info.ppid;
|
|
32225
32920
|
}
|
|
@@ -32297,7 +32992,7 @@ function macOsAuth(o = {}) {
|
|
|
32297
32992
|
} catch {
|
|
32298
32993
|
return { kind: "fail" };
|
|
32299
32994
|
}
|
|
32300
|
-
return new Promise((
|
|
32995
|
+
return new Promise((resolve42) => {
|
|
32301
32996
|
let settled = false;
|
|
32302
32997
|
let timer;
|
|
32303
32998
|
let child;
|
|
@@ -32305,7 +33000,7 @@ function macOsAuth(o = {}) {
|
|
|
32305
33000
|
if (settled) return;
|
|
32306
33001
|
settled = true;
|
|
32307
33002
|
if (timer !== void 0) clearTimeout(timer);
|
|
32308
|
-
|
|
33003
|
+
resolve42(r);
|
|
32309
33004
|
};
|
|
32310
33005
|
try {
|
|
32311
33006
|
const base = o.env ?? process.env;
|
|
@@ -32434,7 +33129,7 @@ function commandOnPath(name, env = process.env) {
|
|
|
32434
33129
|
for (const dir of (env["PATH"] ?? env["Path"] ?? "").split(delimiter)) {
|
|
32435
33130
|
if (!dir) continue;
|
|
32436
33131
|
try {
|
|
32437
|
-
accessSync(
|
|
33132
|
+
accessSync(join26(dir, name), constants6.X_OK);
|
|
32438
33133
|
return true;
|
|
32439
33134
|
} catch {
|
|
32440
33135
|
}
|
|
@@ -32443,14 +33138,14 @@ function commandOnPath(name, env = process.env) {
|
|
|
32443
33138
|
}
|
|
32444
33139
|
var TIMEOUT_MS = 6e4;
|
|
32445
33140
|
function run(spawnFn, cmd, env, timeoutMs) {
|
|
32446
|
-
return new Promise((
|
|
33141
|
+
return new Promise((resolve42) => {
|
|
32447
33142
|
let done = false;
|
|
32448
33143
|
let timer;
|
|
32449
33144
|
const finish = (r) => {
|
|
32450
33145
|
if (done) return;
|
|
32451
33146
|
done = true;
|
|
32452
33147
|
if (timer !== void 0) clearTimeout(timer);
|
|
32453
|
-
|
|
33148
|
+
resolve42(r);
|
|
32454
33149
|
};
|
|
32455
33150
|
try {
|
|
32456
33151
|
const proc = spawnFn(cmd.file, cmd.args, { env, stdio: ["ignore", "pipe", "ignore"] });
|
|
@@ -32532,8 +33227,8 @@ function defaultOsAuth(o = {}) {
|
|
|
32532
33227
|
|
|
32533
33228
|
// ../shield/src/state.ts
|
|
32534
33229
|
init_zod();
|
|
32535
|
-
import { appendFileSync, existsSync as
|
|
32536
|
-
import { dirname as
|
|
33230
|
+
import { appendFileSync, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync19, renameSync as renameSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
33231
|
+
import { dirname as dirname11, join as join27 } from "node:path";
|
|
32537
33232
|
var Sha256 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
32538
33233
|
var PinSchema = external_exports.object({
|
|
32539
33234
|
hash: Sha256,
|
|
@@ -32582,16 +33277,16 @@ var StateSchema = external_exports.object({
|
|
|
32582
33277
|
servers: external_exports.record(ServerStateSchema).default({})
|
|
32583
33278
|
});
|
|
32584
33279
|
var emptyState = () => ({ version: 1, servers: {} });
|
|
32585
|
-
var statePath = (dir) =>
|
|
32586
|
-
var policyPath = (dir) =>
|
|
32587
|
-
var alertsPath = (dir) =>
|
|
32588
|
-
var vaultPath = (dir) =>
|
|
33280
|
+
var statePath = (dir) => join27(dir, "pins.json");
|
|
33281
|
+
var policyPath = (dir) => join27(dir, "policy.json");
|
|
33282
|
+
var alertsPath = (dir) => join27(dir, "alerts.jsonl");
|
|
33283
|
+
var vaultPath = (dir) => join27(dir, "vault");
|
|
32589
33284
|
var PINS_DOMAIN = "exorcist-98:pins:v1";
|
|
32590
33285
|
function pinsText(raw) {
|
|
32591
33286
|
return canonicalJson({ version: raw.version, servers: raw.servers });
|
|
32592
33287
|
}
|
|
32593
33288
|
function loadState(path) {
|
|
32594
|
-
if (!
|
|
33289
|
+
if (!existsSync12(path)) return { ok: true, state: emptyState() };
|
|
32595
33290
|
let json2;
|
|
32596
33291
|
try {
|
|
32597
33292
|
json2 = JSON.parse(readFileSync19(path, "utf8"));
|
|
@@ -32611,7 +33306,7 @@ function loadState(path) {
|
|
|
32611
33306
|
return { ok: true, state: parsed.data };
|
|
32612
33307
|
}
|
|
32613
33308
|
function saveState(path, state) {
|
|
32614
|
-
|
|
33309
|
+
mkdirSync6(dirname11(path), { recursive: true });
|
|
32615
33310
|
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
32616
33311
|
const body = JSON.parse(JSON.stringify({ version: state.version, servers: state.servers }));
|
|
32617
33312
|
const key = getUserKey({ create: true });
|
|
@@ -32629,7 +33324,7 @@ function serverState(state, name) {
|
|
|
32629
33324
|
return s;
|
|
32630
33325
|
}
|
|
32631
33326
|
function appendAlert(path, alert) {
|
|
32632
|
-
|
|
33327
|
+
mkdirSync6(dirname11(path), { recursive: true });
|
|
32633
33328
|
appendFileSync(path, `${JSON.stringify(alert)}
|
|
32634
33329
|
`, "utf8");
|
|
32635
33330
|
}
|
|
@@ -33276,8 +33971,8 @@ function throttle(o = {}) {
|
|
|
33276
33971
|
}
|
|
33277
33972
|
|
|
33278
33973
|
// ../shield/src/canary.ts
|
|
33279
|
-
import { existsSync as
|
|
33280
|
-
import { dirname as
|
|
33974
|
+
import { existsSync as existsSync13, lstatSync as lstatSync11, mkdirSync as mkdirSync7, readFileSync as readFileSync20, readdirSync as readdirSync9, realpathSync as realpathSync10, rmdirSync, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
33975
|
+
import { dirname as dirname12, isAbsolute as isAbsolute17, join as join28, resolve as resolve23 } from "node:path";
|
|
33281
33976
|
var TRAPS = [
|
|
33282
33977
|
{
|
|
33283
33978
|
name: ".env.canary",
|
|
@@ -33320,36 +34015,36 @@ function plantCanaries(root, o = {}) {
|
|
|
33320
34015
|
return { ok: false, error: `Canary traps are already planted in ${root}. To replace them, run "exorcist canary --remove" first.` };
|
|
33321
34016
|
}
|
|
33322
34017
|
for (const d of [".exorcist", CANARY_TRAP_DIR]) {
|
|
33323
|
-
const path =
|
|
33324
|
-
if (
|
|
34018
|
+
const path = join28(root, d);
|
|
34019
|
+
if (existsSync13(path) || isSymlink(path)) {
|
|
33325
34020
|
if (!isRealDir(path)) return { ok: false, error: `${path} is not a real folder (a symlink or a file); no traps were planted.` };
|
|
33326
34021
|
}
|
|
33327
34022
|
}
|
|
33328
34023
|
const traps = TRAPS.slice(0, count);
|
|
33329
34024
|
for (const t2 of traps) {
|
|
33330
|
-
const path =
|
|
33331
|
-
if (
|
|
34025
|
+
const path = join28(root, CANARY_TRAP_DIR, t2.name);
|
|
34026
|
+
if (existsSync13(path)) return { ok: false, error: `${path} already exists; it was not overwritten.` };
|
|
33332
34027
|
}
|
|
33333
34028
|
const created = (o.now ? o.now() : /* @__PURE__ */ new Date()).toISOString();
|
|
33334
34029
|
const records = [];
|
|
33335
|
-
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !
|
|
34030
|
+
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !existsSync13(join28(root, d)));
|
|
33336
34031
|
try {
|
|
33337
|
-
|
|
34032
|
+
mkdirSync7(join28(root, CANARY_TRAP_DIR), { recursive: true });
|
|
33338
34033
|
for (const t2 of traps) {
|
|
33339
34034
|
const token = newToken();
|
|
33340
34035
|
const file = `${CANARY_TRAP_DIR}/${t2.name}`;
|
|
33341
|
-
writeFileSync6(
|
|
34036
|
+
writeFileSync6(join28(root, file), t2.body(token), { flag: "wx" });
|
|
33342
34037
|
records.push({ token, file, created });
|
|
33343
34038
|
}
|
|
33344
34039
|
writeFileSync6(recordsFile, `${JSON.stringify({ version: 1, canaries: records, ...madeDirs.length > 0 ? { madeDirs } : {} }, null, 2)}
|
|
33345
34040
|
`);
|
|
33346
34041
|
} catch (err) {
|
|
33347
|
-
for (const r of records) rmSync3(
|
|
33348
|
-
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(
|
|
34042
|
+
for (const r of records) rmSync3(join28(root, r.file), { force: true });
|
|
34043
|
+
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(join28(root, d));
|
|
33349
34044
|
return { ok: false, error: `Could not plant the canary traps: ${firstLine(err)}` };
|
|
33350
34045
|
}
|
|
33351
34046
|
const result = { ok: true, records, recordsFile };
|
|
33352
|
-
if (o.stateDir &&
|
|
34047
|
+
if (o.stateDir && resolve23(o.stateDir) !== resolve23(root, ".exorcist")) {
|
|
33353
34048
|
const told = setPolicyCanaries(o.stateDir, recordsFile);
|
|
33354
34049
|
if (!told.ok) return { ok: false, error: `Planted the traps, but could not tell the Shield where they are: ${told.error}` };
|
|
33355
34050
|
result.policyUpdated = policyPath(o.stateDir);
|
|
@@ -33362,20 +34057,20 @@ function loadCanaries(root) {
|
|
|
33362
34057
|
}
|
|
33363
34058
|
function rmdirIfEmpty(path) {
|
|
33364
34059
|
try {
|
|
33365
|
-
if (
|
|
34060
|
+
if (lstatSync11(path).isDirectory() && readdirSync9(path).length === 0) rmdirSync(path);
|
|
33366
34061
|
} catch {
|
|
33367
34062
|
}
|
|
33368
34063
|
}
|
|
33369
34064
|
function isSymlink(path) {
|
|
33370
34065
|
try {
|
|
33371
|
-
return
|
|
34066
|
+
return lstatSync11(path).isSymbolicLink();
|
|
33372
34067
|
} catch {
|
|
33373
34068
|
return false;
|
|
33374
34069
|
}
|
|
33375
34070
|
}
|
|
33376
34071
|
function isRealDir(path) {
|
|
33377
34072
|
try {
|
|
33378
|
-
return
|
|
34073
|
+
return lstatSync11(path).isDirectory();
|
|
33379
34074
|
} catch {
|
|
33380
34075
|
return false;
|
|
33381
34076
|
}
|
|
@@ -33387,18 +34082,18 @@ function removeCanaries(root, o = {}) {
|
|
|
33387
34082
|
if (!existing.ok) return existing;
|
|
33388
34083
|
const removed = [];
|
|
33389
34084
|
const warnings = [];
|
|
33390
|
-
const stateFolder =
|
|
33391
|
-
const trapFolder =
|
|
34085
|
+
const stateFolder = join28(root, ".exorcist");
|
|
34086
|
+
const trapFolder = join28(root, CANARY_TRAP_DIR);
|
|
33392
34087
|
const foldersReal = isRealDir(stateFolder) && isRealDir(trapFolder);
|
|
33393
34088
|
let trapReal = null;
|
|
33394
34089
|
try {
|
|
33395
|
-
trapReal = foldersReal ?
|
|
34090
|
+
trapReal = foldersReal ? realpathSync10(trapFolder) : null;
|
|
33396
34091
|
} catch {
|
|
33397
34092
|
trapReal = null;
|
|
33398
34093
|
}
|
|
33399
34094
|
let left = 0;
|
|
33400
34095
|
for (const r of existing.canaries) {
|
|
33401
|
-
const full =
|
|
34096
|
+
const full = join28(root, r.file);
|
|
33402
34097
|
const name = r.file.slice(`${CANARY_TRAP_DIR}/`.length);
|
|
33403
34098
|
const leave = (why) => {
|
|
33404
34099
|
left++;
|
|
@@ -33406,7 +34101,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33406
34101
|
};
|
|
33407
34102
|
let st;
|
|
33408
34103
|
try {
|
|
33409
|
-
st =
|
|
34104
|
+
st = lstatSync11(full);
|
|
33410
34105
|
} catch {
|
|
33411
34106
|
continue;
|
|
33412
34107
|
}
|
|
@@ -33423,7 +34118,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33423
34118
|
continue;
|
|
33424
34119
|
}
|
|
33425
34120
|
try {
|
|
33426
|
-
if (
|
|
34121
|
+
if (realpathSync10(dirname12(full)) !== trapReal) {
|
|
33427
34122
|
leave("it is not inside the trap folder.");
|
|
33428
34123
|
continue;
|
|
33429
34124
|
}
|
|
@@ -33442,7 +34137,7 @@ function removeCanaries(root, o = {}) {
|
|
|
33442
34137
|
return { ok: true, removed, warnings };
|
|
33443
34138
|
}
|
|
33444
34139
|
try {
|
|
33445
|
-
const st =
|
|
34140
|
+
const st = lstatSync11(recordsFile);
|
|
33446
34141
|
if (isRealDir(stateFolder) && st.isFile()) {
|
|
33447
34142
|
rmSync3(recordsFile);
|
|
33448
34143
|
removed.push(CANARY_RECORDS_FILE);
|
|
@@ -33454,12 +34149,12 @@ function removeCanaries(root, o = {}) {
|
|
|
33454
34149
|
}
|
|
33455
34150
|
if (existing.madeDirs.includes(CANARY_TRAP_DIR)) rmdirIfEmpty(trapFolder);
|
|
33456
34151
|
if (existing.madeDirs.includes(".exorcist")) rmdirIfEmpty(stateFolder);
|
|
33457
|
-
if (o.stateDir &&
|
|
34152
|
+
if (o.stateDir && resolve23(o.stateDir) !== resolve23(root, ".exorcist")) clearPolicyCanaries(o.stateDir, recordsFile);
|
|
33458
34153
|
return { ok: true, removed, warnings };
|
|
33459
34154
|
}
|
|
33460
34155
|
function readPolicyObject(stateDir2) {
|
|
33461
34156
|
const path = policyPath(stateDir2);
|
|
33462
|
-
if (!
|
|
34157
|
+
if (!existsSync13(path)) return { ok: true, obj: {} };
|
|
33463
34158
|
try {
|
|
33464
34159
|
const json2 = JSON.parse(readFileSync20(path, "utf8"));
|
|
33465
34160
|
if (!json2 || typeof json2 !== "object" || Array.isArray(json2)) return { ok: false, error: `${path} is not a JSON object.` };
|
|
@@ -33472,10 +34167,10 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33472
34167
|
const p = readPolicyObject(stateDir2);
|
|
33473
34168
|
if (!p.ok) return p;
|
|
33474
34169
|
try {
|
|
33475
|
-
|
|
34170
|
+
mkdirSync7(stateDir2, { recursive: true });
|
|
33476
34171
|
const file = policyPath(stateDir2);
|
|
33477
|
-
const sign = !
|
|
33478
|
-
writeFileSync6(file, `${JSON.stringify({ ...p.obj, canaries:
|
|
34172
|
+
const sign = !existsSync13(file) || policyIsSigned(file);
|
|
34173
|
+
writeFileSync6(file, `${JSON.stringify({ ...p.obj, canaries: resolve23(recordsFile) }, null, 2)}
|
|
33479
34174
|
`);
|
|
33480
34175
|
if (sign) signPolicyFile(file);
|
|
33481
34176
|
return { ok: true };
|
|
@@ -33485,7 +34180,7 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33485
34180
|
}
|
|
33486
34181
|
function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
33487
34182
|
const p = readPolicyObject(stateDir2);
|
|
33488
|
-
if (!p.ok || p.obj["canaries"] !==
|
|
34183
|
+
if (!p.ok || p.obj["canaries"] !== resolve23(recordsFile)) return;
|
|
33489
34184
|
const { canaries: _gone, ...rest } = p.obj;
|
|
33490
34185
|
try {
|
|
33491
34186
|
const file = policyPath(stateDir2);
|
|
@@ -33502,8 +34197,8 @@ function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
|
33502
34197
|
}
|
|
33503
34198
|
}
|
|
33504
34199
|
function canariesFileFor(stateDir2, policyCanaries) {
|
|
33505
|
-
if (!policyCanaries) return
|
|
33506
|
-
return isAbsolute17(policyCanaries) ? policyCanaries :
|
|
34200
|
+
if (!policyCanaries) return join28(stateDir2, "canaries.json");
|
|
34201
|
+
return isAbsolute17(policyCanaries) ? policyCanaries : resolve23(stateDir2, policyCanaries);
|
|
33507
34202
|
}
|
|
33508
34203
|
function allStrings(value) {
|
|
33509
34204
|
const out = [];
|
|
@@ -33517,9 +34212,9 @@ function allStrings(value) {
|
|
|
33517
34212
|
seen.add(v);
|
|
33518
34213
|
if (Array.isArray(v)) for (let i = v.length - 1; i >= 0; i--) stack.push(v[i]);
|
|
33519
34214
|
else {
|
|
33520
|
-
const
|
|
33521
|
-
for (let i =
|
|
33522
|
-
const [k, x] =
|
|
34215
|
+
const entries2 = Object.entries(v);
|
|
34216
|
+
for (let i = entries2.length - 1; i >= 0; i--) {
|
|
34217
|
+
const [k, x] = entries2[i];
|
|
33523
34218
|
stack.push(x, k);
|
|
33524
34219
|
}
|
|
33525
34220
|
}
|
|
@@ -34031,7 +34726,7 @@ var ShieldEngine = class {
|
|
|
34031
34726
|
this.heldCalls.set(promptId, { call, id, tool, hosts, kind: "host", askedAt: this.now(), digest: this.digestOf(call, tool) });
|
|
34032
34727
|
this.callEvent(tool, "held", { ruleId: "EX-016", why: `It would send data to ${hosts.map((h) => cleanText(h, 80)).join(", ")}, which is not on the allowed list. Waiting for your answer in the agent's approval prompt.`, prompt: this.elicitSeq });
|
|
34033
34728
|
const shownTool = cleanText(tool, 80);
|
|
34034
|
-
const
|
|
34729
|
+
const list3 = hosts.map((h) => cleanText(h, 80)).join(", ");
|
|
34035
34730
|
return [{
|
|
34036
34731
|
type: "forward",
|
|
34037
34732
|
to: "client",
|
|
@@ -34040,11 +34735,11 @@ var ShieldEngine = class {
|
|
|
34040
34735
|
id: promptId,
|
|
34041
34736
|
method: "elicitation/create",
|
|
34042
34737
|
params: {
|
|
34043
|
-
message: `Exorcist 98: the tool "${shownTool}" on "${cleanText(this.o.server, 80)}" wants to send data to ${
|
|
34738
|
+
message: `Exorcist 98: the tool "${shownTool}" on "${cleanText(this.o.server, 80)}" wants to send data to ${list3}, which is not on your allowed list. Allow this call?`,
|
|
34044
34739
|
requestedSchema: {
|
|
34045
34740
|
type: "object",
|
|
34046
34741
|
properties: {
|
|
34047
|
-
remember: { type: "boolean", title: `Always allow ${
|
|
34742
|
+
remember: { type: "boolean", title: `Always allow ${list3} for ${cleanText(this.o.server, 80)}`, default: false }
|
|
34048
34743
|
}
|
|
34049
34744
|
}
|
|
34050
34745
|
}
|
|
@@ -34327,8 +35022,8 @@ var ShieldEngine = class {
|
|
|
34327
35022
|
const promptId = `${PROMPT_PREFIX}${++this.elicitSeq}`;
|
|
34328
35023
|
this.heldCalls.set(promptId, { call, id, tool, hosts, kind: "session", askedAt: this.now(), digest: this.digestOf(call, tool) });
|
|
34329
35024
|
this.callEvent(tool, "held", { ruleId: SESSION_RULE_ID, why: `Lethal trifecta in this session: ${out}. Waiting for your answer in the agent's approval prompt.`, prompt: this.elicitSeq });
|
|
34330
|
-
const
|
|
34331
|
-
const also = hosts.length > 0 ? ` It would also reach ${
|
|
35025
|
+
const list3 = hosts.map((h) => cleanText(h, 80)).join(", ");
|
|
35026
|
+
const also = hosts.length > 0 ? ` It would also reach ${list3}, which is not on your allowed list.` : "";
|
|
34332
35027
|
return [{
|
|
34333
35028
|
type: "forward",
|
|
34334
35029
|
to: "client",
|
|
@@ -34772,12 +35467,12 @@ var ShieldEngine = class {
|
|
|
34772
35467
|
|
|
34773
35468
|
// ../shield/src/proxy.ts
|
|
34774
35469
|
import { spawn as spawn3 } from "node:child_process";
|
|
34775
|
-
import { existsSync as
|
|
34776
|
-
import { dirname as
|
|
35470
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync10, readFileSync as readFileSync26, statSync as statSync15 } from "node:fs";
|
|
35471
|
+
import { dirname as dirname16 } from "node:path";
|
|
34777
35472
|
|
|
34778
35473
|
// ../shield/src/lockfile.ts
|
|
34779
|
-
import { existsSync as
|
|
34780
|
-
import { dirname as
|
|
35474
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
35475
|
+
import { dirname as dirname13, join as join29, parse as parsePath, resolve as resolve24 } from "node:path";
|
|
34781
35476
|
init_zod();
|
|
34782
35477
|
var Sha2562 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
34783
35478
|
var LockToolSchema = external_exports.object({
|
|
@@ -34813,7 +35508,7 @@ function lockUrl(url) {
|
|
|
34813
35508
|
return "(not a valid URL)";
|
|
34814
35509
|
}
|
|
34815
35510
|
}
|
|
34816
|
-
var record = (
|
|
35511
|
+
var record = (entries2) => Object.fromEntries(entries2);
|
|
34817
35512
|
function lockServer(l) {
|
|
34818
35513
|
const byName = /* @__PURE__ */ new Map();
|
|
34819
35514
|
for (const t2 of l.tools) {
|
|
@@ -34950,21 +35645,21 @@ function seedFromLock(s, ls, report, o) {
|
|
|
34950
35645
|
var PROJECT_MARKERS2 = [".git", ".kiro", ".exorcist"];
|
|
34951
35646
|
function findLockFile(starts) {
|
|
34952
35647
|
for (const start of starts) {
|
|
34953
|
-
const { root } = parsePath(
|
|
34954
|
-
for (let dir =
|
|
34955
|
-
const candidate =
|
|
34956
|
-
if (
|
|
34957
|
-
if (PROJECT_MARKERS2.some((m) =>
|
|
34958
|
-
if (dir === root ||
|
|
35648
|
+
const { root } = parsePath(resolve24(start));
|
|
35649
|
+
for (let dir = resolve24(start); ; dir = dirname13(dir)) {
|
|
35650
|
+
const candidate = join29(dir, LOCK_FILE);
|
|
35651
|
+
if (existsSync14(candidate)) return candidate;
|
|
35652
|
+
if (PROJECT_MARKERS2.some((m) => existsSync14(join29(dir, m)))) break;
|
|
35653
|
+
if (dir === root || dirname13(dir) === dir) break;
|
|
34959
35654
|
}
|
|
34960
35655
|
}
|
|
34961
35656
|
return null;
|
|
34962
35657
|
}
|
|
34963
35658
|
|
|
34964
35659
|
// ../shield/src/vault.ts
|
|
34965
|
-
import { createHash as
|
|
34966
|
-
import { closeSync as
|
|
34967
|
-
import { basename as
|
|
35660
|
+
import { createHash as createHash12, randomBytes as randomBytes7 } from "node:crypto";
|
|
35661
|
+
import { closeSync as closeSync8, constants as constants7, copyFileSync, existsSync as existsSync15, fstatSync as fstatSync3, lstatSync as lstatSync12, mkdirSync as mkdirSync8, openSync as openSync8, readFileSync as readFileSync21, readdirSync as readdirSync10, realpathSync as realpathSync11, rmSync as rmSync4, statSync as statSync13, writeFileSync as writeFileSync7, writeSync as writeSync5 } from "node:fs";
|
|
35662
|
+
import { basename as basename10, dirname as dirname14, isAbsolute as isAbsolute18, join as join30, resolve as resolve25, sep as sep6 } from "node:path";
|
|
34968
35663
|
init_zod();
|
|
34969
35664
|
var SafeRel = external_exports.string().min(1).max(1024).refine(
|
|
34970
35665
|
(p) => !isAbsolute18(p) && !p.includes("\\") && !p.includes("\0") && p.split("/").every((seg) => seg !== "" && seg !== "." && seg !== ".."),
|
|
@@ -34995,7 +35690,7 @@ var EntrySchema = external_exports.object({
|
|
|
34995
35690
|
/** HMAC with the user key over every other field (MS-5). Missing or wrong: the entry is not trusted. */
|
|
34996
35691
|
mac: external_exports.string().optional()
|
|
34997
35692
|
});
|
|
34998
|
-
var sha2562 = (data) =>
|
|
35693
|
+
var sha2562 = (data) => createHash12("sha256").update(data).digest("hex");
|
|
34999
35694
|
var fail3 = (error2) => ({ ok: false, error: error2 });
|
|
35000
35695
|
var VAULT_DOMAIN = "exorcist-98:vault:v1";
|
|
35001
35696
|
var entryText = (e) => {
|
|
@@ -35004,13 +35699,13 @@ var entryText = (e) => {
|
|
|
35004
35699
|
};
|
|
35005
35700
|
function ensureSafeVault(vaultDir) {
|
|
35006
35701
|
const me = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
35007
|
-
const state =
|
|
35702
|
+
const state = dirname14(vaultDir);
|
|
35008
35703
|
try {
|
|
35009
|
-
|
|
35704
|
+
mkdirSync8(dirname14(state), { recursive: true });
|
|
35010
35705
|
for (const d of [state, vaultDir]) {
|
|
35011
|
-
const st =
|
|
35706
|
+
const st = lstatSync12(d, { throwIfNoEntry: false });
|
|
35012
35707
|
if (st === void 0) {
|
|
35013
|
-
|
|
35708
|
+
mkdirSync8(d, { mode: 448 });
|
|
35014
35709
|
continue;
|
|
35015
35710
|
}
|
|
35016
35711
|
if (st.isSymbolicLink()) return `${d} is a symbolic link, so nothing was written there. Remove the link and try again.`;
|
|
@@ -35023,33 +35718,33 @@ function ensureSafeVault(vaultDir) {
|
|
|
35023
35718
|
}
|
|
35024
35719
|
}
|
|
35025
35720
|
function writeFileSafe(path, text) {
|
|
35026
|
-
const fd =
|
|
35721
|
+
const fd = openSync8(path, constants7.O_WRONLY | constants7.O_CREAT | constants7.O_TRUNC | (constants7.O_NOFOLLOW ?? 0), 384);
|
|
35027
35722
|
try {
|
|
35028
35723
|
if (!fstatSync3(fd).isFile()) throw new Error("not a regular file");
|
|
35029
|
-
|
|
35724
|
+
writeSync5(fd, text);
|
|
35030
35725
|
} finally {
|
|
35031
|
-
|
|
35726
|
+
closeSync8(fd);
|
|
35032
35727
|
}
|
|
35033
35728
|
}
|
|
35034
35729
|
var insideDir = (child, parent) => child === parent || child.startsWith(parent.endsWith(sep6) ? parent : parent + sep6);
|
|
35035
35730
|
function rootFor(vaultDir, target) {
|
|
35036
|
-
const state =
|
|
35037
|
-
if (
|
|
35038
|
-
const project =
|
|
35039
|
-
return insideDir(
|
|
35731
|
+
const state = dirname14(vaultDir);
|
|
35732
|
+
if (basename10(state) !== ".exorcist") return void 0;
|
|
35733
|
+
const project = dirname14(state);
|
|
35734
|
+
return insideDir(resolve25(target), resolve25(project)) ? resolve25(project) : void 0;
|
|
35040
35735
|
}
|
|
35041
35736
|
function realDirOf(target) {
|
|
35042
35737
|
try {
|
|
35043
|
-
return
|
|
35738
|
+
return realpathSync11(dirname14(target));
|
|
35044
35739
|
} catch {
|
|
35045
35740
|
return void 0;
|
|
35046
35741
|
}
|
|
35047
35742
|
}
|
|
35048
35743
|
function targetProblem(e) {
|
|
35049
|
-
const dir = e.kind === "exorcise" ? e.target :
|
|
35744
|
+
const dir = e.kind === "exorcise" ? e.target : dirname14(e.target);
|
|
35050
35745
|
let real;
|
|
35051
35746
|
try {
|
|
35052
|
-
real =
|
|
35747
|
+
real = realpathSync11(existsSync15(dir) ? dir : dirname14(dir));
|
|
35053
35748
|
} catch {
|
|
35054
35749
|
return `${e.target} cannot be resolved.`;
|
|
35055
35750
|
}
|
|
@@ -35057,7 +35752,7 @@ function targetProblem(e) {
|
|
|
35057
35752
|
if (e.root !== void 0) {
|
|
35058
35753
|
let root;
|
|
35059
35754
|
try {
|
|
35060
|
-
root =
|
|
35755
|
+
root = realpathSync11(e.root);
|
|
35061
35756
|
} catch {
|
|
35062
35757
|
return `The project folder ${e.root} cannot be resolved.`;
|
|
35063
35758
|
}
|
|
@@ -35071,24 +35766,24 @@ function newId(label, now) {
|
|
|
35071
35766
|
return `${stamp}-${slug}-${randomBytes7(2).toString("hex")}`;
|
|
35072
35767
|
}
|
|
35073
35768
|
function entryDir(vaultDir, id) {
|
|
35074
|
-
return
|
|
35769
|
+
return join30(vaultDir, id);
|
|
35075
35770
|
}
|
|
35076
35771
|
function writeManifest(vaultDir, e) {
|
|
35077
35772
|
const key = getUserKey({ create: true });
|
|
35078
35773
|
const { trusted: _t, ...plain4 } = e;
|
|
35079
35774
|
const body = key.ok ? { ...plain4, mac: signText(key.key, VAULT_DOMAIN, entryText(plain4)) } : plain4;
|
|
35080
|
-
writeFileSafe(
|
|
35775
|
+
writeFileSafe(join30(entryDir(vaultDir, e.id), "manifest.json"), `${JSON.stringify(body, null, 2)}
|
|
35081
35776
|
`);
|
|
35082
35777
|
}
|
|
35083
35778
|
function listEntries(vaultDir) {
|
|
35084
|
-
if (!
|
|
35779
|
+
if (!existsSync15(vaultDir)) return [];
|
|
35085
35780
|
const key = getUserKey();
|
|
35086
35781
|
const out = [];
|
|
35087
35782
|
for (const name of readdirSync10(vaultDir)) {
|
|
35088
|
-
const file =
|
|
35089
|
-
if (!
|
|
35783
|
+
const file = join30(vaultDir, name, "manifest.json");
|
|
35784
|
+
if (!existsSync15(file)) continue;
|
|
35090
35785
|
try {
|
|
35091
|
-
const st =
|
|
35786
|
+
const st = lstatSync12(file);
|
|
35092
35787
|
if (!st.isFile()) continue;
|
|
35093
35788
|
const parsed = EntrySchema.safeParse(JSON.parse(readFileSync21(file, "utf8")));
|
|
35094
35789
|
if (parsed.success) out.push({ ...parsed.data, trusted: key.ok && verifyText(key.key, VAULT_DOMAIN, entryText(parsed.data), parsed.data.mac) });
|
|
@@ -35123,7 +35818,7 @@ function readConfig(path) {
|
|
|
35123
35818
|
var writeConfig = (path, cfg) => writeFileSync7(path, `${JSON.stringify(cfg, null, 2)}
|
|
35124
35819
|
`, "utf8");
|
|
35125
35820
|
function quarantineServer(o) {
|
|
35126
|
-
const configPath =
|
|
35821
|
+
const configPath = resolve25(o.configPath);
|
|
35127
35822
|
const cfg = readConfig(configPath);
|
|
35128
35823
|
if (!cfg.ok) return cfg;
|
|
35129
35824
|
const entry = cfg.value.mcpServers?.[o.serverName];
|
|
@@ -35136,10 +35831,10 @@ function quarantineServer(o) {
|
|
|
35136
35831
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35137
35832
|
const id = newId(o.serverName, now);
|
|
35138
35833
|
const dir = entryDir(o.vaultDir, id);
|
|
35139
|
-
|
|
35834
|
+
mkdirSync8(dir, { recursive: true });
|
|
35140
35835
|
const backup = `${JSON.stringify(entry, null, 2)}
|
|
35141
35836
|
`;
|
|
35142
|
-
writeFileSafe(
|
|
35837
|
+
writeFileSafe(join30(dir, "entry.json"), backup);
|
|
35143
35838
|
const root = rootFor(o.vaultDir, configPath);
|
|
35144
35839
|
const realDir = realDirOf(configPath);
|
|
35145
35840
|
const e = {
|
|
@@ -35160,16 +35855,16 @@ function quarantineServer(o) {
|
|
|
35160
35855
|
return { ok: true, value: e };
|
|
35161
35856
|
}
|
|
35162
35857
|
function quarantineFile(o) {
|
|
35163
|
-
const target =
|
|
35164
|
-
if (!
|
|
35858
|
+
const target = resolve25(o.filePath);
|
|
35859
|
+
if (!existsSync15(target) || !statSync13(target).isFile()) return fail3(`${target} is not a file.`);
|
|
35165
35860
|
if (activeFor(o.vaultDir, target)) return fail3(`${target} is already in the vault.`);
|
|
35166
35861
|
const safe2 = ensureSafeVault(o.vaultDir);
|
|
35167
35862
|
if (safe2 !== null) return fail3(safe2);
|
|
35168
35863
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35169
|
-
const id = newId(
|
|
35864
|
+
const id = newId(basename10(target), now);
|
|
35170
35865
|
const dir = entryDir(o.vaultDir, id);
|
|
35171
|
-
|
|
35172
|
-
const stored =
|
|
35866
|
+
mkdirSync8(join30(dir, "files"), { recursive: true });
|
|
35867
|
+
const stored = join30(dir, "files", basename10(target));
|
|
35173
35868
|
copyFileSync(target, stored);
|
|
35174
35869
|
const digest = sha2562(readFileSync21(stored));
|
|
35175
35870
|
if (digest !== sha2562(readFileSync21(target))) {
|
|
@@ -35184,12 +35879,12 @@ function quarantineFile(o) {
|
|
|
35184
35879
|
return { ok: true, value: e };
|
|
35185
35880
|
}
|
|
35186
35881
|
function backupAndRewrite(o) {
|
|
35187
|
-
const root =
|
|
35882
|
+
const root = resolve25(o.root);
|
|
35188
35883
|
if (o.files.length === 0) return fail3("There are no files to change.");
|
|
35189
35884
|
for (const f of o.files) {
|
|
35190
35885
|
if (!SafeRel.safeParse(f.rel).success) return fail3(`Refusing to write outside ${root}: ${f.rel}`);
|
|
35191
|
-
const path =
|
|
35192
|
-
if (!
|
|
35886
|
+
const path = join30(root, f.rel);
|
|
35887
|
+
if (!existsSync15(path)) return fail3(`${f.rel} is gone; nothing was changed.`);
|
|
35193
35888
|
if (sha2562(readFileSync21(path)) !== sha2562(Buffer.from(f.before, "utf8"))) {
|
|
35194
35889
|
return fail3(`${f.rel} changed since it was scanned; nothing was changed. Run exorcise again.`);
|
|
35195
35890
|
}
|
|
@@ -35197,16 +35892,16 @@ function backupAndRewrite(o) {
|
|
|
35197
35892
|
const safe2 = ensureSafeVault(o.vaultDir);
|
|
35198
35893
|
if (safe2 !== null) return fail3(safe2);
|
|
35199
35894
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
35200
|
-
const id = newId(`exorcise-${
|
|
35895
|
+
const id = newId(`exorcise-${basename10(root)}`, now);
|
|
35201
35896
|
const dir = entryDir(o.vaultDir, id);
|
|
35202
35897
|
const files = [];
|
|
35203
35898
|
try {
|
|
35204
35899
|
for (const f of o.files) {
|
|
35205
|
-
const stored =
|
|
35206
|
-
|
|
35207
|
-
copyFileSync(
|
|
35900
|
+
const stored = join30(dir, "files", f.rel);
|
|
35901
|
+
mkdirSync8(dirname14(stored), { recursive: true });
|
|
35902
|
+
copyFileSync(join30(root, f.rel), stored);
|
|
35208
35903
|
const digest = sha2562(readFileSync21(stored));
|
|
35209
|
-
if (digest !== sha2562(readFileSync21(
|
|
35904
|
+
if (digest !== sha2562(readFileSync21(join30(root, f.rel)))) throw new Error("mismatch");
|
|
35210
35905
|
files.push({ rel: f.rel, sha256: digest, after: sha2562(Buffer.from(f.after, "utf8")) });
|
|
35211
35906
|
}
|
|
35212
35907
|
} catch {
|
|
@@ -35226,14 +35921,14 @@ function backupAndRewrite(o) {
|
|
|
35226
35921
|
...exRoot ? { root: exRoot } : {}
|
|
35227
35922
|
};
|
|
35228
35923
|
writeManifest(o.vaultDir, e);
|
|
35229
|
-
for (const f of o.files) writeFileSync7(
|
|
35924
|
+
for (const f of o.files) writeFileSync7(join30(root, f.rel), f.after, "utf8");
|
|
35230
35925
|
return { ok: true, value: e };
|
|
35231
35926
|
}
|
|
35232
35927
|
function restoreExorcised(vaultDir, e, force) {
|
|
35233
35928
|
const files = e.files ?? [];
|
|
35234
35929
|
const blocked2 = files.filter((f) => {
|
|
35235
|
-
const path =
|
|
35236
|
-
if (!
|
|
35930
|
+
const path = join30(e.target, f.rel);
|
|
35931
|
+
if (!existsSync15(path)) return false;
|
|
35237
35932
|
const now = sha2562(readFileSync21(path));
|
|
35238
35933
|
return now !== f.after && now !== f.sha256;
|
|
35239
35934
|
});
|
|
@@ -35241,27 +35936,27 @@ function restoreExorcised(vaultDir, e, force) {
|
|
|
35241
35936
|
return fail3(`${blocked2.map((f) => f.rel).join(", ")} changed after the exorcism. Use --force to overwrite ${blocked2.length === 1 ? "it" : "them"} with the backup.`);
|
|
35242
35937
|
}
|
|
35243
35938
|
for (const f of files) {
|
|
35244
|
-
const stored =
|
|
35939
|
+
const stored = join30(entryDir(vaultDir, e.id), "files", f.rel);
|
|
35245
35940
|
if (sha2562(readFileSync21(stored)) !== f.sha256) return fail3(`The backup of ${f.rel} is damaged (sha256 does not match); nothing was restored.`);
|
|
35246
35941
|
}
|
|
35247
35942
|
for (const f of files) {
|
|
35248
|
-
const path =
|
|
35249
|
-
|
|
35250
|
-
copyFileSync(
|
|
35943
|
+
const path = join30(e.target, f.rel);
|
|
35944
|
+
mkdirSync8(dirname14(path), { recursive: true });
|
|
35945
|
+
copyFileSync(join30(entryDir(vaultDir, e.id), "files", f.rel), path);
|
|
35251
35946
|
}
|
|
35252
35947
|
return { ok: true, value: null };
|
|
35253
35948
|
}
|
|
35254
35949
|
function backupFile(vaultDir, e) {
|
|
35255
|
-
return e.kind === "mcp-server" ?
|
|
35950
|
+
return e.kind === "mcp-server" ? join30(entryDir(vaultDir, e.id), "entry.json") : join30(entryDir(vaultDir, e.id), "files", basename10(e.target));
|
|
35256
35951
|
}
|
|
35257
35952
|
function diffEntry(vaultDir, id) {
|
|
35258
35953
|
const e = getEntry(vaultDir, id);
|
|
35259
35954
|
if (!e) return fail3(`There is no vault entry "${id}".`);
|
|
35260
35955
|
if (e.kind === "exorcise") {
|
|
35261
35956
|
const parts2 = (e.files ?? []).map((f) => {
|
|
35262
|
-
const path =
|
|
35263
|
-
const before2 = readFileSync21(
|
|
35264
|
-
const after2 =
|
|
35957
|
+
const path = join30(e.target, f.rel);
|
|
35958
|
+
const before2 = readFileSync21(join30(entryDir(vaultDir, e.id), "files", f.rel), "utf8");
|
|
35959
|
+
const after2 = existsSync15(path) ? readFileSync21(path, "utf8") : "";
|
|
35265
35960
|
return createTwoFilesPatch(`${f.rel} (backup)`, `${f.rel} (now)`, before2, after2, "", "", { context: 3 });
|
|
35266
35961
|
});
|
|
35267
35962
|
return { ok: true, value: parts2.join("") };
|
|
@@ -35273,10 +35968,10 @@ function diffEntry(vaultDir, id) {
|
|
|
35273
35968
|
const now = cfg.ok ? cfg.value.mcpServers?.[e.serverName ?? ""] : void 0;
|
|
35274
35969
|
after = now ? `${JSON.stringify(now, null, 2)}
|
|
35275
35970
|
` : "";
|
|
35276
|
-
} else if (
|
|
35971
|
+
} else if (existsSync15(e.target)) {
|
|
35277
35972
|
after = readFileSync21(e.target, "utf8");
|
|
35278
35973
|
}
|
|
35279
|
-
const label = e.kind === "mcp-server" ? `${e.serverName} in ${
|
|
35974
|
+
const label = e.kind === "mcp-server" ? `${e.serverName} in ${basename10(e.target)}` : basename10(e.target);
|
|
35280
35975
|
return { ok: true, value: createTwoFilesPatch(`${label} (backup)`, `${label} (now)`, before, after, "", "", { context: 3 }) };
|
|
35281
35976
|
}
|
|
35282
35977
|
function restoreEntry(vaultDir, id, opts = {}) {
|
|
@@ -35310,10 +36005,10 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
35310
36005
|
writeConfig(e.target, cfg.value);
|
|
35311
36006
|
} else {
|
|
35312
36007
|
const stored = backupFile(vaultDir, e);
|
|
35313
|
-
if (
|
|
36008
|
+
if (existsSync15(e.target) && sha2562(readFileSync21(e.target)) !== e.sha256 && !opts.force) {
|
|
35314
36009
|
return fail3(`${e.target} exists and is different from the quarantined file. Use --force to overwrite it.`);
|
|
35315
36010
|
}
|
|
35316
|
-
|
|
36011
|
+
mkdirSync8(resolve25(e.target, ".."), { recursive: true });
|
|
35317
36012
|
copyFileSync(stored, e.target);
|
|
35318
36013
|
}
|
|
35319
36014
|
const done = { ...e, status: "restored" };
|
|
@@ -35323,14 +36018,14 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
35323
36018
|
|
|
35324
36019
|
// ../shield/src/events.ts
|
|
35325
36020
|
init_zod();
|
|
35326
|
-
import { closeSync as
|
|
35327
|
-
import { join as
|
|
36021
|
+
import { closeSync as closeSync10, constants as constants9, fstatSync as fstatSync5, lstatSync as lstatSync14, mkdirSync as mkdirSync9, openSync as openSync10, readFileSync as readFileSync24, readSync as readSync5, renameSync as renameSync8, rmdirSync as rmdirSync2, unlinkSync as unlinkSync5, writeSync as writeSync7 } from "node:fs";
|
|
36022
|
+
import { join as join32 } from "node:path";
|
|
35328
36023
|
|
|
35329
36024
|
// ../shield/src/chain.ts
|
|
35330
36025
|
init_zod();
|
|
35331
|
-
import { createHash as
|
|
35332
|
-
import { closeSync as
|
|
35333
|
-
import { join as
|
|
36026
|
+
import { createHash as createHash13, randomBytes as randomBytes8 } from "node:crypto";
|
|
36027
|
+
import { closeSync as closeSync9, constants as constants8, fstatSync as fstatSync4, lstatSync as lstatSync13, openSync as openSync9, readFileSync as readFileSync22, readSync as readSync4, renameSync as renameSync7, unlinkSync as unlinkSync4, writeSync as writeSync6 } from "node:fs";
|
|
36028
|
+
import { join as join31 } from "node:path";
|
|
35334
36029
|
|
|
35335
36030
|
// ../shield/src/chain-core.ts
|
|
35336
36031
|
init_zod();
|
|
@@ -35536,8 +36231,8 @@ function verifyChain(lines, head, genesis, opts) {
|
|
|
35536
36231
|
// ../shield/src/chain.ts
|
|
35537
36232
|
var ok = (value) => ({ ok: true, value });
|
|
35538
36233
|
var fail4 = (error2) => ({ ok: false, error: error2 });
|
|
35539
|
-
var headPath = (dir) =>
|
|
35540
|
-
var genesisPath = (dir) =>
|
|
36234
|
+
var headPath = (dir) => join31(dir, "events.head.json");
|
|
36235
|
+
var genesisPath = (dir) => join31(dir, "events.genesis.json");
|
|
35541
36236
|
var GenesisFileSchema = external_exports.object({ v: external_exports.literal(1), genesis: external_exports.string().regex(HEX64) }).strict();
|
|
35542
36237
|
var MAX_FILE_BYTES4 = 4096;
|
|
35543
36238
|
function errCode(e) {
|
|
@@ -35546,10 +36241,10 @@ function errCode(e) {
|
|
|
35546
36241
|
function readSmall(path) {
|
|
35547
36242
|
let fd = null;
|
|
35548
36243
|
try {
|
|
35549
|
-
const st =
|
|
36244
|
+
const st = lstatSync13(path, { throwIfNoEntry: false });
|
|
35550
36245
|
if (st === void 0) return ok(null);
|
|
35551
36246
|
if (!st.isFile()) return fail4("not a regular file");
|
|
35552
|
-
fd =
|
|
36247
|
+
fd = openSync9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
|
|
35553
36248
|
if (fstatSync4(fd).size > MAX_FILE_BYTES4) return fail4("file is too large");
|
|
35554
36249
|
return ok(readFileSync22(fd, "utf8"));
|
|
35555
36250
|
} catch (e) {
|
|
@@ -35557,7 +36252,7 @@ function readSmall(path) {
|
|
|
35557
36252
|
} finally {
|
|
35558
36253
|
if (fd !== null) {
|
|
35559
36254
|
try {
|
|
35560
|
-
|
|
36255
|
+
closeSync9(fd);
|
|
35561
36256
|
} catch {
|
|
35562
36257
|
}
|
|
35563
36258
|
}
|
|
@@ -35583,15 +36278,15 @@ function readGenesis(dir) {
|
|
|
35583
36278
|
function writeNew(path, text) {
|
|
35584
36279
|
let fd = null;
|
|
35585
36280
|
try {
|
|
35586
|
-
fd =
|
|
35587
|
-
|
|
36281
|
+
fd = openSync9(path, constants8.O_WRONLY | constants8.O_CREAT | constants8.O_EXCL | constants8.O_NOFOLLOW, 384);
|
|
36282
|
+
writeSync6(fd, text);
|
|
35588
36283
|
return ok(void 0);
|
|
35589
36284
|
} catch (e) {
|
|
35590
36285
|
return fail4(errCode(e));
|
|
35591
36286
|
} finally {
|
|
35592
36287
|
if (fd !== null) {
|
|
35593
36288
|
try {
|
|
35594
|
-
|
|
36289
|
+
closeSync9(fd);
|
|
35595
36290
|
} catch {
|
|
35596
36291
|
}
|
|
35597
36292
|
}
|
|
@@ -35601,7 +36296,7 @@ function loadOrCreateGenesis(dir, random = () => randomBytes8(32)) {
|
|
|
35601
36296
|
const existing = readGenesis(dir);
|
|
35602
36297
|
if (!existing.ok) return existing;
|
|
35603
36298
|
if (existing.value !== null) return ok(existing.value);
|
|
35604
|
-
const genesis =
|
|
36299
|
+
const genesis = createHash13("sha256").update(random()).digest("hex");
|
|
35605
36300
|
const w = writeNew(genesisPath(dir), `${JSON.stringify({ v: 1, genesis })}
|
|
35606
36301
|
`);
|
|
35607
36302
|
if (!w.ok) {
|
|
@@ -35622,7 +36317,7 @@ function readHead(dir) {
|
|
|
35622
36317
|
function writeHeadAtomic(dir, head) {
|
|
35623
36318
|
const parsed = HeadRecordSchema.safeParse(head);
|
|
35624
36319
|
if (!parsed.success) return fail4("head file: record is not valid");
|
|
35625
|
-
const tmp =
|
|
36320
|
+
const tmp = join31(dir, `events.head.json.${process.pid}.${randomBytes8(4).toString("hex")}.tmp`);
|
|
35626
36321
|
const w = writeNew(tmp, `${JSON.stringify(parsed.data)}
|
|
35627
36322
|
`);
|
|
35628
36323
|
if (!w.ok) return fail4(`head file: could not write (${w.error})`);
|
|
@@ -35641,10 +36336,10 @@ var CHUNK2 = 1 << 20;
|
|
|
35641
36336
|
function readEventsInto(path, out) {
|
|
35642
36337
|
let fd = null;
|
|
35643
36338
|
try {
|
|
35644
|
-
const st =
|
|
36339
|
+
const st = lstatSync13(path, { throwIfNoEntry: false });
|
|
35645
36340
|
if (st === void 0) return ok(null);
|
|
35646
36341
|
if (!st.isFile()) return fail4("not a regular file");
|
|
35647
|
-
fd =
|
|
36342
|
+
fd = openSync9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
|
|
35648
36343
|
const buf = Buffer.alloc(CHUNK2);
|
|
35649
36344
|
let carry = Buffer.alloc(0);
|
|
35650
36345
|
const take = (raw) => {
|
|
@@ -35683,33 +36378,36 @@ function readEventsInto(path, out) {
|
|
|
35683
36378
|
} finally {
|
|
35684
36379
|
if (fd !== null) {
|
|
35685
36380
|
try {
|
|
35686
|
-
|
|
36381
|
+
closeSync9(fd);
|
|
35687
36382
|
} catch {
|
|
35688
36383
|
}
|
|
35689
36384
|
}
|
|
35690
36385
|
}
|
|
35691
36386
|
}
|
|
35692
36387
|
function verifyLogDir(dir, opts) {
|
|
35693
|
-
const
|
|
35694
|
-
const
|
|
35695
|
-
if (!
|
|
35696
|
-
const
|
|
35697
|
-
|
|
36388
|
+
const unreadable2 = (what, error2) => ({ status: "broken", atSeq: 1, reason: "head-mismatch", detail: `${what} could not be read: ${error2}` });
|
|
36389
|
+
const loc = resolveLogLocation(dir, opts?.location ?? {});
|
|
36390
|
+
if (!loc.ok) return unreadable2("the event log folder", loc.error);
|
|
36391
|
+
const logDir = loc.dir;
|
|
36392
|
+
const head = readHead(logDir);
|
|
36393
|
+
if (!head.ok) return unreadable2("the head record", head.error);
|
|
36394
|
+
const genesis = readGenesis(logDir);
|
|
36395
|
+
if (!genesis.ok) return unreadable2("the genesis value", genesis.error);
|
|
35698
36396
|
const events = [];
|
|
35699
|
-
const old = oldEventsPath(
|
|
36397
|
+
const old = oldEventsPath(logDir);
|
|
35700
36398
|
let rotated = false;
|
|
35701
36399
|
try {
|
|
35702
|
-
rotated =
|
|
36400
|
+
rotated = lstatSync13(old, { throwIfNoEntry: false }) !== void 0;
|
|
35703
36401
|
} catch {
|
|
35704
|
-
return
|
|
36402
|
+
return unreadable2("events.1.jsonl", "not accessible");
|
|
35705
36403
|
}
|
|
35706
36404
|
if (rotated) {
|
|
35707
36405
|
const r = readEventsInto(old, events);
|
|
35708
|
-
if (!r.ok) return
|
|
36406
|
+
if (!r.ok) return unreadable2("events.1.jsonl", r.error);
|
|
35709
36407
|
}
|
|
35710
|
-
const cur = readEventsInto(eventsPath(
|
|
35711
|
-
if (!cur.ok) return
|
|
35712
|
-
const { anchor: useAnchor, ...verifyOpts } = opts ?? {};
|
|
36408
|
+
const cur = readEventsInto(eventsPath(logDir), events);
|
|
36409
|
+
if (!cur.ok) return unreadable2("events.jsonl", cur.error);
|
|
36410
|
+
const { anchor: useAnchor, location: _location, ...verifyOpts } = opts ?? {};
|
|
35713
36411
|
const status2 = verifyChain(events, head.value, genesis.value, { ...verifyOpts, allowRotatedStart: rotated });
|
|
35714
36412
|
if (useAnchor === false || status2.status === "broken") return status2;
|
|
35715
36413
|
const tip = status2.status === "intact" ? { seq: status2.head.seq, hash: status2.head.hash } : null;
|
|
@@ -35728,7 +36426,7 @@ function verifyLogDir(dir, opts) {
|
|
|
35728
36426
|
}
|
|
35729
36427
|
|
|
35730
36428
|
// ../shield/src/procstart.ts
|
|
35731
|
-
import { execFileSync as
|
|
36429
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
35732
36430
|
import { readFileSync as readFileSync23 } from "node:fs";
|
|
35733
36431
|
function processStart(pid, platform = process.platform) {
|
|
35734
36432
|
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
@@ -35740,7 +36438,7 @@ function processStart(pid, platform = process.platform) {
|
|
|
35740
36438
|
return ticks !== void 0 && /^\d+$/.test(ticks) ? `t${ticks}` : null;
|
|
35741
36439
|
}
|
|
35742
36440
|
if (platform === "win32") return null;
|
|
35743
|
-
const out =
|
|
36441
|
+
const out = execFileSync4("/bin/ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "ignore"], env: { PATH: "/usr/bin:/bin", LC_ALL: "C" } }).trim();
|
|
35744
36442
|
return out === "" ? null : `s${out.replace(/\s+/g, " ")}`;
|
|
35745
36443
|
} catch {
|
|
35746
36444
|
return null;
|
|
@@ -35772,9 +36470,9 @@ function holderAlive(pid, start, o = {}) {
|
|
|
35772
36470
|
}
|
|
35773
36471
|
|
|
35774
36472
|
// ../shield/src/events.ts
|
|
35775
|
-
var eventsPath = (dir) =>
|
|
35776
|
-
var oldEventsPath = (dir) =>
|
|
35777
|
-
var lockPath = (dir) =>
|
|
36473
|
+
var eventsPath = (dir) => join32(dir, "events.jsonl");
|
|
36474
|
+
var oldEventsPath = (dir) => join32(dir, "events.1.jsonl");
|
|
36475
|
+
var lockPath = (dir) => join32(dir, "events.lock");
|
|
35778
36476
|
var MAX_EVENT_BYTES = 1024 * 1024;
|
|
35779
36477
|
var MAX_LINE_BYTES = 8 * 1024;
|
|
35780
36478
|
var STALE_LOCK_MS = 1e4;
|
|
@@ -35879,7 +36577,7 @@ function myStart(startOf) {
|
|
|
35879
36577
|
function lockIsStale(lock, d) {
|
|
35880
36578
|
let st;
|
|
35881
36579
|
try {
|
|
35882
|
-
st =
|
|
36580
|
+
st = lstatSync14(lock);
|
|
35883
36581
|
} catch {
|
|
35884
36582
|
return { stale: false, seen: "" };
|
|
35885
36583
|
}
|
|
@@ -35900,7 +36598,7 @@ function lockIsStale(lock, d) {
|
|
|
35900
36598
|
}
|
|
35901
36599
|
function breakLock(lock, seen) {
|
|
35902
36600
|
try {
|
|
35903
|
-
const st =
|
|
36601
|
+
const st = lstatSync14(lock);
|
|
35904
36602
|
if (st.isDirectory()) {
|
|
35905
36603
|
rmdirSync2(lock);
|
|
35906
36604
|
return;
|
|
@@ -35916,8 +36614,8 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35916
36614
|
const take = () => {
|
|
35917
36615
|
let fd = null;
|
|
35918
36616
|
try {
|
|
35919
|
-
fd =
|
|
35920
|
-
|
|
36617
|
+
fd = openSync10(lock, constants9.O_WRONLY | constants9.O_CREAT | constants9.O_EXCL | (constants9.O_NOFOLLOW ?? 0), 384);
|
|
36618
|
+
writeSync7(fd, `${process.pid} ${myStart(d.startOf)}
|
|
35921
36619
|
`);
|
|
35922
36620
|
return true;
|
|
35923
36621
|
} catch (err) {
|
|
@@ -35926,7 +36624,7 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35926
36624
|
} finally {
|
|
35927
36625
|
if (fd !== null) {
|
|
35928
36626
|
try {
|
|
35929
|
-
|
|
36627
|
+
closeSync10(fd);
|
|
35930
36628
|
} catch {
|
|
35931
36629
|
}
|
|
35932
36630
|
}
|
|
@@ -35960,9 +36658,12 @@ function withLock(lock, attempts, fn, d = {}) {
|
|
|
35960
36658
|
var EventLog = class {
|
|
35961
36659
|
constructor(dir, o) {
|
|
35962
36660
|
this.dir = dir;
|
|
35963
|
-
this.
|
|
35964
|
-
this.
|
|
35965
|
-
this.
|
|
36661
|
+
this.locDeps = o.location ?? {};
|
|
36662
|
+
this.loc = resolveLogLocation(dir, this.locDeps);
|
|
36663
|
+
this.logDir = this.loc.ok ? this.loc.dir : dir;
|
|
36664
|
+
this.path = eventsPath(this.logDir);
|
|
36665
|
+
this.old = oldEventsPath(this.logDir);
|
|
36666
|
+
this.lock = lockPath(this.logDir);
|
|
35966
36667
|
this.maxBytes = o.maxBytes ?? MAX_EVENT_BYTES;
|
|
35967
36668
|
this.pid = o.pid ?? process.pid;
|
|
35968
36669
|
this.server = cleanText(o.server, NAME_CHARS2);
|
|
@@ -35974,6 +36675,11 @@ var EventLog = class {
|
|
|
35974
36675
|
this.session = o.session;
|
|
35975
36676
|
}
|
|
35976
36677
|
path;
|
|
36678
|
+
/** The folder that holds the log, its lock and its chain files: the state folder, or a local folder when that one is on a network drive (m19-log). */
|
|
36679
|
+
logDir;
|
|
36680
|
+
loc;
|
|
36681
|
+
prepared = false;
|
|
36682
|
+
locDeps;
|
|
35977
36683
|
old;
|
|
35978
36684
|
lock;
|
|
35979
36685
|
maxBytes;
|
|
@@ -35985,6 +36691,8 @@ var EventLog = class {
|
|
|
35985
36691
|
lockAttempts;
|
|
35986
36692
|
lockDeps;
|
|
35987
36693
|
sessionKey;
|
|
36694
|
+
/** Set while the final "logging is off" event is written: the anchor then carries the time. */
|
|
36695
|
+
offSince;
|
|
35988
36696
|
/** Events not written because the file was full and could not be rotated. */
|
|
35989
36697
|
dropped = 0;
|
|
35990
36698
|
problem = null;
|
|
@@ -36016,7 +36724,12 @@ var EventLog = class {
|
|
|
36016
36724
|
return false;
|
|
36017
36725
|
}
|
|
36018
36726
|
try {
|
|
36019
|
-
|
|
36727
|
+
mkdirSync9(this.dir, { recursive: true });
|
|
36728
|
+
const ready = this.prepare();
|
|
36729
|
+
if (ready !== null) {
|
|
36730
|
+
this.fail(ready);
|
|
36731
|
+
return false;
|
|
36732
|
+
}
|
|
36020
36733
|
if (this.chain) {
|
|
36021
36734
|
const r = withLock(this.lock, this.lockAttempts, () => this.writeChained(parsed.data), this.lockDeps);
|
|
36022
36735
|
if (r.held) return r.value;
|
|
@@ -36032,6 +36745,40 @@ var EventLog = class {
|
|
|
36032
36745
|
return false;
|
|
36033
36746
|
}
|
|
36034
36747
|
}
|
|
36748
|
+
/** Whether the log is in a local folder instead of the state folder, and why (m19-log). */
|
|
36749
|
+
get moved() {
|
|
36750
|
+
return this.loc.ok && this.loc.moved ? { reason: this.loc.reason ?? "" } : null;
|
|
36751
|
+
}
|
|
36752
|
+
/** The folder of the log as decided now, for the line the Shield logs (an error when the folder was refused). */
|
|
36753
|
+
get location() {
|
|
36754
|
+
return this.loc;
|
|
36755
|
+
}
|
|
36756
|
+
/** Make the local folder (mode 0700) and check it before the first write. A problem in words, or null. */
|
|
36757
|
+
prepare() {
|
|
36758
|
+
if (!this.loc.ok) return this.loc.error;
|
|
36759
|
+
if (!this.loc.moved || this.prepared) return null;
|
|
36760
|
+
const r = resolveLogLocation(this.dir, { ...this.locDeps, create: true });
|
|
36761
|
+
if (!r.ok) {
|
|
36762
|
+
this.loc = r;
|
|
36763
|
+
return r.error;
|
|
36764
|
+
}
|
|
36765
|
+
if (r.dir !== this.logDir) return "the event log folder changed since the Shield started";
|
|
36766
|
+
this.prepared = true;
|
|
36767
|
+
return null;
|
|
36768
|
+
}
|
|
36769
|
+
/**
|
|
36770
|
+
* The final event when the user-level setting turns logging off (LG-2.4): written chained, and the anchor
|
|
36771
|
+
* records the time. Written once: when the anchor already holds the time, nothing is added. Returns the time.
|
|
36772
|
+
*/
|
|
36773
|
+
writeOff() {
|
|
36774
|
+
const known = readAnchor(this.dir);
|
|
36775
|
+
if (known.ok && known.anchor?.eventsOffSince !== void 0) return { time: known.anchor.eventsOffSince, written: false };
|
|
36776
|
+
const time3 = this.now().toISOString();
|
|
36777
|
+
this.offSince = time3;
|
|
36778
|
+
const written = this.write({ kind: "alert", severity: "medium", ruleId: "SHIELD", message: `Event logging was turned off by your user-level config ("events": "off") at ${time3}. No later events are written by a Shield.` });
|
|
36779
|
+
this.offSince = void 0;
|
|
36780
|
+
return { time: time3, written };
|
|
36781
|
+
}
|
|
36035
36782
|
encode(e) {
|
|
36036
36783
|
const line = Buffer.from(`${JSON.stringify(e)}
|
|
36037
36784
|
`, "utf8");
|
|
@@ -36053,27 +36800,27 @@ var EventLog = class {
|
|
|
36053
36800
|
return false;
|
|
36054
36801
|
}
|
|
36055
36802
|
}
|
|
36056
|
-
const flags2 =
|
|
36057
|
-
const fd =
|
|
36803
|
+
const flags2 = constants9.O_WRONLY | constants9.O_APPEND | constants9.O_CREAT | (constants9.O_NOFOLLOW ?? 0);
|
|
36804
|
+
const fd = openSync10(this.path, flags2, 384);
|
|
36058
36805
|
try {
|
|
36059
36806
|
if (!fstatSync5(fd).isFile()) {
|
|
36060
36807
|
this.fail(`${this.path} is not a regular file`);
|
|
36061
36808
|
return false;
|
|
36062
36809
|
}
|
|
36063
|
-
|
|
36810
|
+
writeSync7(fd, line);
|
|
36064
36811
|
} finally {
|
|
36065
|
-
|
|
36812
|
+
closeSync10(fd);
|
|
36066
36813
|
}
|
|
36067
36814
|
return true;
|
|
36068
36815
|
}
|
|
36069
36816
|
/** The chained write, with the lock held. Falls back to an unchained line when the chain files are unusable. */
|
|
36070
36817
|
writeChained(event) {
|
|
36071
|
-
const g = loadOrCreateGenesis(this.
|
|
36818
|
+
const g = loadOrCreateGenesis(this.logDir, this.random);
|
|
36072
36819
|
if (!g.ok) {
|
|
36073
36820
|
this.fail(g.error);
|
|
36074
36821
|
return this.append(this.encode(event), true);
|
|
36075
36822
|
}
|
|
36076
|
-
const h = readHead(this.
|
|
36823
|
+
const h = readHead(this.logDir);
|
|
36077
36824
|
if (!h.ok) this.fail(h.error);
|
|
36078
36825
|
const head = h.ok ? h.value : null;
|
|
36079
36826
|
const anchor = readAnchor(this.dir);
|
|
@@ -36087,12 +36834,12 @@ var EventLog = class {
|
|
|
36087
36834
|
return false;
|
|
36088
36835
|
}
|
|
36089
36836
|
if (!this.append(this.encode(chained.data), true)) return false;
|
|
36090
|
-
const w = writeHeadAtomic(this.
|
|
36837
|
+
const w = writeHeadAtomic(this.logDir, { v: 1, genesis: g.value, seq: seq2, hash });
|
|
36091
36838
|
if (!w.ok) this.fail(w.error);
|
|
36092
36839
|
else if (drift) {
|
|
36093
36840
|
this.fail("the event log no longer matches the anchor kept outside the state folder (it was edited or replaced), so the anchor was not moved. Run: exorcist console --verify");
|
|
36094
36841
|
} else {
|
|
36095
|
-
const anchorProblem = writeAnchor(this.dir, { seq: seq2, hash });
|
|
36842
|
+
const anchorProblem = writeAnchor(this.dir, { seq: seq2, hash }, this.offSince !== void 0 ? { eventsOffSince: this.offSince } : {});
|
|
36096
36843
|
if (anchorProblem !== null) this.fail(anchorProblem);
|
|
36097
36844
|
}
|
|
36098
36845
|
return true;
|
|
@@ -36102,7 +36849,7 @@ var EventLog = class {
|
|
|
36102
36849
|
}
|
|
36103
36850
|
size() {
|
|
36104
36851
|
try {
|
|
36105
|
-
return
|
|
36852
|
+
return lstatSync14(this.path).size;
|
|
36106
36853
|
} catch {
|
|
36107
36854
|
return 0;
|
|
36108
36855
|
}
|
|
@@ -36144,7 +36891,7 @@ function parseEventLines(text) {
|
|
|
36144
36891
|
function readFrom(path, from) {
|
|
36145
36892
|
let fd;
|
|
36146
36893
|
try {
|
|
36147
|
-
fd =
|
|
36894
|
+
fd = openSync10(path, constants9.O_RDONLY | (constants9.O_NOFOLLOW ?? 0));
|
|
36148
36895
|
} catch {
|
|
36149
36896
|
return null;
|
|
36150
36897
|
}
|
|
@@ -36171,14 +36918,15 @@ function readFrom(path, from) {
|
|
|
36171
36918
|
if (dropFirst) text = text.slice(text.indexOf("\n") + 1);
|
|
36172
36919
|
return { text, end: start + lastNl + 1, st };
|
|
36173
36920
|
} finally {
|
|
36174
|
-
|
|
36921
|
+
closeSync10(fd);
|
|
36175
36922
|
}
|
|
36176
36923
|
}
|
|
36177
36924
|
var EventTail = class {
|
|
36178
|
-
constructor(dir) {
|
|
36925
|
+
constructor(dir, deps = {}) {
|
|
36179
36926
|
this.dir = dir;
|
|
36180
|
-
|
|
36181
|
-
this.
|
|
36927
|
+
const loc = resolveLogLocation(dir, deps);
|
|
36928
|
+
this.path = loc.ok ? eventsPath(loc.dir) : join32(dir, "events.refused");
|
|
36929
|
+
this.old = loc.ok ? oldEventsPath(loc.dir) : join32(dir, "events.1.refused");
|
|
36182
36930
|
}
|
|
36183
36931
|
cur = null;
|
|
36184
36932
|
skipped = 0;
|
|
@@ -36193,7 +36941,7 @@ var EventTail = class {
|
|
|
36193
36941
|
};
|
|
36194
36942
|
let st = null;
|
|
36195
36943
|
try {
|
|
36196
|
-
st =
|
|
36944
|
+
st = lstatSync14(this.path);
|
|
36197
36945
|
} catch {
|
|
36198
36946
|
st = null;
|
|
36199
36947
|
}
|
|
@@ -36231,10 +36979,10 @@ var EventTail = class {
|
|
|
36231
36979
|
};
|
|
36232
36980
|
|
|
36233
36981
|
// ../shield/src/launch.ts
|
|
36234
|
-
import { createHash as
|
|
36235
|
-
import { existsSync as
|
|
36236
|
-
import { dirname as
|
|
36237
|
-
var sha2563 = (b) =>
|
|
36982
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
36983
|
+
import { existsSync as existsSync16, readFileSync as readFileSync25, statSync as statSync14 } from "node:fs";
|
|
36984
|
+
import { dirname as dirname15, isAbsolute as isAbsolute19, join as join33, parse as parsePath2, relative as relative14, resolve as resolve26, sep as sep7 } from "node:path";
|
|
36985
|
+
var sha2563 = (b) => createHash14("sha256").update(b).digest("hex");
|
|
36238
36986
|
var MAX_HASHED_BYTES = 64 * 1024 * 1024;
|
|
36239
36987
|
var fsReader = (path) => {
|
|
36240
36988
|
try {
|
|
@@ -36256,7 +37004,7 @@ var RUNNERS2 = {
|
|
|
36256
37004
|
bun: ["x"],
|
|
36257
37005
|
pipx: ["run"]
|
|
36258
37006
|
};
|
|
36259
|
-
var
|
|
37007
|
+
var INTERPRETERS3 = /^(node|nodejs|deno|bun|python\d*(\.\d+)?|pythonw|uv|uvx|npx|pnpx|bunx|pnpm|npm|yarn|pipx|java|ruby|php|dotnet|docker|podman|sh|bash|zsh|cmd|powershell|pwsh)$/i;
|
|
36260
37008
|
var baseName3 = (c) => c.split(/[\\/]/).pop()?.replace(/\.(cmd|exe)$/i, "") ?? c;
|
|
36261
37009
|
function packageSpec(command, args) {
|
|
36262
37010
|
const sub = RUNNERS2[baseName3(command)];
|
|
@@ -36307,17 +37055,17 @@ function launchEntryOf(entry) {
|
|
|
36307
37055
|
}
|
|
36308
37056
|
var PROJECT_MARKERS3 = [".git", ".kiro"];
|
|
36309
37057
|
function configLabel(configPath) {
|
|
36310
|
-
const abs =
|
|
37058
|
+
const abs = resolve26(configPath);
|
|
36311
37059
|
const { root } = parsePath2(abs);
|
|
36312
|
-
for (let dir =
|
|
36313
|
-
if (PROJECT_MARKERS3.some((m) =>
|
|
36314
|
-
if (dir === root ||
|
|
37060
|
+
for (let dir = dirname15(abs); ; dir = dirname15(dir)) {
|
|
37061
|
+
if (PROJECT_MARKERS3.some((m) => existsSync16(join33(dir, m)))) return relative14(dir, abs).split(sep7).join("/");
|
|
37062
|
+
if (dir === root || dirname15(dir) === dir) return abs;
|
|
36315
37063
|
}
|
|
36316
37064
|
}
|
|
36317
37065
|
function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
36318
37066
|
const fileLine = (label, value) => {
|
|
36319
37067
|
if (value.length === 0 || value.length > 4096) return void 0;
|
|
36320
|
-
const path = isAbsolute19(value) ? value :
|
|
37068
|
+
const path = isAbsolute19(value) ? value : resolve26(cwd, value);
|
|
36321
37069
|
const f = reader(path);
|
|
36322
37070
|
if (f.kind !== "file") return void 0;
|
|
36323
37071
|
const content = f.size <= MAX_HASHED_BYTES ? `sha256:${sha2563(f.read())}` : `size:${f.size} mtime:${Math.round(f.mtimeMs)}`;
|
|
@@ -36325,7 +37073,7 @@ function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
|
36325
37073
|
};
|
|
36326
37074
|
const parts2 = [];
|
|
36327
37075
|
const commandIsPath = /[\\/]/.test(command);
|
|
36328
|
-
const own = commandIsPath && !
|
|
37076
|
+
const own = commandIsPath && !INTERPRETERS3.test(baseName3(command)) ? fileLine("command", command) : void 0;
|
|
36329
37077
|
parts2.push(own ?? `command ${command}`);
|
|
36330
37078
|
const spec2 = packageSpec(command, args);
|
|
36331
37079
|
if (spec2) parts2.push(`package ${spec2}`);
|
|
@@ -36367,11 +37115,11 @@ function checkLaunch(s, pin, now = /* @__PURE__ */ new Date()) {
|
|
|
36367
37115
|
// ../shield/src/ai-review.ts
|
|
36368
37116
|
var NONE = { block: [], warn: [] };
|
|
36369
37117
|
function withTimeout(p, ms) {
|
|
36370
|
-
return new Promise((
|
|
37118
|
+
return new Promise((resolve42, reject2) => {
|
|
36371
37119
|
const t2 = setTimeout(() => reject2(new Error(`no answer within ${ms} ms`)), ms);
|
|
36372
37120
|
p.then((v) => {
|
|
36373
37121
|
clearTimeout(t2);
|
|
36374
|
-
|
|
37122
|
+
resolve42(v);
|
|
36375
37123
|
}, (e) => {
|
|
36376
37124
|
clearTimeout(t2);
|
|
36377
37125
|
reject2(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -36449,14 +37197,35 @@ async function prepareShield(o) {
|
|
|
36449
37197
|
const stderr = o.stderr ?? process.stderr;
|
|
36450
37198
|
const log = (s) => void stderr.write(`[exorcist] ${s}
|
|
36451
37199
|
`);
|
|
36452
|
-
|
|
37200
|
+
mkdirSync10(o.dir, { recursive: true });
|
|
36453
37201
|
const policy = loadPolicy(policyPath(o.dir));
|
|
36454
37202
|
if (!policy.ok) {
|
|
36455
37203
|
log(policy.error);
|
|
36456
37204
|
return FAIL_CLOSED_EXIT;
|
|
36457
37205
|
}
|
|
36458
37206
|
for (const n of policy.notes) log(n);
|
|
36459
|
-
const
|
|
37207
|
+
const eventLog = new EventLog(o.dir, { server: o.server });
|
|
37208
|
+
const events = policy.policy.events === "off" ? null : eventLog;
|
|
37209
|
+
const envSwitch = process.env["EXORCIST_EVENTS"];
|
|
37210
|
+
if (events === null) {
|
|
37211
|
+
const off = eventLog.writeOff();
|
|
37212
|
+
log(`Event logging is turned off by your user-level config ("events": "off")${off.written ? `; a final event was written (${off.time})` : `, since ${off.time}`}.`);
|
|
37213
|
+
if (eventLog.problem) log(`The console event log: ${eventLog.problem}.`);
|
|
37214
|
+
if (envSwitch !== void 0 && envSwitch !== "") log("The environment variable EXORCIST_EVENTS is ignored.");
|
|
37215
|
+
} else {
|
|
37216
|
+
const where2 = eventLog.location;
|
|
37217
|
+
if (where2.ok && where2.moved) {
|
|
37218
|
+
log(locationNote(where2));
|
|
37219
|
+
const p = writeLocationPointer(o.dir, where2.dir);
|
|
37220
|
+
if (p !== null) log(`The note events.location could not be left in the state folder: ${p}.`);
|
|
37221
|
+
} else if (!where2.ok) {
|
|
37222
|
+
log(`The event log was not written: ${where2.error}. The Shield keeps protecting; only the live console misses events.`);
|
|
37223
|
+
}
|
|
37224
|
+
if (envSwitch !== void 0 && envSwitch !== "") {
|
|
37225
|
+
log('The environment variable EXORCIST_EVENTS was set and is ignored: only "events": "off" in your user-level policy turns logging off.');
|
|
37226
|
+
eventLog.write({ kind: "alert", severity: "medium", ruleId: "SHIELD", message: 'The environment variable EXORCIST_EVENTS was set and ignored. The user-level setting ("events": "off" in your user-level policy) is the way to turn logging off; a project or an MCP config cannot.' });
|
|
37227
|
+
}
|
|
37228
|
+
}
|
|
36460
37229
|
let eventProblemShown = false;
|
|
36461
37230
|
const eventProblem = () => {
|
|
36462
37231
|
if (events?.problem && !eventProblemShown) {
|
|
@@ -36491,13 +37260,13 @@ async function prepareShield(o) {
|
|
|
36491
37260
|
log(canariesFile.error);
|
|
36492
37261
|
return FAIL_CLOSED_EXIT;
|
|
36493
37262
|
}
|
|
36494
|
-
if (policy.policy.canaries && !
|
|
37263
|
+
if (policy.policy.canaries && !existsSync17(canariesAt)) log(`The policy names canary records at ${canariesAt}, but there is no such file; no canary traps are active.`);
|
|
36495
37264
|
const canaries = canariesFile.canaries.map((r) => ({ token: r.token, file: r.file }));
|
|
36496
37265
|
if (canaries.length > 0) log(`Watching for ${canaries.length} canary token${canaries.length === 1 ? "" : "s"} (EX-022).`);
|
|
36497
37266
|
let lockExpected;
|
|
36498
37267
|
let lockLaunch;
|
|
36499
|
-
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [
|
|
36500
|
-
if (lockFile &&
|
|
37268
|
+
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [dirname16(o.configPath)] : [], process.cwd()]) : o.lockPath;
|
|
37269
|
+
if (lockFile && existsSync17(lockFile)) {
|
|
36501
37270
|
let text;
|
|
36502
37271
|
try {
|
|
36503
37272
|
text = readFileSync26(lockFile, "utf8");
|
|
@@ -36830,16 +37599,16 @@ async function runProxy(o) {
|
|
|
36830
37599
|
});
|
|
36831
37600
|
prepared.attach(run3);
|
|
36832
37601
|
const stopWatch = prepared.watch(run3);
|
|
36833
|
-
return await new Promise((
|
|
37602
|
+
return await new Promise((resolve42) => {
|
|
36834
37603
|
child.on("error", (err) => {
|
|
36835
37604
|
stopWatch();
|
|
36836
37605
|
log(`Could not start "${o.command}": ${err.message}`);
|
|
36837
|
-
|
|
37606
|
+
resolve42(127);
|
|
36838
37607
|
});
|
|
36839
37608
|
child.on("close", (code3) => {
|
|
36840
37609
|
stopWatch();
|
|
36841
37610
|
for (const l of fromServer.flush()) fromServerLine(l);
|
|
36842
|
-
void serverQueue.then(() =>
|
|
37611
|
+
void serverQueue.then(() => resolve42(code3 ?? 1));
|
|
36843
37612
|
});
|
|
36844
37613
|
});
|
|
36845
37614
|
}
|
|
@@ -37044,7 +37813,7 @@ async function runRemoteProxy(o) {
|
|
|
37044
37813
|
const fromClient = new LineSplitter();
|
|
37045
37814
|
prepared.attach(deliver);
|
|
37046
37815
|
const stopWatch = prepared.watch(deliver);
|
|
37047
|
-
return await new Promise((
|
|
37816
|
+
return await new Promise((resolve42) => {
|
|
37048
37817
|
stdin.on("data", (chunk) => {
|
|
37049
37818
|
for (const l of fromClient.push(chunk)) deliver(engine.onClientLine(l));
|
|
37050
37819
|
});
|
|
@@ -37064,15 +37833,15 @@ async function runRemoteProxy(o) {
|
|
|
37064
37833
|
} catch {
|
|
37065
37834
|
}
|
|
37066
37835
|
}
|
|
37067
|
-
|
|
37836
|
+
resolve42(0);
|
|
37068
37837
|
})();
|
|
37069
37838
|
});
|
|
37070
37839
|
});
|
|
37071
37840
|
}
|
|
37072
37841
|
|
|
37073
37842
|
// ../shield/src/locate.ts
|
|
37074
|
-
import { existsSync as
|
|
37075
|
-
import { dirname as
|
|
37843
|
+
import { existsSync as existsSync18, readdirSync as readdirSync11, statSync as statSync16 } from "node:fs";
|
|
37844
|
+
import { dirname as dirname17, isAbsolute as isAbsolute20, join as join34, parse as parse2, resolve as resolve27 } from "node:path";
|
|
37076
37845
|
import { fileURLToPath } from "node:url";
|
|
37077
37846
|
function hasDefinitions(dir) {
|
|
37078
37847
|
try {
|
|
@@ -37084,28 +37853,28 @@ function hasDefinitions(dir) {
|
|
|
37084
37853
|
function findDefinitionsDir(o) {
|
|
37085
37854
|
const env = o.env ?? process.env;
|
|
37086
37855
|
const cwd = o.cwd ?? process.cwd();
|
|
37087
|
-
if (o.explicit) return
|
|
37856
|
+
if (o.explicit) return resolve27(cwd, o.explicit);
|
|
37088
37857
|
const fromEnv = env["EXORCIST_DEFINITIONS"];
|
|
37089
|
-
if (fromEnv) return
|
|
37858
|
+
if (fromEnv) return resolve27(cwd, fromEnv);
|
|
37090
37859
|
const installed = findActiveInstalledSet({ env, ...o.publicKeyPem ? { publicKeyPem: o.publicKeyPem } : {} });
|
|
37091
37860
|
if (installed && hasDefinitions(installed.definitionsDir)) return installed.definitionsDir;
|
|
37092
|
-
const here =
|
|
37093
|
-
const candidates = [
|
|
37861
|
+
const here = dirname17(fileURLToPath(o.callerUrl));
|
|
37862
|
+
const candidates = [join34(here, "..", "definitions"), join34(here, "..", "..", "..", "definitions"), join34(cwd, "definitions")];
|
|
37094
37863
|
return candidates.find(hasDefinitions) ?? null;
|
|
37095
37864
|
}
|
|
37096
37865
|
var PROJECT_MARKERS4 = [".exorcist", ".kiro", ".git"];
|
|
37097
37866
|
function findStateDir(o = {}) {
|
|
37098
37867
|
const env = o.env ?? process.env;
|
|
37099
|
-
const cwd =
|
|
37100
|
-
if (o.explicit) return
|
|
37868
|
+
const cwd = resolve27(o.cwd ?? process.cwd());
|
|
37869
|
+
if (o.explicit) return resolve27(cwd, o.explicit);
|
|
37101
37870
|
const fromEnv = env["EXORCIST_DIR"];
|
|
37102
|
-
if (fromEnv) return isAbsolute20(fromEnv) ? fromEnv :
|
|
37871
|
+
if (fromEnv) return isAbsolute20(fromEnv) ? fromEnv : resolve27(cwd, fromEnv);
|
|
37103
37872
|
const { root } = parse2(cwd);
|
|
37104
|
-
for (let dir = cwd; ; dir =
|
|
37105
|
-
if (PROJECT_MARKERS4.some((m) =>
|
|
37106
|
-
if (dir === root ||
|
|
37873
|
+
for (let dir = cwd; ; dir = dirname17(dir)) {
|
|
37874
|
+
if (PROJECT_MARKERS4.some((m) => existsSync18(join34(dir, m)))) return join34(dir, ".exorcist");
|
|
37875
|
+
if (dir === root || dirname17(dir) === dir) break;
|
|
37107
37876
|
}
|
|
37108
|
-
return
|
|
37877
|
+
return join34(cwd, ".exorcist");
|
|
37109
37878
|
}
|
|
37110
37879
|
|
|
37111
37880
|
// ../shield/src/wrap.ts
|
|
@@ -37288,8 +38057,8 @@ var DEFAULT_DIR = "the project's .exorcist folder (or EXORCIST_DIR)";
|
|
|
37288
38057
|
// src/commands/on-access.ts
|
|
37289
38058
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
37290
38059
|
import { execFile as execFile3 } from "node:child_process";
|
|
37291
|
-
import { existsSync as
|
|
37292
|
-
import { resolve as
|
|
38060
|
+
import { existsSync as existsSync19, statSync as statSync17 } from "node:fs";
|
|
38061
|
+
import { resolve as resolve28 } from "node:path";
|
|
37293
38062
|
import { createInterface } from "node:readline";
|
|
37294
38063
|
var ALLOW_READ_HELP = `Usage: exorcist allow-read <file>
|
|
37295
38064
|
|
|
@@ -37481,8 +38250,8 @@ ${ALLOW_READ_HELP}`);
|
|
|
37481
38250
|
io.err("exorcist allow-read only runs in an interactive terminal: the user must review the file and run it themselves. Nothing was allowed.");
|
|
37482
38251
|
return 1;
|
|
37483
38252
|
}
|
|
37484
|
-
const file =
|
|
37485
|
-
if (!
|
|
38253
|
+
const file = resolve28(target);
|
|
38254
|
+
if (!existsSync19(file) || !statSync17(file).isFile()) {
|
|
37486
38255
|
io.err(`Not a readable file: ${shownName(target)}`);
|
|
37487
38256
|
return 1;
|
|
37488
38257
|
}
|
|
@@ -37589,7 +38358,7 @@ ${APPROVE_HELP}`);
|
|
|
37589
38358
|
return 1;
|
|
37590
38359
|
}
|
|
37591
38360
|
const file = policyPath(stateDir(str4(p.values["dir"])));
|
|
37592
|
-
if (!
|
|
38361
|
+
if (!existsSync20(file)) {
|
|
37593
38362
|
io.err(`There is no policy file at ${file}.`);
|
|
37594
38363
|
return 1;
|
|
37595
38364
|
}
|
|
@@ -37650,7 +38419,7 @@ async function alertsCommand(argv, io) {
|
|
|
37650
38419
|
if (!h.ok) io.out(`Event log head: unreadable (${h.error.replace(/[^\x20-\x7e]/g, "?")}).`);
|
|
37651
38420
|
else io.out(h.value === null ? "Event log head: none yet (nothing has been logged in this folder)." : `Event log head: ${h.value.hash} (event ${h.value.seq})`);
|
|
37652
38421
|
};
|
|
37653
|
-
if (!
|
|
38422
|
+
if (!existsSync20(file)) {
|
|
37654
38423
|
io.out("No alerts.");
|
|
37655
38424
|
printHead();
|
|
37656
38425
|
return 0;
|
|
@@ -37670,16 +38439,16 @@ async function alertsCommand(argv, io) {
|
|
|
37670
38439
|
|
|
37671
38440
|
// src/commands/baseline.ts
|
|
37672
38441
|
import { statSync as statSync20, writeFileSync as writeFileSync9 } from "node:fs";
|
|
37673
|
-
import { join as
|
|
38442
|
+
import { join as join38, resolve as resolve31 } from "node:path";
|
|
37674
38443
|
|
|
37675
38444
|
// src/commands/scan.ts
|
|
37676
|
-
import { existsSync as
|
|
37677
|
-
import { basename as
|
|
38445
|
+
import { existsSync as existsSync22, readFileSync as readFileSync29, realpathSync as realpathSync12, statSync as statSync19, writeFileSync as writeFileSync8 } from "node:fs";
|
|
38446
|
+
import { basename as basename12, dirname as dirname18, isAbsolute as isAbsolute21, join as join37, relative as relative15, resolve as resolve30 } from "node:path";
|
|
37678
38447
|
init_bedrock();
|
|
37679
38448
|
|
|
37680
38449
|
// src/commands/detonate.ts
|
|
37681
|
-
import { existsSync as
|
|
37682
|
-
import { basename as
|
|
38450
|
+
import { existsSync as existsSync21, readFileSync as readFileSync28, statSync as statSync18 } from "node:fs";
|
|
38451
|
+
import { basename as basename11, join as join35, resolve as resolve29 } from "node:path";
|
|
37683
38452
|
init_bedrock();
|
|
37684
38453
|
var DEFAULT_DETONATE_MAX = 10;
|
|
37685
38454
|
var EX024 = "EX-024";
|
|
@@ -37717,7 +38486,7 @@ async function makeChamberClient(io, flag, real) {
|
|
|
37717
38486
|
return false;
|
|
37718
38487
|
}
|
|
37719
38488
|
}
|
|
37720
|
-
var RANK4 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
38489
|
+
var RANK4 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
37721
38490
|
function pickTargets(findings, max) {
|
|
37722
38491
|
const best = /* @__PURE__ */ new Map();
|
|
37723
38492
|
for (const f of findings) {
|
|
@@ -37758,12 +38527,12 @@ async function runDetonations(root, findings, client, max, def) {
|
|
|
37758
38527
|
for (const t2 of targets) {
|
|
37759
38528
|
let text;
|
|
37760
38529
|
try {
|
|
37761
|
-
text = readFileSync28(
|
|
38530
|
+
text = readFileSync28(join35(root, t2.file), "utf8");
|
|
37762
38531
|
} catch {
|
|
37763
38532
|
tally.inconclusive++;
|
|
37764
38533
|
continue;
|
|
37765
38534
|
}
|
|
37766
|
-
const r = await detonate(text, "file", client, { fileName:
|
|
38535
|
+
const r = await detonate(text, "file", client, { fileName: basename11(t2.file) });
|
|
37767
38536
|
calls += r.modelCalls;
|
|
37768
38537
|
tally[r.verdict]++;
|
|
37769
38538
|
reports.push({ file: t2.file, report: r });
|
|
@@ -37821,8 +38590,8 @@ ${DETONATE_HELP}`);
|
|
|
37821
38590
|
io.err(`Unknown format "${format}". Use text or json.`);
|
|
37822
38591
|
return 2;
|
|
37823
38592
|
}
|
|
37824
|
-
const abs =
|
|
37825
|
-
if (!
|
|
38593
|
+
const abs = resolve29(target);
|
|
38594
|
+
if (!existsSync21(abs) || !statSync18(abs).isFile()) {
|
|
37826
38595
|
io.err(`File not found: ${target}`);
|
|
37827
38596
|
return 2;
|
|
37828
38597
|
}
|
|
@@ -37832,7 +38601,7 @@ ${DETONATE_HELP}`);
|
|
|
37832
38601
|
}
|
|
37833
38602
|
const client = await makeChamberClient(io, "exorcist detonate", deps.client);
|
|
37834
38603
|
if (client === false) return 2;
|
|
37835
|
-
const report = await detonate(readFileSync28(abs, "utf8"), placement, client, { fileName:
|
|
38604
|
+
const report = await detonate(readFileSync28(abs, "utf8"), placement, client, { fileName: basename11(abs) });
|
|
37836
38605
|
if (format === "json") io.out(`${JSON.stringify({ file: target, model: modelIdFor("haiku"), ...report }, null, 2)}
|
|
37837
38606
|
`);
|
|
37838
38607
|
else io.out(renderTranscript(target, report));
|
|
@@ -37856,8 +38625,204 @@ function warnIfStale(io, o) {
|
|
|
37856
38625
|
);
|
|
37857
38626
|
}
|
|
37858
38627
|
|
|
38628
|
+
// src/home.ts
|
|
38629
|
+
import { closeSync as closeSync11, constants as constants10, fstatSync as fstatSync6, lstatSync as lstatSync15, openSync as openSync11, readdirSync as readdirSync12, readSync as readSync6 } from "node:fs";
|
|
38630
|
+
import { homedir as homedir9 } from "node:os";
|
|
38631
|
+
import { join as join36 } from "node:path";
|
|
38632
|
+
var HOME_MAX_BYTES = 1048576;
|
|
38633
|
+
var MAX_ENTRIES3 = 200;
|
|
38634
|
+
var CLINE_KEY = "saoudrizwan.claude-dev";
|
|
38635
|
+
var loadNodeSqlite = async () => {
|
|
38636
|
+
const spec2 = "node:sqlite";
|
|
38637
|
+
try {
|
|
38638
|
+
const mod = await import(spec2);
|
|
38639
|
+
const ctor = typeof mod === "object" && mod !== null ? mod.DatabaseSync : void 0;
|
|
38640
|
+
return typeof ctor === "function" ? mod : null;
|
|
38641
|
+
} catch {
|
|
38642
|
+
return null;
|
|
38643
|
+
}
|
|
38644
|
+
};
|
|
38645
|
+
function homeFolder(env = process.env) {
|
|
38646
|
+
const forced = env["EXORCIST_HOME"];
|
|
38647
|
+
return forced !== void 0 && forced !== "" ? forced : homedir9();
|
|
38648
|
+
}
|
|
38649
|
+
function readNoFollow(abs) {
|
|
38650
|
+
let st;
|
|
38651
|
+
try {
|
|
38652
|
+
st = lstatSync15(abs);
|
|
38653
|
+
} catch {
|
|
38654
|
+
return { kind: "missing" };
|
|
38655
|
+
}
|
|
38656
|
+
if (st.isSymbolicLink()) return { kind: "link" };
|
|
38657
|
+
if (!st.isFile()) return { kind: "not-file" };
|
|
38658
|
+
if (st.size > HOME_MAX_BYTES) return { kind: "too-large", size: st.size };
|
|
38659
|
+
let fd;
|
|
38660
|
+
try {
|
|
38661
|
+
fd = openSync11(abs, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0));
|
|
38662
|
+
} catch (e) {
|
|
38663
|
+
const code3 = e.code ?? "error";
|
|
38664
|
+
return code3 === "ELOOP" ? { kind: "link" } : { kind: "error", code: code3 };
|
|
38665
|
+
}
|
|
38666
|
+
try {
|
|
38667
|
+
const fst = fstatSync6(fd);
|
|
38668
|
+
if (!fst.isFile()) return { kind: "not-file" };
|
|
38669
|
+
if (fst.size > HOME_MAX_BYTES) return { kind: "too-large", size: fst.size };
|
|
38670
|
+
const buf = Buffer.alloc(HOME_MAX_BYTES + 1);
|
|
38671
|
+
let got = 0;
|
|
38672
|
+
for (; ; ) {
|
|
38673
|
+
const n = readSync6(fd, buf, got, buf.length - got, null);
|
|
38674
|
+
if (n === 0) break;
|
|
38675
|
+
got += n;
|
|
38676
|
+
if (got > HOME_MAX_BYTES) return { kind: "too-large", size: got };
|
|
38677
|
+
}
|
|
38678
|
+
return { kind: "ok", text: buf.subarray(0, got).toString("utf8") };
|
|
38679
|
+
} catch (e) {
|
|
38680
|
+
return { kind: "error", code: e.code ?? "error" };
|
|
38681
|
+
} finally {
|
|
38682
|
+
closeSync11(fd);
|
|
38683
|
+
}
|
|
38684
|
+
}
|
|
38685
|
+
function unreadable(file, kind) {
|
|
38686
|
+
return {
|
|
38687
|
+
source: "signature",
|
|
38688
|
+
ruleId: kind === "cline" ? "EX-007" : "EX-033",
|
|
38689
|
+
title: "Home settings file in an unknown format, not checked",
|
|
38690
|
+
severity: "medium",
|
|
38691
|
+
file,
|
|
38692
|
+
line: 1,
|
|
38693
|
+
col: 1,
|
|
38694
|
+
span: "unknown format, not checked",
|
|
38695
|
+
owasp: ["ASI02 Inadequate Human-in-the-Loop Controls", "LLM06:2025 Excessive Agency"],
|
|
38696
|
+
fix: "exorcist scan --home could not read this agent settings file, so its approval rules were not checked. Open it and check what it allows without asking."
|
|
38697
|
+
};
|
|
38698
|
+
}
|
|
38699
|
+
function tooLarge(file, size) {
|
|
38700
|
+
return {
|
|
38701
|
+
source: "signature",
|
|
38702
|
+
ruleId: "EX-026",
|
|
38703
|
+
title: "Home settings file too large to check",
|
|
38704
|
+
severity: "medium",
|
|
38705
|
+
file,
|
|
38706
|
+
line: 1,
|
|
38707
|
+
col: 1,
|
|
38708
|
+
span: `${(size / HOME_MAX_BYTES).toFixed(1)} MiB, not checked`,
|
|
38709
|
+
owasp: ["LLM01:2025 Prompt Injection", "ASI03 Prompt Injection via External Content"],
|
|
38710
|
+
fix: "This agent settings file is over 1 MiB, so exorcist scan --home did not read it. Settings files are far smaller: open it and check what it holds."
|
|
38711
|
+
};
|
|
38712
|
+
}
|
|
38713
|
+
var ANALYSE = { kiro: kiroPermissionsFindings, agent: kiroAgentFindings, cline: clineFindings };
|
|
38714
|
+
var UNREADABLE = { kiro: "Kiro's permissions", agent: "the Kiro agent profile", cline: "Cline's settings" };
|
|
38715
|
+
function entries(dir) {
|
|
38716
|
+
try {
|
|
38717
|
+
return readdirSync12(dir, { withFileTypes: true }).slice(0, MAX_ENTRIES3).map((d) => ({ name: d.name, dir: d.isDirectory(), file: d.isFile(), link: d.isSymbolicLink() })).sort((a, b) => a.name.localeCompare(b.name));
|
|
38718
|
+
} catch {
|
|
38719
|
+
return [];
|
|
38720
|
+
}
|
|
38721
|
+
}
|
|
38722
|
+
function vscdbPath(o) {
|
|
38723
|
+
const tail = ["Code", "User", "globalStorage", "state.vscdb"];
|
|
38724
|
+
const platform = o.platform ?? process.platform;
|
|
38725
|
+
if (platform === "darwin") return { abs: join36(o.home, "Library", "Application Support", ...tail), shown: `~/Library/Application Support/${tail.join("/")}` };
|
|
38726
|
+
if (platform === "win32") {
|
|
38727
|
+
const appData = o.appData ?? process.env["APPDATA"] ?? join36(o.home, "AppData", "Roaming");
|
|
38728
|
+
return { abs: join36(appData, ...tail), shown: `%APPDATA%/${tail.join("/")}` };
|
|
38729
|
+
}
|
|
38730
|
+
return { abs: join36(o.home, ".config", ...tail), shown: `~/.config/${tail.join("/")}` };
|
|
38731
|
+
}
|
|
38732
|
+
async function scanHome(o) {
|
|
38733
|
+
const out = { findings: [], notes: [], read: [] };
|
|
38734
|
+
const shown2 = (s) => displayFileName(s);
|
|
38735
|
+
const take = (abs, file, kind) => {
|
|
38736
|
+
const r = readNoFollow(abs);
|
|
38737
|
+
if (r.kind === "missing" || r.kind === "not-file") return;
|
|
38738
|
+
if (r.kind === "link") {
|
|
38739
|
+
out.notes.push(`${shown2(file)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38740
|
+
return;
|
|
38741
|
+
}
|
|
38742
|
+
if (r.kind === "too-large") {
|
|
38743
|
+
out.notes.push(`${shown2(file)} was not read: it is larger than 1 MiB.`);
|
|
38744
|
+
out.findings.push(tooLarge(file, r.size));
|
|
38745
|
+
return;
|
|
38746
|
+
}
|
|
38747
|
+
if (r.kind === "error") {
|
|
38748
|
+
out.notes.push(`Could not read ${shown2(file)} (${r.code}).`);
|
|
38749
|
+
return;
|
|
38750
|
+
}
|
|
38751
|
+
out.read.push(file);
|
|
38752
|
+
judge(r.text, file, kind);
|
|
38753
|
+
};
|
|
38754
|
+
const judge = (text, file, kind) => {
|
|
38755
|
+
const res = ANALYSE[kind](text, file);
|
|
38756
|
+
if (res.ok) out.findings.push(...res.findings);
|
|
38757
|
+
else {
|
|
38758
|
+
out.notes.push(`Could not read ${UNREADABLE[kind]} (${res.reason}): ${shown2(file)}.`);
|
|
38759
|
+
out.findings.push(unreadable(file, kind));
|
|
38760
|
+
}
|
|
38761
|
+
};
|
|
38762
|
+
take(join36(o.home, ".kiro", "settings", "permissions.yaml"), "~/.kiro/settings/permissions.yaml", "kiro");
|
|
38763
|
+
for (const e of entries(join36(o.home, ".kiro", "workspace-roots"))) {
|
|
38764
|
+
const file = `~/.kiro/workspace-roots/${e.name}/permissions.yaml`;
|
|
38765
|
+
if (e.link) out.notes.push(`${shown2(`~/.kiro/workspace-roots/${e.name}`)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38766
|
+
else if (e.dir) take(join36(o.home, ".kiro", "workspace-roots", e.name, "permissions.yaml"), file, "kiro");
|
|
38767
|
+
}
|
|
38768
|
+
for (const e of entries(join36(o.home, ".kiro", "agents"))) {
|
|
38769
|
+
if (!e.name.endsWith(".json")) continue;
|
|
38770
|
+
const file = `~/.kiro/agents/${e.name}`;
|
|
38771
|
+
if (e.link) out.notes.push(`${shown2(file)} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38772
|
+
else if (e.file) take(join36(o.home, ".kiro", "agents", e.name), file, "agent");
|
|
38773
|
+
}
|
|
38774
|
+
take(join36(o.home, ".cline", "data", "globalState.json"), "~/.cline/data/globalState.json", "cline");
|
|
38775
|
+
await readVscdb(o, out, judge);
|
|
38776
|
+
return out;
|
|
38777
|
+
}
|
|
38778
|
+
async function readVscdb(o, out, judge) {
|
|
38779
|
+
const { abs, shown: shown2 } = vscdbPath(o);
|
|
38780
|
+
let st;
|
|
38781
|
+
try {
|
|
38782
|
+
st = lstatSync15(abs);
|
|
38783
|
+
} catch {
|
|
38784
|
+
return;
|
|
38785
|
+
}
|
|
38786
|
+
if (st.isSymbolicLink()) {
|
|
38787
|
+
out.notes.push(`${shown2} was not read: it is a symbolic link, and --home does not follow links.`);
|
|
38788
|
+
return;
|
|
38789
|
+
}
|
|
38790
|
+
if (!st.isFile()) return;
|
|
38791
|
+
const mod = await (o.loadSqlite ?? loadNodeSqlite)();
|
|
38792
|
+
if (!mod) {
|
|
38793
|
+
out.notes.push(`Could not read ${shown2}: this Node.js has no node:sqlite (Node 22.5 or later has it).`);
|
|
38794
|
+
return;
|
|
38795
|
+
}
|
|
38796
|
+
let value;
|
|
38797
|
+
try {
|
|
38798
|
+
const db = new mod.DatabaseSync(abs, { readOnly: true });
|
|
38799
|
+
try {
|
|
38800
|
+
const row = db.prepare("SELECT value FROM ItemTable WHERE key = ?").get(CLINE_KEY);
|
|
38801
|
+
value = typeof row === "object" && row !== null ? row.value : void 0;
|
|
38802
|
+
} finally {
|
|
38803
|
+
db.close();
|
|
38804
|
+
}
|
|
38805
|
+
} catch {
|
|
38806
|
+
out.notes.push(`Could not read ${shown2}: it is not a readable SQLite database.`);
|
|
38807
|
+
return;
|
|
38808
|
+
}
|
|
38809
|
+
if (value === void 0 || value === null) return;
|
|
38810
|
+
const text = typeof value === "string" ? value : value instanceof Uint8Array ? Buffer.from(value).toString("utf8") : null;
|
|
38811
|
+
if (text === null) {
|
|
38812
|
+
out.notes.push(`Could not read Cline's settings (unknown format): ${shown2}.`);
|
|
38813
|
+
return;
|
|
38814
|
+
}
|
|
38815
|
+
if (Buffer.byteLength(text, "utf8") > HOME_MAX_BYTES) {
|
|
38816
|
+
out.notes.push(`${shown2} was not read: Cline's settings in it are larger than 1 MiB.`);
|
|
38817
|
+
out.findings.push(tooLarge(shown2, Buffer.byteLength(text, "utf8")));
|
|
38818
|
+
return;
|
|
38819
|
+
}
|
|
38820
|
+
out.read.push(shown2);
|
|
38821
|
+
judge(text, shown2, "cline");
|
|
38822
|
+
}
|
|
38823
|
+
|
|
37859
38824
|
// src/commands/scan.ts
|
|
37860
|
-
var RANK5 = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
38825
|
+
var RANK5 = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
37861
38826
|
var SEVERITY_RANK2 = RANK5;
|
|
37862
38827
|
var FORMATS = ["text", "json", "sarif", "markdown", "badge"];
|
|
37863
38828
|
var MAX_AI_CALLS_PER_FILE = 2 * MAX_SPANS_PER_FILE;
|
|
@@ -37870,8 +38835,9 @@ Options:
|
|
|
37870
38835
|
--format <text|json|sarif|markdown|badge>
|
|
37871
38836
|
Output format (default: text). "badge" writes an
|
|
37872
38837
|
SVG README badge: "exorcised" or "possessed".
|
|
37873
|
-
--fail-on <critical|high|medium|low|none>
|
|
37874
|
-
Exit 1 if a finding is at least this bad (default: high)
|
|
38838
|
+
--fail-on <critical|high|medium|low|info|none>
|
|
38839
|
+
Exit 1 if a finding is at least this bad (default: high).
|
|
38840
|
+
Info findings never fail a scan unless --fail-on info is given.
|
|
37875
38841
|
--ignore <path> Skip a path prefix (repeatable).
|
|
37876
38842
|
--ignore-file <file> Skip the path prefixes listed in a file you name, one per
|
|
37877
38843
|
line. The file should live outside the scanned folder.
|
|
@@ -37896,6 +38862,8 @@ Options:
|
|
|
37896
38862
|
harmful. Nothing is executed. Needs AWS credentials and AWS_REGION;
|
|
37897
38863
|
at most 2 model calls per file. Off by default.
|
|
37898
38864
|
--detonate-max <n> Detonate at most n files (default ${DEFAULT_DETONATE_MAX})
|
|
38865
|
+
--home Opt-in, off by default: also read Kiro and Cline agent settings in your home folder.
|
|
38866
|
+
Only a fixed list of files is read (see REFERENCE, "--home").
|
|
37899
38867
|
Inline suppression (only with --trust-repo-ignores): a comment on the same line as a finding, or on the line
|
|
37900
38868
|
before it, silences one rule on that line, and the reason is listed in the report:
|
|
37901
38869
|
// exorcist-ignore EX-012: reviewed, this is documentation
|
|
@@ -37903,10 +38871,10 @@ Openers: // # <!-- /* -- ; A reason is required. Hidden characters (EX-00
|
|
|
37903
38871
|
secrets (EX-011) cannot be silenced this way. The comment's own text is still scanned.
|
|
37904
38872
|
`;
|
|
37905
38873
|
function readIgnoreFile(root) {
|
|
37906
|
-
return readIgnoreEntries(
|
|
38874
|
+
return readIgnoreEntries(join37(root, ".exorcistignore"));
|
|
37907
38875
|
}
|
|
37908
38876
|
function readIgnoreEntries(file) {
|
|
37909
|
-
if (!
|
|
38877
|
+
if (!existsSync22(file)) return [];
|
|
37910
38878
|
return readFileSync29(file, "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
|
|
37911
38879
|
}
|
|
37912
38880
|
function isIgnored(rel, prefixes) {
|
|
@@ -37954,7 +38922,7 @@ function renderText(findings, stats, suppressed, opts = { trust: false, repoIgno
|
|
|
37954
38922
|
if (f.source === "heuristic" && f.ruleId === EX024) lines.push(` chamber: ${displayMessage(f.rationale)}`);
|
|
37955
38923
|
lines.push(` fix: ${f.fix.replace(/\s+/g, " ").trim()}`);
|
|
37956
38924
|
}
|
|
37957
|
-
const counts = ["critical", "high", "medium", "low"].map((s) => ({ s, n: findings.filter((f) => f.severity === s).length })).filter((c) => c.n > 0).map((c) => `${c.n} ${c.s}`).join(", ");
|
|
38925
|
+
const counts = ["critical", "high", "medium", "low", "info"].map((s) => ({ s, n: findings.filter((f) => f.severity === s).length })).filter((c) => c.n > 0).map((c) => `${c.n} ${c.s}`).join(", ");
|
|
37958
38926
|
const withFindings = new Set(findings.map((f) => f.file)).size;
|
|
37959
38927
|
lines.push("", `${plural(findings.length, "threat")} in ${plural(withFindings, "file")} (${counts}). Scanned ${plural(stats.filesScanned, "file")}.`);
|
|
37960
38928
|
lines.push(...extra, verdict);
|
|
@@ -38011,14 +38979,14 @@ async function makeAiClient(rawMax, io, real) {
|
|
|
38011
38979
|
};
|
|
38012
38980
|
}
|
|
38013
38981
|
async function runScan(opts, io) {
|
|
38014
|
-
const abs =
|
|
38015
|
-
if (!
|
|
38982
|
+
const abs = resolve30(opts.target);
|
|
38983
|
+
if (!existsSync22(abs)) {
|
|
38016
38984
|
io.err(`Path not found: ${opts.target}`);
|
|
38017
38985
|
return { ok: false, code: 2 };
|
|
38018
38986
|
}
|
|
38019
38987
|
const isFile = statSync19(abs).isFile();
|
|
38020
|
-
const root = isFile ?
|
|
38021
|
-
const only = isFile ?
|
|
38988
|
+
const root = isFile ? dirname18(abs) : abs;
|
|
38989
|
+
const only = isFile ? basename12(abs) : null;
|
|
38022
38990
|
const defsDir = findDefinitionsDir2(opts.definitions);
|
|
38023
38991
|
if (!defsDir) {
|
|
38024
38992
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -38078,14 +39046,14 @@ async function runScan(opts, io) {
|
|
|
38078
39046
|
function makeRootReader(root) {
|
|
38079
39047
|
let realRoot;
|
|
38080
39048
|
try {
|
|
38081
|
-
realRoot =
|
|
39049
|
+
realRoot = realpathSync12(root);
|
|
38082
39050
|
} catch {
|
|
38083
39051
|
return () => null;
|
|
38084
39052
|
}
|
|
38085
39053
|
return (file) => {
|
|
38086
39054
|
try {
|
|
38087
|
-
const real =
|
|
38088
|
-
const rel =
|
|
39055
|
+
const real = realpathSync12(resolve30(realRoot, file));
|
|
39056
|
+
const rel = relative15(realRoot, real);
|
|
38089
39057
|
if (rel === "" || rel.startsWith("..") || isAbsolute21(rel)) return null;
|
|
38090
39058
|
if (statSync19(real).size > MAX_DIRECTIVE_FILE_BYTES) return null;
|
|
38091
39059
|
return readFileSync29(real, "utf8");
|
|
@@ -38114,7 +39082,8 @@ async function scanCommand(argv, io, deps = {}) {
|
|
|
38114
39082
|
ai: { type: "boolean" },
|
|
38115
39083
|
"ai-max-calls": { type: "string" },
|
|
38116
39084
|
detonate: { type: "boolean" },
|
|
38117
|
-
"detonate-max": { type: "string" }
|
|
39085
|
+
"detonate-max": { type: "string" },
|
|
39086
|
+
home: { type: "boolean" }
|
|
38118
39087
|
});
|
|
38119
39088
|
if (!p.ok) {
|
|
38120
39089
|
io.err(`${p.error}
|
|
@@ -38140,7 +39109,7 @@ ${SCAN_HELP}`);
|
|
|
38140
39109
|
}
|
|
38141
39110
|
const failOn = str4(p.values["fail-on"]) ?? "high";
|
|
38142
39111
|
if (failOn !== "none" && !(failOn in RANK5)) {
|
|
38143
|
-
io.err(`Unknown --fail-on "${failOn}". Use critical, high, medium, low or none.`);
|
|
39112
|
+
io.err(`Unknown --fail-on "${failOn}". Use critical, high, medium, low, info or none.`);
|
|
38144
39113
|
return 2;
|
|
38145
39114
|
}
|
|
38146
39115
|
const baselinePath = str4(p.values["baseline"]);
|
|
@@ -38148,7 +39117,7 @@ ${SCAN_HELP}`);
|
|
|
38148
39117
|
if (baselinePath !== void 0) {
|
|
38149
39118
|
let text;
|
|
38150
39119
|
try {
|
|
38151
|
-
text = readFileSync29(
|
|
39120
|
+
text = readFileSync29(resolve30(baselinePath), "utf8");
|
|
38152
39121
|
} catch {
|
|
38153
39122
|
io.err(`Could not read the baseline file ${baselinePath}. Check the path, or create one with: exorcist baseline <folder>`);
|
|
38154
39123
|
return 2;
|
|
@@ -38169,11 +39138,11 @@ ${SCAN_HELP}`);
|
|
|
38169
39138
|
const ignoreFilePath = str4(p.values["ignore-file"]);
|
|
38170
39139
|
let userIgnore = [];
|
|
38171
39140
|
if (ignoreFilePath !== void 0) {
|
|
38172
|
-
if (!
|
|
39141
|
+
if (!existsSync22(resolve30(ignoreFilePath))) {
|
|
38173
39142
|
io.err(`Could not read the ignore file ${ignoreFilePath}. Check the path.`);
|
|
38174
39143
|
return 2;
|
|
38175
39144
|
}
|
|
38176
|
-
userIgnore = readIgnoreEntries(
|
|
39145
|
+
userIgnore = readIgnoreEntries(resolve30(ignoreFilePath));
|
|
38177
39146
|
}
|
|
38178
39147
|
const held = { chamber: null, ai: null };
|
|
38179
39148
|
const result = await runScan({
|
|
@@ -38213,6 +39182,14 @@ ${SCAN_HELP}`);
|
|
|
38213
39182
|
}
|
|
38214
39183
|
stats = { ...stats, findingsTotal: findings.length };
|
|
38215
39184
|
const inline = applyInline(findings, makeRootReader(root));
|
|
39185
|
+
if (p.values["home"] === true) {
|
|
39186
|
+
const home = await (deps.homeScan ?? scanHome)({ home: homeFolder() });
|
|
39187
|
+
for (const n of home.notes) io.err(n);
|
|
39188
|
+
io.err(`Home settings (--home): read ${plural(home.read.length, "file")}.`);
|
|
39189
|
+
findings.push(...home.findings);
|
|
39190
|
+
inline.active.push(...home.findings);
|
|
39191
|
+
stats = { ...stats, findingsTotal: findings.length };
|
|
39192
|
+
}
|
|
38216
39193
|
let working = inline.active;
|
|
38217
39194
|
const honoured = trust ? inline.suppressed : [];
|
|
38218
39195
|
if (!trust) {
|
|
@@ -38280,7 +39257,7 @@ ${BASELINE_HELP}`);
|
|
|
38280
39257
|
}
|
|
38281
39258
|
const target = p.positionals[0] ?? ".";
|
|
38282
39259
|
try {
|
|
38283
|
-
if (!statSync20(
|
|
39260
|
+
if (!statSync20(resolve31(target)).isDirectory()) {
|
|
38284
39261
|
io.err(`${target} is a file. Give a folder to baseline.`);
|
|
38285
39262
|
return 2;
|
|
38286
39263
|
}
|
|
@@ -38293,7 +39270,7 @@ ${BASELINE_HELP}`);
|
|
|
38293
39270
|
const { findings, root } = result.run;
|
|
38294
39271
|
const { active } = applyInline(findings, makeRootReader(root));
|
|
38295
39272
|
const baseline = buildBaseline(active);
|
|
38296
|
-
const out = str4(p.values["output"]) ??
|
|
39273
|
+
const out = str4(p.values["output"]) ?? join38(root, BASELINE_FILE);
|
|
38297
39274
|
try {
|
|
38298
39275
|
writeFileSync9(out, `${JSON.stringify(baseline, null, 2)}
|
|
38299
39276
|
`, "utf8");
|
|
@@ -38306,7 +39283,7 @@ ${BASELINE_HELP}`);
|
|
|
38306
39283
|
}
|
|
38307
39284
|
|
|
38308
39285
|
// src/commands/canary.ts
|
|
38309
|
-
import { resolve as
|
|
39286
|
+
import { resolve as resolve32 } from "node:path";
|
|
38310
39287
|
var CANARY_HELP = `Usage: exorcist canary plant [dir] Plant canary traps in a project (3 by default)
|
|
38311
39288
|
exorcist canary --list [dir] Show the planted traps
|
|
38312
39289
|
exorcist canary --remove [dir] Remove the trap files and their records
|
|
@@ -38354,7 +39331,7 @@ ${CANARY_HELP}`);
|
|
|
38354
39331
|
${CANARY_HELP}`);
|
|
38355
39332
|
return 2;
|
|
38356
39333
|
}
|
|
38357
|
-
const dir =
|
|
39334
|
+
const dir = resolve32(positionals[0] ?? ".");
|
|
38358
39335
|
const wantList = p.values["list"] === true || sub === "list";
|
|
38359
39336
|
const wantRemove = p.values["remove"] === true || sub === "remove";
|
|
38360
39337
|
const wantPlant = sub === "plant";
|
|
@@ -38366,13 +39343,13 @@ ${CANARY_HELP}`);
|
|
|
38366
39343
|
}
|
|
38367
39344
|
const explicitDir = str4(p.values["dir"]);
|
|
38368
39345
|
const state = explicitDir !== void 0 || process.env["EXORCIST_DIR"] ? stateDir(explicitDir) : void 0;
|
|
38369
|
-
if (wantList) return
|
|
39346
|
+
if (wantList) return list2(io, dir);
|
|
38370
39347
|
if (wantRemove) return remove(io, dir, state);
|
|
38371
39348
|
const countRaw = str4(p.values["count"]);
|
|
38372
39349
|
const count = countRaw === void 0 ? 3 : Number(countRaw);
|
|
38373
39350
|
return plant(io, dir, state, count);
|
|
38374
39351
|
}
|
|
38375
|
-
function
|
|
39352
|
+
function list2(io, dir) {
|
|
38376
39353
|
const r = loadCanaries(dir);
|
|
38377
39354
|
if (!r.ok) {
|
|
38378
39355
|
io.err(`Exorcist 98: ${r.error}`);
|
|
@@ -38419,9 +39396,9 @@ function remove(io, dir, state) {
|
|
|
38419
39396
|
}
|
|
38420
39397
|
|
|
38421
39398
|
// src/commands/config.ts
|
|
38422
|
-
import { createHash as
|
|
38423
|
-
import { existsSync as
|
|
38424
|
-
import { join as
|
|
39399
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
39400
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync11, readFileSync as readFileSync30, rmSync as rmSync5, writeFileSync as writeFileSync10 } from "node:fs";
|
|
39401
|
+
import { join as join39, resolve as resolve33 } from "node:path";
|
|
38425
39402
|
var WRAP_HELP = `Usage: exorcist wrap <mcp.json> [options]
|
|
38426
39403
|
exorcist unwrap <mcp.json>
|
|
38427
39404
|
|
|
@@ -38432,12 +39409,12 @@ unwrap Put the original file back byte for byte, if it was not edited since
|
|
|
38432
39409
|
|
|
38433
39410
|
Options (wrap):
|
|
38434
39411
|
--bin <command> Command that runs the shield (default: exorcist)
|
|
38435
|
-
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.
|
|
39412
|
+
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.8
|
|
38436
39413
|
--dir <folder> State folder (default: ${DEFAULT_DIR})
|
|
38437
39414
|
--dry-run Show the result without writing the file
|
|
38438
39415
|
`;
|
|
38439
39416
|
function backupPath(dir, configPath) {
|
|
38440
|
-
return
|
|
39417
|
+
return join39(dir, "wrap-backups", `${createHash15("sha256").update(configPath).digest("hex").slice(0, 32)}.json`);
|
|
38441
39418
|
}
|
|
38442
39419
|
function readBackup(file) {
|
|
38443
39420
|
try {
|
|
@@ -38459,7 +39436,7 @@ function dirsInConfig(cfg) {
|
|
|
38459
39436
|
return out;
|
|
38460
39437
|
}
|
|
38461
39438
|
function readConfig2(path, io) {
|
|
38462
|
-
if (!
|
|
39439
|
+
if (!existsSync23(path)) {
|
|
38463
39440
|
io.err(`File not found: ${path}`);
|
|
38464
39441
|
return null;
|
|
38465
39442
|
}
|
|
@@ -38497,7 +39474,7 @@ ${WRAP_HELP}`);
|
|
|
38497
39474
|
${WRAP_HELP}`);
|
|
38498
39475
|
return 2;
|
|
38499
39476
|
}
|
|
38500
|
-
const path =
|
|
39477
|
+
const path = resolve33(file);
|
|
38501
39478
|
const cfg = readConfig2(path, io);
|
|
38502
39479
|
if (!cfg) return 2;
|
|
38503
39480
|
const text = readFileSync30(path, "utf8");
|
|
@@ -38526,7 +39503,7 @@ ${WRAP_HELP}`);
|
|
|
38526
39503
|
writeFileSync10(path, out, "utf8");
|
|
38527
39504
|
const b = backupPath(stateDir(str4(p.values["dir"])), path);
|
|
38528
39505
|
try {
|
|
38529
|
-
|
|
39506
|
+
mkdirSync11(join39(b, ".."), { recursive: true, mode: 448 });
|
|
38530
39507
|
writeFileSync10(b, JSON.stringify({ path, original: text, wrapped: out }), { mode: 384 });
|
|
38531
39508
|
} catch {
|
|
38532
39509
|
io.err("Could not save a copy of the original file; unwrap will still restore the original commands.");
|
|
@@ -38585,7 +39562,7 @@ import { randomBytes as randomBytes11, timingSafeEqual as timingSafeEqual2 } fro
|
|
|
38585
39562
|
import { createServer } from "node:http";
|
|
38586
39563
|
|
|
38587
39564
|
// src/console/model.ts
|
|
38588
|
-
import { lstatSync as
|
|
39565
|
+
import { lstatSync as lstatSync16, readdirSync as readdirSync13 } from "node:fs";
|
|
38589
39566
|
var BACKLOG = 400;
|
|
38590
39567
|
var MAX_SHIELDS = 64;
|
|
38591
39568
|
var MAX_SESSIONS = 16;
|
|
@@ -38627,9 +39604,15 @@ var ConsoleModel = class {
|
|
|
38627
39604
|
* (size, mtime, inode), so a quiet folder costs a few stat calls per poll. Read-only.
|
|
38628
39605
|
*/
|
|
38629
39606
|
chainState() {
|
|
38630
|
-
const
|
|
39607
|
+
const loc = resolveLogLocation(this.dir);
|
|
39608
|
+
if (!loc.ok) {
|
|
39609
|
+
this.chainCache = { chain: { status: "broken", atSeq: 1, reason: "head-mismatch", detail: `the event log folder was refused: ${loc.error}` }, chainHead: null };
|
|
39610
|
+
return this.chainCache;
|
|
39611
|
+
}
|
|
39612
|
+
const logDir = loc.dir;
|
|
39613
|
+
const sig = [eventsPath(logDir), oldEventsPath(logDir), headPath(logDir), genesisPath(logDir)].map((p) => {
|
|
38631
39614
|
try {
|
|
38632
|
-
const st =
|
|
39615
|
+
const st = lstatSync16(p);
|
|
38633
39616
|
return `${st.ino}:${st.size}:${st.mtimeMs}`;
|
|
38634
39617
|
} catch {
|
|
38635
39618
|
return "-";
|
|
@@ -38638,7 +39621,7 @@ var ConsoleModel = class {
|
|
|
38638
39621
|
if (sig === this.chainSig) return this.chainCache;
|
|
38639
39622
|
this.chainSig = sig;
|
|
38640
39623
|
const present = sig.split("|").some((x, i) => x !== "-" && i !== 3);
|
|
38641
|
-
const h = readHead(
|
|
39624
|
+
const h = readHead(logDir);
|
|
38642
39625
|
const chainHead = h.ok && h.value ? { seq: h.value.seq, hash: h.value.hash } : null;
|
|
38643
39626
|
this.chainCache = { chain: present ? verifyLogDir(this.dir) : null, chainHead };
|
|
38644
39627
|
return this.chainCache;
|
|
@@ -38712,7 +39695,7 @@ var ConsoleModel = class {
|
|
|
38712
39695
|
const root = sessionsPath(this.dir);
|
|
38713
39696
|
let names = [];
|
|
38714
39697
|
try {
|
|
38715
|
-
names =
|
|
39698
|
+
names = readdirSync13(root).filter((k) => isSessionKey(k));
|
|
38716
39699
|
} catch {
|
|
38717
39700
|
names = [];
|
|
38718
39701
|
}
|
|
@@ -38721,7 +39704,7 @@ var ConsoleModel = class {
|
|
|
38721
39704
|
for (const key of [...keys].slice(0, 256)) {
|
|
38722
39705
|
let isDir2 = false;
|
|
38723
39706
|
try {
|
|
38724
|
-
isDir2 =
|
|
39707
|
+
isDir2 = lstatSync16(`${root}/${key}`).isDirectory();
|
|
38725
39708
|
} catch {
|
|
38726
39709
|
isDir2 = false;
|
|
38727
39710
|
}
|
|
@@ -39502,11 +40485,11 @@ data: ${data}
|
|
|
39502
40485
|
});
|
|
39503
40486
|
server.headersTimeout = 1e4;
|
|
39504
40487
|
server.requestTimeout = 0;
|
|
39505
|
-
await new Promise((
|
|
40488
|
+
await new Promise((resolve42, reject2) => {
|
|
39506
40489
|
server.once("error", reject2);
|
|
39507
40490
|
server.listen(o.port ?? 0, "127.0.0.1", () => {
|
|
39508
40491
|
server.off("error", reject2);
|
|
39509
|
-
|
|
40492
|
+
resolve42();
|
|
39510
40493
|
});
|
|
39511
40494
|
});
|
|
39512
40495
|
port = server.address().port;
|
|
@@ -39552,8 +40535,9 @@ Exit codes: 0 the log is intact, or has no chain yet ("not chained", an old log)
|
|
|
39552
40535
|
2 usage error.
|
|
39553
40536
|
`;
|
|
39554
40537
|
var HEX643 = /^[0-9a-f]{64}$/;
|
|
39555
|
-
var
|
|
39556
|
-
var
|
|
40538
|
+
var eventsOffNote = (time3) => `Note: logging was turned off by your user-level config at ${plain3(time3)}: a Shield started under that setting writes no events, so an empty or short log after that time is not evidence that nothing happened.`;
|
|
40539
|
+
var eventsOffSince = (dir) => readEventsOffSince(dir);
|
|
40540
|
+
var envSwitchNote = (env = process.env) => env["EXORCIST_EVENTS"] === "0" ? 'Note: EXORCIST_EVENTS=0 is set in this environment, but it is ignored: it does not turn event logging off. Only "events": "off" in your user-level policy does.' : null;
|
|
39557
40541
|
function parseExpect(raw) {
|
|
39558
40542
|
const v = raw.trim().toLowerCase();
|
|
39559
40543
|
if (HEX643.test(v)) return { kind: "tip", hash: v };
|
|
@@ -39640,9 +40624,13 @@ ${VERIFY_LOG_HELP}`);
|
|
|
39640
40624
|
return 2;
|
|
39641
40625
|
}
|
|
39642
40626
|
}
|
|
39643
|
-
const
|
|
39644
|
-
|
|
39645
|
-
|
|
40627
|
+
const dir = stateDir(str4(p.values["dir"]));
|
|
40628
|
+
const status2 = run2(dir, expect);
|
|
40629
|
+
const offAt = eventsOffSince(dir);
|
|
40630
|
+
if (offAt !== null) io.err(eventsOffNote(offAt));
|
|
40631
|
+
const envNote = envSwitchNote();
|
|
40632
|
+
if (envNote !== null) io.err(envNote);
|
|
40633
|
+
io.out(p.values["json"] === true ? JSON.stringify(offAt !== null ? { ...status2, loggingTurnedOff: true, eventsOffSince: offAt } : status2) : describe(status2, expect !== null));
|
|
39646
40634
|
if (status2.status === "broken") return 1;
|
|
39647
40635
|
if (status2.status === "not-chained" && expect !== null) return 1;
|
|
39648
40636
|
return 0;
|
|
@@ -39678,11 +40666,11 @@ function openCommand(platform, url) {
|
|
|
39678
40666
|
if (platform === "win32") return { file: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
|
|
39679
40667
|
return { file: "xdg-open", args: [url] };
|
|
39680
40668
|
}
|
|
39681
|
-
var untilSignal = () => new Promise((
|
|
40669
|
+
var untilSignal = () => new Promise((resolve42) => {
|
|
39682
40670
|
const stop2 = () => {
|
|
39683
40671
|
process.off("SIGINT", stop2);
|
|
39684
40672
|
process.off("SIGTERM", stop2);
|
|
39685
|
-
|
|
40673
|
+
resolve42();
|
|
39686
40674
|
};
|
|
39687
40675
|
process.on("SIGINT", stop2);
|
|
39688
40676
|
process.on("SIGTERM", stop2);
|
|
@@ -39700,8 +40688,12 @@ ${CONSOLE_HELP}`);
|
|
|
39700
40688
|
return 0;
|
|
39701
40689
|
}
|
|
39702
40690
|
if (p.values["verify"] === true) {
|
|
39703
|
-
|
|
39704
|
-
const
|
|
40691
|
+
const verifyDir = stateDir(str4(p.values["dir"]));
|
|
40692
|
+
const offAt = eventsOffSince(verifyDir);
|
|
40693
|
+
if (offAt !== null) io.err(eventsOffNote(offAt));
|
|
40694
|
+
const envNote = envSwitchNote();
|
|
40695
|
+
if (envNote !== null) io.err(envNote);
|
|
40696
|
+
const status2 = verifyLogDir(verifyDir);
|
|
39705
40697
|
if (status2.status === "broken") {
|
|
39706
40698
|
io.out(`TAMPERED: the event log is broken at event ${status2.atSeq}. ${status2.detail.replace(/[^\x20-\x7e]/g, "?")}`);
|
|
39707
40699
|
return 1;
|
|
@@ -39730,7 +40722,10 @@ ${CONSOLE_HELP}`);
|
|
|
39730
40722
|
return 1;
|
|
39731
40723
|
}
|
|
39732
40724
|
io.out(`Exorcist 98 Shield console (read-only) for ${dir}`);
|
|
39733
|
-
|
|
40725
|
+
const offAtStart = eventsOffSince(dir);
|
|
40726
|
+
if (offAtStart !== null) io.out(eventsOffNote(offAtStart));
|
|
40727
|
+
const envNoteAtStart = envSwitchNote();
|
|
40728
|
+
if (envNoteAtStart !== null) io.out(envNoteAtStart);
|
|
39734
40729
|
if (p.values["no-open"] === true) {
|
|
39735
40730
|
io.out(` ${server.url}`);
|
|
39736
40731
|
io.out("Only this machine can open it, and only with the token in the URL. Press Ctrl+C to stop.");
|
|
@@ -39752,8 +40747,8 @@ ${CONSOLE_HELP}`);
|
|
|
39752
40747
|
}
|
|
39753
40748
|
|
|
39754
40749
|
// src/commands/exorcise.ts
|
|
39755
|
-
import { existsSync as
|
|
39756
|
-
import { basename as
|
|
40750
|
+
import { existsSync as existsSync24, readFileSync as readFileSync31, statSync as statSync21 } from "node:fs";
|
|
40751
|
+
import { basename as basename13, dirname as dirname19, isAbsolute as isAbsolute22, relative as relative16, resolve as resolve34 } from "node:path";
|
|
39757
40752
|
var EXORCISE_HELP = `Usage: exorcist exorcise [path] [options]
|
|
39758
40753
|
|
|
39759
40754
|
Disinfect: repair the threats that have one safe, mechanical fix, and report
|
|
@@ -39837,14 +40832,14 @@ ${EXORCISE_HELP}`);
|
|
|
39837
40832
|
return 2;
|
|
39838
40833
|
}
|
|
39839
40834
|
const target = p.positionals[0] ?? ".";
|
|
39840
|
-
const abs =
|
|
39841
|
-
if (!
|
|
40835
|
+
const abs = resolve34(target);
|
|
40836
|
+
if (!existsSync24(abs)) {
|
|
39842
40837
|
io.err(`Path not found: ${target}`);
|
|
39843
40838
|
return 2;
|
|
39844
40839
|
}
|
|
39845
40840
|
const isFile = statSync21(abs).isFile();
|
|
39846
|
-
const root = isFile ?
|
|
39847
|
-
const single = isFile ?
|
|
40841
|
+
const root = isFile ? dirname19(abs) : abs;
|
|
40842
|
+
const single = isFile ? basename13(abs) : null;
|
|
39848
40843
|
const defsDir = findDefinitionsDir2(str4(p.values["definitions"]));
|
|
39849
40844
|
if (!defsDir) {
|
|
39850
40845
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -39862,7 +40857,7 @@ ${EXORCISE_HELP}`);
|
|
|
39862
40857
|
return 2;
|
|
39863
40858
|
}
|
|
39864
40859
|
const vault = vaultPath(stateDir(str4(p.values["dir"])));
|
|
39865
|
-
const state =
|
|
40860
|
+
const state = relative16(root, resolve34(vault, ".."));
|
|
39866
40861
|
const ignore = [...strs(p.values["ignore"]), ...readIgnoreFile(root)];
|
|
39867
40862
|
if (state === "") ignore.push("vault");
|
|
39868
40863
|
else if (!state.startsWith("..") && !isAbsolute22(state)) ignore.push(state.replace(/\\/g, "/"));
|
|
@@ -39911,7 +40906,7 @@ ${EXORCISE_HELP}`);
|
|
|
39911
40906
|
return 1;
|
|
39912
40907
|
}
|
|
39913
40908
|
const changedSet = new Set(changed.map((r) => r.file));
|
|
39914
|
-
const now = changed.map((r) => ({ file: r.file, text: readFileSync31(
|
|
40909
|
+
const now = changed.map((r) => ({ file: r.file, text: readFileSync31(resolve34(root, r.file), "utf8") }));
|
|
39915
40910
|
const after = [...findings.filter((f) => !changedSet.has(f.file)), ...rescanTexts(now, defs).filter((f) => keep(f.file))];
|
|
39916
40911
|
const removed = Math.max(0, findings.length - after.length);
|
|
39917
40912
|
const dirFlag = str4(p.values["dir"]) ? ` --dir ${str4(p.values["dir"])}` : "";
|
|
@@ -39930,10 +40925,10 @@ ${EXORCISE_HELP}`);
|
|
|
39930
40925
|
}
|
|
39931
40926
|
|
|
39932
40927
|
// src/commands/gate.ts
|
|
39933
|
-
import { existsSync as
|
|
40928
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
39934
40929
|
import { lstat as lstat2, readFile as readFile6 } from "node:fs/promises";
|
|
39935
|
-
import { resolve as
|
|
39936
|
-
var GATE_HELP = `Usage: exorcist gate [dir] [--fail-on <critical|high|medium|low>] [--dir <state folder>]
|
|
40930
|
+
import { resolve as resolve35 } from "node:path";
|
|
40931
|
+
var GATE_HELP = `Usage: exorcist gate [dir] [--fail-on <critical|high|medium|low|info>] [--dir <state folder>]
|
|
39937
40932
|
The gate for the end of an agent's turn. It looks only at the files an AI agent
|
|
39938
40933
|
obeys (steering, specs, hooks, custom agents, MCP configs, AGENTS.md and the
|
|
39939
40934
|
other rule files, READMEs) that changed since the last commit, and exits 1 with
|
|
@@ -39946,7 +40941,7 @@ When the Shield's state folder has an event-log head file, its head hash is
|
|
|
39946
40941
|
printed too (see "exorcist verify-log").
|
|
39947
40942
|
The Kiro hook written by "exorcist init" runs it when the agent stops.
|
|
39948
40943
|
`;
|
|
39949
|
-
var THRESHOLDS = ["critical", "high", "medium", "low"];
|
|
40944
|
+
var THRESHOLDS = ["critical", "high", "medium", "low", "info"];
|
|
39950
40945
|
var GIT_MS = 1e4;
|
|
39951
40946
|
function headLine(explicit) {
|
|
39952
40947
|
const h = readHead(stateDir(explicit));
|
|
@@ -40016,8 +41011,8 @@ ${GATE_HELP}`);
|
|
|
40016
41011
|
${GATE_HELP}`);
|
|
40017
41012
|
return 2;
|
|
40018
41013
|
}
|
|
40019
|
-
const start =
|
|
40020
|
-
if (!
|
|
41014
|
+
const start = resolve35(p.positionals[0] ?? ".");
|
|
41015
|
+
if (!existsSync25(start)) return nothingChecked(io, "that folder does not exist");
|
|
40021
41016
|
const top = await gitRepoRoot(start);
|
|
40022
41017
|
if (!top) return nothingChecked(io, "this folder is not a git repository, or git is not available");
|
|
40023
41018
|
const repo = { root: top };
|
|
@@ -40034,7 +41029,7 @@ ${GATE_HELP}`);
|
|
|
40034
41029
|
const onDisk = [];
|
|
40035
41030
|
const sizes = /* @__PURE__ */ new Map();
|
|
40036
41031
|
for (const rel of changed.files) {
|
|
40037
|
-
const info = await lstat2(
|
|
41032
|
+
const info = await lstat2(resolve35(repo.root, rel)).catch(() => null);
|
|
40038
41033
|
if (!info || !info.isFile()) continue;
|
|
40039
41034
|
onDisk.push(rel);
|
|
40040
41035
|
sizes.set(rel, info.size);
|
|
@@ -40051,7 +41046,7 @@ ${GATE_HELP}`);
|
|
|
40051
41046
|
if (f) added.push(f);
|
|
40052
41047
|
continue;
|
|
40053
41048
|
}
|
|
40054
|
-
const after = await readFile6(
|
|
41049
|
+
const after = await readFile6(resolve35(repo.root, rel), "utf8").catch(() => null);
|
|
40055
41050
|
if (after === null) continue;
|
|
40056
41051
|
const before = then.has(rel) ? await committed(repo.root, rel) : null;
|
|
40057
41052
|
added.push(...gateFindings(rel, before, after, defs));
|
|
@@ -40069,8 +41064,8 @@ ${head}`);
|
|
|
40069
41064
|
|
|
40070
41065
|
// src/commands/guard-mcp-write.ts
|
|
40071
41066
|
import { randomBytes as randomBytes12 } from "node:crypto";
|
|
40072
|
-
import { createReadStream, createWriteStream, openSync as
|
|
40073
|
-
import { homedir as
|
|
41067
|
+
import { createReadStream, createWriteStream, openSync as openSync12, writeSync as writeSync8 } from "node:fs";
|
|
41068
|
+
import { homedir as homedir10 } from "node:os";
|
|
40074
41069
|
import { createInterface as createInterface2 } from "node:readline";
|
|
40075
41070
|
var GUARD_MCP_WRITE_HELP = `Usage: exorcist guard-mcp-write (Kiro hook helper)
|
|
40076
41071
|
Reads a Kiro PreToolUse hook event from stdin. When the tool would write to
|
|
@@ -40089,14 +41084,14 @@ var PROMPT_TIMEOUT_MS = 125e3;
|
|
|
40089
41084
|
function hookDeps() {
|
|
40090
41085
|
let fd = null;
|
|
40091
41086
|
try {
|
|
40092
|
-
fd =
|
|
41087
|
+
fd = openSync12("/dev/tty", "r+");
|
|
40093
41088
|
} catch {
|
|
40094
41089
|
fd = null;
|
|
40095
41090
|
}
|
|
40096
41091
|
const tty = fd;
|
|
40097
41092
|
const write = (s) => {
|
|
40098
41093
|
if (tty !== null) try {
|
|
40099
|
-
|
|
41094
|
+
writeSync8(tty, s.endsWith("\n") ? s : `${s}
|
|
40100
41095
|
`);
|
|
40101
41096
|
} catch {
|
|
40102
41097
|
}
|
|
@@ -40120,7 +41115,7 @@ function hookDeps() {
|
|
|
40120
41115
|
dialog: macDialog,
|
|
40121
41116
|
nonce: () => randomBytes12(4).toString("hex").slice(0, 6)
|
|
40122
41117
|
};
|
|
40123
|
-
return { term, promptIo: { out: write, err: write }, home:
|
|
41118
|
+
return { term, promptIo: { out: write, err: write }, home: homedir10(), timeoutMs: PROMPT_TIMEOUT_MS };
|
|
40124
41119
|
}
|
|
40125
41120
|
function dialogMessage(kind, path) {
|
|
40126
41121
|
if (kind === "trusted-commands") return `Your AI agent wants to change which commands it may run without asking you:
|
|
@@ -40218,10 +41213,10 @@ function guardEnvWriteCommand(stdin, io) {
|
|
|
40218
41213
|
}
|
|
40219
41214
|
|
|
40220
41215
|
// src/commands/guard-web-fetch.ts
|
|
40221
|
-
import { createHash as
|
|
41216
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
40222
41217
|
import { readFileSync as readFileSync32, writeFileSync as writeFileSync11 } from "node:fs";
|
|
40223
|
-
import { tmpdir as
|
|
40224
|
-
import { isAbsolute as isAbsolute24, join as
|
|
41218
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
41219
|
+
import { isAbsolute as isAbsolute24, join as join40 } from "node:path";
|
|
40225
41220
|
var GUARD_WEB_FETCH_HELP = `Usage: exorcist guard-web-fetch (Kiro hook helper)
|
|
40226
41221
|
Reads a Kiro PreToolUse hook event for the web_fetch tool from stdin. When the
|
|
40227
41222
|
address holds a secret (a key or token), a canary token, or a value from a .env
|
|
@@ -40257,8 +41252,8 @@ function guardWebFetchCommand(stdin, io) {
|
|
|
40257
41252
|
}
|
|
40258
41253
|
function sentStore(cwd, event) {
|
|
40259
41254
|
const sid = typeof event === "object" && event !== null && typeof event["session_id"] === "string" ? String(event["session_id"]) : "";
|
|
40260
|
-
const id =
|
|
40261
|
-
const file =
|
|
41255
|
+
const id = createHash16("sha256").update(`${cwd}\0${sid}`).digest("hex").slice(0, 24);
|
|
41256
|
+
const file = join40(tmpdir3(), `exorcist98-sent-${id}.json`);
|
|
40262
41257
|
return {
|
|
40263
41258
|
load: () => {
|
|
40264
41259
|
try {
|
|
@@ -40360,8 +41355,8 @@ async function guardShellReadCommand(stdin, io) {
|
|
|
40360
41355
|
}
|
|
40361
41356
|
|
|
40362
41357
|
// src/commands/hook-scan.ts
|
|
40363
|
-
import { existsSync as
|
|
40364
|
-
import { resolve as
|
|
41358
|
+
import { existsSync as existsSync26, statSync as statSync22 } from "node:fs";
|
|
41359
|
+
import { resolve as resolve36 } from "node:path";
|
|
40365
41360
|
async function hookScanCommand(stdin, io) {
|
|
40366
41361
|
let event;
|
|
40367
41362
|
try {
|
|
@@ -40371,14 +41366,14 @@ async function hookScanCommand(stdin, io) {
|
|
|
40371
41366
|
}
|
|
40372
41367
|
if (typeof event.file_path !== "string" || event.file_path === "") return 0;
|
|
40373
41368
|
const base = typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
|
|
40374
|
-
const file =
|
|
40375
|
-
if (!
|
|
41369
|
+
const file = resolve36(base, event.file_path);
|
|
41370
|
+
if (!existsSync26(file) || !statSync22(file).isFile()) return 0;
|
|
40376
41371
|
return await scanCommand([file, "--fail-on", "high"], { out: io.err, err: io.err });
|
|
40377
41372
|
}
|
|
40378
41373
|
|
|
40379
41374
|
// src/commands/init.ts
|
|
40380
|
-
import { chmodSync, existsSync as
|
|
40381
|
-
import { dirname as
|
|
41375
|
+
import { chmodSync, existsSync as existsSync27, lstatSync as lstatSync17, mkdirSync as mkdirSync12, readFileSync as readFileSync33, writeFileSync as writeFileSync12 } from "node:fs";
|
|
41376
|
+
import { dirname as dirname20, join as join41, resolve as resolve37 } from "node:path";
|
|
40382
41377
|
|
|
40383
41378
|
// src/kiro-hook-script.ts
|
|
40384
41379
|
var KIRO_HOOK_SCRIPT = [
|
|
@@ -40506,8 +41501,8 @@ function reviewerAgentForProject(mcpCommand) {
|
|
|
40506
41501
|
}
|
|
40507
41502
|
|
|
40508
41503
|
// src/commands/init.ts
|
|
40509
|
-
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.
|
|
40510
|
-
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.
|
|
41504
|
+
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.8";
|
|
41505
|
+
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.8";
|
|
40511
41506
|
var MISSING_FROM_DEFAULT_BIN = /* @__PURE__ */ new Set();
|
|
40512
41507
|
var INIT_HELP = `Usage: exorcist init [folder] [--kiro] [--shield] [--sandbox] [--no-agent] [--force]
|
|
40513
41508
|
[--bin <command>] [--mcp-bin <command>]
|
|
@@ -40546,15 +41541,15 @@ Existing files are never overwritten unless you pass --force.
|
|
|
40546
41541
|
var SANDBOX_REL = ".kiro/settings/sandbox.json";
|
|
40547
41542
|
var SANDBOX_SETTINGS = { enabled: true, networkAccess: "DEFAULT_BLOCKED", mcpSandboxing: true };
|
|
40548
41543
|
function writeSandboxFile(root, io) {
|
|
40549
|
-
const path =
|
|
41544
|
+
const path = join41(root, SANDBOX_REL);
|
|
40550
41545
|
let present = false;
|
|
40551
41546
|
try {
|
|
40552
|
-
|
|
41547
|
+
lstatSync17(path);
|
|
40553
41548
|
present = true;
|
|
40554
41549
|
} catch {
|
|
40555
41550
|
}
|
|
40556
41551
|
if (!present) {
|
|
40557
|
-
|
|
41552
|
+
mkdirSync12(dirname20(path), { recursive: true });
|
|
40558
41553
|
try {
|
|
40559
41554
|
writeFileSync12(path, `${JSON.stringify(SANDBOX_SETTINGS, null, 2)}
|
|
40560
41555
|
`, { encoding: "utf8", flag: "wx" });
|
|
@@ -40568,7 +41563,7 @@ function writeSandboxFile(root, io) {
|
|
|
40568
41563
|
io.out(`Left ${SANDBOX_REL} unchanged: it already exists. Delete it and rerun to get the Exorcist settings.`);
|
|
40569
41564
|
return false;
|
|
40570
41565
|
}
|
|
40571
|
-
var
|
|
41566
|
+
var hook2 = (name, description, body) => `${JSON.stringify({ version: "v1", hooks: [{ name, description, ...body }] }, null, 2)}
|
|
40572
41567
|
`;
|
|
40573
41568
|
var STEERING = `---
|
|
40574
41569
|
inclusion: always
|
|
@@ -40620,13 +41615,13 @@ function splitCommand(s) {
|
|
|
40620
41615
|
}
|
|
40621
41616
|
var MAX_NAME = 60;
|
|
40622
41617
|
function describeMcpConfig(path) {
|
|
40623
|
-
if (!
|
|
41618
|
+
if (!existsSync27(path)) return { exists: false, warnings: [], line: "no .kiro/settings/mcp.json yet (the mcp-scan hook scans it once you add one)" };
|
|
40624
41619
|
try {
|
|
40625
41620
|
const cfg = JSON.parse(readFileSync33(path, "utf8"));
|
|
40626
|
-
const
|
|
40627
|
-
const shielded =
|
|
40628
|
-
const warnings =
|
|
40629
|
-
return { exists: true, warnings, line: `.kiro/settings/mcp.json: ${
|
|
41621
|
+
const entries2 = Object.entries(cfg.mcpServers ?? {});
|
|
41622
|
+
const shielded = entries2.filter(([, e]) => isWrapped(e)).map(([n]) => n);
|
|
41623
|
+
const warnings = entries2.filter(([, e]) => Array.isArray(e.autoApprove) && e.autoApprove.includes("*")).map(([n]) => `WARNING: server "${displayMessage(n.slice(0, MAX_NAME).replace(/[\t\n\r]/g, " "))}${n.length > MAX_NAME ? "..." : ""}" has autoApprove "*": your agent can run every tool of it without asking you. List only the tools you trust, or remove autoApprove.`);
|
|
41624
|
+
return { exists: true, warnings, line: `.kiro/settings/mcp.json: ${entries2.length} server${entries2.length === 1 ? "" : "s"}, ${shielded.length} behind the Shield` };
|
|
40630
41625
|
} catch {
|
|
40631
41626
|
return { exists: true, warnings: [], line: ".kiro/settings/mcp.json is not valid JSON; fix it before using --shield" };
|
|
40632
41627
|
}
|
|
@@ -40658,7 +41653,7 @@ ${INIT_HELP}`);
|
|
|
40658
41653
|
${INIT_HELP}`);
|
|
40659
41654
|
return 2;
|
|
40660
41655
|
}
|
|
40661
|
-
const root =
|
|
41656
|
+
const root = resolve37(p.positionals[0] ?? ".");
|
|
40662
41657
|
const bin = str4(p.values["bin"]) ?? DEFAULT_BIN;
|
|
40663
41658
|
const mcpBin = str4(p.values["mcp-bin"]) ?? DEFAULT_MCP_BIN;
|
|
40664
41659
|
const force = p.values["force"] === true;
|
|
@@ -40696,7 +41691,7 @@ ${INIT_HELP}`);
|
|
|
40696
41691
|
{
|
|
40697
41692
|
rel: ".kiro/hooks/exorcist-secrets.json",
|
|
40698
41693
|
summary: "PreToolUse on shell tools: blocks git commit while staged files hold secrets",
|
|
40699
|
-
body:
|
|
41694
|
+
body: hook2("exorcist-secrets", "Block git commit while staged files contain secrets. Exit code 2 blocks the shell command.", {
|
|
40700
41695
|
trigger: "PreToolUse",
|
|
40701
41696
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40702
41697
|
action: { type: "command", command: `${HOOK_RUNNER} --guard ${bin} guard-commit` },
|
|
@@ -40706,7 +41701,7 @@ ${INIT_HELP}`);
|
|
|
40706
41701
|
{
|
|
40707
41702
|
rel: ".kiro/hooks/exorcist-mcp-scan.json",
|
|
40708
41703
|
summary: "PostFileSave on MCP configs: scans the saved file and reports high or critical findings",
|
|
40709
|
-
body:
|
|
41704
|
+
body: hook2("exorcist-mcp-scan", "Scan MCP configuration with Exorcist 98 whenever it is saved.", {
|
|
40710
41705
|
trigger: "PostFileSave",
|
|
40711
41706
|
matcher: "(\\.kiro/settings/mcp\\.json|\\.cursor/mcp\\.json|\\.vscode/mcp\\.json|claude_desktop_config\\.json)$",
|
|
40712
41707
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} hook-scan` },
|
|
@@ -40716,7 +41711,7 @@ ${INIT_HELP}`);
|
|
|
40716
41711
|
{
|
|
40717
41712
|
rel: ".kiro/hooks/exorcist-on-access.json",
|
|
40718
41713
|
summary: onAccessOff ? 'PreToolUse on read tools: WRITTEN DISABLED, because the published version in the default command has no on-access command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on read tools: blocks reading a file that hides instructions for the AI",
|
|
40719
|
-
body:
|
|
41714
|
+
body: hook2("exorcist-on-access", "Scan a file for instructions aimed at the AI before the agent reads it. Exit code 2 blocks the read.", {
|
|
40720
41715
|
trigger: "PreToolUse",
|
|
40721
41716
|
matcher: "read|readFile|read_file|readCode|fs_read|readMultipleFiles|grep|grep_search|grepSearch|file_search|fileSearch|glob|list_directory|listDirectory|code",
|
|
40722
41717
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} on-access` },
|
|
@@ -40727,7 +41722,7 @@ ${INIT_HELP}`);
|
|
|
40727
41722
|
{
|
|
40728
41723
|
rel: ".kiro/hooks/exorcist-gate.json",
|
|
40729
41724
|
summary: gateOff ? 'Stop: WRITTEN DISABLED, because the published version in the default command has no gate command (pass --bin with a newer build, then set "enabled": true)' : "Stop: when the agent finishes, fails if it added a high or critical finding to a file agents obey",
|
|
40730
|
-
body:
|
|
41725
|
+
body: hook2("exorcist-gate", "When the agent finishes its turn, check the agent files it changed against the last commit. Exit code 1 sends the list to the agent.", {
|
|
40731
41726
|
trigger: "Stop",
|
|
40732
41727
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} gate` },
|
|
40733
41728
|
timeout: 30,
|
|
@@ -40737,7 +41732,7 @@ ${INIT_HELP}`);
|
|
|
40737
41732
|
{
|
|
40738
41733
|
rel: ".kiro/hooks/exorcist-mcp-write-guard.json",
|
|
40739
41734
|
summary: mcpWriteOff ? 'PreToolUse on write and shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-mcp-write command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on write and shell tools: a person must confirm any agent write to an MCP config, trusted commands or hook/agent file",
|
|
40740
|
-
body:
|
|
41735
|
+
body: hook2("exorcist-mcp-write-guard", "A person must confirm any agent write to an MCP config, any change that adds a trusted command in .vscode/settings.json, and any change to a file in .kiro/hooks/ or .kiro/agents/. Exit code 2 blocks the write.", {
|
|
40741
41736
|
trigger: "PreToolUse",
|
|
40742
41737
|
matcher: "write|shell",
|
|
40743
41738
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-mcp-write` },
|
|
@@ -40748,7 +41743,7 @@ ${INIT_HELP}`);
|
|
|
40748
41743
|
{
|
|
40749
41744
|
rel: ".kiro/hooks/exorcist-guard-web-fetch.json",
|
|
40750
41745
|
summary: webFetchOff ? 'PreToolUse on web_fetch: WRITTEN DISABLED, because the published version in the default command has no guard-web-fetch command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on web_fetch: blocks a fetch whose address holds a secret, canary or .env value",
|
|
40751
|
-
body:
|
|
41746
|
+
body: hook2("exorcist-guard-web-fetch", "Blocks the web_fetch tool when the address holds a secret (key or token), a canary token, or a value from a .env file of this project. Exit code 2 blocks the fetch; the reason names the kind of value and the host, never the value.", {
|
|
40752
41747
|
trigger: "PreToolUse",
|
|
40753
41748
|
matcher: "web_fetch|webFetch|remote_web_search|web_search|webSearch|shell|execute_bash|executeBash|run_command|bash",
|
|
40754
41749
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-web-fetch` },
|
|
@@ -40759,7 +41754,7 @@ ${INIT_HELP}`);
|
|
|
40759
41754
|
{
|
|
40760
41755
|
rel: ".kiro/hooks/exorcist-guard-env-write.json",
|
|
40761
41756
|
summary: envWriteOff ? 'PreToolUse on write tools: WRITTEN DISABLED, because the published version in the default command has no guard-env-write command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on write tools: blocks writing a .env value into any other file",
|
|
40762
|
-
body:
|
|
41757
|
+
body: hook2("exorcist-guard-env-write", "Blocks the write tools (fs_write, str_replace) when the text to be written holds a value from a .env file of this project and the destination is not itself a .env file. Exit code 2 blocks the write; the reason names the file, never the value.", {
|
|
40763
41758
|
trigger: "PreToolUse",
|
|
40764
41759
|
matcher: "write|fs_write|str_replace|shell|execute_bash|executeBash|run_command|bash",
|
|
40765
41760
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-env-write` },
|
|
@@ -40770,7 +41765,7 @@ ${INIT_HELP}`);
|
|
|
40770
41765
|
{
|
|
40771
41766
|
rel: ".kiro/hooks/exorcist-guard-run-scripts.json",
|
|
40772
41767
|
summary: runScriptsOff ? 'PreToolUse on shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-run-scripts command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on shell tools: blocks npm test, npm install and similar when a script they run reads secrets and sends them out",
|
|
40773
|
-
body:
|
|
41768
|
+
body: hook2("exorcist-guard-run-scripts", "Blocks a shell command that would run a package script (npm, pnpm, yarn, npx of a local bin) whose file reads a secret and sends data out. Exit code 2 blocks the command; the reason names the script and the file, never file text. Nothing is run to find out.", {
|
|
40774
41769
|
trigger: "PreToolUse",
|
|
40775
41770
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40776
41771
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-run-scripts` },
|
|
@@ -40781,7 +41776,7 @@ ${INIT_HELP}`);
|
|
|
40781
41776
|
{
|
|
40782
41777
|
rel: ".kiro/hooks/exorcist-guard-shell-read.json",
|
|
40783
41778
|
summary: shellReadOff ? 'PreToolUse on shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-shell-read command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on shell tools: scans a file before cat, head, tail, grep, sed -n, awk, bat or nl reads it",
|
|
40784
|
-
body:
|
|
41779
|
+
body: hook2("exorcist-guard-shell-read", "Scans the files a shell command reads (cat, head, tail, less, more, sed -n, awk, bat, nl, grep) the way the on-access hook scans a read, and blocks the command when a high or critical rule fires. Exit code 2 blocks the command; the reason never quotes the file.", {
|
|
40785
41780
|
trigger: "PreToolUse",
|
|
40786
41781
|
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
40787
41782
|
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-shell-read` },
|
|
@@ -40804,13 +41799,13 @@ ${INIT_HELP}`);
|
|
|
40804
41799
|
}
|
|
40805
41800
|
const done = [];
|
|
40806
41801
|
for (const f of files) {
|
|
40807
|
-
const path =
|
|
40808
|
-
if (
|
|
41802
|
+
const path = join41(root, f.rel);
|
|
41803
|
+
if (existsSync27(path) && !force) {
|
|
40809
41804
|
io.err(`Kept existing ${f.rel} (use --force to replace it).`);
|
|
40810
41805
|
done.push({ f, wrote: false });
|
|
40811
41806
|
continue;
|
|
40812
41807
|
}
|
|
40813
|
-
|
|
41808
|
+
mkdirSync12(dirname20(path), { recursive: true });
|
|
40814
41809
|
writeFileSync12(path, f.body, "utf8");
|
|
40815
41810
|
if (f.executable) chmodSync(path, 493);
|
|
40816
41811
|
if (!kiro) io.out(`Wrote ${f.rel}`);
|
|
@@ -40822,7 +41817,7 @@ ${INIT_HELP}`);
|
|
|
40822
41817
|
return wroteAny ? 0 : 1;
|
|
40823
41818
|
}
|
|
40824
41819
|
if (sandbox) writeSandboxFile(root, io);
|
|
40825
|
-
const mcpPath =
|
|
41820
|
+
const mcpPath = join41(root, ".kiro/settings/mcp.json");
|
|
40826
41821
|
let shieldOk = true;
|
|
40827
41822
|
let shieldLine = null;
|
|
40828
41823
|
if (shield) {
|
|
@@ -40832,7 +41827,7 @@ ${INIT_HELP}`);
|
|
|
40832
41827
|
shieldOk = false;
|
|
40833
41828
|
} else {
|
|
40834
41829
|
const [head, ...rest] = binWords;
|
|
40835
|
-
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${
|
|
41830
|
+
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${join41(root, ".exorcist")}`];
|
|
40836
41831
|
const notes = [];
|
|
40837
41832
|
const code3 = await wrapCommand(args, { out: io.out, err: (s) => notes.push(s) }, "wrap");
|
|
40838
41833
|
for (const n of notes) io.err(n);
|
|
@@ -40876,7 +41871,7 @@ ${INIT_HELP}`);
|
|
|
40876
41871
|
"then reconnect MCP servers in the MCP panel so they start through the Shield."
|
|
40877
41872
|
];
|
|
40878
41873
|
if (isDefaultBin) {
|
|
40879
|
-
lines.push("Commands run through npx (@exorcist-98/cli@0.3.
|
|
41874
|
+
lines.push("Commands run through npx (@exorcist-98/cli@0.3.8). If Kiro cannot start a wrapped server or a hook cannot find npx,");
|
|
40880
41875
|
lines.push('rerun with --bin "<absolute path to node> <absolute path to the exorcist CLI>" and --force.');
|
|
40881
41876
|
}
|
|
40882
41877
|
io.out(lines.join("\n"));
|
|
@@ -40885,8 +41880,8 @@ ${INIT_HELP}`);
|
|
|
40885
41880
|
}
|
|
40886
41881
|
|
|
40887
41882
|
// src/commands/lock.ts
|
|
40888
|
-
import { existsSync as
|
|
40889
|
-
import { isAbsolute as isAbsolute27, join as
|
|
41883
|
+
import { existsSync as existsSync28, readFileSync as readFileSync34, writeFileSync as writeFileSync13 } from "node:fs";
|
|
41884
|
+
import { isAbsolute as isAbsolute27, join as join42, resolve as resolve38 } from "node:path";
|
|
40890
41885
|
|
|
40891
41886
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js
|
|
40892
41887
|
var NEVER2 = Object.freeze({
|
|
@@ -41014,9 +42009,9 @@ function assertNever(_x) {
|
|
|
41014
42009
|
}
|
|
41015
42010
|
function assert(_) {
|
|
41016
42011
|
}
|
|
41017
|
-
function getEnumValues(
|
|
41018
|
-
const numericValues = Object.values(
|
|
41019
|
-
const values = Object.entries(
|
|
42012
|
+
function getEnumValues(entries2) {
|
|
42013
|
+
const numericValues = Object.values(entries2).filter((v) => typeof v === "number");
|
|
42014
|
+
const values = Object.entries(entries2).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
41020
42015
|
return values;
|
|
41021
42016
|
}
|
|
41022
42017
|
function joinValues(array2, separator = "|") {
|
|
@@ -44476,10 +45471,10 @@ var ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
44476
45471
|
};
|
|
44477
45472
|
});
|
|
44478
45473
|
function _enum(values, params) {
|
|
44479
|
-
const
|
|
45474
|
+
const entries2 = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
44480
45475
|
return new ZodEnum2({
|
|
44481
45476
|
type: "enum",
|
|
44482
|
-
entries,
|
|
45477
|
+
entries: entries2,
|
|
44483
45478
|
...util_exports.normalizeParams(params)
|
|
44484
45479
|
});
|
|
44485
45480
|
}
|
|
@@ -46756,7 +47751,7 @@ var Protocol = class {
|
|
|
46756
47751
|
return;
|
|
46757
47752
|
}
|
|
46758
47753
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
46759
|
-
await new Promise((
|
|
47754
|
+
await new Promise((resolve42) => setTimeout(resolve42, pollInterval));
|
|
46760
47755
|
options?.signal?.throwIfAborted();
|
|
46761
47756
|
}
|
|
46762
47757
|
} catch (error2) {
|
|
@@ -46773,7 +47768,7 @@ var Protocol = class {
|
|
|
46773
47768
|
*/
|
|
46774
47769
|
request(request, resultSchema, options) {
|
|
46775
47770
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
46776
|
-
return new Promise((
|
|
47771
|
+
return new Promise((resolve42, reject2) => {
|
|
46777
47772
|
const earlyReject = (error2) => {
|
|
46778
47773
|
reject2(error2);
|
|
46779
47774
|
};
|
|
@@ -46851,7 +47846,7 @@ var Protocol = class {
|
|
|
46851
47846
|
if (!parseResult.success) {
|
|
46852
47847
|
reject2(parseResult.error);
|
|
46853
47848
|
} else {
|
|
46854
|
-
|
|
47849
|
+
resolve42(parseResult.data);
|
|
46855
47850
|
}
|
|
46856
47851
|
} catch (error2) {
|
|
46857
47852
|
reject2(error2);
|
|
@@ -47113,12 +48108,12 @@ var Protocol = class {
|
|
|
47113
48108
|
}
|
|
47114
48109
|
} catch {
|
|
47115
48110
|
}
|
|
47116
|
-
return new Promise((
|
|
48111
|
+
return new Promise((resolve42, reject2) => {
|
|
47117
48112
|
if (signal.aborted) {
|
|
47118
48113
|
reject2(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
47119
48114
|
return;
|
|
47120
48115
|
}
|
|
47121
|
-
const timeoutId = setTimeout(
|
|
48116
|
+
const timeoutId = setTimeout(resolve42, interval);
|
|
47122
48117
|
signal.addEventListener("abort", () => {
|
|
47123
48118
|
clearTimeout(timeoutId);
|
|
47124
48119
|
reject2(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -48069,7 +49064,7 @@ var StdioClientTransport = class {
|
|
|
48069
49064
|
if (this._process) {
|
|
48070
49065
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
48071
49066
|
}
|
|
48072
|
-
return new Promise((
|
|
49067
|
+
return new Promise((resolve42, reject2) => {
|
|
48073
49068
|
this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
|
|
48074
49069
|
// merge default env with server env because mcp server needs some env vars
|
|
48075
49070
|
env: {
|
|
@@ -48086,7 +49081,7 @@ var StdioClientTransport = class {
|
|
|
48086
49081
|
this.onerror?.(error2);
|
|
48087
49082
|
});
|
|
48088
49083
|
this._process.on("spawn", () => {
|
|
48089
|
-
|
|
49084
|
+
resolve42();
|
|
48090
49085
|
});
|
|
48091
49086
|
this._process.on("close", (_code) => {
|
|
48092
49087
|
this._process = void 0;
|
|
@@ -48151,22 +49146,22 @@ var StdioClientTransport = class {
|
|
|
48151
49146
|
if (this._process) {
|
|
48152
49147
|
const processToClose = this._process;
|
|
48153
49148
|
this._process = void 0;
|
|
48154
|
-
const closePromise = new Promise((
|
|
49149
|
+
const closePromise = new Promise((resolve42) => {
|
|
48155
49150
|
processToClose.once("close", () => {
|
|
48156
|
-
|
|
49151
|
+
resolve42();
|
|
48157
49152
|
});
|
|
48158
49153
|
});
|
|
48159
49154
|
try {
|
|
48160
49155
|
processToClose.stdin?.end();
|
|
48161
49156
|
} catch {
|
|
48162
49157
|
}
|
|
48163
|
-
await Promise.race([closePromise, new Promise((
|
|
49158
|
+
await Promise.race([closePromise, new Promise((resolve42) => setTimeout(resolve42, 2e3).unref())]);
|
|
48164
49159
|
if (processToClose.exitCode === null) {
|
|
48165
49160
|
try {
|
|
48166
49161
|
processToClose.kill("SIGTERM");
|
|
48167
49162
|
} catch {
|
|
48168
49163
|
}
|
|
48169
|
-
await Promise.race([closePromise, new Promise((
|
|
49164
|
+
await Promise.race([closePromise, new Promise((resolve42) => setTimeout(resolve42, 2e3).unref())]);
|
|
48170
49165
|
}
|
|
48171
49166
|
if (processToClose.exitCode === null) {
|
|
48172
49167
|
try {
|
|
@@ -48178,15 +49173,15 @@ var StdioClientTransport = class {
|
|
|
48178
49173
|
this._readBuffer.clear();
|
|
48179
49174
|
}
|
|
48180
49175
|
send(message) {
|
|
48181
|
-
return new Promise((
|
|
49176
|
+
return new Promise((resolve42) => {
|
|
48182
49177
|
if (!this._process?.stdin) {
|
|
48183
49178
|
throw new Error("Not connected");
|
|
48184
49179
|
}
|
|
48185
49180
|
const json2 = serializeMessage(message);
|
|
48186
49181
|
if (this._process.stdin.write(json2)) {
|
|
48187
|
-
|
|
49182
|
+
resolve42();
|
|
48188
49183
|
} else {
|
|
48189
|
-
this._process.stdin.once("drain",
|
|
49184
|
+
this._process.stdin.once("drain", resolve42);
|
|
48190
49185
|
}
|
|
48191
49186
|
});
|
|
48192
49187
|
}
|
|
@@ -48195,7 +49190,7 @@ var StdioClientTransport = class {
|
|
|
48195
49190
|
// src/commands/lock.ts
|
|
48196
49191
|
init_zod();
|
|
48197
49192
|
var DEFAULT_LOCK_TIMEOUT_MS = 2e4;
|
|
48198
|
-
var DEFAULT_CONFIG =
|
|
49193
|
+
var DEFAULT_CONFIG = join42(".kiro", "settings", "mcp.json");
|
|
48199
49194
|
var MAX_PAGES = 100;
|
|
48200
49195
|
var LOCK_HELP = `Usage: exorcist lock [options]
|
|
48201
49196
|
exorcist lock --check [options]
|
|
@@ -48259,7 +49254,7 @@ var RawToolsPage = external_exports.object({ tools: external_exports.array(exter
|
|
|
48259
49254
|
var firstLine2 = (err) => (err instanceof Error ? err.message : String(err)).split("\n")[0]?.slice(0, 300) ?? "unknown error";
|
|
48260
49255
|
async function listTools(o) {
|
|
48261
49256
|
const transport = new StdioClientTransport({ command: o.command, args: o.args, env: o.env, cwd: o.cwd, stderr: "ignore" });
|
|
48262
|
-
const client = new Client({ name: "exorcist-lock", version: "0.3.
|
|
49257
|
+
const client = new Client({ name: "exorcist-lock", version: "0.3.8" }, { capabilities: {} });
|
|
48263
49258
|
let timer;
|
|
48264
49259
|
const timedOut = new Promise((res) => {
|
|
48265
49260
|
timer = setTimeout(() => res({ ok: false, error: `it did not list its tools within ${o.timeoutMs} ms.` }), o.timeoutMs);
|
|
@@ -48300,7 +49295,7 @@ function serverEnv(base, entryEnv = {}) {
|
|
|
48300
49295
|
return { ...Object.fromEntries(inherited), ...entryEnv };
|
|
48301
49296
|
}
|
|
48302
49297
|
async function collectListings(config2, o) {
|
|
48303
|
-
const
|
|
49298
|
+
const list3 = o.list ?? listTools;
|
|
48304
49299
|
const listings = [];
|
|
48305
49300
|
const kept = [];
|
|
48306
49301
|
const notes = [];
|
|
@@ -48342,14 +49337,14 @@ async function collectListings(config2, o) {
|
|
|
48342
49337
|
if (loaders.length > 0) {
|
|
48343
49338
|
warnings.push(`HIGH EX-025: "${name}" sets ${loaders.join(", ")} in its env, which changes how its program loads (for example NODE_OPTIONS=--require runs extra code first). Make sure you know why it is there.`);
|
|
48344
49339
|
}
|
|
48345
|
-
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute27(entry.cwd) ? entry.cwd :
|
|
49340
|
+
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute27(entry.cwd) ? entry.cwd : resolve38(o.cwd, entry.cwd);
|
|
48346
49341
|
if (o.static) {
|
|
48347
49342
|
const old = o.previous && Object.hasOwn(o.previous.servers, name) ? o.previous.servers[name] : void 0;
|
|
48348
49343
|
kept.push([name, { launch: launchFingerprint(command, entry.args, cwd, void 0, pinEntry).hash, tools: old?.tools ?? {} }]);
|
|
48349
49344
|
continue;
|
|
48350
49345
|
}
|
|
48351
49346
|
jobs.push((async () => {
|
|
48352
|
-
const r = await
|
|
49347
|
+
const r = await list3({ command, args: entry.args, env: serverEnv(process.env, entry.env), cwd, timeoutMs: o.timeoutMs });
|
|
48353
49348
|
if (!r.ok) {
|
|
48354
49349
|
errors.push(`Could not list the tools of "${name}": ${r.error}`);
|
|
48355
49350
|
return;
|
|
@@ -48411,7 +49406,7 @@ ${LOCK_HELP}`);
|
|
|
48411
49406
|
io.err("--timeout must be a positive whole number of milliseconds.");
|
|
48412
49407
|
return 2;
|
|
48413
49408
|
}
|
|
48414
|
-
const lockPath2 =
|
|
49409
|
+
const lockPath2 = resolve38(str4(p.values["lock"]) ?? LOCK_FILE);
|
|
48415
49410
|
const checking = p.values["check"] === true;
|
|
48416
49411
|
const fromShield = p.values["from-shield"] === true;
|
|
48417
49412
|
const isStatic = p.values["static"] === true;
|
|
@@ -48424,7 +49419,7 @@ ${LOCK_HELP}`);
|
|
|
48424
49419
|
return 2;
|
|
48425
49420
|
}
|
|
48426
49421
|
let previous;
|
|
48427
|
-
if (
|
|
49422
|
+
if (existsSync28(lockPath2)) {
|
|
48428
49423
|
let text2;
|
|
48429
49424
|
try {
|
|
48430
49425
|
text2 = readFileSync34(lockPath2, "utf8");
|
|
@@ -48452,8 +49447,8 @@ ${LOCK_HELP}`);
|
|
|
48452
49447
|
}
|
|
48453
49448
|
current = pinsToLock(st.state);
|
|
48454
49449
|
} else {
|
|
48455
|
-
const configPath =
|
|
48456
|
-
if (!
|
|
49450
|
+
const configPath = resolve38(str4(p.values["config"]) ?? DEFAULT_CONFIG);
|
|
49451
|
+
if (!existsSync28(configPath)) {
|
|
48457
49452
|
io.err(`MCP config not found: ${configPath}. Pass --config <file>, or --from-shield.`);
|
|
48458
49453
|
return 2;
|
|
48459
49454
|
}
|
|
@@ -48501,8 +49496,8 @@ ${LOCK_HELP}`);
|
|
|
48501
49496
|
}
|
|
48502
49497
|
|
|
48503
49498
|
// src/commands/map.ts
|
|
48504
|
-
import { existsSync as
|
|
48505
|
-
import { resolve as
|
|
49499
|
+
import { existsSync as existsSync29, statSync as statSync23 } from "node:fs";
|
|
49500
|
+
import { resolve as resolve39 } from "node:path";
|
|
48506
49501
|
var MAP_HELP = `Usage: exorcist map [dir] [options]
|
|
48507
49502
|
|
|
48508
49503
|
The Haunted House Map: for every MCP config in a folder (default: the current
|
|
@@ -48559,8 +49554,8 @@ function renderConfig(c, finding) {
|
|
|
48559
49554
|
lines.push(" One poisoned page, issue or message could make the agent read your secrets and send them out.");
|
|
48560
49555
|
} else {
|
|
48561
49556
|
const empty = ROOMS.filter((r) => c.legs[r.cap].length === 0).map((r) => r.room);
|
|
48562
|
-
const
|
|
48563
|
-
lines.push(` OK No trifecta: the ${
|
|
49557
|
+
const list3 = empty.length === 1 ? empty[0] : `${empty.slice(0, -1).join(", ")} and ${empty[empty.length - 1]}`;
|
|
49558
|
+
lines.push(` OK No trifecta: the ${list3} ${empty.length === 1 ? "room is" : "rooms are"} empty.`);
|
|
48564
49559
|
}
|
|
48565
49560
|
return [...lines, ""];
|
|
48566
49561
|
}
|
|
@@ -48597,8 +49592,8 @@ ${MAP_HELP}`);
|
|
|
48597
49592
|
return 2;
|
|
48598
49593
|
}
|
|
48599
49594
|
const target = p.positionals[0] ?? ".";
|
|
48600
|
-
const root =
|
|
48601
|
-
if (!
|
|
49595
|
+
const root = resolve39(target);
|
|
49596
|
+
if (!existsSync29(root) || !statSync23(root).isDirectory()) {
|
|
48602
49597
|
io.err(`Folder not found: ${target}`);
|
|
48603
49598
|
return 2;
|
|
48604
49599
|
}
|
|
@@ -48620,8 +49615,8 @@ ${MAP_HELP}`);
|
|
|
48620
49615
|
}
|
|
48621
49616
|
|
|
48622
49617
|
// src/commands/origin.ts
|
|
48623
|
-
import { existsSync as
|
|
48624
|
-
import { posix as posix3, relative as
|
|
49618
|
+
import { existsSync as existsSync30, realpathSync as realpathSync13, statSync as statSync24 } from "node:fs";
|
|
49619
|
+
import { posix as posix3, relative as relative17, resolve as resolve40, sep as sep8 } from "node:path";
|
|
48625
49620
|
var ORIGIN_HELP = `Usage: exorcist origin [dir] [options]
|
|
48626
49621
|
|
|
48627
49622
|
Scan a git repository, then walk its history to find the commit that
|
|
@@ -48743,8 +49738,8 @@ ${ORIGIN_HELP}`);
|
|
|
48743
49738
|
${ORIGIN_HELP}`);
|
|
48744
49739
|
return 2;
|
|
48745
49740
|
}
|
|
48746
|
-
const target =
|
|
48747
|
-
if (!
|
|
49741
|
+
const target = resolve40(p.positionals[0] ?? ".");
|
|
49742
|
+
if (!existsSync30(target) || !statSync24(target).isDirectory()) {
|
|
48748
49743
|
io.err(`Not a directory: ${target}`);
|
|
48749
49744
|
return 2;
|
|
48750
49745
|
}
|
|
@@ -48758,8 +49753,8 @@ ${ORIGIN_HELP}`);
|
|
|
48758
49753
|
return 2;
|
|
48759
49754
|
}
|
|
48760
49755
|
const { root: repoRoot, shallow, boundaries } = repo;
|
|
48761
|
-
const scanRoot =
|
|
48762
|
-
const prefix =
|
|
49756
|
+
const scanRoot = realpathSync13(target);
|
|
49757
|
+
const prefix = relative17(realpathSync13(repoRoot), scanRoot).split(sep8).join("/");
|
|
48763
49758
|
if (prefix.startsWith("..")) {
|
|
48764
49759
|
io.err(`The folder is outside the git repository git reported (${repoRoot}).`);
|
|
48765
49760
|
return 2;
|
|
@@ -48831,7 +49826,7 @@ ${ORIGIN_HELP}`);
|
|
|
48831
49826
|
}
|
|
48832
49827
|
|
|
48833
49828
|
// src/commands/shield.ts
|
|
48834
|
-
import { resolve as
|
|
49829
|
+
import { resolve as resolve41 } from "node:path";
|
|
48835
49830
|
var SHIELD_HELP = `Usage: exorcist shield --server <name> [options] -- <command> [args...]
|
|
48836
49831
|
exorcist shield --server <name> --url <https://...> [options]
|
|
48837
49832
|
|
|
@@ -48936,7 +49931,7 @@ ${SHIELD_HELP}`);
|
|
|
48936
49931
|
server,
|
|
48937
49932
|
dir: stateDir(str4(p.values["dir"])),
|
|
48938
49933
|
definitionsDir: defs,
|
|
48939
|
-
...config2 ? { configPath:
|
|
49934
|
+
...config2 ? { configPath: resolve41(config2) } : {},
|
|
48940
49935
|
// Desktop notifications for critical and high alerts; EXORCIST_NOTIFY=0 or policy notify:false turns them off.
|
|
48941
49936
|
...process.env["EXORCIST_NOTIFY"] === "0" ? {} : { notify: desktopNotifier() }
|
|
48942
49937
|
};
|
|
@@ -49092,12 +50087,12 @@ ${VAULT_HELP}`);
|
|
|
49092
50087
|
};
|
|
49093
50088
|
switch (sub) {
|
|
49094
50089
|
case "list": {
|
|
49095
|
-
const
|
|
49096
|
-
if (
|
|
50090
|
+
const entries2 = listEntries(vault);
|
|
50091
|
+
if (entries2.length === 0) {
|
|
49097
50092
|
io.out("The vault is empty.");
|
|
49098
50093
|
return 0;
|
|
49099
50094
|
}
|
|
49100
|
-
for (const e of
|
|
50095
|
+
for (const e of entries2) {
|
|
49101
50096
|
io.out(`${e.id} ${e.status.padEnd(11)} ${e.kind === "mcp-server" ? `server ${e.serverName}` : e.kind === "exorcise" ? `exorcism of ${e.files?.length ?? 0} file(s) in` : "file"} ${e.target} (${e.reason})${e.trusted === true ? "" : " [NOT SIGNED BY THIS MACHINE: it cannot be restored]"}`);
|
|
49102
50097
|
}
|
|
49103
50098
|
return 0;
|
|
@@ -49157,7 +50152,7 @@ ${VAULT_HELP}`);
|
|
|
49157
50152
|
}
|
|
49158
50153
|
|
|
49159
50154
|
// src/index.ts
|
|
49160
|
-
var VERSION = "0.3.
|
|
50155
|
+
var VERSION = "0.3.8";
|
|
49161
50156
|
var HELP = `Exorcist 98 ${VERSION}: antivirus for AI coding agents
|
|
49162
50157
|
|
|
49163
50158
|
Usage: exorcist <command> [options]
|