@exorcist-98/mcp-server 0.3.0 → 0.3.1
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 +1 -1
- package/definitions/EX-036-lifecycle-script-exfiltration.yaml +27 -0
- package/dist/index.mjs +465 -105
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ out of results unless you ask for it, and is then marked as untrusted.
|
|
|
37
37
|
```json
|
|
38
38
|
{
|
|
39
39
|
"mcpServers": {
|
|
40
|
-
"exorcist": { "command": "npx", "args": ["-y", "@exorcist-98/mcp-server@0.3.
|
|
40
|
+
"exorcist": { "command": "npx", "args": ["-y", "@exorcist-98/mcp-server@0.3.1"] }
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
id: EX-036
|
|
2
|
+
title: Lifecycle script sends secrets out through a local file
|
|
3
|
+
severity: critical
|
|
4
|
+
applies_to:
|
|
5
|
+
- manifest
|
|
6
|
+
match:
|
|
7
|
+
# Code check (packages/core/src/lifecycle-scripts.ts), run by scanRepo on every
|
|
8
|
+
# walked package.json. A script that a package manager runs by itself
|
|
9
|
+
# (preinstall, install, postinstall, prepare, prepublish, and the pre/post
|
|
10
|
+
# hook of any script such as pretest) is followed into the local file it runs
|
|
11
|
+
# (node x.js, sh x.sh, python x.py, ./x). It is reported only when that file
|
|
12
|
+
# holds both a secret source (.env, .npmrc, ~/.aws, ~/.ssh, a private key
|
|
13
|
+
# file, the whole of process.env) and a sender (http, https, fetch, a socket,
|
|
14
|
+
# curl or wget). A script that only builds, lints or starts a local server,
|
|
15
|
+
# reads .env and never sends, or sends and reads no secret, is quiet.
|
|
16
|
+
# Not a text pattern: the signature engine skips this rule.
|
|
17
|
+
analysis: lifecycle-scripts
|
|
18
|
+
owasp:
|
|
19
|
+
- "ASI07 Supply Chain Vulnerabilities"
|
|
20
|
+
- "LLM02:2025 Sensitive Information Disclosure"
|
|
21
|
+
- "ASI05 Sensitive Data Leakage"
|
|
22
|
+
fix: >
|
|
23
|
+
Do not run this project's scripts until you have read the file named in the
|
|
24
|
+
finding. A script like this runs when you (or your AI agent) install the
|
|
25
|
+
project or run its tests, and it sends your .env or credentials to another
|
|
26
|
+
computer with no instruction for the agent to obey. Remove the script, or
|
|
27
|
+
remove the code in the file that reads secrets or sends data out.
|
package/dist/index.mjs
CHANGED
|
@@ -7083,7 +7083,7 @@ var require_compile = __commonJS({
|
|
|
7083
7083
|
const schOrFunc = root.refs[ref];
|
|
7084
7084
|
if (schOrFunc)
|
|
7085
7085
|
return schOrFunc;
|
|
7086
|
-
let _sch =
|
|
7086
|
+
let _sch = resolve7.call(this, root, ref);
|
|
7087
7087
|
if (_sch === void 0) {
|
|
7088
7088
|
const schema2 = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
7089
7089
|
const { schemaId } = this.opts;
|
|
@@ -7110,7 +7110,7 @@ var require_compile = __commonJS({
|
|
|
7110
7110
|
function sameSchemaEnv(s1, s2) {
|
|
7111
7111
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
7112
7112
|
}
|
|
7113
|
-
function
|
|
7113
|
+
function resolve7(root, ref) {
|
|
7114
7114
|
let sch;
|
|
7115
7115
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
7116
7116
|
ref = sch;
|
|
@@ -7974,7 +7974,7 @@ var require_fast_uri = __commonJS({
|
|
|
7974
7974
|
}
|
|
7975
7975
|
return uri;
|
|
7976
7976
|
}
|
|
7977
|
-
function
|
|
7977
|
+
function resolve7(baseURI, relativeURI, options) {
|
|
7978
7978
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
7979
7979
|
const {
|
|
7980
7980
|
parsed: baseParsed,
|
|
@@ -8010,50 +8010,50 @@ var require_fast_uri = __commonJS({
|
|
|
8010
8010
|
schemelessOptions.skipEscape = true;
|
|
8011
8011
|
return serialize(resolved, schemelessOptions);
|
|
8012
8012
|
}
|
|
8013
|
-
function resolveComponent(base,
|
|
8013
|
+
function resolveComponent(base, relative5, options, skipNormalization) {
|
|
8014
8014
|
const target = {};
|
|
8015
8015
|
if (!skipNormalization) {
|
|
8016
8016
|
base = parse4(serialize(base, options), options);
|
|
8017
|
-
|
|
8017
|
+
relative5 = parse4(serialize(relative5, options), options);
|
|
8018
8018
|
}
|
|
8019
8019
|
options = options || {};
|
|
8020
|
-
if (!options.tolerant &&
|
|
8021
|
-
target.scheme =
|
|
8022
|
-
target.userinfo =
|
|
8023
|
-
target.host =
|
|
8024
|
-
target.port =
|
|
8025
|
-
target.path = removeDotSegments(
|
|
8026
|
-
target.query =
|
|
8020
|
+
if (!options.tolerant && relative5.scheme) {
|
|
8021
|
+
target.scheme = relative5.scheme;
|
|
8022
|
+
target.userinfo = relative5.userinfo;
|
|
8023
|
+
target.host = relative5.host;
|
|
8024
|
+
target.port = relative5.port;
|
|
8025
|
+
target.path = removeDotSegments(relative5.path || "");
|
|
8026
|
+
target.query = relative5.query;
|
|
8027
8027
|
} else {
|
|
8028
|
-
if (
|
|
8029
|
-
target.userinfo =
|
|
8030
|
-
target.host =
|
|
8031
|
-
target.port =
|
|
8032
|
-
target.path = removeDotSegments(
|
|
8033
|
-
target.query =
|
|
8028
|
+
if (relative5.userinfo !== void 0 || relative5.host !== void 0 || relative5.port !== void 0) {
|
|
8029
|
+
target.userinfo = relative5.userinfo;
|
|
8030
|
+
target.host = relative5.host;
|
|
8031
|
+
target.port = relative5.port;
|
|
8032
|
+
target.path = removeDotSegments(relative5.path || "");
|
|
8033
|
+
target.query = relative5.query;
|
|
8034
8034
|
} else {
|
|
8035
|
-
if (!
|
|
8035
|
+
if (!relative5.path) {
|
|
8036
8036
|
target.path = base.path;
|
|
8037
|
-
if (
|
|
8038
|
-
target.query =
|
|
8037
|
+
if (relative5.query !== void 0) {
|
|
8038
|
+
target.query = relative5.query;
|
|
8039
8039
|
} else {
|
|
8040
8040
|
target.query = base.query;
|
|
8041
8041
|
}
|
|
8042
8042
|
} else {
|
|
8043
|
-
if (
|
|
8044
|
-
target.path = removeDotSegments(
|
|
8043
|
+
if (relative5.path[0] === "/") {
|
|
8044
|
+
target.path = removeDotSegments(relative5.path);
|
|
8045
8045
|
} else {
|
|
8046
8046
|
const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
|
|
8047
8047
|
if (baseHasAuthority && !base.path) {
|
|
8048
|
-
target.path = "/" +
|
|
8048
|
+
target.path = "/" + relative5.path;
|
|
8049
8049
|
} else if (!base.path) {
|
|
8050
|
-
target.path =
|
|
8050
|
+
target.path = relative5.path;
|
|
8051
8051
|
} else {
|
|
8052
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
8052
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative5.path;
|
|
8053
8053
|
}
|
|
8054
8054
|
target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
|
|
8055
8055
|
}
|
|
8056
|
-
target.query =
|
|
8056
|
+
target.query = relative5.query;
|
|
8057
8057
|
}
|
|
8058
8058
|
target.userinfo = base.userinfo;
|
|
8059
8059
|
target.host = base.host;
|
|
@@ -8061,7 +8061,7 @@ var require_fast_uri = __commonJS({
|
|
|
8061
8061
|
}
|
|
8062
8062
|
target.scheme = base.scheme;
|
|
8063
8063
|
}
|
|
8064
|
-
target.fragment =
|
|
8064
|
+
target.fragment = relative5.fragment;
|
|
8065
8065
|
return target;
|
|
8066
8066
|
}
|
|
8067
8067
|
function equal(uriA, uriB, options) {
|
|
@@ -8365,7 +8365,7 @@ var require_fast_uri = __commonJS({
|
|
|
8365
8365
|
var fastUri = {
|
|
8366
8366
|
SCHEMES,
|
|
8367
8367
|
normalize: normalize2,
|
|
8368
|
-
resolve:
|
|
8368
|
+
resolve: resolve7,
|
|
8369
8369
|
resolveComponent,
|
|
8370
8370
|
equal,
|
|
8371
8371
|
serialize,
|
|
@@ -20237,7 +20237,7 @@ var Protocol = class {
|
|
|
20237
20237
|
return;
|
|
20238
20238
|
}
|
|
20239
20239
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
20240
|
-
await new Promise((
|
|
20240
|
+
await new Promise((resolve7) => setTimeout(resolve7, pollInterval));
|
|
20241
20241
|
options?.signal?.throwIfAborted();
|
|
20242
20242
|
}
|
|
20243
20243
|
} catch (error2) {
|
|
@@ -20254,7 +20254,7 @@ var Protocol = class {
|
|
|
20254
20254
|
*/
|
|
20255
20255
|
request(request, resultSchema, options) {
|
|
20256
20256
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
20257
|
-
return new Promise((
|
|
20257
|
+
return new Promise((resolve7, reject) => {
|
|
20258
20258
|
const earlyReject = (error2) => {
|
|
20259
20259
|
reject(error2);
|
|
20260
20260
|
};
|
|
@@ -20332,7 +20332,7 @@ var Protocol = class {
|
|
|
20332
20332
|
if (!parseResult.success) {
|
|
20333
20333
|
reject(parseResult.error);
|
|
20334
20334
|
} else {
|
|
20335
|
-
|
|
20335
|
+
resolve7(parseResult.data);
|
|
20336
20336
|
}
|
|
20337
20337
|
} catch (error2) {
|
|
20338
20338
|
reject(error2);
|
|
@@ -20594,12 +20594,12 @@ var Protocol = class {
|
|
|
20594
20594
|
}
|
|
20595
20595
|
} catch {
|
|
20596
20596
|
}
|
|
20597
|
-
return new Promise((
|
|
20597
|
+
return new Promise((resolve7, reject) => {
|
|
20598
20598
|
if (signal.aborted) {
|
|
20599
20599
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
20600
20600
|
return;
|
|
20601
20601
|
}
|
|
20602
|
-
const timeoutId = setTimeout(
|
|
20602
|
+
const timeoutId = setTimeout(resolve7, interval);
|
|
20603
20603
|
signal.addEventListener("abort", () => {
|
|
20604
20604
|
clearTimeout(timeoutId);
|
|
20605
20605
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -21740,7 +21740,7 @@ var McpServer = class {
|
|
|
21740
21740
|
let task = createTaskResult.task;
|
|
21741
21741
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
21742
21742
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
21743
|
-
await new Promise((
|
|
21743
|
+
await new Promise((resolve7) => setTimeout(resolve7, pollInterval));
|
|
21744
21744
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
21745
21745
|
if (!updatedTask) {
|
|
21746
21746
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -22404,12 +22404,12 @@ var StdioServerTransport = class {
|
|
|
22404
22404
|
this.onclose?.();
|
|
22405
22405
|
}
|
|
22406
22406
|
send(message) {
|
|
22407
|
-
return new Promise((
|
|
22407
|
+
return new Promise((resolve7) => {
|
|
22408
22408
|
const json2 = serializeMessage(message);
|
|
22409
22409
|
if (this._stdout.write(json2)) {
|
|
22410
|
-
|
|
22410
|
+
resolve7();
|
|
22411
22411
|
} else {
|
|
22412
|
-
this._stdout.once("drain",
|
|
22412
|
+
this._stdout.once("drain", resolve7);
|
|
22413
22413
|
}
|
|
22414
22414
|
});
|
|
22415
22415
|
}
|
|
@@ -22421,7 +22421,7 @@ import { homedir as homedir3 } from "node:os";
|
|
|
22421
22421
|
import { delimiter } from "node:path";
|
|
22422
22422
|
|
|
22423
22423
|
// src/tools.ts
|
|
22424
|
-
import { existsSync as
|
|
22424
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync5 } from "node:fs";
|
|
22425
22425
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
22426
22426
|
|
|
22427
22427
|
// ../shield/src/jsonrpc.ts
|
|
@@ -25694,7 +25694,8 @@ var MatchSchema = external_exports.object({
|
|
|
25694
25694
|
// `detonation` is the Detonation Chamber (EX-024, m5-detonation): a
|
|
25695
25695
|
// sandboxed model run, only with `--detonate`.
|
|
25696
25696
|
// `path-names` checks the names of every walked path (EX-029, path-names.ts).
|
|
25697
|
-
|
|
25697
|
+
// `lifecycle-scripts` follows a package.json lifecycle script into the local file it runs (EX-036, lifecycle-scripts.ts).
|
|
25698
|
+
analysis: external_exports.enum(["trifecta", "detonation", "path-names", "lifecycle-scripts"]).optional(),
|
|
25698
25699
|
// Text an element hides from a person by its style (EX-028, hidden-text.ts):
|
|
25699
25700
|
// reported only when the hidden text addresses the AI or asks for actions.
|
|
25700
25701
|
hidden_text: external_exports.boolean().optional(),
|
|
@@ -27791,7 +27792,7 @@ function skipArgument(text, p, lang, limit) {
|
|
|
27791
27792
|
}
|
|
27792
27793
|
return -1;
|
|
27793
27794
|
}
|
|
27794
|
-
function findKeyString(text, open3, lang, limit,
|
|
27795
|
+
function findKeyString(text, open3, lang, limit, sep3) {
|
|
27795
27796
|
let depth = 0;
|
|
27796
27797
|
let i = open3;
|
|
27797
27798
|
let lit = null;
|
|
@@ -27801,7 +27802,7 @@ function findKeyString(text, open3, lang, limit, sep2) {
|
|
|
27801
27802
|
};
|
|
27802
27803
|
const sepAt = (p) => {
|
|
27803
27804
|
const j = skipTrivia(text, p, lang, limit);
|
|
27804
|
-
if (text[j] !==
|
|
27805
|
+
if (text[j] !== sep3 || sep3 === "=" && text[j + 1] === "=") return -1;
|
|
27805
27806
|
return j + 1;
|
|
27806
27807
|
};
|
|
27807
27808
|
while (i < limit) {
|
|
@@ -28159,12 +28160,328 @@ function checkPathSegment(name) {
|
|
|
28159
28160
|
return null;
|
|
28160
28161
|
}
|
|
28161
28162
|
|
|
28163
|
+
// ../core/src/lifecycle-scripts.ts
|
|
28164
|
+
import { closeSync, existsSync, openSync, readSync, realpathSync, statSync } from "node:fs";
|
|
28165
|
+
import { isAbsolute as isAbsolute2, join as join5, relative as relative3, resolve as resolve2, sep } from "node:path";
|
|
28166
|
+
|
|
28167
|
+
// ../core/src/shell-words.ts
|
|
28168
|
+
var MAX_COMMAND_CHARS = 65536;
|
|
28169
|
+
var REDIRECT = /^\d*[<>]+&?\d*-?$/;
|
|
28170
|
+
var REDIRECT_WITH_TARGET = /^\d*[<>]+&?[^\s<>]/;
|
|
28171
|
+
function splitShell(command) {
|
|
28172
|
+
if (command.length > MAX_COMMAND_CHARS) return { ok: false };
|
|
28173
|
+
const segments = [];
|
|
28174
|
+
let words2 = [];
|
|
28175
|
+
let cur = "";
|
|
28176
|
+
let started = false;
|
|
28177
|
+
let quote = null;
|
|
28178
|
+
const endWord = () => {
|
|
28179
|
+
if (started) words2.push(cur);
|
|
28180
|
+
cur = "";
|
|
28181
|
+
started = false;
|
|
28182
|
+
};
|
|
28183
|
+
const endSegment = () => {
|
|
28184
|
+
endWord();
|
|
28185
|
+
const kept = [];
|
|
28186
|
+
for (let i = 0; i < words2.length; i++) {
|
|
28187
|
+
const w = words2[i] ?? "";
|
|
28188
|
+
if (REDIRECT.test(w)) {
|
|
28189
|
+
i += 1;
|
|
28190
|
+
continue;
|
|
28191
|
+
}
|
|
28192
|
+
if (REDIRECT_WITH_TARGET.test(w)) continue;
|
|
28193
|
+
kept.push(w);
|
|
28194
|
+
}
|
|
28195
|
+
if (kept.length > 0) segments.push(kept);
|
|
28196
|
+
words2 = [];
|
|
28197
|
+
};
|
|
28198
|
+
for (let i = 0; i < command.length; i++) {
|
|
28199
|
+
const c = command[i] ?? "";
|
|
28200
|
+
if (quote === "'") {
|
|
28201
|
+
if (c === "'") quote = null;
|
|
28202
|
+
else cur += c;
|
|
28203
|
+
continue;
|
|
28204
|
+
}
|
|
28205
|
+
if (quote === '"') {
|
|
28206
|
+
if (c === '"') quote = null;
|
|
28207
|
+
else if (c === "\\" && i + 1 < command.length && /["\\$`]/.test(command[i + 1] ?? "")) {
|
|
28208
|
+
cur += command[i + 1] ?? "";
|
|
28209
|
+
i += 1;
|
|
28210
|
+
} else cur += c;
|
|
28211
|
+
continue;
|
|
28212
|
+
}
|
|
28213
|
+
if (c === "\\") {
|
|
28214
|
+
if (i + 1 >= command.length) return { ok: false };
|
|
28215
|
+
cur += command[i + 1] ?? "";
|
|
28216
|
+
started = true;
|
|
28217
|
+
i += 1;
|
|
28218
|
+
} else if (c === "'" || c === '"') {
|
|
28219
|
+
quote = c;
|
|
28220
|
+
started = true;
|
|
28221
|
+
} else if (c === " " || c === " ") {
|
|
28222
|
+
endWord();
|
|
28223
|
+
} else if (c === ";" || c === "\n" || c === "|" || c === "&" || c === "(" || c === ")") {
|
|
28224
|
+
if (c === "&" && (/[<>]$/.test(cur) || command[i + 1] === ">")) {
|
|
28225
|
+
cur += c;
|
|
28226
|
+
started = true;
|
|
28227
|
+
continue;
|
|
28228
|
+
}
|
|
28229
|
+
endSegment();
|
|
28230
|
+
} else {
|
|
28231
|
+
cur += c;
|
|
28232
|
+
started = true;
|
|
28233
|
+
}
|
|
28234
|
+
}
|
|
28235
|
+
if (quote !== null) return { ok: false };
|
|
28236
|
+
endSegment();
|
|
28237
|
+
return { ok: true, segments };
|
|
28238
|
+
}
|
|
28239
|
+
function isPlainWord(word) {
|
|
28240
|
+
return word !== "" && !/[$`*?[\]{}]/.test(word) && !word.startsWith("~") && !word.includes("\0");
|
|
28241
|
+
}
|
|
28242
|
+
function stripPrefixes(words2) {
|
|
28243
|
+
let i = 0;
|
|
28244
|
+
for (; ; ) {
|
|
28245
|
+
const w = words2[i];
|
|
28246
|
+
if (w === void 0) break;
|
|
28247
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(w)) {
|
|
28248
|
+
i += 1;
|
|
28249
|
+
continue;
|
|
28250
|
+
}
|
|
28251
|
+
if (w === "env" || w === "sudo" || w === "time" || w === "nohup" || w === "command" || w === "exec") {
|
|
28252
|
+
i += 1;
|
|
28253
|
+
continue;
|
|
28254
|
+
}
|
|
28255
|
+
if (w === "cross-env") {
|
|
28256
|
+
i += 1;
|
|
28257
|
+
continue;
|
|
28258
|
+
}
|
|
28259
|
+
break;
|
|
28260
|
+
}
|
|
28261
|
+
return words2.slice(i);
|
|
28262
|
+
}
|
|
28263
|
+
|
|
28264
|
+
// ../core/src/lifecycle-scripts.ts
|
|
28265
|
+
var INSTALL_HOOKS = [
|
|
28266
|
+
"preinstall",
|
|
28267
|
+
"install",
|
|
28268
|
+
"postinstall",
|
|
28269
|
+
"prepublish",
|
|
28270
|
+
"preprepare",
|
|
28271
|
+
"prepare",
|
|
28272
|
+
"postprepare",
|
|
28273
|
+
"prepublishOnly",
|
|
28274
|
+
"prepack",
|
|
28275
|
+
"postpack"
|
|
28276
|
+
];
|
|
28277
|
+
var HOOK_BASES = /* @__PURE__ */ new Set(["test", "start", "stop", "restart", "build", "install", "publish", "version", "pack", "uninstall", "shrinkwrap"]);
|
|
28278
|
+
var MAX_FOLLOW_DEPTH = 3;
|
|
28279
|
+
var MAX_SOURCE_BYTES = 1048576;
|
|
28280
|
+
var MAX_SCRIPTS = 500;
|
|
28281
|
+
function parseScripts(pkgText) {
|
|
28282
|
+
try {
|
|
28283
|
+
const parsed = JSON.parse(pkgText);
|
|
28284
|
+
if (typeof parsed !== "object" || parsed === null) return {};
|
|
28285
|
+
const s = parsed["scripts"];
|
|
28286
|
+
if (typeof s !== "object" || s === null || Array.isArray(s)) return {};
|
|
28287
|
+
const out = {};
|
|
28288
|
+
for (const [k, v] of Object.entries(s).slice(0, MAX_SCRIPTS)) if (typeof v === "string") out[k] = v;
|
|
28289
|
+
return out;
|
|
28290
|
+
} catch {
|
|
28291
|
+
return {};
|
|
28292
|
+
}
|
|
28293
|
+
}
|
|
28294
|
+
function isAutoScript(name, scripts) {
|
|
28295
|
+
if (INSTALL_HOOKS.includes(name)) return true;
|
|
28296
|
+
const m = /^(pre|post)(.+)$/.exec(name);
|
|
28297
|
+
if (!m) return false;
|
|
28298
|
+
const base = m[2] ?? "";
|
|
28299
|
+
return Object.prototype.hasOwnProperty.call(scripts, base) || HOOK_BASES.has(base);
|
|
28300
|
+
}
|
|
28301
|
+
function autoScriptNames(scripts) {
|
|
28302
|
+
return Object.keys(scripts).filter((n) => isAutoScript(n, scripts));
|
|
28303
|
+
}
|
|
28304
|
+
var INTERPRETERS = /* @__PURE__ */ new Set(["node", "nodejs", "tsx", "ts-node", "bun", "deno", "sh", "bash", "zsh", "dash", "python", "python3", "ruby", "perl", "php"]);
|
|
28305
|
+
var INLINE_FLAGS = /* @__PURE__ */ new Set(["-e", "-c", "-p", "--eval", "--print"]);
|
|
28306
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set(["-r", "--require", "--import", "--loader", "--experimental-loader", "-C", "-W", "-X", "-m"]);
|
|
28307
|
+
var RUN_WORDS = /* @__PURE__ */ new Set(["run", "run-script", "rum", "urn"]);
|
|
28308
|
+
function cleanRel(p) {
|
|
28309
|
+
if (!isPlainWord(p) || /^[a-z][a-z0-9+.-]*:/i.test(p) || isAbsolute2(p) || p.length > 300) return null;
|
|
28310
|
+
const rel = p.replace(/^(?:\.\/)+/, "");
|
|
28311
|
+
return rel === "" ? null : rel;
|
|
28312
|
+
}
|
|
28313
|
+
function scriptTargets(name, scripts, depth = 0, seen = /* @__PURE__ */ new Set()) {
|
|
28314
|
+
const out = { files: [], inline: [], scripts: [] };
|
|
28315
|
+
const text = scripts[name];
|
|
28316
|
+
if (text === void 0 || seen.has(name) || depth > MAX_FOLLOW_DEPTH) return out;
|
|
28317
|
+
seen.add(name);
|
|
28318
|
+
out.inline.push(text);
|
|
28319
|
+
const split = splitShell(text);
|
|
28320
|
+
if (!split.ok) return out;
|
|
28321
|
+
for (const raw of split.segments) {
|
|
28322
|
+
const words2 = stripPrefixes(raw);
|
|
28323
|
+
const head = words2[0];
|
|
28324
|
+
if (head === void 0) continue;
|
|
28325
|
+
const base = head.split("/").pop() ?? head;
|
|
28326
|
+
if ((base === "npm" || base === "pnpm" || base === "yarn") && depth < MAX_FOLLOW_DEPTH) {
|
|
28327
|
+
const sub = words2[1] === "run" || RUN_WORDS.has(words2[1] ?? "") ? words2[2] : base === "yarn" || base === "pnpm" ? words2[1] : void 0;
|
|
28328
|
+
if (sub !== void 0 && Object.prototype.hasOwnProperty.call(scripts, sub)) {
|
|
28329
|
+
out.scripts.push(sub);
|
|
28330
|
+
const inner = scriptTargets(sub, scripts, depth + 1, seen);
|
|
28331
|
+
out.files.push(...inner.files);
|
|
28332
|
+
out.inline.push(...inner.inline);
|
|
28333
|
+
out.scripts.push(...inner.scripts);
|
|
28334
|
+
}
|
|
28335
|
+
continue;
|
|
28336
|
+
}
|
|
28337
|
+
if (INTERPRETERS.has(base)) {
|
|
28338
|
+
for (let i = 1; i < words2.length; i++) {
|
|
28339
|
+
const w = words2[i] ?? "";
|
|
28340
|
+
if (INLINE_FLAGS.has(w)) {
|
|
28341
|
+
out.inline.push(words2[i + 1] ?? "");
|
|
28342
|
+
break;
|
|
28343
|
+
}
|
|
28344
|
+
if (VALUE_FLAGS.has(w)) {
|
|
28345
|
+
i += 1;
|
|
28346
|
+
continue;
|
|
28347
|
+
}
|
|
28348
|
+
if (w.startsWith("-")) continue;
|
|
28349
|
+
if (base === "deno" && (w === "run" || w === "task")) continue;
|
|
28350
|
+
const rel = cleanRel(w);
|
|
28351
|
+
if (rel !== null) out.files.push(rel);
|
|
28352
|
+
break;
|
|
28353
|
+
}
|
|
28354
|
+
continue;
|
|
28355
|
+
}
|
|
28356
|
+
if (head.startsWith("./") || head.startsWith("scripts/") || head.includes("/") && !head.startsWith("-") && !head.includes(":")) {
|
|
28357
|
+
const rel = cleanRel(head);
|
|
28358
|
+
if (rel !== null) out.files.push(rel);
|
|
28359
|
+
}
|
|
28360
|
+
}
|
|
28361
|
+
return out;
|
|
28362
|
+
}
|
|
28363
|
+
var SECRET_PATTERNS = [
|
|
28364
|
+
[/(?<![\w])\.env(?!\.(?:example|sample|template|dist))(?:\.[A-Za-z]+)?(?![\w-])/, ".env"],
|
|
28365
|
+
[/(?<![\w])\.npmrc\b/, ".npmrc"],
|
|
28366
|
+
[/(?<![\w])\.aws(?![\w-])/, "~/.aws"],
|
|
28367
|
+
[/(?<![\w])\.ssh(?![\w-])/, "~/.ssh"],
|
|
28368
|
+
[/\bid_(?:rsa|ed25519|ecdsa)\b/, "a private key file"],
|
|
28369
|
+
[/(?<![\w])\.(?:netrc|git-credentials|pypirc)\b/, "a credentials file"],
|
|
28370
|
+
[/JSON\.stringify\(\s*process\.env\s*[,)]/, "the whole of process.env"],
|
|
28371
|
+
[/Object\.(?:entries|keys|values|fromEntries|assign)\(\s*(?:\{\}\s*,\s*)?process\.env\s*\)/, "the whole of process.env"],
|
|
28372
|
+
[/\{\s*\.\.\.\s*process\.env\s*\}/, "the whole of process.env"],
|
|
28373
|
+
[/\bdict\(\s*os\.environ\s*\)|\bos\.environ\.(?:items|copy)\(\)|json\.dumps\(\s*os\.environ/, "the whole of os.environ"],
|
|
28374
|
+
[/(?:^|[;&|]\s*|\$\(\s*)(?:printenv|env)\s*(?:$|[|>)]|\s*\|)/, "the whole environment"]
|
|
28375
|
+
];
|
|
28376
|
+
var SEND_PATTERNS = [
|
|
28377
|
+
[/\bhttps?\.(?:request|get)\s*\(/, "an http request"],
|
|
28378
|
+
[/\bfetch\s*\(/, "fetch"],
|
|
28379
|
+
[/\baxios(?:\.\w+)?\s*\(|\bgot(?:\.(?:post|get|put))?\s*\(\s*['"`]/, "an http client call"],
|
|
28380
|
+
[/new\s+XMLHttpRequest\b|new\s+WebSocket\s*\(/, "a browser-style request"],
|
|
28381
|
+
[/\bnet\.(?:connect|createConnection|Socket)\b/, "a socket"],
|
|
28382
|
+
[/require\(\s*['"](?:node:)?dgram['"]\s*\)|from\s+['"](?:node:)?dgram['"]/, "a datagram socket"],
|
|
28383
|
+
[/\b(?:curl|wget)\s+(?:-\S+\s+)*\S/, "curl or wget"],
|
|
28384
|
+
[/\/dev\/tcp\//, "/dev/tcp"],
|
|
28385
|
+
[/\bnc\s+\S+\s+\d+/, "netcat"],
|
|
28386
|
+
[/\burlopen\s*\(|\brequests\.(?:get|post|put)\s*\(|\bhttp\.client\b|\bsocket\.(?:socket|create_connection)\b|\bsmtplib\b/, "a python network call"]
|
|
28387
|
+
];
|
|
28388
|
+
var lineHit = (lines, patterns) => {
|
|
28389
|
+
for (let i = 0; i < lines.length; i++) {
|
|
28390
|
+
const line = lines[i] ?? "";
|
|
28391
|
+
if (line.length > 4e3) continue;
|
|
28392
|
+
for (const [re2, label] of patterns) if (re2.test(line)) return { line: i + 1, label };
|
|
28393
|
+
}
|
|
28394
|
+
return null;
|
|
28395
|
+
};
|
|
28396
|
+
function analyzeSource(text) {
|
|
28397
|
+
const lines = text.split(/\r?\n/);
|
|
28398
|
+
return { secret: lineHit(lines, SECRET_PATTERNS), send: lineHit(lines, SEND_PATTERNS) };
|
|
28399
|
+
}
|
|
28400
|
+
function locateScript(pkgText, name) {
|
|
28401
|
+
const start = pkgText.search(/"scripts"\s*:/);
|
|
28402
|
+
const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
28403
|
+
const re2 = new RegExp(`"${esc2}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`, "g");
|
|
28404
|
+
re2.lastIndex = Math.max(0, start);
|
|
28405
|
+
const m = re2.exec(pkgText);
|
|
28406
|
+
if (!m) return { line: 1, col: 1, span: name.slice(0, 120) };
|
|
28407
|
+
const valueIndex = m.index + m[0].indexOf('"', m[0].indexOf(":")) + 1;
|
|
28408
|
+
const before = pkgText.slice(0, valueIndex);
|
|
28409
|
+
const line = before.split("\n").length;
|
|
28410
|
+
const col = valueIndex - (before.lastIndexOf("\n") + 1) + 1;
|
|
28411
|
+
return { line, col, span: (m[1] ?? "").slice(0, 120) };
|
|
28412
|
+
}
|
|
28413
|
+
function lifecycleFindings(input) {
|
|
28414
|
+
const scripts = parseScripts(input.pkgText);
|
|
28415
|
+
const names = (input.names ?? autoScriptNames(scripts)).filter((n) => Object.prototype.hasOwnProperty.call(scripts, n));
|
|
28416
|
+
const hits = [];
|
|
28417
|
+
for (const name of names) {
|
|
28418
|
+
let found = null;
|
|
28419
|
+
try {
|
|
28420
|
+
const targets = scriptTargets(name, scripts);
|
|
28421
|
+
const where = locateScript(input.pkgText, name);
|
|
28422
|
+
const base = { script: name, scriptText: scripts[name] ?? "", ...where };
|
|
28423
|
+
for (const rel of [...new Set(targets.files)]) {
|
|
28424
|
+
const text = input.readLocal(rel);
|
|
28425
|
+
if (text === null) continue;
|
|
28426
|
+
const a = analyzeSource(text);
|
|
28427
|
+
if (a.secret && a.send) {
|
|
28428
|
+
found = { ...base, file: rel, secret: a.secret, send: a.send };
|
|
28429
|
+
break;
|
|
28430
|
+
}
|
|
28431
|
+
}
|
|
28432
|
+
if (!found) {
|
|
28433
|
+
for (const inline of targets.inline) {
|
|
28434
|
+
const a = analyzeSource(inline);
|
|
28435
|
+
if (a.secret && a.send) {
|
|
28436
|
+
found = { ...base, file: null, secret: a.secret, send: a.send };
|
|
28437
|
+
break;
|
|
28438
|
+
}
|
|
28439
|
+
}
|
|
28440
|
+
}
|
|
28441
|
+
} catch {
|
|
28442
|
+
found = null;
|
|
28443
|
+
}
|
|
28444
|
+
if (found) hits.push(found);
|
|
28445
|
+
}
|
|
28446
|
+
return hits;
|
|
28447
|
+
}
|
|
28448
|
+
function describeHit(h) {
|
|
28449
|
+
const where = h.file === null ? `The script text itself reads ${h.secret.label} and sends data out (${h.send.label}).` : `It runs ${h.file}, which reads ${h.secret.label} (line ${h.secret.line}) and sends data out through ${h.send.label} (line ${h.send.line}).`;
|
|
28450
|
+
return `The "${h.script}" script of package.json runs by itself when a package manager installs or tests this project. ${where}`;
|
|
28451
|
+
}
|
|
28452
|
+
function readLocalText(pkgDir, rel) {
|
|
28453
|
+
try {
|
|
28454
|
+
const abs = resolve2(pkgDir, rel);
|
|
28455
|
+
const within = (root, p) => {
|
|
28456
|
+
const r = relative3(root, p);
|
|
28457
|
+
return r !== "" && !r.startsWith("..") && !isAbsolute2(r) && !r.split(sep).includes("..");
|
|
28458
|
+
};
|
|
28459
|
+
if (!within(pkgDir, abs) || !existsSync(abs)) return null;
|
|
28460
|
+
const real = realpathSync(abs);
|
|
28461
|
+
if (!within(realpathSync(pkgDir), real)) return null;
|
|
28462
|
+
const st = statSync(real);
|
|
28463
|
+
if (!st.isFile() || st.size > MAX_SOURCE_BYTES) return null;
|
|
28464
|
+
const buf = Buffer.alloc(st.size);
|
|
28465
|
+
const fd = openSync(real, "r");
|
|
28466
|
+
try {
|
|
28467
|
+
readSync(fd, buf, 0, st.size, 0);
|
|
28468
|
+
} finally {
|
|
28469
|
+
closeSync(fd);
|
|
28470
|
+
}
|
|
28471
|
+
if (buf.includes(0)) return null;
|
|
28472
|
+
return buf.toString("utf8");
|
|
28473
|
+
} catch {
|
|
28474
|
+
return null;
|
|
28475
|
+
}
|
|
28476
|
+
}
|
|
28477
|
+
|
|
28162
28478
|
// ../core/src/scanner/orchestrator.ts
|
|
28479
|
+
import { dirname } from "node:path";
|
|
28163
28480
|
init_heuristic_engine();
|
|
28164
28481
|
|
|
28165
28482
|
// ../core/src/capabilities.ts
|
|
28166
28483
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
28167
|
-
import { join as
|
|
28484
|
+
import { join as join6 } from "node:path";
|
|
28168
28485
|
init_zod();
|
|
28169
28486
|
var CAPABILITIES = ["private-data", "untrusted-input", "exfiltration"];
|
|
28170
28487
|
var CAPABILITIES_FILE = "capabilities.yaml";
|
|
@@ -28237,7 +28554,7 @@ function parseCapabilityRules(data) {
|
|
|
28237
28554
|
async function loadCapabilityRules(definitionsDir) {
|
|
28238
28555
|
let raw;
|
|
28239
28556
|
try {
|
|
28240
|
-
raw = await readFile2(
|
|
28557
|
+
raw = await readFile2(join6(definitionsDir, CAPABILITIES_FILE), "utf8");
|
|
28241
28558
|
} catch {
|
|
28242
28559
|
return { ok: false, missing: true, error: `${CAPABILITIES_FILE} was not found in ${definitionsDir}` };
|
|
28243
28560
|
}
|
|
@@ -28519,7 +28836,7 @@ function classifyCapabilities(server2, rules) {
|
|
|
28519
28836
|
init_zod();
|
|
28520
28837
|
import { constants } from "node:fs";
|
|
28521
28838
|
import { lstat, open as open2 } from "node:fs/promises";
|
|
28522
|
-
import { join as
|
|
28839
|
+
import { join as join7 } from "node:path";
|
|
28523
28840
|
init_severity_paths();
|
|
28524
28841
|
init_walker();
|
|
28525
28842
|
var TRIFECTA_RULE_ID = "EX-023";
|
|
@@ -28658,7 +28975,7 @@ function parsePins(json2) {
|
|
|
28658
28975
|
return out;
|
|
28659
28976
|
}
|
|
28660
28977
|
async function readPins(root, maxBytes = MAX_PINS_BYTES) {
|
|
28661
|
-
const path =
|
|
28978
|
+
const path = join7(root, ".exorcist", "pins.json");
|
|
28662
28979
|
const none = (note) => ({ pins: /* @__PURE__ */ new Map(), note });
|
|
28663
28980
|
let info;
|
|
28664
28981
|
try {
|
|
@@ -28818,6 +29135,21 @@ async function* pathNameFindings(root, def) {
|
|
|
28818
29135
|
} catch {
|
|
28819
29136
|
}
|
|
28820
29137
|
}
|
|
29138
|
+
function lifecycleScanFindings(text, absPath, rel, def) {
|
|
29139
|
+
const dir = dirname(absPath);
|
|
29140
|
+
return lifecycleFindings({ pkgText: text, readLocal: (r) => readLocalText(dir, r) }).map((h) => ({
|
|
29141
|
+
source: "signature",
|
|
29142
|
+
ruleId: def.id,
|
|
29143
|
+
title: def.title,
|
|
29144
|
+
severity: def.severity,
|
|
29145
|
+
file: rel,
|
|
29146
|
+
line: h.line,
|
|
29147
|
+
col: h.col,
|
|
29148
|
+
span: h.span,
|
|
29149
|
+
owasp: def.owasp,
|
|
29150
|
+
fix: `${describeHit(h)} ${def.fix}`
|
|
29151
|
+
}));
|
|
29152
|
+
}
|
|
28821
29153
|
async function* scanRepo(root, options) {
|
|
28822
29154
|
const defs = await loadDefinitions(options.definitionsDir);
|
|
28823
29155
|
const canaries = loadCanariesFile(canariesPath(root));
|
|
@@ -28834,6 +29166,7 @@ async function* scanRepo(root, options) {
|
|
|
28834
29166
|
let filesSkipped = 0;
|
|
28835
29167
|
let findingsTotal = 0;
|
|
28836
29168
|
const ex026 = defs.find((d) => d.id === "EX-026");
|
|
29169
|
+
const ex036 = defs.find((d) => d.id === "EX-036" && d.enabled !== false && d.match.analysis === "lifecycle-scripts");
|
|
28837
29170
|
for await (const file of walkRepo(root, options.maxFileSizeBytes)) {
|
|
28838
29171
|
yield { type: "file", file };
|
|
28839
29172
|
if (file.tooLarge) {
|
|
@@ -28869,7 +29202,8 @@ async function* scanRepo(root, options) {
|
|
|
28869
29202
|
const heurs = options.bedrockClient ? await runHeuristics(file, norm, sigs, options.bedrockClient) : [];
|
|
28870
29203
|
const traps = canaryFindings(text, file.rel, records, ex022);
|
|
28871
29204
|
const sourceTools = (file.role === "code" || file.role === "unknown") && languageOf(file.rel) !== null ? scanSourceTools(file, text, defs) : [];
|
|
28872
|
-
|
|
29205
|
+
const lifecycle = ex036 && file.role === "manifest" && file.rel.split("/").pop() === "package.json" ? lifecycleScanFindings(text, file.path, file.rel, ex036) : [];
|
|
29206
|
+
let deduped = deduplicate([...sigs, ...heurs, ...traps, ...sandboxFindings(text, file.rel), ...sourceTools, ...lifecycle]);
|
|
28873
29207
|
if (checkVault && deduped.length > 0 && file.rel.includes(".exorcist/vault/")) {
|
|
28874
29208
|
const backup = checkVault(file.rel, await readFile3(file.path));
|
|
28875
29209
|
if (backup) deduped = deduped.map((f) => asBackupFinding(f, backup));
|
|
@@ -29129,6 +29463,10 @@ var ENTRIES = {
|
|
|
29129
29463
|
headline: "This project file switches off the sandbox around your AI tool servers",
|
|
29130
29464
|
attack: "A committed Kiro sandbox file turns MCP sandboxing, or the whole command sandbox, off, so local tool servers run without the operating-system boundary. This is only information: a project file can only tighten your global sandbox policy, so your global setting may still apply."
|
|
29131
29465
|
},
|
|
29466
|
+
"EX-036": {
|
|
29467
|
+
headline: "A script that runs by itself sends your secrets out",
|
|
29468
|
+
attack: 'This package has a script that npm, pnpm or yarn runs on its own (on install, or before or after "npm test"), and the file it runs reads your .env or other credentials and sends data to another computer. Your AI agent only has to run the tests or install the project; it does not have to obey anything.'
|
|
29469
|
+
},
|
|
29132
29470
|
"EX-027": {
|
|
29133
29471
|
headline: "Your AI read untrusted text and private data, and now wants to send something out",
|
|
29134
29472
|
attack: "Earlier in this session your AI read text anyone can write (a web page, an issue, a message) and then private data (a secrets file, a key). Each step looked harmless. Sending data out now is exactly how a prompt injection steals it, so the Shield holds the call until you say yes."
|
|
@@ -29301,9 +29639,9 @@ var BUNDLED_DEFINITIONS_VERSION = "20261124.0";
|
|
|
29301
29639
|
// ../core/src/liveupdate.ts
|
|
29302
29640
|
init_zod();
|
|
29303
29641
|
import { createHash as createHash2, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes as randomBytes2, sign as edSign, verify as edVerify } from "node:crypto";
|
|
29304
|
-
import { closeSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync as readFileSync3, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
29642
|
+
import { closeSync as closeSync2, fstatSync, lstatSync, mkdirSync, openSync as openSync2, readFileSync as readFileSync3, readSync as readSync2, readdirSync, renameSync, rmSync, statSync as statSync2, writeFileSync } from "node:fs";
|
|
29305
29643
|
import { homedir } from "node:os";
|
|
29306
|
-
import { basename as basename3, join as
|
|
29644
|
+
import { basename as basename3, join as join8, resolve as resolve3 } from "node:path";
|
|
29307
29645
|
var DEFINITIONS_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
29308
29646
|
MCowBQYDK2VwAyEAn4o+dmOJXIzsygT2CF/3go/1E/bk9Ub16r4hGtJJjhM=
|
|
29309
29647
|
-----END PUBLIC KEY-----
|
|
@@ -29381,19 +29719,19 @@ function parseManifest(manifestBytes) {
|
|
|
29381
29719
|
}
|
|
29382
29720
|
function installedDefinitionsRoot(env = process.env) {
|
|
29383
29721
|
const fromEnv = env["EXORCIST_DEFINITIONS_HOME"];
|
|
29384
|
-
if (fromEnv) return
|
|
29385
|
-
return
|
|
29722
|
+
if (fromEnv) return resolve3(fromEnv);
|
|
29723
|
+
return join8(env["HOME"] || env["USERPROFILE"] || homedir(), ".exorcist", "definitions");
|
|
29386
29724
|
}
|
|
29387
29725
|
function verifySetFolder(dir, expectedVersion, publicKeyPem) {
|
|
29388
29726
|
try {
|
|
29389
29727
|
if (!lstatSync(dir).isDirectory()) return fail("not a real folder (a symlink or a file)");
|
|
29390
|
-
const defsDir =
|
|
29391
|
-
for (const [p, kind] of [[
|
|
29728
|
+
const defsDir = join8(dir, "definitions");
|
|
29729
|
+
for (const [p, kind] of [[join8(dir, MANIFEST_NAME), "file"], [join8(dir, SIGNATURE_NAME), "file"], [defsDir, "dir"]]) {
|
|
29392
29730
|
const st = lstatSync(p);
|
|
29393
29731
|
if (kind === "file" ? !st.isFile() : !st.isDirectory()) return fail(`${basename3(p)} is not a plain ${kind === "file" ? "file" : "folder"}`);
|
|
29394
29732
|
}
|
|
29395
|
-
const manifestBytes = readFileSync3(
|
|
29396
|
-
const bad = verifySignature(manifestBytes, readFileSync3(
|
|
29733
|
+
const manifestBytes = readFileSync3(join8(dir, MANIFEST_NAME));
|
|
29734
|
+
const bad = verifySignature(manifestBytes, readFileSync3(join8(dir, SIGNATURE_NAME)), publicKeyPem);
|
|
29397
29735
|
if (bad) return fail("the manifest signature does not verify");
|
|
29398
29736
|
const m = parseManifest(manifestBytes);
|
|
29399
29737
|
if (!m.ok) return m;
|
|
@@ -29403,7 +29741,7 @@ function verifySetFolder(dir, expectedVersion, publicKeyPem) {
|
|
|
29403
29741
|
const extra = onDisk.filter((n) => !listed.includes(n));
|
|
29404
29742
|
if (extra.length > 0) return fail(`definitions/ holds files the manifest does not list: ${extra.map((n) => printable(n)).join(", ")}`);
|
|
29405
29743
|
for (const name of listed) {
|
|
29406
|
-
const p =
|
|
29744
|
+
const p = join8(defsDir, name);
|
|
29407
29745
|
let st;
|
|
29408
29746
|
try {
|
|
29409
29747
|
st = lstatSync(p);
|
|
@@ -29434,7 +29772,7 @@ function findActiveInstalledSet(o = {}) {
|
|
|
29434
29772
|
}
|
|
29435
29773
|
const newer = names.filter((n) => isValidVersion(n) && compareVersions(n, BUNDLED_DEFINITIONS_VERSION) > 0).sort((a, b) => compareVersions(b, a));
|
|
29436
29774
|
for (const name of newer) {
|
|
29437
|
-
const r = verifyInstalledSet(
|
|
29775
|
+
const r = verifyInstalledSet(join8(root, name), pem);
|
|
29438
29776
|
if (r.ok) return r.set;
|
|
29439
29777
|
}
|
|
29440
29778
|
return null;
|
|
@@ -29480,6 +29818,28 @@ var SessionJsonSchema = external_exports.object({
|
|
|
29480
29818
|
approveForMe: external_exports.boolean().optional()
|
|
29481
29819
|
}).passthrough();
|
|
29482
29820
|
|
|
29821
|
+
// ../core/src/run-scripts-guard.ts
|
|
29822
|
+
var INSTALL_SET = [...INSTALL_HOOKS];
|
|
29823
|
+
|
|
29824
|
+
// ../core/src/shell-read-guard.ts
|
|
29825
|
+
var VALUE_FLAGS2 = {
|
|
29826
|
+
cat: /* @__PURE__ */ new Set(),
|
|
29827
|
+
head: /* @__PURE__ */ new Set(["-n", "-c", "--lines", "--bytes"]),
|
|
29828
|
+
tail: /* @__PURE__ */ new Set(["-n", "-c", "--lines", "--bytes", "-s", "--sleep-interval"]),
|
|
29829
|
+
less: /* @__PURE__ */ new Set(["-b", "-h", "-j", "-p", "-P", "-t", "-T", "-x", "-y", "-z"]),
|
|
29830
|
+
more: /* @__PURE__ */ new Set(["-n", "-p"]),
|
|
29831
|
+
bat: /* @__PURE__ */ new Set(["-l", "--language", "-r", "--line-range", "--theme", "--style", "--tabs", "--wrap"]),
|
|
29832
|
+
batcat: /* @__PURE__ */ new Set(["-l", "--language", "-r", "--line-range", "--theme", "--style", "--tabs", "--wrap"]),
|
|
29833
|
+
nl: /* @__PURE__ */ new Set(["-b", "-d", "-f", "-h", "-i", "-l", "-n", "-s", "-v", "-w"]),
|
|
29834
|
+
sed: /* @__PURE__ */ new Set(["-e", "-f", "--expression", "--file", "-l", "-E", "-s"]),
|
|
29835
|
+
awk: /* @__PURE__ */ new Set(["-F", "-v", "-f", "--file", "-e", "--source"]),
|
|
29836
|
+
gawk: /* @__PURE__ */ new Set(["-F", "-v", "-f", "--file", "-e", "--source"]),
|
|
29837
|
+
grep: /* @__PURE__ */ new Set(["-e", "-f", "-m", "-A", "-B", "-C", "--include", "--exclude", "--exclude-dir", "--regexp", "--file", "--max-count", "--label", "--color", "-d", "-D"])
|
|
29838
|
+
};
|
|
29839
|
+
VALUE_FLAGS2["egrep"] = VALUE_FLAGS2["grep"] ?? /* @__PURE__ */ new Set();
|
|
29840
|
+
VALUE_FLAGS2["fgrep"] = VALUE_FLAGS2["grep"] ?? /* @__PURE__ */ new Set();
|
|
29841
|
+
var FILE_PROGRAMS = new Set(Object.keys(VALUE_FLAGS2));
|
|
29842
|
+
|
|
29483
29843
|
// ../shield/src/paraphrase.ts
|
|
29484
29844
|
var W = String.raw`[\s\W_]{0,3}`;
|
|
29485
29845
|
var words = (...ws) => ws.join(`${W}`);
|
|
@@ -29726,11 +30086,11 @@ var LockSchema = external_exports.object({
|
|
|
29726
30086
|
|
|
29727
30087
|
// ../shield/src/vault.ts
|
|
29728
30088
|
import { createHash as createHash3, randomBytes as randomBytes3 } from "node:crypto";
|
|
29729
|
-
import { copyFileSync, existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync4, readdirSync as readdirSync2, rmSync as rmSync2, statSync as
|
|
29730
|
-
import { basename as basename4, dirname, isAbsolute as
|
|
30089
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync4, readdirSync as readdirSync2, rmSync as rmSync2, statSync as statSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
30090
|
+
import { basename as basename4, dirname as dirname2, isAbsolute as isAbsolute3, join as join9, resolve as resolve4 } from "node:path";
|
|
29731
30091
|
init_zod();
|
|
29732
30092
|
var SafeRel = external_exports.string().min(1).max(1024).refine(
|
|
29733
|
-
(p) => !
|
|
30093
|
+
(p) => !isAbsolute3(p) && !p.includes("\\") && !p.includes("\0") && p.split("/").every((seg) => seg !== "" && seg !== "." && seg !== ".."),
|
|
29734
30094
|
"unsafe path"
|
|
29735
30095
|
);
|
|
29736
30096
|
var EditedFileSchema = external_exports.object({
|
|
@@ -29760,18 +30120,18 @@ function newId(label, now) {
|
|
|
29760
30120
|
return `${stamp}-${slug}-${randomBytes3(2).toString("hex")}`;
|
|
29761
30121
|
}
|
|
29762
30122
|
function entryDir(vaultDir, id) {
|
|
29763
|
-
return
|
|
30123
|
+
return join9(vaultDir, id);
|
|
29764
30124
|
}
|
|
29765
30125
|
function writeManifest(vaultDir, e) {
|
|
29766
|
-
writeFileSync2(
|
|
30126
|
+
writeFileSync2(join9(entryDir(vaultDir, e.id), "manifest.json"), `${JSON.stringify(e, null, 2)}
|
|
29767
30127
|
`, "utf8");
|
|
29768
30128
|
}
|
|
29769
30129
|
function listEntries(vaultDir) {
|
|
29770
|
-
if (!
|
|
30130
|
+
if (!existsSync2(vaultDir)) return [];
|
|
29771
30131
|
const out = [];
|
|
29772
30132
|
for (const name of readdirSync2(vaultDir)) {
|
|
29773
|
-
const file =
|
|
29774
|
-
if (!
|
|
30133
|
+
const file = join9(vaultDir, name, "manifest.json");
|
|
30134
|
+
if (!existsSync2(file)) continue;
|
|
29775
30135
|
try {
|
|
29776
30136
|
const parsed = EntrySchema.safeParse(JSON.parse(readFileSync4(file, "utf8")));
|
|
29777
30137
|
if (parsed.success) out.push(parsed.data);
|
|
@@ -29803,7 +30163,7 @@ function readConfig(path) {
|
|
|
29803
30163
|
var writeConfig = (path, cfg) => writeFileSync2(path, `${JSON.stringify(cfg, null, 2)}
|
|
29804
30164
|
`, "utf8");
|
|
29805
30165
|
function quarantineServer(o) {
|
|
29806
|
-
const configPath =
|
|
30166
|
+
const configPath = resolve4(o.configPath);
|
|
29807
30167
|
const cfg = readConfig(configPath);
|
|
29808
30168
|
if (!cfg.ok) return cfg;
|
|
29809
30169
|
const entry = cfg.value.mcpServers?.[o.serverName];
|
|
@@ -29817,7 +30177,7 @@ function quarantineServer(o) {
|
|
|
29817
30177
|
mkdirSync2(dir, { recursive: true });
|
|
29818
30178
|
const backup = `${JSON.stringify(entry, null, 2)}
|
|
29819
30179
|
`;
|
|
29820
|
-
writeFileSync2(
|
|
30180
|
+
writeFileSync2(join9(dir, "entry.json"), backup, "utf8");
|
|
29821
30181
|
const e = {
|
|
29822
30182
|
id,
|
|
29823
30183
|
kind: "mcp-server",
|
|
@@ -29995,12 +30355,12 @@ var MAX_HASHED_BYTES = 64 * 1024 * 1024;
|
|
|
29995
30355
|
var MAX_EVENT_BYTES2 = 16 * 1024 * 1024;
|
|
29996
30356
|
|
|
29997
30357
|
// ../shield/src/locate.ts
|
|
29998
|
-
import { existsSync as
|
|
29999
|
-
import { dirname as
|
|
30358
|
+
import { existsSync as existsSync3, readdirSync as readdirSync3, statSync as statSync4 } from "node:fs";
|
|
30359
|
+
import { dirname as dirname3, isAbsolute as isAbsolute4, join as join10, parse as parse3, resolve as resolve5 } from "node:path";
|
|
30000
30360
|
import { fileURLToPath } from "node:url";
|
|
30001
30361
|
function hasDefinitions(dir) {
|
|
30002
30362
|
try {
|
|
30003
|
-
return
|
|
30363
|
+
return statSync4(dir).isDirectory() && readdirSync3(dir).some((f) => /^EX-\d{3}.*\.yaml$/.test(f));
|
|
30004
30364
|
} catch {
|
|
30005
30365
|
return false;
|
|
30006
30366
|
}
|
|
@@ -30008,13 +30368,13 @@ function hasDefinitions(dir) {
|
|
|
30008
30368
|
function findDefinitionsDir(o) {
|
|
30009
30369
|
const env = o.env ?? process.env;
|
|
30010
30370
|
const cwd = o.cwd ?? process.cwd();
|
|
30011
|
-
if (o.explicit) return
|
|
30371
|
+
if (o.explicit) return resolve5(cwd, o.explicit);
|
|
30012
30372
|
const fromEnv = env["EXORCIST_DEFINITIONS"];
|
|
30013
|
-
if (fromEnv) return
|
|
30373
|
+
if (fromEnv) return resolve5(cwd, fromEnv);
|
|
30014
30374
|
const installed = findActiveInstalledSet({ env, ...o.publicKeyPem ? { publicKeyPem: o.publicKeyPem } : {} });
|
|
30015
30375
|
if (installed && hasDefinitions(installed.definitionsDir)) return installed.definitionsDir;
|
|
30016
|
-
const here =
|
|
30017
|
-
const candidates = [
|
|
30376
|
+
const here = dirname3(fileURLToPath(o.callerUrl));
|
|
30377
|
+
const candidates = [join10(here, "..", "definitions"), join10(here, "..", "..", "..", "definitions"), join10(cwd, "definitions")];
|
|
30018
30378
|
return candidates.find(hasDefinitions) ?? null;
|
|
30019
30379
|
}
|
|
30020
30380
|
|
|
@@ -30048,7 +30408,7 @@ function isWrapped(entry) {
|
|
|
30048
30408
|
|
|
30049
30409
|
// src/tools.ts
|
|
30050
30410
|
import { homedir as homedir2 } from "node:os";
|
|
30051
|
-
import { basename as basename5, dirname as
|
|
30411
|
+
import { basename as basename5, dirname as dirname4, isAbsolute as isAbsolute5, join as join11, relative as relative4, resolve as resolve6, sep as sep2 } from "node:path";
|
|
30052
30412
|
var quotesWanted = (ctx2, asked) => asked === true && ctx2.noQuotes !== true;
|
|
30053
30413
|
var RANK = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
30054
30414
|
var HIDDEN2 = /[\u200B-\u200D\uFEFF\u202A-\u202E\u2066-\u2069\u{E0000}-\u{E007F}]/gu;
|
|
@@ -30060,17 +30420,17 @@ function findDefinitionsDir2(cwd) {
|
|
|
30060
30420
|
return findDefinitionsDir({ callerUrl: import.meta.url, cwd });
|
|
30061
30421
|
}
|
|
30062
30422
|
function resolveInside(cwd, p, roots = [], primary) {
|
|
30063
|
-
const real = (d) =>
|
|
30064
|
-
const extra = roots.filter((r) =>
|
|
30423
|
+
const real = (d) => realpathSync2(d);
|
|
30424
|
+
const extra = roots.filter((r) => existsSync4(r)).map(real);
|
|
30065
30425
|
const first = primary !== void 0 && extra.includes(real(primary)) ? [real(primary)] : [];
|
|
30066
30426
|
const bases = [.../* @__PURE__ */ new Set([...first, real(cwd), ...extra])];
|
|
30067
|
-
const tries =
|
|
30068
|
-
const found = tries.find((t) =>
|
|
30427
|
+
const tries = isAbsolute5(p) ? [p] : bases.map((b) => resolve6(b, p));
|
|
30428
|
+
const found = tries.find((t) => existsSync4(t));
|
|
30069
30429
|
if (!found) return { ok: false, error: `Path not found: ${p}` };
|
|
30070
|
-
const target =
|
|
30430
|
+
const target = realpathSync2(found);
|
|
30071
30431
|
const base = bases.find((b) => {
|
|
30072
|
-
const rel =
|
|
30073
|
-
return !rel.startsWith("..") && !
|
|
30432
|
+
const rel = relative4(b, target);
|
|
30433
|
+
return !rel.startsWith("..") && !isAbsolute5(rel);
|
|
30074
30434
|
});
|
|
30075
30435
|
if (!base) {
|
|
30076
30436
|
const where = bases.length > 1 ? `the project folder (${bases[0]}) or the folders your client shared` : `the project folder (${bases[0]})`;
|
|
@@ -30101,23 +30461,23 @@ var PROJECT_MARKERS = [
|
|
|
30101
30461
|
"README"
|
|
30102
30462
|
];
|
|
30103
30463
|
function looksLikeProject(dir) {
|
|
30104
|
-
const has = (n) =>
|
|
30464
|
+
const has = (n) => existsSync4(join11(dir, n));
|
|
30105
30465
|
if (has("plugin.json") || has("POWER.md")) return false;
|
|
30106
30466
|
return PROJECT_MARKERS.some(has);
|
|
30107
30467
|
}
|
|
30108
|
-
var SENSITIVE_IN_HOME = [".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", ".config", ".password-store",
|
|
30468
|
+
var SENSITIVE_IN_HOME = [".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", ".config", ".password-store", join11("Library", "Keychains")];
|
|
30109
30469
|
var SENSITIVE_ABSOLUTE = ["/etc", "/private/etc", "/System", "/var/root", "/root"];
|
|
30110
30470
|
var isWithin = (base, p) => {
|
|
30111
|
-
const rel =
|
|
30112
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
30471
|
+
const rel = relative4(base, p);
|
|
30472
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
30113
30473
|
};
|
|
30114
30474
|
function sensitiveReason(real, home = homedir2()) {
|
|
30115
|
-
const realHome =
|
|
30116
|
-
if (
|
|
30475
|
+
const realHome = existsSync4(home) ? realpathSync2(home) : home;
|
|
30476
|
+
if (dirname4(real) === real) return "it is the filesystem root";
|
|
30117
30477
|
if (isWithin(real, realHome)) return real === realHome ? "it is the home folder" : "it contains the home folder";
|
|
30118
30478
|
for (const n of SENSITIVE_IN_HOME) {
|
|
30119
|
-
const s =
|
|
30120
|
-
if (isWithin(s, real) || isWithin(real, s)) return `it holds credentials or settings (${n.split(
|
|
30479
|
+
const s = join11(realHome, n);
|
|
30480
|
+
if (isWithin(s, real) || isWithin(real, s)) return `it holds credentials or settings (${n.split(sep2)[0]})`;
|
|
30121
30481
|
}
|
|
30122
30482
|
for (const s of SENSITIVE_ABSOLUTE) if (isWithin(s, real)) return "it is a system folder";
|
|
30123
30483
|
return null;
|
|
@@ -30130,21 +30490,21 @@ function approvalMessage(folder) {
|
|
|
30130
30490
|
}
|
|
30131
30491
|
var FIXES = "Either set EXORCIST_ROOTS to the absolute path of the project folder in the env of the exorcist MCP server, or add the exorcist server to the workspace .kiro/settings/mcp.json, where Kiro starts it in the project folder.";
|
|
30132
30492
|
function noProjectError(ctx2, p, inside2) {
|
|
30133
|
-
if (inside2.outside ||
|
|
30493
|
+
if (inside2.outside || isAbsolute5(p) || (ctx2.roots?.length ?? 0) > 0 || looksLikeProject(ctx2.cwd)) return null;
|
|
30134
30494
|
const how = ctx2.ask ? "Call the tool again with the absolute path of the project folder; the person will be asked to allow it for this session. Other fixes: set EXORCIST_ROOTS to that folder in the env of the exorcist MCP server, or add the exorcist server to the workspace .kiro/settings/mcp.json, where Kiro starts it in the project folder." : FIXES;
|
|
30135
30495
|
return `No project folder is known, so "${p}" was not scanned. This server was started in ${ctx2.cwd}, which is not a project, and the client did not share a workspace folder (MCP roots). Nothing was checked. ${how} Do not report this as a clean scan.`;
|
|
30136
30496
|
}
|
|
30137
30497
|
async function resolveAllowed(ctx2, p) {
|
|
30138
30498
|
const first = resolveInside(ctx2.cwd, p, ctx2.roots, ctx2.base);
|
|
30139
|
-
if (first.ok || !first.outside || !
|
|
30499
|
+
if (first.ok || !first.outside || !isAbsolute5(p)) return first;
|
|
30140
30500
|
const noRoots = (ctx2.roots?.length ?? 0) === 0;
|
|
30141
30501
|
if (!ctx2.ask) {
|
|
30142
30502
|
return noRoots && !looksLikeProject(ctx2.cwd) ? { ...first, error: `${first.error} No project folder is known. ${FIXES}` } : first;
|
|
30143
30503
|
}
|
|
30144
30504
|
let folder;
|
|
30145
30505
|
try {
|
|
30146
|
-
const real =
|
|
30147
|
-
folder =
|
|
30506
|
+
const real = realpathSync2(p);
|
|
30507
|
+
folder = statSync5(real).isDirectory() ? real : dirname4(real);
|
|
30148
30508
|
} catch {
|
|
30149
30509
|
return first;
|
|
30150
30510
|
}
|
|
@@ -30176,16 +30536,16 @@ function usableRoots(entries, home) {
|
|
|
30176
30536
|
continue;
|
|
30177
30537
|
}
|
|
30178
30538
|
} else if (/^[a-z][a-z0-9+.-]*:/i.test(path) && !/^[a-z]:[\\/]/i.test(path)) continue;
|
|
30179
|
-
if (!
|
|
30539
|
+
if (!isAbsolute5(path) || !existsSync4(path)) continue;
|
|
30180
30540
|
let real;
|
|
30181
30541
|
try {
|
|
30182
|
-
if (!
|
|
30183
|
-
real =
|
|
30542
|
+
if (!statSync5(path).isDirectory()) continue;
|
|
30543
|
+
real = realpathSync2(path);
|
|
30184
30544
|
} catch {
|
|
30185
30545
|
continue;
|
|
30186
30546
|
}
|
|
30187
|
-
const realHome =
|
|
30188
|
-
if (real ===
|
|
30547
|
+
const realHome = existsSync4(home) ? realpathSync2(home) : home;
|
|
30548
|
+
if (real === resolve6("/") || real === realHome || dirname4(real) === real) continue;
|
|
30189
30549
|
if (!out.includes(real)) out.push(real);
|
|
30190
30550
|
}
|
|
30191
30551
|
return out;
|
|
@@ -30227,8 +30587,8 @@ async function scanRepoTool(ctx2, a) {
|
|
|
30227
30587
|
if (!inside2.ok) return err(inside2.error);
|
|
30228
30588
|
const defs = await loadDefs(ctx2);
|
|
30229
30589
|
if (!defs.ok) return err(defs.error);
|
|
30230
|
-
const isFile =
|
|
30231
|
-
const root = isFile ?
|
|
30590
|
+
const isFile = statSync5(inside2.path).isFile();
|
|
30591
|
+
const root = isFile ? dirname4(inside2.path) : inside2.path;
|
|
30232
30592
|
const only = isFile ? basename5(inside2.path) : null;
|
|
30233
30593
|
const findings = [];
|
|
30234
30594
|
let files = 0;
|
|
@@ -30245,7 +30605,7 @@ async function scanMcpConfigTool(ctx2, a) {
|
|
|
30245
30605
|
const none = noProjectError(ctx2, a.path, inside2);
|
|
30246
30606
|
if (none) return err(none);
|
|
30247
30607
|
if (!inside2.ok) return err(inside2.error);
|
|
30248
|
-
if (!
|
|
30608
|
+
if (!statSync5(inside2.path).isFile()) return err(`${a.path} is a folder. Give the path of an MCP config file.`);
|
|
30249
30609
|
const defs = await loadDefs(ctx2);
|
|
30250
30610
|
if (!defs.ok) return err(defs.error);
|
|
30251
30611
|
const text = readFileSync5(inside2.path, "utf8");
|
|
@@ -30255,7 +30615,7 @@ async function scanMcpConfigTool(ctx2, a) {
|
|
|
30255
30615
|
} catch {
|
|
30256
30616
|
return err(`${a.path} is not valid JSON.`);
|
|
30257
30617
|
}
|
|
30258
|
-
const rel =
|
|
30618
|
+
const rel = relative4(inside2.base, inside2.path);
|
|
30259
30619
|
const findings = scanText(text, "mcp-config", defs.defs, rel);
|
|
30260
30620
|
const servers = Object.entries(config2.mcpServers ?? {});
|
|
30261
30621
|
const local = servers.filter(([, e]) => typeof e["command"] === "string");
|
|
@@ -30294,7 +30654,7 @@ async function quarantineTool(ctx2, a) {
|
|
|
30294
30654
|
configPath: inside2.path,
|
|
30295
30655
|
serverName: a.server,
|
|
30296
30656
|
reason: a.reason?.slice(0, 200) ?? "quarantined from an AI agent request",
|
|
30297
|
-
vaultDir:
|
|
30657
|
+
vaultDir: join11(inside2.base, ".exorcist", "vault")
|
|
30298
30658
|
});
|
|
30299
30659
|
if (!r.ok) return err(r.error);
|
|
30300
30660
|
return {
|
|
@@ -30304,7 +30664,7 @@ Tell the user. They can undo this with: exorcist vault restore ${r.value.id}`
|
|
|
30304
30664
|
}
|
|
30305
30665
|
|
|
30306
30666
|
// src/index.ts
|
|
30307
|
-
var VERSION = "0.3.
|
|
30667
|
+
var VERSION = "0.3.1";
|
|
30308
30668
|
var ctx = {
|
|
30309
30669
|
cwd: process.cwd(),
|
|
30310
30670
|
approved: [],
|