@kenhkl/agent-moss 0.17.33 → 0.17.35
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/cli.js +390 -258
- package/dist/engine/coordinator.js +146 -110
- package/dist/rules/mc_rules.json +1 -1
- package/dist/server.js +348 -219
- package/package.json +1 -1
|
@@ -442,22 +442,22 @@ function loadToolRegistry() {
|
|
|
442
442
|
data.tools = tools;
|
|
443
443
|
return data;
|
|
444
444
|
}
|
|
445
|
-
function scanStructEntry(cat, value,
|
|
445
|
+
function scanStructEntry(cat, value, path8) {
|
|
446
446
|
if (cat === "skills") {
|
|
447
447
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
448
|
-
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
448
|
+
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 skills \u5E94\u4E3A\u5BF9\u8C61\uFF08{\u7C7B\u522B: {\u6280\u80FD\u540D: [\u5173\u952E\u8BCD]}}\uFF09\u2014\u2014 \u5DF2\u8DF3\u8FC7\u3002`);
|
|
449
449
|
return null;
|
|
450
450
|
}
|
|
451
451
|
const out = {};
|
|
452
452
|
for (const [skCat, skills] of Object.entries(value)) {
|
|
453
453
|
if (!skills || typeof skills !== "object" || Array.isArray(skills)) {
|
|
454
|
-
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
454
|
+
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 skills.${skCat} \u5E94\u4E3A\u5BF9\u8C61\uFF08\u6280\u80FD\u540D \u2192 \u5173\u952E\u8BCD\u6570\u7EC4\uFF09\u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u7C7B\u522B\u3002`);
|
|
455
455
|
continue;
|
|
456
456
|
}
|
|
457
457
|
const keep = {};
|
|
458
458
|
for (const [name, kws] of Object.entries(skills)) {
|
|
459
459
|
if (Array.isArray(kws)) keep[name] = kws;
|
|
460
|
-
else console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
460
|
+
else console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 skills.${skCat}.${name} \u5173\u952E\u8BCD\u4E0D\u662F\u6570\u7EC4 \u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u6761\u3002`);
|
|
461
461
|
}
|
|
462
462
|
if (Object.keys(keep).length > 0) out[skCat] = keep;
|
|
463
463
|
}
|
|
@@ -465,37 +465,37 @@ function scanStructEntry(cat, value, path7) {
|
|
|
465
465
|
}
|
|
466
466
|
if (cat === "ltl_rules") {
|
|
467
467
|
if (!Array.isArray(value)) {
|
|
468
|
-
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
468
|
+
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 ltl_rules \u5E94\u4E3A\u5BF9\u8C61\u6570\u7EC4 \u2014\u2014 \u5DF2\u8DF3\u8FC7\u3002`);
|
|
469
469
|
return null;
|
|
470
470
|
}
|
|
471
471
|
const keep = value.filter((r) => r && typeof r === "object" && r.id);
|
|
472
472
|
if (keep.length !== value.length) {
|
|
473
|
-
console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
473
|
+
console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 ltl_rules \u6709\u6761\u76EE\u7F3A id \u6216\u4E0D\u662F\u5BF9\u8C61 \u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u6761\u3002`);
|
|
474
474
|
}
|
|
475
475
|
return keep.length > 0 ? keep : null;
|
|
476
476
|
}
|
|
477
477
|
if (cat === "tools") {
|
|
478
478
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
479
|
-
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
479
|
+
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 tools \u5E94\u4E3A\u5BF9\u8C61\uFF08{\u5DE5\u5177\u540D: {actionClass, ...}}\uFF09\u2014\u2014 \u5DF2\u8DF3\u8FC7\u3002`);
|
|
480
480
|
return null;
|
|
481
481
|
}
|
|
482
482
|
const keep = {};
|
|
483
483
|
for (const [k, v] of Object.entries(value)) {
|
|
484
484
|
if (v && typeof v === "object" && !Array.isArray(v)) keep[k] = v;
|
|
485
|
-
else console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
485
|
+
else console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684 tools.${k} \u4E0D\u662F\u5BF9\u8C61 \u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u6761\u3002`);
|
|
486
486
|
}
|
|
487
487
|
return Object.keys(keep).length > 0 ? keep : null;
|
|
488
488
|
}
|
|
489
489
|
return null;
|
|
490
490
|
}
|
|
491
|
-
function scanRulesFile(
|
|
491
|
+
function scanRulesFile(path8, kind) {
|
|
492
492
|
const out = {};
|
|
493
493
|
const label = kind === "override" ? "\u8986\u76D6" : "\u8FFD\u52A0";
|
|
494
494
|
let parsed;
|
|
495
495
|
try {
|
|
496
|
-
parsed = JSON.parse(readFileSync2(
|
|
496
|
+
parsed = JSON.parse(readFileSync2(path8, "utf-8"));
|
|
497
497
|
} catch (e) {
|
|
498
|
-
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
498
|
+
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u635F\u574F/\u4E0D\u53EF\u8BFB\uFF0C\u5DF2\u8DF3\u8FC7\uFF08${kind} \u89C4\u5219\u4E0D\u751F\u6548\uFF09: ${e.message}`);
|
|
499
499
|
return out;
|
|
500
500
|
}
|
|
501
501
|
const classifyFlat = (r) => {
|
|
@@ -519,44 +519,44 @@ function scanRulesFile(path7, kind) {
|
|
|
519
519
|
}
|
|
520
520
|
if (flatBad > 0) {
|
|
521
521
|
console.warn(
|
|
522
|
-
`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
522
|
+
`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u6709 ${flatBad} \u6761\u5E73\u94FA\u6761\u76EE\u65E0\u6CD5\u5F52\u7C7B\uFF08\u88F8 pattern \u4E0D\u5E26 risk_level/risk_type \u65F6\u533A\u5206\u4E0D\u4E86 L1 \u5371\u9669\u547D\u4EE4\u4E0E L2 \u6388\u6743\u7C7B\uFF09\u2014\u2014 \u8BF7\u6539\u7528\u5BF9\u8C61\u5F62\u5F0F\uFF1A{"\u7C7B\u522B\u952E": [\u6761\u76EE...]}\u3002`
|
|
523
523
|
);
|
|
524
524
|
}
|
|
525
525
|
} else {
|
|
526
|
-
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
526
|
+
console.error(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u9876\u5C42\u5E94\u662F\u5BF9\u8C61\uFF08\u7C7B\u522B\u952E\u2192\u6761\u76EE\u6570\u7EC4\uFF09\u6216\u6570\u7EC4\uFF0C\u5DF2\u8DF3\u8FC7\u3002`);
|
|
527
527
|
return out;
|
|
528
528
|
}
|
|
529
529
|
for (const [cat, rules] of pairs) {
|
|
530
530
|
if (String(cat).startsWith("_")) continue;
|
|
531
531
|
if (STRUCT_KEYS.includes(cat)) {
|
|
532
|
-
const got = scanStructEntry(cat, rules,
|
|
532
|
+
const got = scanStructEntry(cat, rules, path8);
|
|
533
533
|
if (got !== null) out[cat] = got;
|
|
534
534
|
continue;
|
|
535
535
|
}
|
|
536
536
|
const required = EXTRA_CATEGORIES[cat];
|
|
537
537
|
if (!required) {
|
|
538
538
|
console.warn(
|
|
539
|
-
`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
539
|
+
`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u542B\u672A\u77E5\u7C7B\u522B\u952E "${cat}"\uFF08\u53EF\u7528\uFF1A${Object.keys(EXTRA_CATEGORIES).join(", ")}\uFF09\u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u7C7B\u522B\u3002`
|
|
540
540
|
);
|
|
541
541
|
continue;
|
|
542
542
|
}
|
|
543
543
|
if (rules && typeof rules === "object" && !Array.isArray(rules)) {
|
|
544
544
|
console.error(
|
|
545
|
-
`[AgentMoss] \u274C \u89C4\u5219\u6587\u4EF6 ${
|
|
545
|
+
`[AgentMoss] \u274C \u89C4\u5219\u6587\u4EF6 ${path8} \u7684\u7C7B\u522B "${cat}" \u662F**\u5BF9\u8C61**\uFF0C\u5E94\u4E3A**\u5BF9\u8C61\u6570\u7EC4** \u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u7C7B\u522B\u3002
|
|
546
546
|
\u6B63\u786E\u5199\u6CD5: {"${cat}": [{"pattern": "...", "risk_level": "high", ...}]}
|
|
547
547
|
\u4F60\u5199\u7684\u50CF\u662F runtime config \u7684\u683C\u5F0F\uFF08{"category_enabled": ..., "rules": [...]}\uFF09\u2014\u2014\u90A3\u662F ~/.config/agentmoss/agent_moss_runtime.json \u7684\u683C\u5F0F\uFF0C\u4E0D\u80FD\u76F4\u63A5\u5F53\u89C4\u5219\u6587\u4EF6\u7528\u3002`
|
|
548
548
|
);
|
|
549
549
|
continue;
|
|
550
550
|
}
|
|
551
551
|
if (!Array.isArray(rules)) {
|
|
552
|
-
console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
552
|
+
console.warn(`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7684\u7C7B\u522B "${cat}" \u5E94\u4E3A\u6570\u7EC4\uFF0C\u5B9E\u9645\u662F ${typeof rules} \u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u7C7B\u522B\u3002`);
|
|
553
553
|
continue;
|
|
554
554
|
}
|
|
555
555
|
const items = [];
|
|
556
556
|
for (const r of rules) {
|
|
557
557
|
if (!r || typeof r !== "object" || !required.every((k) => r[k])) {
|
|
558
558
|
console.warn(
|
|
559
|
-
`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${
|
|
559
|
+
`[AgentMoss] \u89C4\u5219\u6587\u4EF6 ${path8} \u7C7B\u522B ${cat} \u6709\u6761\u76EE\u7F3A\u5FC5\u9700\u5B57\u6BB5 [${required.join(", ")}] \u2014\u2014 \u5DF2\u8DF3\u8FC7\u8BE5\u6761\u3002`
|
|
560
560
|
);
|
|
561
561
|
continue;
|
|
562
562
|
}
|
|
@@ -566,7 +566,7 @@ function scanRulesFile(path7, kind) {
|
|
|
566
566
|
}
|
|
567
567
|
if (Object.keys(out).length > 0) {
|
|
568
568
|
console.info(
|
|
569
|
-
`[AgentMoss] \u5DF2\u52A0\u8F7D${label}\u89C4\u5219\u6587\u4EF6 ${
|
|
569
|
+
`[AgentMoss] \u5DF2\u52A0\u8F7D${label}\u89C4\u5219\u6587\u4EF6 ${path8}\uFF1A` + Object.entries(out).map(([k, v]) => `${k}\xD7${v.length}`).join(", ")
|
|
570
570
|
);
|
|
571
571
|
}
|
|
572
572
|
return out;
|
|
@@ -969,7 +969,7 @@ function _loadSensitivePathScope(scope, osType = "linux") {
|
|
|
969
969
|
os: String(sp.os || "linux").toLowerCase()
|
|
970
970
|
}));
|
|
971
971
|
}
|
|
972
|
-
function _scopeOf(
|
|
972
|
+
function _scopeOf(os5, path8) {
|
|
973
973
|
if (!_scopeIndex) {
|
|
974
974
|
_scopeIndex = /* @__PURE__ */ new Map();
|
|
975
975
|
for (const sp of loadL1().sensitive_path_access || []) {
|
|
@@ -977,7 +977,7 @@ function _scopeOf(os4, path7) {
|
|
|
977
977
|
if (!_scopeIndex.has(key)) _scopeIndex.set(key, sp.scope);
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
|
-
return _scopeIndex.get(`${String(
|
|
980
|
+
return _scopeIndex.get(`${String(os5 || "linux").toLowerCase()}|${path8}`) || "root";
|
|
981
981
|
}
|
|
982
982
|
function getSensitivePathsForOs(osType) {
|
|
983
983
|
const effective = runtimeConfigBridge.current?.effectiveSensitivePaths(osType);
|
|
@@ -1696,36 +1696,36 @@ function checkReadBeforeWrite(actionType, actionDetailRaw, actionHistory, reason
|
|
|
1696
1696
|
}
|
|
1697
1697
|
const preciseEdit = isPreciseEditTool(actionType);
|
|
1698
1698
|
const unreadPaths = [];
|
|
1699
|
-
for (const
|
|
1700
|
-
if (isDirectoryTarget(
|
|
1699
|
+
for (const path8 of checkTargets) {
|
|
1700
|
+
if (isDirectoryTarget(path8)) continue;
|
|
1701
1701
|
let isFullRead = [...normalizedFullReads].some(
|
|
1702
|
-
(rp) => pathIsSameOrUnder(
|
|
1702
|
+
(rp) => pathIsSameOrUnder(path8, rp) || pathIsSameOrUnder(rp, path8)
|
|
1703
1703
|
);
|
|
1704
1704
|
if (!isFullRead && preciseEdit && [...normalizedWrittenPaths].some(
|
|
1705
|
-
(wp) => pathIsSameOrUnder(
|
|
1705
|
+
(wp) => pathIsSameOrUnder(path8, wp) || pathIsSameOrUnder(wp, path8)
|
|
1706
1706
|
)) {
|
|
1707
1707
|
isFullRead = true;
|
|
1708
1708
|
}
|
|
1709
|
-
if (!isFullRead && !isProtectedWritePath(
|
|
1709
|
+
if (!isFullRead && !isProtectedWritePath(path8) && isScriptGeneratedTarget(path8, historyWrittenScripts, shellRunActions)) {
|
|
1710
1710
|
isFullRead = true;
|
|
1711
1711
|
}
|
|
1712
1712
|
let isPartialCovered = false;
|
|
1713
1713
|
if (!isFullRead) {
|
|
1714
1714
|
for (const [pp, upto] of normalizedPartialReads) {
|
|
1715
|
-
if (!(pathIsSameOrUnder(
|
|
1716
|
-
if (preciseEdit || upto != null && fileHasAtMostLines(
|
|
1715
|
+
if (!(pathIsSameOrUnder(path8, pp) || pathIsSameOrUnder(pp, path8))) continue;
|
|
1716
|
+
if (preciseEdit || upto != null && fileHasAtMostLines(path8, upto)) {
|
|
1717
1717
|
isPartialCovered = true;
|
|
1718
1718
|
break;
|
|
1719
1719
|
}
|
|
1720
1720
|
}
|
|
1721
1721
|
}
|
|
1722
1722
|
if (!isFullRead && !isPartialCovered) {
|
|
1723
|
-
let isCreate = !fs.existsSync(
|
|
1723
|
+
let isCreate = !fs.existsSync(path8);
|
|
1724
1724
|
if (!isCreate) {
|
|
1725
1725
|
isCreate = CREATE_KEYWORDS.some((kw) => reason.toLowerCase().includes(kw) || actionDetail.includes(kw));
|
|
1726
1726
|
}
|
|
1727
1727
|
if (!isCreate) {
|
|
1728
|
-
unreadPaths.push(
|
|
1728
|
+
unreadPaths.push(path8);
|
|
1729
1729
|
}
|
|
1730
1730
|
}
|
|
1731
1731
|
}
|
|
@@ -1919,16 +1919,16 @@ var init_logic_rules = __esm({
|
|
|
1919
1919
|
ALL_QUOTES_RE = /'[^']*'|"[^"]*"/g;
|
|
1920
1920
|
ROOT_SENSITIVE_PATHS = _loadSensitivePathScope("root");
|
|
1921
1921
|
HOME_SENSITIVE_PATHS = _loadSensitivePathScope("home");
|
|
1922
|
-
CREDENTIAL_PATHS = _loadSensitivePathScope("credential").map(({ path:
|
|
1922
|
+
CREDENTIAL_PATHS = _loadSensitivePathScope("credential").map(({ path: path8, riskLevel, desc, dirDelOnly }) => ({ path: path8, riskLevel, desc, credential: true, dirDelOnly }));
|
|
1923
1923
|
ROOT_SENSITIVE_PATHS_WINDOWS = _loadSensitivePathScope("root", "windows");
|
|
1924
1924
|
HOME_SENSITIVE_PATHS_WINDOWS = _loadSensitivePathScope("home", "windows");
|
|
1925
|
-
CREDENTIAL_PATHS_WINDOWS = _loadSensitivePathScope("credential", "windows").map(({ path:
|
|
1925
|
+
CREDENTIAL_PATHS_WINDOWS = _loadSensitivePathScope("credential", "windows").map(({ path: path8, riskLevel, desc, dirDelOnly }) => ({ path: path8, riskLevel, desc, credential: true, dirDelOnly }));
|
|
1926
1926
|
ROOT_SENSITIVE_PATHS_MACOS = _loadSensitivePathScope("root", "macos");
|
|
1927
1927
|
HOME_SENSITIVE_PATHS_MACOS = _loadSensitivePathScope("home", "macos");
|
|
1928
|
-
CREDENTIAL_PATHS_MACOS = _loadSensitivePathScope("credential", "macos").map(({ path:
|
|
1928
|
+
CREDENTIAL_PATHS_MACOS = _loadSensitivePathScope("credential", "macos").map(({ path: path8, riskLevel, desc, dirDelOnly }) => ({ path: path8, riskLevel, desc, credential: true, dirDelOnly }));
|
|
1929
1929
|
ROOT_SENSITIVE_PATHS_HARMONY = _loadSensitivePathScope("root", "harmony");
|
|
1930
1930
|
HOME_SENSITIVE_PATHS_HARMONY = _loadSensitivePathScope("home", "harmony");
|
|
1931
|
-
CREDENTIAL_PATHS_HARMONY = _loadSensitivePathScope("credential", "harmony").map(({ path:
|
|
1931
|
+
CREDENTIAL_PATHS_HARMONY = _loadSensitivePathScope("credential", "harmony").map(({ path: path8, riskLevel, desc, dirDelOnly }) => ({ path: path8, riskLevel, desc, credential: true, dirDelOnly }));
|
|
1932
1932
|
_scopeIndex = null;
|
|
1933
1933
|
NON_WRITE_TOOLS = /* @__PURE__ */ new Set([
|
|
1934
1934
|
"ask_user_question",
|
|
@@ -2404,8 +2404,8 @@ function filterEnabledRules(rules, categoryEnabled = true) {
|
|
|
2404
2404
|
function _filterRulesByOs(rules, osType) {
|
|
2405
2405
|
const accepted = acceptedOsValues(osType);
|
|
2406
2406
|
return rules.filter((r) => {
|
|
2407
|
-
const
|
|
2408
|
-
return
|
|
2407
|
+
const os5 = String(r.os || "linux").toLowerCase();
|
|
2408
|
+
return os5 === "all" || accepted.includes(os5);
|
|
2409
2409
|
});
|
|
2410
2410
|
}
|
|
2411
2411
|
function _userCustomRules(runtime, layers, requiredKey) {
|
|
@@ -2607,7 +2607,7 @@ function _l2SensitivePathsToRules() {
|
|
|
2607
2607
|
const { root, home, credential } = getSensitivePathsForOsBuiltin(osName);
|
|
2608
2608
|
const all = [...root, ...home, ...credential];
|
|
2609
2609
|
for (const sp of all) {
|
|
2610
|
-
const
|
|
2610
|
+
const os5 = String(sp.os || "linux").toLowerCase();
|
|
2611
2611
|
const denyMode = sp.denyMode || _deriveDenyMode({
|
|
2612
2612
|
deny_mode: sp.deny_mode,
|
|
2613
2613
|
credential: sp.credential,
|
|
@@ -2617,7 +2617,7 @@ function _l2SensitivePathsToRules() {
|
|
|
2617
2617
|
// id = path_<平台>_<slug>_<hash8>:平台段消除跨平台同名(.ssh/.aws 各一条),
|
|
2618
2618
|
// hash 段消除同平台 slug 撞车(macOS 的 /Library/LaunchAgents 与
|
|
2619
2619
|
// Library/LaunchAgents)—— Console 按 id 操作,撞 id 会误改别的规则。
|
|
2620
|
-
id: `path_${
|
|
2620
|
+
id: `path_${os5}_${_slugify(sp.path)}_${_fnv1a32(sp.path)}`,
|
|
2621
2621
|
path: sp.path,
|
|
2622
2622
|
risk_level: sp.riskLevel,
|
|
2623
2623
|
desc: sp.desc,
|
|
@@ -2626,7 +2626,7 @@ function _l2SensitivePathsToRules() {
|
|
|
2626
2626
|
skip_l3_on_disabled: true,
|
|
2627
2627
|
enabled: true,
|
|
2628
2628
|
builtin: true,
|
|
2629
|
-
os:
|
|
2629
|
+
os: os5
|
|
2630
2630
|
};
|
|
2631
2631
|
_syncDenyModeFields(rule);
|
|
2632
2632
|
if (sp.dirDelOnly) rule.dir_del_only = true;
|
|
@@ -3164,8 +3164,8 @@ function _filterDefaultsByOs(rules, osType) {
|
|
|
3164
3164
|
const accepted = acceptedOsValues(osType);
|
|
3165
3165
|
return rules.filter((r) => {
|
|
3166
3166
|
if (!r.os) return true;
|
|
3167
|
-
const
|
|
3168
|
-
return
|
|
3167
|
+
const os5 = String(r.os).toLowerCase();
|
|
3168
|
+
return os5 === "all" || accepted.includes(os5);
|
|
3169
3169
|
});
|
|
3170
3170
|
}
|
|
3171
3171
|
function _hasRulesForOs(rules, osType) {
|
|
@@ -4207,24 +4207,24 @@ function extractWritePayload(actionType, actionDetailRaw) {
|
|
|
4207
4207
|
const detail = actionDetailRaw || "";
|
|
4208
4208
|
const m = detail.match(WRITE_PREFIX_RE);
|
|
4209
4209
|
if (m) {
|
|
4210
|
-
const
|
|
4210
|
+
const path8 = m[1];
|
|
4211
4211
|
let content = m[2] || "";
|
|
4212
|
-
if (!
|
|
4212
|
+
if (!path8 || path8 === "?" || path8 === "-" || !content.trim()) return null;
|
|
4213
4213
|
if ((actionType || "").toLowerCase().includes("editfile")) {
|
|
4214
4214
|
const nm = content.match(EDIT_NEW_RE);
|
|
4215
4215
|
if (nm) content = nm[1];
|
|
4216
4216
|
}
|
|
4217
|
-
return { path:
|
|
4217
|
+
return { path: path8, content };
|
|
4218
4218
|
}
|
|
4219
4219
|
const stripped = detail.trim();
|
|
4220
4220
|
if (stripped.startsWith("{")) {
|
|
4221
4221
|
try {
|
|
4222
4222
|
const obj = JSON.parse(stripped);
|
|
4223
4223
|
if (obj && typeof obj === "object") {
|
|
4224
|
-
const
|
|
4224
|
+
const path8 = obj.path || obj.file_path || obj.filePath;
|
|
4225
4225
|
const content = obj.content || obj.newString || obj.new_string;
|
|
4226
|
-
if (typeof
|
|
4227
|
-
return { path:
|
|
4226
|
+
if (typeof path8 === "string" && path8 !== "" && path8 !== "?" && path8 !== "-" && typeof content === "string" && content.trim()) {
|
|
4227
|
+
return { path: path8, content };
|
|
4228
4228
|
}
|
|
4229
4229
|
}
|
|
4230
4230
|
} catch {
|
|
@@ -4237,8 +4237,8 @@ function handlesWrittenContent(actionType, actionDetailRaw) {
|
|
|
4237
4237
|
if (extractWritePayload(actionType, actionDetailRaw) !== null) return true;
|
|
4238
4238
|
return /^(?:写入文件|编辑文件|应用补丁)\s*[::]/.test(actionDetailRaw || "");
|
|
4239
4239
|
}
|
|
4240
|
-
function detectLanguage(
|
|
4241
|
-
const ext =
|
|
4240
|
+
function detectLanguage(path8, content) {
|
|
4241
|
+
const ext = path8.slice(path8.lastIndexOf(".") >= 0 ? path8.lastIndexOf(".") : path8.length).toLowerCase();
|
|
4242
4242
|
if (SHELL_EXTS.has(ext)) return "shell";
|
|
4243
4243
|
if (PY_EXTS.has(ext)) return "python";
|
|
4244
4244
|
if (DATA_EXTS.has(ext)) return "data";
|
|
@@ -4396,8 +4396,8 @@ function extractDangerousSnippets(actionType, actionDetailRaw, literalStripper)
|
|
|
4396
4396
|
if (!handlesWrittenContent(actionType, actionDetailRaw)) return null;
|
|
4397
4397
|
const payload = extractWritePayload(actionType, actionDetailRaw);
|
|
4398
4398
|
if (!payload) return [];
|
|
4399
|
-
const { path:
|
|
4400
|
-
const language = detectLanguage(
|
|
4399
|
+
const { path: path8, content: rawContent } = payload;
|
|
4400
|
+
const language = detectLanguage(path8, rawContent);
|
|
4401
4401
|
if (language === "data") return [];
|
|
4402
4402
|
let content = rawContent.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\t/g, " ").slice(0, MAX_CONTENT);
|
|
4403
4403
|
const started = Date.now();
|
|
@@ -4891,16 +4891,16 @@ function checkSensitivePath(command, cwd, agentExt, osType) {
|
|
|
4891
4891
|
if (String(osType || "").toLowerCase() === "windows") {
|
|
4892
4892
|
pathScanTexts.push(...pathScanTexts.map((t) => t.replace(/\//g, "\\")));
|
|
4893
4893
|
}
|
|
4894
|
-
const pathMatches = (text,
|
|
4895
|
-
const parts =
|
|
4894
|
+
const pathMatches = (text, path8) => {
|
|
4895
|
+
const parts = path8.split(/(\(\?!.*?\))/);
|
|
4896
4896
|
const escaped = parts.map((part) => {
|
|
4897
4897
|
if (part.startsWith("(?!")) return part;
|
|
4898
4898
|
return part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4899
4899
|
}).join("");
|
|
4900
|
-
const re =
|
|
4900
|
+
const re = path8.startsWith(".") || path8.startsWith("/") ? new RegExp(`(?:^|[\\s/\\\\'"])${escaped}\\b`, "i") : new RegExp(`\\b${escaped}\\b`, "i");
|
|
4901
4901
|
return re.test(text);
|
|
4902
4902
|
};
|
|
4903
|
-
const pathMatchesAny = (
|
|
4903
|
+
const pathMatchesAny = (path8) => pathScanTexts.some((t) => pathMatches(t, path8));
|
|
4904
4904
|
for (const sp of rootPaths) {
|
|
4905
4905
|
if (pathMatchesAny(sp.path.toLowerCase())) {
|
|
4906
4906
|
if (keygenGenerate) continue;
|
|
@@ -5043,8 +5043,8 @@ function checkSensitivePath(command, cwd, agentExt, osType) {
|
|
|
5043
5043
|
}
|
|
5044
5044
|
return null;
|
|
5045
5045
|
}
|
|
5046
|
-
function isHomeValue(
|
|
5047
|
-
let p =
|
|
5046
|
+
function isHomeValue(path8) {
|
|
5047
|
+
let p = path8.trim().toLowerCase();
|
|
5048
5048
|
if (p.startsWith("$(") && p.endsWith(")")) {
|
|
5049
5049
|
const inner = p.slice(2, -1).trim();
|
|
5050
5050
|
return HOME_TARGET_RE.test(" " + inner);
|
|
@@ -5100,15 +5100,15 @@ function checkHomeDeletion(actionType, actionDetail) {
|
|
|
5100
5100
|
}
|
|
5101
5101
|
const assigned = {};
|
|
5102
5102
|
for (const m of actionDetail.matchAll(HOME_ASSIGN_RE)) assigned[m[1]] = m[2];
|
|
5103
|
-
for (const [varName,
|
|
5104
|
-
if (!isHomeValue(
|
|
5103
|
+
for (const [varName, path8] of Object.entries(assigned)) {
|
|
5104
|
+
if (!isHomeValue(path8)) continue;
|
|
5105
5105
|
const varRefRe = new RegExp(`(?:${escapeRegExp(varName)}|\\$\\{${escapeRegExp(varName)}\\})`);
|
|
5106
5106
|
for (const seg of segs) {
|
|
5107
5107
|
if (!isDeleteCommand(seg)) continue;
|
|
5108
5108
|
if (varRefRe.test(seg)) {
|
|
5109
5109
|
return {
|
|
5110
5110
|
allowed: false,
|
|
5111
|
-
reason: `\u68C0\u6D4B\u5230\u901A\u8FC7\u53D8\u91CF ${varName}\uFF08=${
|
|
5111
|
+
reason: `\u68C0\u6D4B\u5230\u901A\u8FC7\u53D8\u91CF ${varName}\uFF08=${path8}\uFF0C\u4E3B\u76EE\u5F55\uFF09\u6267\u884C\u5220\u9664`,
|
|
5112
5112
|
riskLevel: "high",
|
|
5113
5113
|
riskType: "script_execution",
|
|
5114
5114
|
confidence: 90,
|
|
@@ -6299,15 +6299,15 @@ function parseShellString(s) {
|
|
|
6299
6299
|
let m;
|
|
6300
6300
|
while ((m = CHILD_CALL_RE.exec(s)) !== null) {
|
|
6301
6301
|
const interp = m[1];
|
|
6302
|
-
const
|
|
6302
|
+
const path8 = m[2].trim();
|
|
6303
6303
|
let rest = m[3].trim();
|
|
6304
|
-
if (
|
|
6304
|
+
if (path8.startsWith("-") || path8.startsWith("$") || path8.includes("/dev/")) continue;
|
|
6305
6305
|
rest = rest.split(/[;|&<>]/)[0].trim();
|
|
6306
6306
|
const args = [];
|
|
6307
6307
|
for (const tm of rest.matchAll(/(["'])(.*?)\1|(\S+)/g)) {
|
|
6308
6308
|
args.push(tm[1] ? tm[2] : tm[3]);
|
|
6309
6309
|
}
|
|
6310
|
-
return { path:
|
|
6310
|
+
return { path: path8, args, interpreter: interp };
|
|
6311
6311
|
}
|
|
6312
6312
|
return null;
|
|
6313
6313
|
}
|
|
@@ -6353,9 +6353,9 @@ function extractCallsFromTree(tree, reachableLines) {
|
|
|
6353
6353
|
}
|
|
6354
6354
|
if (allStr && elts.length >= 2) {
|
|
6355
6355
|
const interp = elts[0];
|
|
6356
|
-
const
|
|
6357
|
-
if (!
|
|
6358
|
-
add({ path:
|
|
6356
|
+
const path8 = elts[1];
|
|
6357
|
+
if (!path8.startsWith("-") && !path8.startsWith("$") && !path8.includes("/dev/")) {
|
|
6358
|
+
add({ path: path8, args: elts.slice(2), interpreter: interp });
|
|
6359
6359
|
return true;
|
|
6360
6360
|
}
|
|
6361
6361
|
}
|
|
@@ -6395,15 +6395,15 @@ function extractCallsRegex(content) {
|
|
|
6395
6395
|
let m;
|
|
6396
6396
|
while ((m = CHILD_CALL_RE.exec(content)) !== null) {
|
|
6397
6397
|
const interp = m[1];
|
|
6398
|
-
const
|
|
6398
|
+
const path8 = m[2].trim();
|
|
6399
6399
|
let rest = m[3].trim();
|
|
6400
|
-
if (
|
|
6400
|
+
if (path8.startsWith("-") || path8.startsWith("$") || path8.includes("/dev/")) continue;
|
|
6401
6401
|
rest = rest.split(/[;|&<>]/)[0].trim();
|
|
6402
6402
|
const args = [];
|
|
6403
6403
|
for (const tm of rest.matchAll(/(["'])(.*?)\1|(\S+)/g)) {
|
|
6404
6404
|
args.push(tm[1] ? tm[2] : tm[3]);
|
|
6405
6405
|
}
|
|
6406
|
-
calls.push({ path:
|
|
6406
|
+
calls.push({ path: path8, args, interpreter: interp });
|
|
6407
6407
|
}
|
|
6408
6408
|
return calls;
|
|
6409
6409
|
}
|
|
@@ -7144,15 +7144,15 @@ function extractCallsFromContent(content) {
|
|
|
7144
7144
|
CHILD_CALL_RE2.lastIndex = 0;
|
|
7145
7145
|
while ((m = CHILD_CALL_RE2.exec(content)) !== null) {
|
|
7146
7146
|
const interp = m[1];
|
|
7147
|
-
const
|
|
7147
|
+
const path8 = m[2].trim();
|
|
7148
7148
|
let rest = m[3].trim();
|
|
7149
|
-
if (
|
|
7149
|
+
if (path8.startsWith("-") || path8.startsWith("$") || path8.includes("/dev/")) continue;
|
|
7150
7150
|
rest = rest.split(/[;|&<>]/)[0].trim();
|
|
7151
7151
|
const args = [];
|
|
7152
7152
|
for (const tm of rest.matchAll(/(["'])(.*?)\1|(\S+)/g)) {
|
|
7153
7153
|
args.push(tm[1] ? tm[2] : tm[3]);
|
|
7154
7154
|
}
|
|
7155
|
-
calls.push({ path:
|
|
7155
|
+
calls.push({ path: path8, args, interpreter: interp });
|
|
7156
7156
|
}
|
|
7157
7157
|
return calls;
|
|
7158
7158
|
}
|
|
@@ -8477,6 +8477,28 @@ function formatHints(previous) {
|
|
|
8477
8477
|
}
|
|
8478
8478
|
return hints.length > 0 ? hints.join("\n\n") : "\u7279\u5F81\u5339\u914D\u68C0\u6D4B\u548C\u903B\u8F91\u89C4\u5219\u68C0\u6D4B\u5747\u672A\u53D1\u73B0\u98CE\u9669\u3002";
|
|
8479
8479
|
}
|
|
8480
|
+
function maskedBaseUrl(raw) {
|
|
8481
|
+
try {
|
|
8482
|
+
const u = new URL(raw || "https://api.openai.com/v1");
|
|
8483
|
+
return `${u.protocol}//${u.hostname}${u.port ? ":" + u.port : ""}${u.pathname || ""}`;
|
|
8484
|
+
} catch {
|
|
8485
|
+
return "(unparseable)";
|
|
8486
|
+
}
|
|
8487
|
+
}
|
|
8488
|
+
function llmErrorDetail(err, config, attempt, maxRetries, elapsedMs, promptChars, timeoutMs) {
|
|
8489
|
+
const chain = [];
|
|
8490
|
+
let cur = err;
|
|
8491
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8492
|
+
while (cur && !seen.has(cur) && chain.length < 4) {
|
|
8493
|
+
seen.add(cur);
|
|
8494
|
+
chain.push(`${cur?.constructor?.name || typeof cur}(${String(cur?.message ?? cur).replace(/\n/g, " ").slice(0, 300)})`);
|
|
8495
|
+
cur = cur?.cause ?? cur?.context;
|
|
8496
|
+
}
|
|
8497
|
+
const proxy = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY"].filter((n) => process.env[n]).join(",") || "none";
|
|
8498
|
+
const cause = err?.cause ?? err?.context;
|
|
8499
|
+
const errno = cause?.errno ?? cause?.code ?? err?.errno ?? err?.code;
|
|
8500
|
+
return `attempt=${attempt}/${maxRetries + 1} elapsed=${(elapsedMs / 1e3).toFixed(1)}s timeout=${(timeoutMs / 1e3).toFixed(1)}s model=${config.model} provider=${config.provider || "auto"} base_url=${maskedBaseUrl(config.baseUrl)} proxy=${proxy} prompt_chars=${promptChars} errno=${errno ?? "-"} chain=${chain.join(" <- ")}`;
|
|
8501
|
+
}
|
|
8480
8502
|
async function analyzeWithLLM(prompt, config) {
|
|
8481
8503
|
console.log(`[AgentMoss] LLM analyzing with model: ${config.model}, url: ${config.baseUrl}`);
|
|
8482
8504
|
const _llmStart = performance.now();
|
|
@@ -8524,6 +8546,7 @@ async function analyzeWithLLM(prompt, config) {
|
|
|
8524
8546
|
if (abortController.signal.aborted) {
|
|
8525
8547
|
break;
|
|
8526
8548
|
}
|
|
8549
|
+
const attemptStart = performance.now();
|
|
8527
8550
|
try {
|
|
8528
8551
|
const response = await client.chat.completions.create({
|
|
8529
8552
|
model: config.model,
|
|
@@ -8639,7 +8662,16 @@ async function analyzeWithLLM(prompt, config) {
|
|
|
8639
8662
|
const errObj = err;
|
|
8640
8663
|
const status = errObj?.status ?? errObj?.statusCode;
|
|
8641
8664
|
const body = errObj?.error ?? errObj?.body;
|
|
8642
|
-
const
|
|
8665
|
+
const baseDetail = status !== void 0 || body !== void 0 ? `${err.message} status=${status} body=${String(JSON.stringify(body)).slice(0, 300)}` : err.message;
|
|
8666
|
+
const detail = `${baseDetail} | ${llmErrorDetail(
|
|
8667
|
+
err,
|
|
8668
|
+
config,
|
|
8669
|
+
attempt + 1,
|
|
8670
|
+
maxRetries,
|
|
8671
|
+
performance.now() - attemptStart,
|
|
8672
|
+
prompt.length,
|
|
8673
|
+
(config.timeout || timeoutCfg.prompt1Timeout) * 1e3
|
|
8674
|
+
)}`;
|
|
8643
8675
|
if (attempt < maxRetries) {
|
|
8644
8676
|
console.error(`[AgentMoss] LLM call failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying in ${retryCfg.retryInterval}s: ${detail}`);
|
|
8645
8677
|
await new Promise((resolve11) => setTimeout(resolve11, retryCfg.retryInterval * 1e3));
|
|
@@ -8692,8 +8724,8 @@ function uuid() {
|
|
|
8692
8724
|
var BrainRuleStore = class {
|
|
8693
8725
|
path;
|
|
8694
8726
|
data;
|
|
8695
|
-
constructor(
|
|
8696
|
-
this.path =
|
|
8727
|
+
constructor(path8) {
|
|
8728
|
+
this.path = path8 || getRulesPath();
|
|
8697
8729
|
this.data = this.load();
|
|
8698
8730
|
}
|
|
8699
8731
|
load() {
|
|
@@ -9139,10 +9171,10 @@ ${reason.slice(0, 500)}
|
|
|
9139
9171
|
const pathRe = new RegExp(pathPrefix + pathBody + pathSuffix, "g");
|
|
9140
9172
|
let mm;
|
|
9141
9173
|
while ((mm = pathRe.exec(src)) !== null) {
|
|
9142
|
-
const
|
|
9143
|
-
if (
|
|
9144
|
-
if (["/dev/null", "/dev/zero", "/dev/random", "/dev/urandom"].includes(
|
|
9145
|
-
const gen = this.generalizePath(
|
|
9174
|
+
const path8 = mm[1];
|
|
9175
|
+
if (path8.split("/").length < 3) continue;
|
|
9176
|
+
if (["/dev/null", "/dev/zero", "/dev/random", "/dev/urandom"].includes(path8)) continue;
|
|
9177
|
+
const gen = this.generalizePath(path8);
|
|
9146
9178
|
if (seen.has(gen)) continue;
|
|
9147
9179
|
seen.add(gen);
|
|
9148
9180
|
patterns.push({ pattern: gen, layer: 1, scope: "openat", ruleType: "deny_path" });
|
|
@@ -9161,8 +9193,8 @@ ${reason.slice(0, 500)}
|
|
|
9161
9193
|
}
|
|
9162
9194
|
return false;
|
|
9163
9195
|
}
|
|
9164
|
-
generalizePath(
|
|
9165
|
-
const p =
|
|
9196
|
+
generalizePath(path8) {
|
|
9197
|
+
const p = path8.toLowerCase();
|
|
9166
9198
|
if (/\/etc\/(shadow|passwd|sudoers|security|ssh)/.test(p)) {
|
|
9167
9199
|
return "(?:^|[^a-z0-9_-])etc/(?:shadow|passwd|sudoers|security/|ssh/)";
|
|
9168
9200
|
}
|
|
@@ -9971,12 +10003,12 @@ function allNodesFlat(mg) {
|
|
|
9971
10003
|
// src/engine/formal-engine/properties.ts
|
|
9972
10004
|
init_esm_shims();
|
|
9973
10005
|
init_rules_loader();
|
|
9974
|
-
function graphFromPath(nodes,
|
|
10006
|
+
function graphFromPath(nodes, path8, edgeType = "next", propertyMeta, roles, witnessLast = true, propertyExpression) {
|
|
9975
10007
|
const byKey = /* @__PURE__ */ new Map();
|
|
9976
10008
|
for (const n of nodes) byKey.set(`${n.sessionId}#${n.seq}`, n);
|
|
9977
10009
|
const gNodes = [];
|
|
9978
10010
|
const gEdges = [];
|
|
9979
|
-
for (const item of
|
|
10011
|
+
for (const item of path8) {
|
|
9980
10012
|
const n = byKey.get(`${item.sessionId}#${item.seq}`);
|
|
9981
10013
|
gNodes.push({
|
|
9982
10014
|
session_id: item.sessionId,
|
|
@@ -10045,22 +10077,22 @@ function checkCrossSessionChain(graph) {
|
|
|
10045
10077
|
if (witness !== void 0) {
|
|
10046
10078
|
if (nodes[witness].stage !== stages[stages.length - 1]) continue;
|
|
10047
10079
|
let matched = 0;
|
|
10048
|
-
const
|
|
10080
|
+
const path8 = [];
|
|
10049
10081
|
for (let k = 0; k < witness; k++) {
|
|
10050
10082
|
const n = nodes[k];
|
|
10051
10083
|
if (matched < stages.length - 1 && n.stage === stages[matched]) {
|
|
10052
10084
|
matched += 1;
|
|
10053
|
-
|
|
10085
|
+
path8.push({ sessionId: n.sessionId, seq: n.seq, detail: n.actionDetail.slice(0, 60) });
|
|
10054
10086
|
}
|
|
10055
10087
|
}
|
|
10056
10088
|
if (matched < stages.length - 1) continue;
|
|
10057
|
-
|
|
10089
|
+
path8.push({ sessionId: nodes[witness].sessionId, seq: nodes[witness].seq, detail: nodes[witness].actionDetail.slice(0, 60) });
|
|
10058
10090
|
violations.push({
|
|
10059
10091
|
propertyId: "cross-" + chain.id,
|
|
10060
10092
|
reason: chain.reason,
|
|
10061
10093
|
riskLevel: chain.riskLevel,
|
|
10062
|
-
path:
|
|
10063
|
-
graph: graphFromPath(nodes,
|
|
10094
|
+
path: path8,
|
|
10095
|
+
graph: graphFromPath(nodes, path8, "next", {
|
|
10064
10096
|
property_id: "cross-" + chain.id,
|
|
10065
10097
|
property_short: "P1",
|
|
10066
10098
|
property_name: "\u8DE8\u4F1A\u8BDD\u7EC4\u5408\u94FE"
|
|
@@ -10070,11 +10102,11 @@ function checkCrossSessionChain(graph) {
|
|
|
10070
10102
|
} else {
|
|
10071
10103
|
let matched = 0;
|
|
10072
10104
|
let stageIdx = 0;
|
|
10073
|
-
const
|
|
10105
|
+
const path8 = [];
|
|
10074
10106
|
for (const n of nodes) {
|
|
10075
10107
|
if (stageIdx < stages.length && n.stage === stages[stageIdx]) {
|
|
10076
10108
|
matched += 1;
|
|
10077
|
-
|
|
10109
|
+
path8.push({ sessionId: n.sessionId, seq: n.seq, detail: n.actionDetail.slice(0, 60) });
|
|
10078
10110
|
stageIdx += 1;
|
|
10079
10111
|
if (matched >= stages.length) break;
|
|
10080
10112
|
}
|
|
@@ -10084,8 +10116,8 @@ function checkCrossSessionChain(graph) {
|
|
|
10084
10116
|
propertyId: "cross-" + chain.id,
|
|
10085
10117
|
reason: chain.reason,
|
|
10086
10118
|
riskLevel: chain.riskLevel,
|
|
10087
|
-
path:
|
|
10088
|
-
graph: graphFromPath(nodes,
|
|
10119
|
+
path: path8,
|
|
10120
|
+
graph: graphFromPath(nodes, path8, "next", {
|
|
10089
10121
|
property_id: "cross-" + chain.id,
|
|
10090
10122
|
property_short: "P1",
|
|
10091
10123
|
property_name: "\u8DE8\u4F1A\u8BDD\u7EC4\u5408\u94FE"
|
|
@@ -10314,7 +10346,7 @@ function checkNeverExfilAfterPrivesc(graph) {
|
|
|
10314
10346
|
if (candidates.length > 0) {
|
|
10315
10347
|
const pre = nodes[candidates[candidates.length - 1]];
|
|
10316
10348
|
const post = nodes[firstEv];
|
|
10317
|
-
const
|
|
10349
|
+
const path8 = [
|
|
10318
10350
|
{ sessionId: pre.sessionId, seq: pre.seq, detail: pre.actionDetail.slice(0, 60) },
|
|
10319
10351
|
{ sessionId: post.sessionId, seq: post.seq, detail: post.actionDetail.slice(0, 60) }
|
|
10320
10352
|
];
|
|
@@ -10322,8 +10354,8 @@ function checkNeverExfilAfterPrivesc(graph) {
|
|
|
10322
10354
|
propertyId: "no-exfil-after-privesc",
|
|
10323
10355
|
reason: "\u63D0\u6743\u540E\u51FA\u73B0\u5916\u4F20\uFF1A\u63D0\u6743(\u524D) \u2192 \u5916\u4F20(\u540E)\uFF0C\u8FDD\u53CD \u25A1(PRIVESC\u2192\u25C7EXFIL) \u7A97\u53E3\u7EA6\u675F",
|
|
10324
10356
|
riskLevel: "critical",
|
|
10325
|
-
path:
|
|
10326
|
-
graph: graphFromPath(nodes,
|
|
10357
|
+
path: path8,
|
|
10358
|
+
graph: graphFromPath(nodes, path8, "next", {
|
|
10327
10359
|
property_id: "no-exfil-after-privesc",
|
|
10328
10360
|
property_short: "P4",
|
|
10329
10361
|
property_name: "\u63D0\u6743\u540E\u7981\u6B62\u5916\u4F20"
|
|
@@ -10340,7 +10372,7 @@ function checkNeverExfilAfterPrivesc(graph) {
|
|
|
10340
10372
|
for (let j = i + 1; j < nodes.length; j++) {
|
|
10341
10373
|
if (!isExfilNode(nodes[j])) continue;
|
|
10342
10374
|
if (privescInWindow(nodes, [i], j, windowSec).length === 0) continue;
|
|
10343
|
-
const
|
|
10375
|
+
const path8 = [
|
|
10344
10376
|
{ sessionId: nodes[i].sessionId, seq: nodes[i].seq, detail: nodes[i].actionDetail.slice(0, 60) },
|
|
10345
10377
|
{ sessionId: nodes[j].sessionId, seq: nodes[j].seq, detail: nodes[j].actionDetail.slice(0, 60) }
|
|
10346
10378
|
];
|
|
@@ -10348,8 +10380,8 @@ function checkNeverExfilAfterPrivesc(graph) {
|
|
|
10348
10380
|
propertyId: "no-exfil-after-privesc",
|
|
10349
10381
|
reason: "\u63D0\u6743\u540E\u51FA\u73B0\u5916\u4F20\uFF1A\u63D0\u6743(\u524D) \u2192 \u5916\u4F20(\u540E)\uFF0C\u8FDD\u53CD \u25A1(PRIVESC\u2192\u25C7EXFIL) \u7A97\u53E3\u7EA6\u675F",
|
|
10350
10382
|
riskLevel: "critical",
|
|
10351
|
-
path:
|
|
10352
|
-
graph: graphFromPath(nodes,
|
|
10383
|
+
path: path8,
|
|
10384
|
+
graph: graphFromPath(nodes, path8, "next", {
|
|
10353
10385
|
property_id: "no-exfil-after-privesc",
|
|
10354
10386
|
property_short: "P4",
|
|
10355
10387
|
property_name: "\u63D0\u6743\u540E\u7981\u6B62\u5916\u4F20"
|
|
@@ -10381,7 +10413,7 @@ function checkNeverExfilAfterCred(graph) {
|
|
|
10381
10413
|
}
|
|
10382
10414
|
if (pre) {
|
|
10383
10415
|
const post = nodes[firstEv];
|
|
10384
|
-
const
|
|
10416
|
+
const path8 = [
|
|
10385
10417
|
{ sessionId: pre.sessionId, seq: pre.seq, detail: pre.actionDetail.slice(0, 60) },
|
|
10386
10418
|
{ sessionId: post.sessionId, seq: post.seq, detail: post.actionDetail.slice(0, 60) }
|
|
10387
10419
|
];
|
|
@@ -10389,8 +10421,8 @@ function checkNeverExfilAfterCred(graph) {
|
|
|
10389
10421
|
propertyId: "no-exfil-after-credential",
|
|
10390
10422
|
reason: "\u8BFB\u53D6\u51ED\u636E\u540E\u51FA\u73B0\u5916\u4F20\uFF0C\u8FDD\u53CD \u25A1(CRED\u2192\xAC\u25C7EXFIL)",
|
|
10391
10423
|
riskLevel: "critical",
|
|
10392
|
-
path:
|
|
10393
|
-
graph: graphFromPath(nodes,
|
|
10424
|
+
path: path8,
|
|
10425
|
+
graph: graphFromPath(nodes, path8, "data", {
|
|
10394
10426
|
property_id: "no-exfil-after-credential",
|
|
10395
10427
|
property_short: "P5",
|
|
10396
10428
|
property_name: "\u8BFB\u53D6\u51ED\u636E\u540E\u7981\u6B62\u5916\u4F20"
|
|
@@ -10406,7 +10438,7 @@ function checkNeverExfilAfterCred(graph) {
|
|
|
10406
10438
|
if (!isCredNode(nodes[i])) continue;
|
|
10407
10439
|
for (let j = i + 1; j < nodes.length; j++) {
|
|
10408
10440
|
if (isExfilNode(nodes[j])) {
|
|
10409
|
-
const
|
|
10441
|
+
const path8 = [
|
|
10410
10442
|
{ sessionId: nodes[i].sessionId, seq: nodes[i].seq, detail: nodes[i].actionDetail.slice(0, 60) },
|
|
10411
10443
|
{ sessionId: nodes[j].sessionId, seq: nodes[j].seq, detail: nodes[j].actionDetail.slice(0, 60) }
|
|
10412
10444
|
];
|
|
@@ -10414,8 +10446,8 @@ function checkNeverExfilAfterCred(graph) {
|
|
|
10414
10446
|
propertyId: "no-exfil-after-credential",
|
|
10415
10447
|
reason: "\u8BFB\u53D6\u51ED\u636E\u540E\u51FA\u73B0\u5916\u4F20\uFF0C\u8FDD\u53CD \u25A1(CRED\u2192\xAC\u25C7EXFIL)",
|
|
10416
10448
|
riskLevel: "critical",
|
|
10417
|
-
path:
|
|
10418
|
-
graph: graphFromPath(nodes,
|
|
10449
|
+
path: path8,
|
|
10450
|
+
graph: graphFromPath(nodes, path8, "data", {
|
|
10419
10451
|
property_id: "no-exfil-after-credential",
|
|
10420
10452
|
property_short: "P5",
|
|
10421
10453
|
property_name: "\u8BFB\u53D6\u51ED\u636E\u540E\u7981\u6B62\u5916\u4F20"
|
|
@@ -10579,13 +10611,13 @@ function checkSensitiveDataAggregation(graph) {
|
|
|
10579
10611
|
if (!isExfilNode(n)) continue;
|
|
10580
10612
|
const srcs = sourcesFor(i);
|
|
10581
10613
|
if (srcs.size >= 2) {
|
|
10582
|
-
const
|
|
10614
|
+
const path8 = [{ sessionId: n.sessionId, seq: n.seq, detail: n.actionDetail.slice(0, 60) }];
|
|
10583
10615
|
violations.push({
|
|
10584
10616
|
propertyId: "sensitive-data-aggregation",
|
|
10585
10617
|
reason: `\u654F\u611F\u6570\u636E\u805A\u5408\u5916\u4F20\uFF1Aegress \u805A\u5408 ${srcs.size} \u4E2A\u4E8B\u4EF6\u6E90\u6570\u636E\uFF08Rule 12\uFF09`,
|
|
10586
10618
|
riskLevel: "critical",
|
|
10587
|
-
path:
|
|
10588
|
-
graph: graphFromPath(nodes,
|
|
10619
|
+
path: path8,
|
|
10620
|
+
graph: graphFromPath(nodes, path8, "next", {
|
|
10589
10621
|
property_id: "sensitive-data-aggregation",
|
|
10590
10622
|
property_short: "P8",
|
|
10591
10623
|
property_name: "\u654F\u611F\u6570\u636E\u805A\u5408\u5916\u4F20"
|
|
@@ -10672,12 +10704,16 @@ var FormalEngine = class {
|
|
|
10672
10704
|
// src/engine/formal-engine/stateful.ts
|
|
10673
10705
|
init_esm_shims();
|
|
10674
10706
|
init_rules_loader();
|
|
10675
|
-
|
|
10676
|
-
// src/engine/formal-engine/chain_state.ts
|
|
10677
|
-
init_esm_shims();
|
|
10678
10707
|
import * as fs5 from "fs";
|
|
10679
10708
|
import * as os3 from "os";
|
|
10680
10709
|
import * as path6 from "path";
|
|
10710
|
+
import { gzipSync } from "zlib";
|
|
10711
|
+
|
|
10712
|
+
// src/engine/formal-engine/chain_state.ts
|
|
10713
|
+
init_esm_shims();
|
|
10714
|
+
import * as fs6 from "fs";
|
|
10715
|
+
import * as os4 from "os";
|
|
10716
|
+
import * as path7 from "path";
|
|
10681
10717
|
import { createHash as createHash2 } from "crypto";
|
|
10682
10718
|
|
|
10683
10719
|
// src/engine/coordinator.ts
|