@node9/policy-engine 2.52.0 → 2.53.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 +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +143 -6
- package/dist/index.mjs +143 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -973,7 +973,8 @@ interface PolicyVerdict {
|
|
|
973
973
|
/**
|
|
974
974
|
* False when NO human may override this verdict: the SSRF tier-1 floors,
|
|
975
975
|
* whose own reason string already tells the user "This address cannot be
|
|
976
|
-
* allowlisted"
|
|
976
|
+
* allowlisted", and a credential-file block (NOT_OVERRIDABLE_CHECKS,
|
|
977
|
+
* node9Firewall#441). Absent means an override is a legitimate product decision,
|
|
977
978
|
* which is every other verdict.
|
|
978
979
|
*
|
|
979
980
|
* It exists because the host downgrades a hard block into a review whenever a
|
|
@@ -2434,7 +2435,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
|
|
|
2434
2435
|
* and fails CI when the hash drifts without a version bump — forgetting
|
|
2435
2436
|
* is loud, not silent.
|
|
2436
2437
|
*/
|
|
2437
|
-
declare const CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
2438
|
+
declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
2438
2439
|
/**
|
|
2439
2440
|
* SHA-256 prefix of the detector-source files
|
|
2440
2441
|
* (canonical.ts + pii.ts + destructive-regex.ts).
|
|
@@ -2445,7 +2446,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v38";
|
|
|
2445
2446
|
* files changed, this hash must change too, and you must consciously
|
|
2446
2447
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2447
2448
|
*/
|
|
2448
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2449
|
+
declare const CANONICAL_EXTRACTOR_HASH = "e07d9e5e537017ae";
|
|
2449
2450
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2450
2451
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2451
2452
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -973,7 +973,8 @@ interface PolicyVerdict {
|
|
|
973
973
|
/**
|
|
974
974
|
* False when NO human may override this verdict: the SSRF tier-1 floors,
|
|
975
975
|
* whose own reason string already tells the user "This address cannot be
|
|
976
|
-
* allowlisted"
|
|
976
|
+
* allowlisted", and a credential-file block (NOT_OVERRIDABLE_CHECKS,
|
|
977
|
+
* node9Firewall#441). Absent means an override is a legitimate product decision,
|
|
977
978
|
* which is every other verdict.
|
|
978
979
|
*
|
|
979
980
|
* It exists because the host downgrades a hard block into a review whenever a
|
|
@@ -2434,7 +2435,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
|
|
|
2434
2435
|
* and fails CI when the hash drifts without a version bump — forgetting
|
|
2435
2436
|
* is loud, not silent.
|
|
2436
2437
|
*/
|
|
2437
|
-
declare const CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
2438
|
+
declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
2438
2439
|
/**
|
|
2439
2440
|
* SHA-256 prefix of the detector-source files
|
|
2440
2441
|
* (canonical.ts + pii.ts + destructive-regex.ts).
|
|
@@ -2445,7 +2446,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v38";
|
|
|
2445
2446
|
* files changed, this hash must change too, and you must consciously
|
|
2446
2447
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2447
2448
|
*/
|
|
2448
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2449
|
+
declare const CANONICAL_EXTRACTOR_HASH = "e07d9e5e537017ae";
|
|
2449
2450
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2450
2451
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2451
2452
|
/**
|
package/dist/index.js
CHANGED
|
@@ -5205,6 +5205,95 @@ function protectedLiteral(code, isProtected) {
|
|
|
5205
5205
|
}
|
|
5206
5206
|
return null;
|
|
5207
5207
|
}
|
|
5208
|
+
var READ_CALL = {
|
|
5209
|
+
python: String.raw`(?:\b(?:io|codecs)\.)?\bopen|\b(?:dotenv_values|load_dotenv|get_key|read_file|loadtxt|read_csv)`,
|
|
5210
|
+
node: String.raw`\b(?:readFileSync|readFile|createReadStream|readTextFile(?:Sync)?|readFileStr|openSync|file)`,
|
|
5211
|
+
perl: String.raw`\b(?:open|sysopen|read_file|slurp)`,
|
|
5212
|
+
ruby: String.raw`\b(?:File|IO)\.(?:read|binread|readlines|foreach|open)|\bDotenv\.(?:load|parse|overload)`,
|
|
5213
|
+
php: String.raw`\b(?:file_get_contents|fopen|file|readfile|parse_ini_file|highlight_file|show_source)`
|
|
5214
|
+
};
|
|
5215
|
+
var ARG = String.raw`(?:(?:(?:my|our|local)\s+)?[\w.$]+(?:\s*\(\s*\))?|'[^'\n]{0,8}'|"[^"\n]{0,8}")\s*,\s*`;
|
|
5216
|
+
var WRAP = String.raw`(?:(?:new\s+)?[\w.$]+\s*\(\s*(?:${ARG}){0,3}){0,3}`;
|
|
5217
|
+
var STR_PREFIX = String.raw`[rRbBuUfF]{0,2}`;
|
|
5218
|
+
var WRITE_MODE_LITERAL = String.raw`['"](?=[rbtU+]*w|(?![^'"]*\+)[rbtU]*[ax])[rwaxbtU+]{1,4}['"]`;
|
|
5219
|
+
var WRITE_MODE = String.raw`\s*,\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL}`;
|
|
5220
|
+
var WRITE_MODE_AFTER = new RegExp(`^(?:\\s*\\)){0,3}${WRITE_MODE}`);
|
|
5221
|
+
var PERL_WRITE_BEFORE = /['"]\s*(?:\+?[>|]|>>)\s*['"]\s*,\s*$/;
|
|
5222
|
+
var readCallBefore = (language) => new RegExp(
|
|
5223
|
+
String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}${STR_PREFIX}$`
|
|
5224
|
+
);
|
|
5225
|
+
var READ_BEFORE = {
|
|
5226
|
+
python: readCallBefore("python"),
|
|
5227
|
+
node: readCallBefore("node"),
|
|
5228
|
+
perl: readCallBefore("perl"),
|
|
5229
|
+
ruby: readCallBefore("ruby"),
|
|
5230
|
+
php: readCallBefore("php")
|
|
5231
|
+
};
|
|
5232
|
+
var READ_AFTER = {
|
|
5233
|
+
python: new RegExp(
|
|
5234
|
+
String.raw`^\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\((?!\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL})`
|
|
5235
|
+
)
|
|
5236
|
+
};
|
|
5237
|
+
var ASSIGNED = new RegExp(String.raw`([$\w]+)\s*=\s*${WRAP}${STR_PREFIX}$`);
|
|
5238
|
+
var openedName = (language) => new RegExp(
|
|
5239
|
+
String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}([$\w]+)(?!${WRITE_MODE})\s*[),]` + (language === "python" ? String.raw`|\bPath\s*\(\s*([$\w]+)\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\(` : ""),
|
|
5240
|
+
"g"
|
|
5241
|
+
);
|
|
5242
|
+
var OPENED_NAME = {
|
|
5243
|
+
python: openedName("python"),
|
|
5244
|
+
node: openedName("node"),
|
|
5245
|
+
perl: openedName("perl"),
|
|
5246
|
+
ruby: openedName("ruby"),
|
|
5247
|
+
php: openedName("php")
|
|
5248
|
+
};
|
|
5249
|
+
var DOTENV = {
|
|
5250
|
+
node: {
|
|
5251
|
+
load: /\brequire\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)|\bimport\s*(?:[\w${}\s,*]+\s+from\s*)?['"`]dotenv(?:\/config)?['"`]|\bimport\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)/,
|
|
5252
|
+
values: /\.parsed\b|[(,]\s*(?:require\s*\(\s*['"`]dotenv['"`]\s*\)|dotenv)\s*\.\s*config\s*\(/,
|
|
5253
|
+
env: /\b(?:process|Deno|Bun)\s*\.\s*env\b/,
|
|
5254
|
+
literalPath: /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*['"`]/
|
|
5255
|
+
},
|
|
5256
|
+
python: {
|
|
5257
|
+
load: /\b(?:load_dotenv|dotenv_values|get_key)\s*\(/,
|
|
5258
|
+
values: /\b(?:dotenv_values|get_key)\s*\(/,
|
|
5259
|
+
env: /\b(?:environ|getenv)\b/,
|
|
5260
|
+
literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
|
|
5261
|
+
}
|
|
5262
|
+
};
|
|
5263
|
+
var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
|
|
5264
|
+
function inlineReadPaths(language, code, preload = {}) {
|
|
5265
|
+
const out = [];
|
|
5266
|
+
const before = READ_BEFORE[language];
|
|
5267
|
+
const after = READ_AFTER[language];
|
|
5268
|
+
const assigned = /* @__PURE__ */ new Map();
|
|
5269
|
+
for (const m of code.matchAll(STRING_LITERAL)) {
|
|
5270
|
+
const raw = m[2].trim();
|
|
5271
|
+
const value = raw.replace(/^[<+]\s*/, "");
|
|
5272
|
+
if (!value) continue;
|
|
5273
|
+
const head = code.slice(Math.max(0, m.index - 160), m.index);
|
|
5274
|
+
const tail = code.slice(m.index + m[0].length, m.index + m[0].length + 40);
|
|
5275
|
+
if (/^[>|]/.test(raw) || WRITE_MODE_AFTER.test(tail) || PERL_WRITE_BEFORE.test(head)) continue;
|
|
5276
|
+
if (before.test(head) || after?.test(tail) || language === "node" && DOTENV_PATH_OPTION.test(head)) {
|
|
5277
|
+
out.push(value);
|
|
5278
|
+
continue;
|
|
5279
|
+
}
|
|
5280
|
+
const name = ASSIGNED.exec(head)?.[1];
|
|
5281
|
+
if (name) assigned.set(name, [...assigned.get(name) ?? [], value]);
|
|
5282
|
+
}
|
|
5283
|
+
if (assigned.size > 0) {
|
|
5284
|
+
const opened = /* @__PURE__ */ new Set();
|
|
5285
|
+
for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
|
|
5286
|
+
for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
|
|
5287
|
+
}
|
|
5288
|
+
if (language === "python" || language === "node") {
|
|
5289
|
+
const d = DOTENV[language];
|
|
5290
|
+
const readsEnv = d.env.test(code);
|
|
5291
|
+
const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
|
|
5292
|
+
if ((loads || preload.dotenv) && (readsEnv || d.values.test(code))) out.push(".env");
|
|
5293
|
+
if (readsEnv) out.push(...preload.envFiles ?? []);
|
|
5294
|
+
}
|
|
5295
|
+
return out;
|
|
5296
|
+
}
|
|
5208
5297
|
function amplifies(language, code) {
|
|
5209
5298
|
const loop = language === "python" ? /\bwhile\s+(?:True|1)\s*:/ : language === "node" ? /\bwhile\s*\(\s*(?:true|1)\s*\)|\bfor\s*\(\s*;\s*;\s*\)|\bsetInterval\s*\(/ : /\bwhile\s*\(?\s*(?:1|true)\s*\)?|\bloop\s+do\b|\bfor\s*\(\s*;\s*;\s*\)/;
|
|
5210
5299
|
const m = loop.exec(code);
|
|
@@ -6834,6 +6923,7 @@ function attachedCode(interp, flag) {
|
|
|
6834
6923
|
if (letters === "ep" && /^[ep]*$/i.test(rest)) rest = "";
|
|
6835
6924
|
return rest === "" ? null : rest;
|
|
6836
6925
|
}
|
|
6926
|
+
var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
|
|
6837
6927
|
function inlineExecCall(stmt, pipeFed) {
|
|
6838
6928
|
const cmd = stmt?.Cmd;
|
|
6839
6929
|
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
@@ -6858,15 +6948,28 @@ function inlineExecCall(stmt, pipeFed) {
|
|
|
6858
6948
|
const fromStdin = () => {
|
|
6859
6949
|
if (stdinFed) {
|
|
6860
6950
|
const { code, source } = stdinCodeOf(redirs);
|
|
6861
|
-
return { interp, code: [code], source };
|
|
6951
|
+
return { interp, code: [code], source, preload };
|
|
6862
6952
|
}
|
|
6863
6953
|
return { interp, code: [null], source: "pipe" };
|
|
6864
6954
|
};
|
|
6865
6955
|
let positionals2 = 0;
|
|
6866
6956
|
let selectedProgram = false;
|
|
6867
6957
|
const codes = [];
|
|
6958
|
+
const preload = {};
|
|
6959
|
+
const nodeFamily = inlineLanguageOf(interp) === "node";
|
|
6868
6960
|
for (let i = 0; i < args.length; i++) {
|
|
6869
6961
|
const a = args[i];
|
|
6962
|
+
if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
|
|
6963
|
+
const flag = NODE_VALUE_FLAG.exec(a);
|
|
6964
|
+
if (flag) {
|
|
6965
|
+
const value = flag[2] ?? args[++i];
|
|
6966
|
+
if (value != null) {
|
|
6967
|
+
if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
|
|
6968
|
+
else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
|
|
6969
|
+
}
|
|
6970
|
+
continue;
|
|
6971
|
+
}
|
|
6972
|
+
}
|
|
6870
6973
|
if (a == null) {
|
|
6871
6974
|
if (codes.length > 0) break;
|
|
6872
6975
|
positionals2++;
|
|
@@ -6903,7 +7006,12 @@ function inlineExecCall(stmt, pipeFed) {
|
|
|
6903
7006
|
}
|
|
6904
7007
|
}
|
|
6905
7008
|
if (codes.length > 0) {
|
|
6906
|
-
return {
|
|
7009
|
+
return {
|
|
7010
|
+
interp,
|
|
7011
|
+
code: codes,
|
|
7012
|
+
source: codes.includes(null) ? "variable" : void 0,
|
|
7013
|
+
preload
|
|
7014
|
+
};
|
|
6907
7015
|
}
|
|
6908
7016
|
if (positionals2 === 0 && (stdinFed || pipeFed)) {
|
|
6909
7017
|
if (!/^(bash|sh|zsh)$/i.test(interp)) return fromStdin();
|
|
@@ -7922,7 +8030,7 @@ var FS_OP_CACHE_MAX = 5e3;
|
|
|
7922
8030
|
var fsOpCache = /* @__PURE__ */ new Map();
|
|
7923
8031
|
function analyzeFsOperation(command) {
|
|
7924
8032
|
const normalized = normalizeCommandForPolicy(command);
|
|
7925
|
-
if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command))
|
|
8033
|
+
if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized))
|
|
7926
8034
|
return null;
|
|
7927
8035
|
if (fsOpCache.has(command)) {
|
|
7928
8036
|
const hit = fsOpCache.get(command) ?? null;
|
|
@@ -7930,7 +8038,8 @@ function analyzeFsOperation(command) {
|
|
|
7930
8038
|
fsOpCache.set(command, hit);
|
|
7931
8039
|
return hit;
|
|
7932
8040
|
}
|
|
7933
|
-
const
|
|
8041
|
+
const direct = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
|
|
8042
|
+
const computed = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
|
|
7934
8043
|
if (fsOpCache.size >= FS_OP_CACHE_MAX) {
|
|
7935
8044
|
const oldest = fsOpCache.keys().next().value;
|
|
7936
8045
|
if (oldest !== void 0) fsOpCache.delete(oldest);
|
|
@@ -8740,6 +8849,26 @@ function structuralJailRead(command) {
|
|
|
8740
8849
|
}
|
|
8741
8850
|
return review;
|
|
8742
8851
|
}
|
|
8852
|
+
var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
|
|
8853
|
+
var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
|
|
8854
|
+
function inlineCodeJailRead(command) {
|
|
8855
|
+
const calls = inlineExecCalls(command);
|
|
8856
|
+
if (calls === PARSE_FAIL) return null;
|
|
8857
|
+
let review = null;
|
|
8858
|
+
for (const call of calls) {
|
|
8859
|
+
const language = inlineLanguageOf(call.interp);
|
|
8860
|
+
if (language === null) continue;
|
|
8861
|
+
for (const code of call.code) {
|
|
8862
|
+
if (code === null) continue;
|
|
8863
|
+
for (const p of inlineReadPaths(language, code, call.preload)) {
|
|
8864
|
+
const hit = matchSensitivePath(p);
|
|
8865
|
+
if (hit?.verdict === "block") return hit;
|
|
8866
|
+
review ??= hit;
|
|
8867
|
+
}
|
|
8868
|
+
}
|
|
8869
|
+
}
|
|
8870
|
+
return review;
|
|
8871
|
+
}
|
|
8743
8872
|
function baseWord(w) {
|
|
8744
8873
|
return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
|
|
8745
8874
|
}
|
|
@@ -18256,7 +18385,15 @@ function egressPolicyVerdict(eg) {
|
|
|
18256
18385
|
checkId: "network.unknown-host"
|
|
18257
18386
|
};
|
|
18258
18387
|
}
|
|
18388
|
+
var NOT_OVERRIDABLE_CHECKS = /* @__PURE__ */ new Set([
|
|
18389
|
+
"data.credential-files",
|
|
18390
|
+
"data.credential-files-other"
|
|
18391
|
+
]);
|
|
18259
18392
|
async function evaluatePolicy(config, toolName, args, context = {}, hostHooks = {}) {
|
|
18393
|
+
const v = await evaluatePolicyVerdict(config, toolName, args, context, hostHooks);
|
|
18394
|
+
return v.decision === "block" && v.checkId !== void 0 && NOT_OVERRIDABLE_CHECKS.has(v.checkId) ? { ...v, overridable: false } : v;
|
|
18395
|
+
}
|
|
18396
|
+
async function evaluatePolicyVerdict(config, toolName, args, context = {}, hostHooks = {}) {
|
|
18260
18397
|
let protectedVerdict = null;
|
|
18261
18398
|
const layers = inspectionLayers(config.policy);
|
|
18262
18399
|
if (context.agent !== "Terminal") {
|
|
@@ -20470,8 +20607,8 @@ function matchCanaryArgs(args, values) {
|
|
|
20470
20607
|
|
|
20471
20608
|
// src/scan/canonical.ts
|
|
20472
20609
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20473
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
20474
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20610
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
20611
|
+
var CANONICAL_EXTRACTOR_HASH = "e07d9e5e537017ae";
|
|
20475
20612
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20476
20613
|
function extractCanonicalFindings(call, ctx) {
|
|
20477
20614
|
const out = [];
|
package/dist/index.mjs
CHANGED
|
@@ -4942,6 +4942,95 @@ function protectedLiteral(code, isProtected) {
|
|
|
4942
4942
|
}
|
|
4943
4943
|
return null;
|
|
4944
4944
|
}
|
|
4945
|
+
var READ_CALL = {
|
|
4946
|
+
python: String.raw`(?:\b(?:io|codecs)\.)?\bopen|\b(?:dotenv_values|load_dotenv|get_key|read_file|loadtxt|read_csv)`,
|
|
4947
|
+
node: String.raw`\b(?:readFileSync|readFile|createReadStream|readTextFile(?:Sync)?|readFileStr|openSync|file)`,
|
|
4948
|
+
perl: String.raw`\b(?:open|sysopen|read_file|slurp)`,
|
|
4949
|
+
ruby: String.raw`\b(?:File|IO)\.(?:read|binread|readlines|foreach|open)|\bDotenv\.(?:load|parse|overload)`,
|
|
4950
|
+
php: String.raw`\b(?:file_get_contents|fopen|file|readfile|parse_ini_file|highlight_file|show_source)`
|
|
4951
|
+
};
|
|
4952
|
+
var ARG = String.raw`(?:(?:(?:my|our|local)\s+)?[\w.$]+(?:\s*\(\s*\))?|'[^'\n]{0,8}'|"[^"\n]{0,8}")\s*,\s*`;
|
|
4953
|
+
var WRAP = String.raw`(?:(?:new\s+)?[\w.$]+\s*\(\s*(?:${ARG}){0,3}){0,3}`;
|
|
4954
|
+
var STR_PREFIX = String.raw`[rRbBuUfF]{0,2}`;
|
|
4955
|
+
var WRITE_MODE_LITERAL = String.raw`['"](?=[rbtU+]*w|(?![^'"]*\+)[rbtU]*[ax])[rwaxbtU+]{1,4}['"]`;
|
|
4956
|
+
var WRITE_MODE = String.raw`\s*,\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL}`;
|
|
4957
|
+
var WRITE_MODE_AFTER = new RegExp(`^(?:\\s*\\)){0,3}${WRITE_MODE}`);
|
|
4958
|
+
var PERL_WRITE_BEFORE = /['"]\s*(?:\+?[>|]|>>)\s*['"]\s*,\s*$/;
|
|
4959
|
+
var readCallBefore = (language) => new RegExp(
|
|
4960
|
+
String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}${STR_PREFIX}$`
|
|
4961
|
+
);
|
|
4962
|
+
var READ_BEFORE = {
|
|
4963
|
+
python: readCallBefore("python"),
|
|
4964
|
+
node: readCallBefore("node"),
|
|
4965
|
+
perl: readCallBefore("perl"),
|
|
4966
|
+
ruby: readCallBefore("ruby"),
|
|
4967
|
+
php: readCallBefore("php")
|
|
4968
|
+
};
|
|
4969
|
+
var READ_AFTER = {
|
|
4970
|
+
python: new RegExp(
|
|
4971
|
+
String.raw`^\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\((?!\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL})`
|
|
4972
|
+
)
|
|
4973
|
+
};
|
|
4974
|
+
var ASSIGNED = new RegExp(String.raw`([$\w]+)\s*=\s*${WRAP}${STR_PREFIX}$`);
|
|
4975
|
+
var openedName = (language) => new RegExp(
|
|
4976
|
+
String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}([$\w]+)(?!${WRITE_MODE})\s*[),]` + (language === "python" ? String.raw`|\bPath\s*\(\s*([$\w]+)\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\(` : ""),
|
|
4977
|
+
"g"
|
|
4978
|
+
);
|
|
4979
|
+
var OPENED_NAME = {
|
|
4980
|
+
python: openedName("python"),
|
|
4981
|
+
node: openedName("node"),
|
|
4982
|
+
perl: openedName("perl"),
|
|
4983
|
+
ruby: openedName("ruby"),
|
|
4984
|
+
php: openedName("php")
|
|
4985
|
+
};
|
|
4986
|
+
var DOTENV = {
|
|
4987
|
+
node: {
|
|
4988
|
+
load: /\brequire\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)|\bimport\s*(?:[\w${}\s,*]+\s+from\s*)?['"`]dotenv(?:\/config)?['"`]|\bimport\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)/,
|
|
4989
|
+
values: /\.parsed\b|[(,]\s*(?:require\s*\(\s*['"`]dotenv['"`]\s*\)|dotenv)\s*\.\s*config\s*\(/,
|
|
4990
|
+
env: /\b(?:process|Deno|Bun)\s*\.\s*env\b/,
|
|
4991
|
+
literalPath: /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*['"`]/
|
|
4992
|
+
},
|
|
4993
|
+
python: {
|
|
4994
|
+
load: /\b(?:load_dotenv|dotenv_values|get_key)\s*\(/,
|
|
4995
|
+
values: /\b(?:dotenv_values|get_key)\s*\(/,
|
|
4996
|
+
env: /\b(?:environ|getenv)\b/,
|
|
4997
|
+
literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
|
|
4998
|
+
}
|
|
4999
|
+
};
|
|
5000
|
+
var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
|
|
5001
|
+
function inlineReadPaths(language, code, preload = {}) {
|
|
5002
|
+
const out = [];
|
|
5003
|
+
const before = READ_BEFORE[language];
|
|
5004
|
+
const after = READ_AFTER[language];
|
|
5005
|
+
const assigned = /* @__PURE__ */ new Map();
|
|
5006
|
+
for (const m of code.matchAll(STRING_LITERAL)) {
|
|
5007
|
+
const raw = m[2].trim();
|
|
5008
|
+
const value = raw.replace(/^[<+]\s*/, "");
|
|
5009
|
+
if (!value) continue;
|
|
5010
|
+
const head = code.slice(Math.max(0, m.index - 160), m.index);
|
|
5011
|
+
const tail = code.slice(m.index + m[0].length, m.index + m[0].length + 40);
|
|
5012
|
+
if (/^[>|]/.test(raw) || WRITE_MODE_AFTER.test(tail) || PERL_WRITE_BEFORE.test(head)) continue;
|
|
5013
|
+
if (before.test(head) || after?.test(tail) || language === "node" && DOTENV_PATH_OPTION.test(head)) {
|
|
5014
|
+
out.push(value);
|
|
5015
|
+
continue;
|
|
5016
|
+
}
|
|
5017
|
+
const name = ASSIGNED.exec(head)?.[1];
|
|
5018
|
+
if (name) assigned.set(name, [...assigned.get(name) ?? [], value]);
|
|
5019
|
+
}
|
|
5020
|
+
if (assigned.size > 0) {
|
|
5021
|
+
const opened = /* @__PURE__ */ new Set();
|
|
5022
|
+
for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
|
|
5023
|
+
for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
|
|
5024
|
+
}
|
|
5025
|
+
if (language === "python" || language === "node") {
|
|
5026
|
+
const d = DOTENV[language];
|
|
5027
|
+
const readsEnv = d.env.test(code);
|
|
5028
|
+
const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
|
|
5029
|
+
if ((loads || preload.dotenv) && (readsEnv || d.values.test(code))) out.push(".env");
|
|
5030
|
+
if (readsEnv) out.push(...preload.envFiles ?? []);
|
|
5031
|
+
}
|
|
5032
|
+
return out;
|
|
5033
|
+
}
|
|
4945
5034
|
function amplifies(language, code) {
|
|
4946
5035
|
const loop = language === "python" ? /\bwhile\s+(?:True|1)\s*:/ : language === "node" ? /\bwhile\s*\(\s*(?:true|1)\s*\)|\bfor\s*\(\s*;\s*;\s*\)|\bsetInterval\s*\(/ : /\bwhile\s*\(?\s*(?:1|true)\s*\)?|\bloop\s+do\b|\bfor\s*\(\s*;\s*;\s*\)/;
|
|
4947
5036
|
const m = loop.exec(code);
|
|
@@ -6571,6 +6660,7 @@ function attachedCode(interp, flag) {
|
|
|
6571
6660
|
if (letters === "ep" && /^[ep]*$/i.test(rest)) rest = "";
|
|
6572
6661
|
return rest === "" ? null : rest;
|
|
6573
6662
|
}
|
|
6663
|
+
var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
|
|
6574
6664
|
function inlineExecCall(stmt, pipeFed) {
|
|
6575
6665
|
const cmd = stmt?.Cmd;
|
|
6576
6666
|
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
@@ -6595,15 +6685,28 @@ function inlineExecCall(stmt, pipeFed) {
|
|
|
6595
6685
|
const fromStdin = () => {
|
|
6596
6686
|
if (stdinFed) {
|
|
6597
6687
|
const { code, source } = stdinCodeOf(redirs);
|
|
6598
|
-
return { interp, code: [code], source };
|
|
6688
|
+
return { interp, code: [code], source, preload };
|
|
6599
6689
|
}
|
|
6600
6690
|
return { interp, code: [null], source: "pipe" };
|
|
6601
6691
|
};
|
|
6602
6692
|
let positionals2 = 0;
|
|
6603
6693
|
let selectedProgram = false;
|
|
6604
6694
|
const codes = [];
|
|
6695
|
+
const preload = {};
|
|
6696
|
+
const nodeFamily = inlineLanguageOf(interp) === "node";
|
|
6605
6697
|
for (let i = 0; i < args.length; i++) {
|
|
6606
6698
|
const a = args[i];
|
|
6699
|
+
if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
|
|
6700
|
+
const flag = NODE_VALUE_FLAG.exec(a);
|
|
6701
|
+
if (flag) {
|
|
6702
|
+
const value = flag[2] ?? args[++i];
|
|
6703
|
+
if (value != null) {
|
|
6704
|
+
if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
|
|
6705
|
+
else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
|
|
6706
|
+
}
|
|
6707
|
+
continue;
|
|
6708
|
+
}
|
|
6709
|
+
}
|
|
6607
6710
|
if (a == null) {
|
|
6608
6711
|
if (codes.length > 0) break;
|
|
6609
6712
|
positionals2++;
|
|
@@ -6640,7 +6743,12 @@ function inlineExecCall(stmt, pipeFed) {
|
|
|
6640
6743
|
}
|
|
6641
6744
|
}
|
|
6642
6745
|
if (codes.length > 0) {
|
|
6643
|
-
return {
|
|
6746
|
+
return {
|
|
6747
|
+
interp,
|
|
6748
|
+
code: codes,
|
|
6749
|
+
source: codes.includes(null) ? "variable" : void 0,
|
|
6750
|
+
preload
|
|
6751
|
+
};
|
|
6644
6752
|
}
|
|
6645
6753
|
if (positionals2 === 0 && (stdinFed || pipeFed)) {
|
|
6646
6754
|
if (!/^(bash|sh|zsh)$/i.test(interp)) return fromStdin();
|
|
@@ -7659,7 +7767,7 @@ var FS_OP_CACHE_MAX = 5e3;
|
|
|
7659
7767
|
var fsOpCache = /* @__PURE__ */ new Map();
|
|
7660
7768
|
function analyzeFsOperation(command) {
|
|
7661
7769
|
const normalized = normalizeCommandForPolicy(command);
|
|
7662
|
-
if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command))
|
|
7770
|
+
if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized))
|
|
7663
7771
|
return null;
|
|
7664
7772
|
if (fsOpCache.has(command)) {
|
|
7665
7773
|
const hit = fsOpCache.get(command) ?? null;
|
|
@@ -7667,7 +7775,8 @@ function analyzeFsOperation(command) {
|
|
|
7667
7775
|
fsOpCache.set(command, hit);
|
|
7668
7776
|
return hit;
|
|
7669
7777
|
}
|
|
7670
|
-
const
|
|
7778
|
+
const direct = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
|
|
7779
|
+
const computed = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
|
|
7671
7780
|
if (fsOpCache.size >= FS_OP_CACHE_MAX) {
|
|
7672
7781
|
const oldest = fsOpCache.keys().next().value;
|
|
7673
7782
|
if (oldest !== void 0) fsOpCache.delete(oldest);
|
|
@@ -8477,6 +8586,26 @@ function structuralJailRead(command) {
|
|
|
8477
8586
|
}
|
|
8478
8587
|
return review;
|
|
8479
8588
|
}
|
|
8589
|
+
var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
|
|
8590
|
+
var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
|
|
8591
|
+
function inlineCodeJailRead(command) {
|
|
8592
|
+
const calls = inlineExecCalls(command);
|
|
8593
|
+
if (calls === PARSE_FAIL) return null;
|
|
8594
|
+
let review = null;
|
|
8595
|
+
for (const call of calls) {
|
|
8596
|
+
const language = inlineLanguageOf(call.interp);
|
|
8597
|
+
if (language === null) continue;
|
|
8598
|
+
for (const code of call.code) {
|
|
8599
|
+
if (code === null) continue;
|
|
8600
|
+
for (const p of inlineReadPaths(language, code, call.preload)) {
|
|
8601
|
+
const hit = matchSensitivePath(p);
|
|
8602
|
+
if (hit?.verdict === "block") return hit;
|
|
8603
|
+
review ??= hit;
|
|
8604
|
+
}
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8607
|
+
return review;
|
|
8608
|
+
}
|
|
8480
8609
|
function baseWord(w) {
|
|
8481
8610
|
return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
|
|
8482
8611
|
}
|
|
@@ -17993,7 +18122,15 @@ function egressPolicyVerdict(eg) {
|
|
|
17993
18122
|
checkId: "network.unknown-host"
|
|
17994
18123
|
};
|
|
17995
18124
|
}
|
|
18125
|
+
var NOT_OVERRIDABLE_CHECKS = /* @__PURE__ */ new Set([
|
|
18126
|
+
"data.credential-files",
|
|
18127
|
+
"data.credential-files-other"
|
|
18128
|
+
]);
|
|
17996
18129
|
async function evaluatePolicy(config, toolName, args, context = {}, hostHooks = {}) {
|
|
18130
|
+
const v = await evaluatePolicyVerdict(config, toolName, args, context, hostHooks);
|
|
18131
|
+
return v.decision === "block" && v.checkId !== void 0 && NOT_OVERRIDABLE_CHECKS.has(v.checkId) ? { ...v, overridable: false } : v;
|
|
18132
|
+
}
|
|
18133
|
+
async function evaluatePolicyVerdict(config, toolName, args, context = {}, hostHooks = {}) {
|
|
17997
18134
|
let protectedVerdict = null;
|
|
17998
18135
|
const layers = inspectionLayers(config.policy);
|
|
17999
18136
|
if (context.agent !== "Terminal") {
|
|
@@ -20207,8 +20344,8 @@ function matchCanaryArgs(args, values) {
|
|
|
20207
20344
|
|
|
20208
20345
|
// src/scan/canonical.ts
|
|
20209
20346
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20210
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
20211
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20347
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
20348
|
+
var CANONICAL_EXTRACTOR_HASH = "e07d9e5e537017ae";
|
|
20212
20349
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20213
20350
|
function extractCanonicalFindings(call, ctx) {
|
|
20214
20351
|
const out = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node9/policy-engine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.53.0",
|
|
4
4
|
"description": "Shared policy evaluation engine for node9 — DLP, smart rules, AST shell parsing, shields, loop detection. Pure functions, no I/O. Used by both node9-proxy and the node9 SaaS firewall.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://node9.ai",
|