@node9/policy-engine 2.32.0 → 2.33.0
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/dist/index.d.mts +44 -18
- package/dist/index.d.ts +44 -18
- package/dist/index.js +313 -85
- package/dist/index.mjs +311 -85
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -137,6 +137,8 @@ __export(src_exports, {
|
|
|
137
137
|
hostMatches: () => hostMatches,
|
|
138
138
|
incompleteFileVerdict: () => incompleteFileVerdict,
|
|
139
139
|
inspectArgumentSecrets: () => inspectArgumentSecrets,
|
|
140
|
+
inspectionEntry: () => inspectionEntry,
|
|
141
|
+
inspectionLayers: () => inspectionLayers,
|
|
140
142
|
isAgentInstructionPath: () => isAgentInstructionPath,
|
|
141
143
|
isBashTool: () => isBashTool,
|
|
142
144
|
isDestructiveToolName: () => isDestructiveToolName,
|
|
@@ -4727,36 +4729,129 @@ var BASH_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
4727
4729
|
"shell",
|
|
4728
4730
|
"exec_command"
|
|
4729
4731
|
]);
|
|
4730
|
-
var MCP_EXECUTORS = /* @__PURE__ */ new Set([
|
|
4732
|
+
var MCP_EXECUTORS = /* @__PURE__ */ new Set([
|
|
4733
|
+
...BASH_TOOL_NAMES,
|
|
4734
|
+
"exec",
|
|
4735
|
+
"run_command",
|
|
4736
|
+
"terminal",
|
|
4737
|
+
"execute_command",
|
|
4738
|
+
"execute_shell",
|
|
4739
|
+
"execute_shell_command",
|
|
4740
|
+
"shell_execute",
|
|
4741
|
+
"run_shell",
|
|
4742
|
+
"run_terminal_command",
|
|
4743
|
+
"start_process"
|
|
4744
|
+
]);
|
|
4745
|
+
var BUILTIN_FIELDS = ["command", "cmd", "script"];
|
|
4746
|
+
var ARGV_FIELDS = ["args", "argv"];
|
|
4747
|
+
var BARE_WORD = /^[A-Za-z0-9_./+:@%,-]+$/;
|
|
4748
|
+
var MAX_ARGV_CHARACTERS = 262144;
|
|
4731
4749
|
function isBashTool(tool) {
|
|
4732
4750
|
return BASH_TOOL_NAMES.has(tool.toLowerCase());
|
|
4733
4751
|
}
|
|
4734
|
-
function
|
|
4752
|
+
function inspectionLayers(policy) {
|
|
4753
|
+
return { trusted: policy.toolInspection, project: policy.projectToolInspection };
|
|
4754
|
+
}
|
|
4755
|
+
function isShellEntry(value) {
|
|
4756
|
+
return typeof value === "object" && value !== null && value.kind === "shell" && typeof value.field === "string" && Object.keys(value).length === 2;
|
|
4757
|
+
}
|
|
4758
|
+
function isInspectionLayers(input) {
|
|
4759
|
+
const trusted = input.trusted;
|
|
4760
|
+
return typeof trusted === "object" && trusted !== null && !isShellEntry(trusted);
|
|
4761
|
+
}
|
|
4762
|
+
function layersOf(input) {
|
|
4763
|
+
return isInspectionLayers(input) ? { trusted: input.trusted, project: input.project ?? {} } : { trusted: input, project: {} };
|
|
4764
|
+
}
|
|
4765
|
+
function entryOf(tool, inspection) {
|
|
4735
4766
|
const pattern = Object.keys(inspection).find((p) => matchesPattern(tool, p));
|
|
4736
4767
|
return pattern === void 0 ? void 0 : inspection[pattern];
|
|
4737
4768
|
}
|
|
4769
|
+
function inspectionEntry(tool, inspection = {}) {
|
|
4770
|
+
const { trusted, project } = layersOf(inspection);
|
|
4771
|
+
return entryOf(tool, trusted) ?? entryOf(tool, project);
|
|
4772
|
+
}
|
|
4773
|
+
function executorName(tool) {
|
|
4774
|
+
const name = tool.toLowerCase();
|
|
4775
|
+
if (!name.startsWith("mcp__")) return name;
|
|
4776
|
+
const at = name.lastIndexOf("__");
|
|
4777
|
+
return at >= "mcp__".length ? name.slice(at + 2) : name;
|
|
4778
|
+
}
|
|
4779
|
+
function entryFields(entry) {
|
|
4780
|
+
if (typeof entry === "object") return [entry.field];
|
|
4781
|
+
return entry === "command" ? ["command"] : null;
|
|
4782
|
+
}
|
|
4738
4783
|
function shellFields(tool, inspection) {
|
|
4739
4784
|
if (isBashTool(tool)) return ["command"];
|
|
4740
|
-
const
|
|
4741
|
-
|
|
4742
|
-
if (
|
|
4743
|
-
const
|
|
4744
|
-
|
|
4785
|
+
const { trusted, project } = layersOf(inspection);
|
|
4786
|
+
const trustedEntry = entryOf(tool, trusted);
|
|
4787
|
+
if (trustedEntry !== void 0) return entryFields(trustedEntry);
|
|
4788
|
+
const builtin = MCP_EXECUTORS.has(executorName(tool)) ? BUILTIN_FIELDS : null;
|
|
4789
|
+
const projectEntry = entryOf(tool, project);
|
|
4790
|
+
if (projectEntry === void 0) return builtin;
|
|
4791
|
+
const added = entryFields(projectEntry);
|
|
4792
|
+
if (!builtin) return added;
|
|
4793
|
+
if (!added) return builtin;
|
|
4794
|
+
return [.../* @__PURE__ */ new Set([...builtin, ...added])];
|
|
4745
4795
|
}
|
|
4746
4796
|
function isShellShapedTool(tool, inspection = {}) {
|
|
4747
4797
|
return shellFields(tool, inspection) !== null;
|
|
4748
4798
|
}
|
|
4799
|
+
function shellWord(word) {
|
|
4800
|
+
if (BARE_WORD.test(word)) return word;
|
|
4801
|
+
return word === "" ? "''" : `'${word.replace(/'/g, `'\\''`)}'`;
|
|
4802
|
+
}
|
|
4803
|
+
function isStringArray(value) {
|
|
4804
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
4805
|
+
}
|
|
4806
|
+
function commandLine(args, fieldPath, value, native) {
|
|
4807
|
+
const missing = { reason: "Shell command field is missing or is not a string" };
|
|
4808
|
+
const unreadable = { reason: "Shell command arguments could not be read" };
|
|
4809
|
+
if (typeof value !== "string" && (native || !Array.isArray(value))) return missing;
|
|
4810
|
+
const dot = fieldPath.lastIndexOf(".");
|
|
4811
|
+
const parent = dot === -1 ? args : getNestedValue(args, fieldPath.slice(0, dot));
|
|
4812
|
+
const siblings = ARGV_FIELDS.map((key) => ({
|
|
4813
|
+
key,
|
|
4814
|
+
value: parent && typeof parent === "object" ? parent[key] : void 0
|
|
4815
|
+
})).filter(({ value: value2 }) => value2 !== void 0 && value2 !== null);
|
|
4816
|
+
let argv = siblings[0];
|
|
4817
|
+
if (native) argv = siblings.find(({ value: v }) => isStringArray(v));
|
|
4818
|
+
else if (siblings.length === 2 && JSON.stringify(siblings[0].value) !== JSON.stringify(siblings[1].value))
|
|
4819
|
+
return { reason: "Shell command arguments disagree" };
|
|
4820
|
+
let command;
|
|
4821
|
+
let source = fieldPath;
|
|
4822
|
+
if (Array.isArray(value)) {
|
|
4823
|
+
if (argv || !value.length || !isStringArray(value)) return unreadable;
|
|
4824
|
+
command = value.map(shellWord).join(" ");
|
|
4825
|
+
} else if (!argv) {
|
|
4826
|
+
return { command: value, fieldPath };
|
|
4827
|
+
} else {
|
|
4828
|
+
if (!isStringArray(argv.value)) return unreadable;
|
|
4829
|
+
if (!argv.value.length) return { command: value, fieldPath };
|
|
4830
|
+
command = `${value} ${argv.value.map(shellWord).join(" ")}`;
|
|
4831
|
+
source = `${fieldPath}+${argv.key}`;
|
|
4832
|
+
}
|
|
4833
|
+
if (command.length > MAX_ARGV_CHARACTERS)
|
|
4834
|
+
return { reason: "Shell command arguments exceed the inspectable size" };
|
|
4835
|
+
return { command, fieldPath: source };
|
|
4836
|
+
}
|
|
4749
4837
|
function resolveShellInput(tool, args, inspection = {}) {
|
|
4750
4838
|
const fields = shellFields(tool, inspection);
|
|
4751
4839
|
if (!fields) return { kind: "not-shell" };
|
|
4752
4840
|
const values = fields.map((fieldPath) => ({ fieldPath, value: getNestedValue(args, fieldPath) })).filter(({ value }) => value !== void 0 && value !== null && value !== "");
|
|
4753
|
-
if (!values.length
|
|
4841
|
+
if (!values.length) {
|
|
4754
4842
|
return { kind: "uninspectable", reason: "Shell command field is missing or is not a string" };
|
|
4755
4843
|
}
|
|
4756
|
-
|
|
4844
|
+
const native = isBashTool(tool);
|
|
4845
|
+
const lines = values.map(({ fieldPath, value }) => commandLine(args, fieldPath, value, native));
|
|
4846
|
+
const failed = lines.find((line) => "reason" in line);
|
|
4847
|
+
if (failed) return { kind: "uninspectable", reason: failed.reason };
|
|
4848
|
+
const commands = lines.filter(
|
|
4849
|
+
(line) => "command" in line
|
|
4850
|
+
);
|
|
4851
|
+
if (new Set(commands.map(({ command }) => command)).size !== 1) {
|
|
4757
4852
|
return { kind: "uninspectable", reason: "Multiple shell command fields disagree" };
|
|
4758
4853
|
}
|
|
4759
|
-
return { kind: "shell",
|
|
4854
|
+
return { kind: "shell", ...commands[0] };
|
|
4760
4855
|
}
|
|
4761
4856
|
function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
|
|
4762
4857
|
if (!ruleTool || !matchesPattern("bash", ruleTool) || matchesPattern(tool, ruleTool)) return args;
|
|
@@ -7641,20 +7736,26 @@ var BIP39_PUBLIC_VECTORS = /* @__PURE__ */ new Set([
|
|
|
7641
7736
|
var indices = new Map(BIP39_ENGLISH.map((word, i) => [word, i]));
|
|
7642
7737
|
var lengths = [24, 21, 18, 15, 12];
|
|
7643
7738
|
var hash = (value) => (0, import_node_crypto.createHash)("sha256").update(value).digest();
|
|
7644
|
-
|
|
7645
|
-
|
|
7739
|
+
var MAX_MNEMONIC_HASHES = 25e3;
|
|
7740
|
+
function findMnemonic(text, budget = { hashes: 0, reasons: /* @__PURE__ */ new Set() }) {
|
|
7646
7741
|
let run = [];
|
|
7742
|
+
let runIndex = [];
|
|
7647
7743
|
let previousEnd = 0;
|
|
7648
7744
|
const rejected = /* @__PURE__ */ new Set();
|
|
7649
7745
|
const inspect = () => {
|
|
7746
|
+
if (run.length < 12) return false;
|
|
7747
|
+
const ascending = new Array(run.length).fill(0);
|
|
7748
|
+
for (let i = 1; i < run.length; i++)
|
|
7749
|
+
ascending[i] = ascending[i - 1] + (runIndex[i] > runIndex[i - 1] ? 1 : 0);
|
|
7650
7750
|
for (let start = 0; start + 12 <= run.length; start++) {
|
|
7651
7751
|
for (const count of lengths) {
|
|
7652
7752
|
if (start + count > run.length) continue;
|
|
7753
|
+
if (ascending[start + count - 1] - ascending[start] === count - 1) continue;
|
|
7653
7754
|
const candidate = run.slice(start, start + count);
|
|
7654
7755
|
const sentence = candidate.join(" ");
|
|
7655
7756
|
if (rejected.has(sentence)) continue;
|
|
7656
|
-
if (++budget.
|
|
7657
|
-
budget.reasons.add("mnemonic-
|
|
7757
|
+
if (++budget.hashes > MAX_MNEMONIC_HASHES) {
|
|
7758
|
+
budget.reasons.add("mnemonic-budget");
|
|
7658
7759
|
return false;
|
|
7659
7760
|
}
|
|
7660
7761
|
if (BIP39_PUBLIC_VECTORS.has(hash(sentence).toString("hex"))) {
|
|
@@ -7672,13 +7773,18 @@ function findMnemonic(text, budget = { candidates: 0, reasons: /* @__PURE__ */ n
|
|
|
7672
7773
|
}
|
|
7673
7774
|
return false;
|
|
7674
7775
|
};
|
|
7675
|
-
for (const word of
|
|
7676
|
-
|
|
7776
|
+
for (const word of text.matchAll(/[a-zA-Z]+/g)) {
|
|
7777
|
+
const index = indices.get(word[0]);
|
|
7778
|
+
if (index === void 0 || run.length && !/^\s+$/.test(text.slice(previousEnd, word.index))) {
|
|
7677
7779
|
if (inspect()) return true;
|
|
7678
|
-
if (budget.reasons.has("mnemonic-
|
|
7780
|
+
if (budget.reasons.has("mnemonic-budget")) return false;
|
|
7679
7781
|
run = [];
|
|
7782
|
+
runIndex = [];
|
|
7783
|
+
}
|
|
7784
|
+
if (index !== void 0) {
|
|
7785
|
+
run.push(word[0]);
|
|
7786
|
+
runIndex.push(index);
|
|
7680
7787
|
}
|
|
7681
|
-
if (indices.has(word[0])) run.push(word[0]);
|
|
7682
7788
|
previousEnd = word.index + word[0].length;
|
|
7683
7789
|
}
|
|
7684
7790
|
return inspect();
|
|
@@ -7921,6 +8027,10 @@ function validateCask(raw) {
|
|
|
7921
8027
|
|
|
7922
8028
|
// src/dlp/normalize.ts
|
|
7923
8029
|
var INVISIBLE_RE = /[͏----︀-️]|[\u{E0000}-\u{E007F}]/gu;
|
|
8030
|
+
function isInvisibleChar(char) {
|
|
8031
|
+
return INVISIBLE_ONE.test(char);
|
|
8032
|
+
}
|
|
8033
|
+
var INVISIBLE_ONE = new RegExp(`^(?:${INVISIBLE_RE.source.split("|")[0]})$`, "u");
|
|
7924
8034
|
function stripInvisible(text) {
|
|
7925
8035
|
return text.replace(INVISIBLE_RE, "");
|
|
7926
8036
|
}
|
|
@@ -8096,7 +8206,7 @@ function scanInjection(text, ctx = {}) {
|
|
|
8096
8206
|
}
|
|
8097
8207
|
}
|
|
8098
8208
|
if (matched.length === 0) return null;
|
|
8099
|
-
const untrusted = !!ctx.tool && UNTRUSTED_TOOLS.test(ctx.tool);
|
|
8209
|
+
const untrusted = ctx.untrusted ?? (!!ctx.tool && UNTRUSTED_TOOLS.test(ctx.tool));
|
|
8100
8210
|
const score = matched.length + (untrusted ? 1 : 0);
|
|
8101
8211
|
const confidence = score >= 3 ? "high" : score === 2 ? "medium" : "low";
|
|
8102
8212
|
return { signals: untrusted ? [...matched, "untrusted-origin"] : matched, confidence };
|
|
@@ -8884,6 +8994,46 @@ function matchArgumentText(text, fieldPath, budget) {
|
|
|
8884
8994
|
}
|
|
8885
8995
|
return best;
|
|
8886
8996
|
}
|
|
8997
|
+
var BATCH_SEPARATOR = "\n";
|
|
8998
|
+
function matchArgumentBatch(fragments, fieldPath, budget) {
|
|
8999
|
+
if (!fragments.length) return null;
|
|
9000
|
+
const text = fragments.join(BATCH_SEPARATOR);
|
|
9001
|
+
const lower2 = text.toLowerCase();
|
|
9002
|
+
let best = null;
|
|
9003
|
+
for (const pattern of DLP_PATTERNS) {
|
|
9004
|
+
if (pattern.keywords && !pattern.keywords.some((kw) => lower2.includes(kw.toLowerCase())))
|
|
9005
|
+
continue;
|
|
9006
|
+
const flags = pattern.regex.flags.replace(/[gmy]/g, "");
|
|
9007
|
+
if (!new RegExp(pattern.regex.source, flags + "m").test(text)) continue;
|
|
9008
|
+
for (const fragment of fragments) {
|
|
9009
|
+
if (firstAcceptedMatch(pattern, fragment) === null) continue;
|
|
9010
|
+
const severity = pattern.contextBoost && isAssignmentContext(fragment) ? "block" : pattern.severity;
|
|
9011
|
+
if (severity === "block")
|
|
9012
|
+
return {
|
|
9013
|
+
patternName: pattern.name,
|
|
9014
|
+
fieldPath,
|
|
9015
|
+
redactedSample: "[encoded secret]",
|
|
9016
|
+
severity
|
|
9017
|
+
};
|
|
9018
|
+
best ??= {
|
|
9019
|
+
patternName: pattern.name,
|
|
9020
|
+
fieldPath,
|
|
9021
|
+
redactedSample: "[encoded secret]",
|
|
9022
|
+
severity
|
|
9023
|
+
};
|
|
9024
|
+
if (!pattern.contextBoost) break;
|
|
9025
|
+
}
|
|
9026
|
+
}
|
|
9027
|
+
if (findMnemonic(text, budget)) {
|
|
9028
|
+
return {
|
|
9029
|
+
patternName: "BIP-39 Recovery Phrase",
|
|
9030
|
+
fieldPath,
|
|
9031
|
+
redactedSample: "[recovery phrase]",
|
|
9032
|
+
severity: "block"
|
|
9033
|
+
};
|
|
9034
|
+
}
|
|
9035
|
+
return best;
|
|
9036
|
+
}
|
|
8887
9037
|
function scanArgs(args, depth = 0, fieldPath = "args") {
|
|
8888
9038
|
if (depth > MAX_DEPTH2 || args === null || args === void 0) return null;
|
|
8889
9039
|
if (Array.isArray(args)) {
|
|
@@ -10342,12 +10492,23 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
10342
10492
|
|
|
10343
10493
|
// src/dlp/secret-views.ts
|
|
10344
10494
|
var SECRET_VIEW_LIMITS = {
|
|
10495
|
+
/** A decoded text that itself decodes is followed this many layers; a deeper layer is reviewed. */
|
|
10345
10496
|
maxDepth: 4,
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10497
|
+
/** Nested views per parent view, and nested text per call; past either the call is reviewed. */
|
|
10498
|
+
maxNestedViewsPerLeaf: 64,
|
|
10499
|
+
maxNestedBytes: 1048576,
|
|
10500
|
+
/** Joined hostname-label text per call; past it the call is reviewed. */
|
|
10501
|
+
maxJoinedLabelBytes: 1048576,
|
|
10502
|
+
/** Decoded fragments are matched in batches of about this many characters. */
|
|
10503
|
+
batchCharacters: 65536,
|
|
10504
|
+
/** Only a valid DNS name has its labels joined. */
|
|
10505
|
+
maxHostLength: 253,
|
|
10506
|
+
maxLabelLength: 63,
|
|
10507
|
+
maxLabels: 127
|
|
10350
10508
|
};
|
|
10509
|
+
function newSecretViewBudget() {
|
|
10510
|
+
return { hashes: 0, nestedBytes: 0, joinedLabelBytes: 0, reasons: /* @__PURE__ */ new Set() };
|
|
10511
|
+
}
|
|
10351
10512
|
function textBytes(buf) {
|
|
10352
10513
|
if (buf.length < 16) return null;
|
|
10353
10514
|
const text = buf.toString("utf8");
|
|
@@ -10366,13 +10527,41 @@ function percentOnce(text) {
|
|
|
10366
10527
|
}
|
|
10367
10528
|
});
|
|
10368
10529
|
}
|
|
10530
|
+
function* wrappedBase64(text) {
|
|
10531
|
+
if (!text.includes("\n")) return;
|
|
10532
|
+
const word = /^[A-Za-z0-9+/_-]+={0,2}$/;
|
|
10533
|
+
let run = [];
|
|
10534
|
+
let width = 0;
|
|
10535
|
+
const flush = function* () {
|
|
10536
|
+
if (run.length >= 2) yield run.join("");
|
|
10537
|
+
run = [];
|
|
10538
|
+
width = 0;
|
|
10539
|
+
};
|
|
10540
|
+
for (const raw of text.split("\n")) {
|
|
10541
|
+
const line = raw.trim();
|
|
10542
|
+
const full = line.length >= 16 && word.test(line) && !line.includes("=");
|
|
10543
|
+
if (full && (!run.length || line.length === width)) {
|
|
10544
|
+
run.push(line);
|
|
10545
|
+
width = line.length;
|
|
10546
|
+
continue;
|
|
10547
|
+
}
|
|
10548
|
+
if (run.length && word.test(line) && line.length >= 2 && line.length <= width) {
|
|
10549
|
+
run.push(line);
|
|
10550
|
+
yield* flush();
|
|
10551
|
+
continue;
|
|
10552
|
+
}
|
|
10553
|
+
yield* flush();
|
|
10554
|
+
if (full) {
|
|
10555
|
+
run.push(line);
|
|
10556
|
+
width = line.length;
|
|
10557
|
+
}
|
|
10558
|
+
}
|
|
10559
|
+
yield* flush();
|
|
10560
|
+
}
|
|
10369
10561
|
function* encodedRegions(text, budget) {
|
|
10370
10562
|
yield [text, false];
|
|
10563
|
+
for (const block of wrappedBase64(text)) yield [block, false];
|
|
10371
10564
|
for (const match of text.matchAll(/(?<![a-z0-9+.-])[a-z][a-z0-9+.-]{0,30}:\/\/[^\s<>"']+/gi)) {
|
|
10372
|
-
if (++budget.candidates > SECRET_VIEW_LIMITS.maxCandidates) {
|
|
10373
|
-
budget.reasons.add("decode-candidates");
|
|
10374
|
-
return;
|
|
10375
|
-
}
|
|
10376
10565
|
try {
|
|
10377
10566
|
new URL(match[0]);
|
|
10378
10567
|
} catch {
|
|
@@ -10392,6 +10581,8 @@ function* encodedRegions(text, budget) {
|
|
|
10392
10581
|
];
|
|
10393
10582
|
for (const region of regions) if (region) yield [region, false];
|
|
10394
10583
|
const labels = host2.split(".");
|
|
10584
|
+
if (host2.length > SECRET_VIEW_LIMITS.maxHostLength || labels.length > SECRET_VIEW_LIMITS.maxLabels || !labels.every((l) => l.length >= 1 && l.length <= SECRET_VIEW_LIMITS.maxLabelLength))
|
|
10585
|
+
continue;
|
|
10395
10586
|
for (let start = 0; start < labels.length; start++) {
|
|
10396
10587
|
let joined = labels[start];
|
|
10397
10588
|
for (let end = start + 1; end < Math.min(labels.length, start + 8); end++) {
|
|
@@ -10399,11 +10590,13 @@ function* encodedRegions(text, budget) {
|
|
|
10399
10590
|
if (!run.every((s) => /^[a-f0-9]{2,}$/i.test(s)) && !run.every((s) => /^[A-Z2-7]{4,}$/i.test(s)))
|
|
10400
10591
|
break;
|
|
10401
10592
|
joined += labels[end];
|
|
10402
|
-
if (
|
|
10403
|
-
|
|
10593
|
+
if (joined.length < 16) continue;
|
|
10594
|
+
budget.joinedLabelBytes += joined.length;
|
|
10595
|
+
if (budget.joinedLabelBytes > SECRET_VIEW_LIMITS.maxJoinedLabelBytes) {
|
|
10596
|
+
budget.reasons.add("decode-labels");
|
|
10404
10597
|
return;
|
|
10405
10598
|
}
|
|
10406
|
-
|
|
10599
|
+
yield [joined, true];
|
|
10407
10600
|
}
|
|
10408
10601
|
}
|
|
10409
10602
|
}
|
|
@@ -10440,10 +10633,6 @@ function* decodedCandidates(text, budget) {
|
|
|
10440
10633
|
if (joined) yield ["dns-labels", region];
|
|
10441
10634
|
for (const [kind, re] of families) {
|
|
10442
10635
|
for (const match of region.matchAll(re)) {
|
|
10443
|
-
if (++budget.candidates > SECRET_VIEW_LIMITS.maxCandidates) {
|
|
10444
|
-
budget.reasons.add("decode-candidates");
|
|
10445
|
-
return;
|
|
10446
|
-
}
|
|
10447
10636
|
const raw = match[0];
|
|
10448
10637
|
let buf;
|
|
10449
10638
|
if (kind === "base64") {
|
|
@@ -10466,37 +10655,47 @@ function* decodedCandidates(text, budget) {
|
|
|
10466
10655
|
}
|
|
10467
10656
|
}
|
|
10468
10657
|
}
|
|
10469
|
-
function
|
|
10658
|
+
function secretViews(text, budget) {
|
|
10470
10659
|
const seen = /* @__PURE__ */ new Set([text]);
|
|
10471
|
-
const
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
for (const
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10660
|
+
const out = [];
|
|
10661
|
+
let frontier = [{ text, transforms: [] }];
|
|
10662
|
+
for (let depth = 1; depth <= SECRET_VIEW_LIMITS.maxDepth; depth++) {
|
|
10663
|
+
const next = [];
|
|
10664
|
+
for (const parent of frontier) {
|
|
10665
|
+
let perLeaf = 0;
|
|
10666
|
+
for (const [kind, decoded] of decodedCandidates(parent.text, budget)) {
|
|
10667
|
+
if (seen.has(decoded)) continue;
|
|
10668
|
+
seen.add(decoded);
|
|
10669
|
+
const normalizing = kind === "invisibles" || kind === "percent";
|
|
10670
|
+
if (depth >= 2 && !normalizing) {
|
|
10671
|
+
budget.nestedBytes += Buffer.byteLength(decoded);
|
|
10672
|
+
if (++perLeaf > SECRET_VIEW_LIMITS.maxNestedViewsPerLeaf || budget.nestedBytes > SECRET_VIEW_LIMITS.maxNestedBytes) {
|
|
10673
|
+
budget.reasons.add("decode-nested");
|
|
10674
|
+
return out;
|
|
10675
|
+
}
|
|
10676
|
+
}
|
|
10677
|
+
const view = { text: decoded, transforms: [...parent.transforms, kind] };
|
|
10678
|
+
out.push(view);
|
|
10679
|
+
next.push(view);
|
|
10485
10680
|
}
|
|
10486
|
-
seen.add(decoded);
|
|
10487
|
-
budget.views++;
|
|
10488
|
-
budget.bytes += bytes;
|
|
10489
|
-
queue.push({ text: decoded, transforms: [...view.transforms, kind] });
|
|
10490
10681
|
}
|
|
10491
|
-
|
|
10682
|
+
frontier = next;
|
|
10683
|
+
if (!frontier.length) return out;
|
|
10684
|
+
}
|
|
10685
|
+
for (const view of frontier) {
|
|
10686
|
+
if (!decodedCandidates(view.text, budget).next().done) {
|
|
10687
|
+
budget.reasons.add("decode-nested");
|
|
10688
|
+
break;
|
|
10689
|
+
}
|
|
10492
10690
|
}
|
|
10691
|
+
return out;
|
|
10493
10692
|
}
|
|
10494
10693
|
|
|
10495
10694
|
// src/dlp/arguments.ts
|
|
10496
10695
|
var ARGUMENT_SCAN_LIMITS = {
|
|
10497
10696
|
maxDepth: 12,
|
|
10498
10697
|
maxNodes: 16384,
|
|
10499
|
-
/**
|
|
10698
|
+
/** Text is matched and decoded in windows of this size. */
|
|
10500
10699
|
maxStringCharacters: 1e5,
|
|
10501
10700
|
/** Windows overlap by this much so a token on a window edge is still seen whole. */
|
|
10502
10701
|
windowOverlap: 4096,
|
|
@@ -10506,17 +10705,46 @@ var ARGUMENT_SCAN_LIMITS = {
|
|
|
10506
10705
|
maxTailBytes: 4194304,
|
|
10507
10706
|
maxJsonCharacters: 1e4
|
|
10508
10707
|
};
|
|
10708
|
+
var RUN_CHAR = /[A-Za-z0-9+/=_%\\.-]/;
|
|
10709
|
+
var runChar = (value, index) => {
|
|
10710
|
+
const char = value[index] ?? "";
|
|
10711
|
+
return RUN_CHAR.test(char) || char !== "" && isInvisibleChar(char);
|
|
10712
|
+
};
|
|
10713
|
+
function batches(views) {
|
|
10714
|
+
const out = [];
|
|
10715
|
+
let current = [];
|
|
10716
|
+
let size = 0;
|
|
10717
|
+
for (const { text } of views) {
|
|
10718
|
+
if (current.length && size + text.length > SECRET_VIEW_LIMITS.batchCharacters) {
|
|
10719
|
+
out.push(current);
|
|
10720
|
+
current = [];
|
|
10721
|
+
size = 0;
|
|
10722
|
+
}
|
|
10723
|
+
current.push(text);
|
|
10724
|
+
size += text.length;
|
|
10725
|
+
}
|
|
10726
|
+
if (current.length) out.push(current);
|
|
10727
|
+
return out;
|
|
10728
|
+
}
|
|
10509
10729
|
function inspectArgumentSecrets(args) {
|
|
10510
|
-
const budget =
|
|
10730
|
+
const budget = newSecretViewBudget();
|
|
10511
10731
|
const ancestors = /* @__PURE__ */ new Set();
|
|
10512
10732
|
let nodes = 0;
|
|
10513
10733
|
let sourceBytes = 0;
|
|
10514
10734
|
let tailBytes = 0;
|
|
10515
10735
|
let best = null;
|
|
10736
|
+
const blocked = () => best?.severity === "block";
|
|
10516
10737
|
const accept = (match) => {
|
|
10517
10738
|
if (match && (!best || best.severity !== "block" && match.severity === "block")) best = match;
|
|
10518
10739
|
};
|
|
10740
|
+
const decodeSegment = (segment, fieldPath) => {
|
|
10741
|
+
for (const batch of batches(secretViews(segment, budget))) {
|
|
10742
|
+
accept(matchArgumentBatch(batch, fieldPath, budget));
|
|
10743
|
+
if (blocked()) return;
|
|
10744
|
+
}
|
|
10745
|
+
};
|
|
10519
10746
|
const visit = (value, depth, fieldPath) => {
|
|
10747
|
+
if (blocked()) return;
|
|
10520
10748
|
if (++nodes > ARGUMENT_SCAN_LIMITS.maxNodes) {
|
|
10521
10749
|
budget.reasons.add("argument-nodes");
|
|
10522
10750
|
return;
|
|
@@ -10558,14 +10786,11 @@ function inspectArgumentSecrets(args) {
|
|
|
10558
10786
|
}
|
|
10559
10787
|
sourceBytes += Math.min(bytes, Math.max(0, remaining));
|
|
10560
10788
|
if (!text) return;
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
if (hit)
|
|
10564
|
-
accept(view.transforms.length ? { ...hit, redactedSample: "[encoded secret]" } : hit);
|
|
10565
|
-
}
|
|
10789
|
+
accept(matchArgumentText(text, fieldPath, budget));
|
|
10790
|
+
let scannedEnd = text.length;
|
|
10566
10791
|
if (!truncated && value.length > window) {
|
|
10567
|
-
budget.reasons.add("decode-window");
|
|
10568
10792
|
for (let start = window - overlap; start < value.length; start += window - overlap) {
|
|
10793
|
+
if (blocked()) return;
|
|
10569
10794
|
const chunk = value.slice(start, start + window);
|
|
10570
10795
|
const chunkBytes = Buffer.byteLength(chunk);
|
|
10571
10796
|
if (tailBytes + chunkBytes > ARGUMENT_SCAN_LIMITS.maxTailBytes) {
|
|
@@ -10574,9 +10799,16 @@ function inspectArgumentSecrets(args) {
|
|
|
10574
10799
|
}
|
|
10575
10800
|
tailBytes += chunkBytes;
|
|
10576
10801
|
accept(matchArgumentText(chunk, fieldPath, budget));
|
|
10802
|
+
scannedEnd = start + chunk.length;
|
|
10577
10803
|
if (start + window >= value.length) break;
|
|
10578
10804
|
}
|
|
10579
10805
|
}
|
|
10806
|
+
for (let start = 0; start < scannedEnd && !blocked(); ) {
|
|
10807
|
+
let end = Math.min(start + window, scannedEnd);
|
|
10808
|
+
while (end < scannedEnd && runChar(value, end - 1) && runChar(value, end)) end++;
|
|
10809
|
+
decodeSegment(value.slice(start, end), fieldPath);
|
|
10810
|
+
start = end;
|
|
10811
|
+
}
|
|
10580
10812
|
const trimmed = text.trim();
|
|
10581
10813
|
if (value.length < ARGUMENT_SCAN_LIMITS.maxJsonCharacters && (trimmed.startsWith("{") || trimmed.startsWith("["))) {
|
|
10582
10814
|
try {
|
|
@@ -10595,7 +10827,7 @@ function inspectArgumentSecrets(args) {
|
|
|
10595
10827
|
function scanArgumentSecrets(args) {
|
|
10596
10828
|
const result = inspectArgumentSecrets(args);
|
|
10597
10829
|
if (result.match) return result.match;
|
|
10598
|
-
return result.
|
|
10830
|
+
return result.coverage === "incomplete" ? {
|
|
10599
10831
|
patternName: "Argument inspection incomplete",
|
|
10600
10832
|
fieldPath: "args",
|
|
10601
10833
|
redactedSample: "[uninspected content]",
|
|
@@ -10630,18 +10862,13 @@ function tokenize2(toolName) {
|
|
|
10630
10862
|
return toolName.toLowerCase().split(/[_.\-\s]+/).filter(Boolean);
|
|
10631
10863
|
}
|
|
10632
10864
|
function extractShellCommand(toolName, args, toolInspection) {
|
|
10633
|
-
const
|
|
10634
|
-
|
|
10635
|
-
if (!matchingPattern) return null;
|
|
10636
|
-
const fieldPath = toolInspection[matchingPattern];
|
|
10865
|
+
const fieldPath = inspectionEntry(toolName, toolInspection);
|
|
10866
|
+
if (fieldPath === void 0) return null;
|
|
10637
10867
|
const value = getNestedValue(args, typeof fieldPath === "string" ? fieldPath : fieldPath.field);
|
|
10638
10868
|
return typeof value === "string" ? value : null;
|
|
10639
10869
|
}
|
|
10640
10870
|
function isSqlTool(toolName, toolInspection) {
|
|
10641
|
-
const
|
|
10642
|
-
const matchingPattern = patterns.find((p) => matchesPattern(toolName, p));
|
|
10643
|
-
if (!matchingPattern) return false;
|
|
10644
|
-
const fieldName = toolInspection[matchingPattern];
|
|
10871
|
+
const fieldName = inspectionEntry(toolName, toolInspection);
|
|
10645
10872
|
return fieldName === "sql" || fieldName === "query";
|
|
10646
10873
|
}
|
|
10647
10874
|
var SQL_DML_KEYWORDS = /* @__PURE__ */ new Set(["select", "insert", "update", "delete", "merge", "upsert"]);
|
|
@@ -10718,9 +10945,10 @@ function egressPolicyVerdict(eg) {
|
|
|
10718
10945
|
}
|
|
10719
10946
|
async function evaluatePolicy(config, toolName, args, context = {}, hooks = {}) {
|
|
10720
10947
|
let protectedVerdict = null;
|
|
10948
|
+
const layers = inspectionLayers(config.policy);
|
|
10721
10949
|
if (context.agent !== "Terminal") {
|
|
10722
10950
|
try {
|
|
10723
|
-
const accesses = context.accesses ?? collectFileAccesses(toolName, args, context,
|
|
10951
|
+
const accesses = context.accesses ?? collectFileAccesses(toolName, args, context, layers);
|
|
10724
10952
|
protectedVerdict = evaluateProtectedFileAccess(accesses, context, catalogSettings(config));
|
|
10725
10953
|
} catch {
|
|
10726
10954
|
protectedVerdict = incompleteFileVerdict();
|
|
@@ -10755,7 +10983,7 @@ async function evaluatePolicy(config, toolName, args, context = {}, hooks = {})
|
|
|
10755
10983
|
hooks
|
|
10756
10984
|
);
|
|
10757
10985
|
if (result.decision === "block") return result;
|
|
10758
|
-
if (context.agent !== "Terminal" && resolveShellInput(toolName, args,
|
|
10986
|
+
if (context.agent !== "Terminal" && resolveShellInput(toolName, args, layers).kind === "uninspectable") {
|
|
10759
10987
|
return {
|
|
10760
10988
|
decision: "review",
|
|
10761
10989
|
ruleName: "shell-inspection-incomplete",
|
|
@@ -10771,13 +10999,14 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
10771
10999
|
const { agent, cwd, activeEnvironment } = context;
|
|
10772
11000
|
const { checkProvenance, isTrustedHost } = hooks;
|
|
10773
11001
|
const settingsView = catalogSettings(config);
|
|
11002
|
+
const layers = inspectionLayers(config.policy);
|
|
10774
11003
|
const cv = (id) => checkValue(settingsView, id);
|
|
10775
11004
|
let loggedFinding;
|
|
10776
11005
|
const noteLogged = (v) => {
|
|
10777
11006
|
if (v?.logged && !loggedFinding) loggedFinding = v;
|
|
10778
11007
|
};
|
|
10779
11008
|
const allowed = () => loggedFinding ?? { decision: "allow" };
|
|
10780
|
-
const shellInput = resolveShellInput(toolName, args,
|
|
11009
|
+
const shellInput = resolveShellInput(toolName, args, layers);
|
|
10781
11010
|
const wouldBeIgnored = matchesPattern(toolName, config.policy.ignoredTools);
|
|
10782
11011
|
{
|
|
10783
11012
|
const dest = ssrfDestinationFloor(toolName, args, {
|
|
@@ -10882,13 +11111,10 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
10882
11111
|
return { id, value: cv(id) };
|
|
10883
11112
|
};
|
|
10884
11113
|
const matches = config.policy.smartRules.filter((rule) => {
|
|
10885
|
-
if (!toolMatchesRule(toolName, rule.tool,
|
|
11114
|
+
if (!toolMatchesRule(toolName, rule.tool, layers)) return false;
|
|
10886
11115
|
if (astSuppressed(rule)) return false;
|
|
10887
11116
|
if (rmCleanupWaiver && rule.name === "review-rm" && rule.verdict === "review") return false;
|
|
10888
|
-
if (!evaluateSmartConditions(
|
|
10889
|
-
shellRuleArgs(toolName, args, rule.tool, config.policy.toolInspection),
|
|
10890
|
-
rule
|
|
10891
|
-
))
|
|
11117
|
+
if (!evaluateSmartConditions(shellRuleArgs(toolName, args, rule.tool, layers), rule))
|
|
10892
11118
|
return false;
|
|
10893
11119
|
const check = ruleCheck(rule);
|
|
10894
11120
|
if (check?.value === "off") return false;
|
|
@@ -10935,7 +11161,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
10935
11161
|
let allTokens = [];
|
|
10936
11162
|
let pathTokens = [];
|
|
10937
11163
|
if (pendingToolEgress) return pendingToolEgress;
|
|
10938
|
-
const shellCommand = shellInput.kind === "shell" ? shellInput.command : shellInput.kind === "not-shell" ? extractShellCommand(toolName, args,
|
|
11164
|
+
const shellCommand = shellInput.kind === "shell" ? shellInput.command : shellInput.kind === "not-shell" ? extractShellCommand(toolName, args, layers) : null;
|
|
10939
11165
|
if (shellCommand) {
|
|
10940
11166
|
const analyzed = analyzeShellCommand(shellCommand);
|
|
10941
11167
|
allTokens = analyzed.allTokens;
|
|
@@ -11012,7 +11238,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
11012
11238
|
if (["ssh", "scp", "rsync"].includes(firstToken)) {
|
|
11013
11239
|
const rawTokens = shellCommand.trim().split(/\s+/);
|
|
11014
11240
|
const sshHosts = extractAllSshHosts(rawTokens.slice(1));
|
|
11015
|
-
allTokens.
|
|
11241
|
+
allTokens = allTokens.concat(sshHosts);
|
|
11016
11242
|
}
|
|
11017
11243
|
if (firstToken && firstToken.startsWith("/") && checkProvenance) {
|
|
11018
11244
|
const prov = checkProvenance(firstToken, cwd);
|
|
@@ -11041,7 +11267,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
11041
11267
|
};
|
|
11042
11268
|
}
|
|
11043
11269
|
}
|
|
11044
|
-
if (isSqlTool(toolName,
|
|
11270
|
+
if (isSqlTool(toolName, layers)) {
|
|
11045
11271
|
allTokens = allTokens.filter((t) => !SQL_DML_KEYWORDS.has(t.toLowerCase()));
|
|
11046
11272
|
}
|
|
11047
11273
|
} else {
|
|
@@ -11049,7 +11275,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
11049
11275
|
if (args && typeof args === "object") {
|
|
11050
11276
|
const flattenedArgs = JSON.stringify(args).toLowerCase();
|
|
11051
11277
|
const extraTokens = flattenedArgs.split(/[^a-zA-Z0-9]+/).filter((t) => t.length > 1);
|
|
11052
|
-
allTokens.
|
|
11278
|
+
allTokens = allTokens.concat(extraTokens);
|
|
11053
11279
|
}
|
|
11054
11280
|
}
|
|
11055
11281
|
const isManual = agent === "Terminal";
|
|
@@ -12337,8 +12563,8 @@ function matchCanaryArgs(args, values) {
|
|
|
12337
12563
|
|
|
12338
12564
|
// src/scan/canonical.ts
|
|
12339
12565
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
12340
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
12341
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
12566
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
|
|
12567
|
+
var CANONICAL_EXTRACTOR_HASH = "dec8c65145686360";
|
|
12342
12568
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
12343
12569
|
function extractCanonicalFindings(call, ctx) {
|
|
12344
12570
|
const out = [];
|
|
@@ -12816,6 +13042,8 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
12816
13042
|
hostMatches,
|
|
12817
13043
|
incompleteFileVerdict,
|
|
12818
13044
|
inspectArgumentSecrets,
|
|
13045
|
+
inspectionEntry,
|
|
13046
|
+
inspectionLayers,
|
|
12819
13047
|
isAgentInstructionPath,
|
|
12820
13048
|
isBashTool,
|
|
12821
13049
|
isDestructiveToolName,
|