@causyne/agent 1.20.121 → 1.20.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +81 -26
- package/src/acp/agentCatalog.ts +73 -29
- package/src/acp/client.js +210 -53
- package/src/acp/client.ts +202 -52
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +37 -8
- package/src/acp/protocol.ts +30 -8
- package/src/acp/server.js +123 -25
- package/src/acp/server.ts +124 -24
- package/src/agent/errorClassifier.js +6 -2
- package/src/agent/errorClassifier.ts +6 -2
- package/src/agentLoop.js +11 -5
- package/src/agentLoop.ts +11 -5
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +48 -15
- package/src/approvalPolicy.ts +46 -15
- package/src/autoUpdate.js +5 -2
- package/src/autoUpdate.ts +5 -2
- package/src/browser/causyneBrowser.js +3 -2
- package/src/browser/causyneBrowser.ts +3 -2
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/config.js +287 -250
- package/src/config.ts +342 -0
- package/src/configVault.js +84 -17
- package/src/configVault.ts +77 -17
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +10 -3
- package/src/continuum/sanitizer.ts +9 -3
- package/src/continuum/ui/continuumPickerView.js +3 -2
- package/src/continuum/ui/continuumPickerView.ts +3 -2
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +7 -5
- package/src/creative/liveBridge.ts +7 -5
- package/src/creative/studioScripts.js +16 -5
- package/src/creative/studioScripts.ts +14 -5
- package/src/decisionPolicy.js +16 -4
- package/src/decisionPolicy.ts +14 -4
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/headlessCli.js +2 -1
- package/src/headlessCli.ts +2 -1
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +3 -0
- package/src/hooks.ts +3 -0
- package/src/implementationPlan.js +21 -11
- package/src/implementationPlan.ts +21 -11
- package/src/infra/atomicWriter.js +4 -1
- package/src/infra/atomicWriter.ts +4 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/observer/evidence.js +10 -4
- package/src/observer/evidence.ts +10 -4
- package/src/osKeychain.js +62 -8
- package/src/osKeychain.ts +50 -8
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +2 -2
- package/src/planCache.ts +2 -2
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +1 -1
- package/src/providers/acp.ts +1 -1
- package/src/providers/anthropic.js +327 -401
- package/src/providers/anthropic.ts +386 -0
- package/src/providers/antigravity.js +10 -4
- package/src/providers/antigravity.ts +10 -4
- package/src/providers/base.js +221 -319
- package/src/providers/base.ts +340 -0
- package/src/providers/byokHttp.js +58 -15
- package/src/providers/byokHttp.ts +59 -16
- package/src/providers/byokStream.js +142 -51
- package/src/providers/byokStream.ts +146 -42
- package/src/providers/dashscope-byok.js +97 -89
- package/src/providers/dashscope-byok.ts +114 -0
- package/src/providers/deepseek.js +73 -72
- package/src/providers/deepseek.ts +99 -0
- package/src/providers/factory.js +35 -28
- package/src/providers/factory.ts +40 -0
- package/src/providers/gemini.js +227 -278
- package/src/providers/gemini.ts +261 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +70 -72
- package/src/providers/moonshot.ts +93 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +114 -106
- package/src/providers/ollama.ts +135 -0
- package/src/providers/openai-compatible.js +113 -96
- package/src/providers/openai-compatible.ts +139 -0
- package/src/providers/openai.js +22 -15
- package/src/providers/openai.ts +30 -0
- package/src/providers/openrouter.js +136 -74
- package/src/providers/openrouter.ts +133 -72
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +96 -87
- package/src/providers/qwen-byok.ts +113 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +78 -11
- package/src/providers/wireNormalizer.ts +68 -12
- package/src/providers/xai.js +73 -72
- package/src/providers/xai.ts +97 -0
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/sandbox.js +489 -554
- package/src/sandbox.ts +552 -0
- package/src/sandboxPolicy.js +95 -16
- package/src/sandboxPolicy.ts +97 -16
- package/src/sessionJournal.js +8 -3
- package/src/sessionJournal.ts +9 -3
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/smartToolsUse.js +28 -4
- package/src/smartToolsUse.ts +29 -7
- package/src/stallGuard.js +45 -22
- package/src/stallGuard.ts +46 -22
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +43 -28
- package/src/tokenTracker.ts +44 -30
- package/src/toolPacks.js +3 -1
- package/src/toolPacks.ts +3 -1
- package/src/tools/archive.js +245 -35
- package/src/tools/archive.ts +244 -35
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/fsEdit.js +101 -30
- package/src/tools/fsEdit.ts +105 -32
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsRead.js +119 -13
- package/src/tools/fsRead.ts +124 -13
- package/src/tools/fsWrite.js +17 -5
- package/src/tools/fsWrite.ts +17 -7
- package/src/tools/generateMediaViaApi.js +82 -19
- package/src/tools/generateMediaViaApi.ts +80 -19
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +100 -30
- package/src/tools/multiEdit.ts +104 -32
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +54 -14
- package/src/tools/osSandbox.ts +48 -14
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/sysRun.js +69 -29
- package/src/tools/sysRun.ts +66 -24
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolScanner.js +13 -10
- package/src/tools/toolScanner.ts +13 -10
- package/src/tools/toolSelfRepair.js +94 -28
- package/src/tools/toolSelfRepair.ts +96 -28
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +105 -10
- package/src/tools/webFetch.ts +105 -11
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/consoleGuard.js +12 -4
- package/src/tui/consoleGuard.ts +9 -4
- package/src/tui/messageInteraction.js +2 -3
- package/src/tui/messageInteraction.ts +2 -3
- package/src/tui/modelPicker.js +1 -0
- package/src/tui/modelPicker.ts +1 -0
- package/src/tui/overlay.js +3 -1
- package/src/tui/overlay.ts +3 -1
- package/src/tui/sessionPicker.js +3 -2
- package/src/tui/sessionPicker.ts +3 -2
- package/src/tui/sessionPickerView.js +7 -1
- package/src/tui/sessionPickerView.ts +6 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/config.d.ts +0 -2
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/sandbox.d.ts +0 -1
package/src/sandbox.js
CHANGED
|
@@ -1,580 +1,515 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import { isIP } from 'node:net';
|
|
4
5
|
import { loadConfig } from './config.js';
|
|
5
6
|
import { isDevEmulator } from './devMode.js';
|
|
6
7
|
import { validateBrowserActSandbox } from './browser/causyneBrowser.js';
|
|
7
|
-
import { isPhysicalPathAllowed } from './agent/workspaceBoundary.js';
|
|
8
|
-
import {
|
|
9
|
-
isBlockedWorkspaceRoot,
|
|
10
|
-
isExtendedCredentialPath,
|
|
11
|
-
isSensitiveWriteTarget,
|
|
12
|
-
analyzeShellCommand,
|
|
13
|
-
isExtremeRemovalSegment,
|
|
14
|
-
isFetchAndExecPipeline
|
|
15
|
-
} from './sandboxPolicy.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Read-only invocations of tools whose NAME is dangerous but whose subcommand
|
|
19
|
-
* is not. Keyed by the leading word; the pattern must match the whole segment.
|
|
20
|
-
*
|
|
21
|
-
* WHY THIS EXISTS. `brew` is in DANGEROUS_PREFIXES because `brew install` runs
|
|
22
|
-
* arbitrary install scripts. The prefix rule cannot tell that from
|
|
23
|
-
* `brew --version`, so asking Blender's version escalated a chain to
|
|
24
|
-
* DANGEROUS and put a red approval modal in front of the user. That is not a
|
|
25
|
-
* cosmetic problem: a gate that cries wolf on `--version` is a gate people
|
|
26
|
-
* learn to approve without reading, and then it is not a gate at all.
|
|
27
|
-
*
|
|
28
|
-
* THE RULE FOR ADDING TO THIS TABLE: the subcommand must be incapable of
|
|
29
|
-
* changing anything — no install, no remove, no start/stop, no write. When in
|
|
30
|
-
* doubt, leave it out; a false alarm is cheap and a missed one is not.
|
|
31
|
-
*
|
|
32
|
-
* `sudo` and `su` are deliberately absent and must stay absent: `sudo brew
|
|
33
|
-
* --version` is a privilege escalation whatever follows it.
|
|
34
|
-
*/
|
|
8
|
+
import { isPhysicalPathAllowed, physicalPath } from './agent/workspaceBoundary.js';
|
|
9
|
+
import { isBlockedWorkspaceRoot, isExtendedCredentialPath, isSensitiveWriteTarget, analyzeShellCommand, isExtremeRemovalSegment, isFetchAndExecPipeline } from './sandboxPolicy.js';
|
|
35
10
|
const READ_ONLY_INVOCATIONS = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
kill: /^kill\s+(-l|-0)\b/,
|
|
47
|
-
git: /^git\s+reset\s+(--\s*)?$/
|
|
11
|
+
brew: /^brew\s+(--version|-v|list|info|search|config|outdated|deps|home|--prefix|--cellar)\b/,
|
|
12
|
+
apt: /^apt\s+(--version|list|show|search|policy)\b/,
|
|
13
|
+
'apt-get': /^apt-get\s+(--version|-v)\b/,
|
|
14
|
+
yum: /^yum\s+(--version|list|info|search)\b/,
|
|
15
|
+
dnf: /^dnf\s+(--version|list|info|search)\b/,
|
|
16
|
+
systemctl: /^systemctl\s+(status|show|cat|is-active|is-enabled|is-failed|list-units|list-unit-files|--version)\b/,
|
|
17
|
+
service: /^service\s+[\w.@-]+\s+status\b/,
|
|
18
|
+
crontab: /^crontab\s+-l\b/,
|
|
19
|
+
kill: /^kill\s+(-l|-0)\b/,
|
|
20
|
+
git: /^git\s+reset\s+(--\s*)?$/
|
|
48
21
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
22
|
+
function hasLinearPipeToShell(lowerText) {
|
|
23
|
+
const pipeIdx = lowerText.indexOf('|');
|
|
24
|
+
if (pipeIdx === -1)
|
|
25
|
+
return false;
|
|
26
|
+
const beforePipe = lowerText.slice(0, pipeIdx);
|
|
27
|
+
if (!/\b(?:curl|wget)\s/.test(beforePipe))
|
|
28
|
+
return false;
|
|
29
|
+
const afterPipe = lowerText.slice(pipeIdx + 1).trimStart();
|
|
30
|
+
return /^(?:sh|bash)(?:\s|$)/.test(afterPipe);
|
|
31
|
+
}
|
|
32
|
+
function hasRansomwareKeyword(lowerText) {
|
|
33
|
+
if (lowerText.includes('ransomware'))
|
|
34
|
+
return true;
|
|
35
|
+
const encIdx = lowerText.indexOf('encrypt');
|
|
36
|
+
return encIdx !== -1 && lowerText.indexOf('ransom', encIdx + 7) !== -1;
|
|
37
|
+
}
|
|
38
|
+
function hasDangerousFindAction(unit) {
|
|
39
|
+
const findMatch = /\bfind\b/.exec(unit);
|
|
40
|
+
if (!findMatch)
|
|
41
|
+
return false;
|
|
42
|
+
const tail = unit.slice(findMatch.index + findMatch[0].length);
|
|
43
|
+
return /\s-(?:exec|execdir|delete)\b/.test(tail);
|
|
44
|
+
}
|
|
56
45
|
function isReadOnlyInvocation(segment) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
const text = String(segment || '').trim();
|
|
47
|
+
const leadingWord = text.split(/\s+/)[0] || '';
|
|
48
|
+
if (!leadingWord || !Object.hasOwn(READ_ONLY_INVOCATIONS, leadingWord))
|
|
49
|
+
return false;
|
|
50
|
+
const pattern = READ_ONLY_INVOCATIONS[leadingWord];
|
|
51
|
+
return Boolean(pattern && pattern.test(text));
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Does this command line hand a string to something that will execute it?
|
|
65
|
-
*
|
|
66
|
-
* Quote masking is right for `echo "rm -rf /"` and wrong for
|
|
67
|
-
* `bash -c "rm -rf ~"` — in the second the quoted text IS the payload. When an
|
|
68
|
-
* interpreter is present we judge the raw line instead, so masking can never
|
|
69
|
-
* downgrade a real destructive command.
|
|
70
|
-
*/
|
|
71
|
-
// Includes the scripting interpreters (perl/ruby/awk/python/node/…) so that a
|
|
72
|
-
// `python3 -c "import os; os.system('rm -rf ~')"` or `perl -e '...'` is judged on
|
|
73
|
-
// the RAW line: the destructive payload lives in the quoted argument, and without
|
|
74
|
-
// these an attacker could hide any command inside an interpreter string and have
|
|
75
|
-
// it read as merely 'moderate' (auto-run in Mode C). Matching only forces the raw
|
|
76
|
-
// line to be scanned — a benign `python3 script.py` still classifies as before.
|
|
77
53
|
const INTERPRETER_INVOCATION = /(^|\s)(sh|bash|zsh|ksh|dash|fish|eval|xargs|ssh|sudo|env|nohup|command|perl|ruby|awk|gawk|mawk|tclsh|php|lua|luajit|python3|python|pwsh|powershell|node|deno|bun|rscript)(\s|$)/i;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Files where a single appended line changes what the machine does next, or who
|
|
81
|
-
* can log into it. Written out plainly and unencoded — this is Vision section 10
|
|
82
|
-
* defence code and must stay auditable.
|
|
83
|
-
*/
|
|
84
|
-
/**
|
|
85
|
-
* Credential stores and key material.
|
|
86
|
-
*
|
|
87
|
-
* A user may deliberately select a workspace that contains credential material.
|
|
88
|
-
* These paths are not silently trusted just because they sit below that root:
|
|
89
|
-
* touching one is classified 'extreme' for supervised-mode approval and audit.
|
|
90
|
-
* Mode C still applies the selected-workspace boundary and hard safety blocks.
|
|
91
|
-
*/
|
|
92
54
|
const CREDENTIAL_PATHS = [
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/(^|\/)\.pgpass$/i,
|
|
108
|
-
/(^|\/)\.my\.cnf$/i
|
|
55
|
+
/(^|\/)\.ssh(\/|$)/,
|
|
56
|
+
/(^|\/)\.aws(\/|$)/,
|
|
57
|
+
/(^|\/)\.gnupg(\/|$)/,
|
|
58
|
+
/(^|\/)\.docker\/config\.json$/,
|
|
59
|
+
/(^|\/)\.netrc$/,
|
|
60
|
+
/(^|\/)\.npmrc$/,
|
|
61
|
+
/(^|\/)\.kube(\/|$)/,
|
|
62
|
+
/(^|\/)Library\/Keychains(\/|$)/i,
|
|
63
|
+
/(^|\/)\.causyne(\/|$)/,
|
|
64
|
+
/(^|\/)\.envrc$/i,
|
|
65
|
+
/(^|\/)\.git-credentials$/i,
|
|
66
|
+
/(^|\/)\.pypirc$/i,
|
|
67
|
+
/(^|\/)\.pgpass$/i,
|
|
68
|
+
/(^|\/)\.my\.cnf$/i
|
|
109
69
|
];
|
|
110
|
-
|
|
111
70
|
export function isCredentialPath(targetPath) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
71
|
+
if (typeof targetPath !== 'string' || targetPath.length === 0 || targetPath.includes('\0'))
|
|
72
|
+
return false;
|
|
73
|
+
const normalized = targetPath.replace(/\\/g, '/');
|
|
74
|
+
return CREDENTIAL_PATHS.some(pattern => pattern.test(normalized)) || isExtendedCredentialPath(normalized);
|
|
115
75
|
}
|
|
116
|
-
|
|
117
76
|
const SENSITIVE_WRITE_TARGETS = [
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// Scheduled execution.
|
|
131
|
-
/(^|\/)(crontab|cron\.d)(\/|$)/,
|
|
132
|
-
/\/etc\//,
|
|
133
|
-
// Causyne's own state: config.json holds the encrypted API key and .vault_key
|
|
134
|
-
// is the key that decrypts it.
|
|
135
|
-
/(^|\/)\.causyne\//
|
|
77
|
+
/(^|\/)\.(bashrc|bash_profile|bash_login|profile|zshrc|zprofile|zshenv|zlogin)$/,
|
|
78
|
+
/(^|\/)\.config\/fish\/config\.fish$/,
|
|
79
|
+
/(^|\/)\.ssh\//,
|
|
80
|
+
/(^|\/)\.aws\//,
|
|
81
|
+
/(^|\/)\.kube\//,
|
|
82
|
+
/(^|\/)\.gnupg\//,
|
|
83
|
+
/(^|\/)\.docker\/config\.json$/,
|
|
84
|
+
/(^|\/)\.(npmrc|netrc|git-credentials|pypirc|envrc)$/,
|
|
85
|
+
/(^|\/)\.git\/(hooks(\/|$)|config$)/,
|
|
86
|
+
/(^|\/)(crontab|cron\.d)(\/|$)/,
|
|
87
|
+
/\/etc\//,
|
|
88
|
+
/(^|\/)\.causyne\//
|
|
136
89
|
];
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Extract the file targets a command line redirects into.
|
|
140
|
-
*
|
|
141
|
-
* Context-aware per rule ZM-09: `2>&1` and `>&2` are descriptor duplications,
|
|
142
|
-
* not files, and must not be reported as write targets — a guard that fires on
|
|
143
|
-
* those would be disabled within a day.
|
|
144
|
-
*/
|
|
145
90
|
function redirectionTargets(maskedCommand) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
91
|
+
const targets = [];
|
|
92
|
+
const pattern = /(?:^|[^0-9&>])>>?\s*([^\s;|&<>]+)/g;
|
|
93
|
+
let match;
|
|
94
|
+
while ((match = pattern.exec(maskedCommand)) !== null) {
|
|
95
|
+
const target = match[1];
|
|
96
|
+
if (!target || target.startsWith('&'))
|
|
97
|
+
continue;
|
|
98
|
+
targets.push(target);
|
|
99
|
+
}
|
|
100
|
+
return targets;
|
|
155
101
|
}
|
|
156
|
-
|
|
157
102
|
function redirectsIntoSensitiveTarget(maskedCommand) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
103
|
+
for (const target of redirectionTargets(maskedCommand)) {
|
|
104
|
+
if (isSensitiveWriteTarget(target))
|
|
105
|
+
return true;
|
|
106
|
+
const normalizedTarget = target.replace(/^~/, '/home/user');
|
|
107
|
+
for (const pattern of SENSITIVE_WRITE_TARGETS) {
|
|
108
|
+
if (pattern.test(normalizedTarget))
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
162
111
|
}
|
|
163
|
-
|
|
164
|
-
return false;
|
|
112
|
+
return false;
|
|
165
113
|
}
|
|
166
|
-
|
|
167
114
|
export class Sandbox {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// V5: Add a single workspace path (enforces the same blocked-root checks as updateWorkspacePaths)
|
|
209
|
-
addWorkspacePath(newPath) {
|
|
210
|
-
if (typeof newPath !== 'string' || isBlockedWorkspaceRoot(newPath)) {
|
|
211
|
-
return this.workspacePaths;
|
|
212
|
-
}
|
|
213
|
-
const resolved = path.resolve(newPath);
|
|
214
|
-
if (!this.workspacePaths.includes(resolved)) {
|
|
215
|
-
this.workspacePaths.push(resolved);
|
|
216
|
-
}
|
|
217
|
-
return this.workspacePaths;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
validate(toolName, args) {
|
|
221
|
-
// 1. Tool availability check
|
|
222
|
-
const canonicalToolName = String(toolName || '').replace(/\./g, '_');
|
|
223
|
-
if (this.deniedTools.has(canonicalToolName)) {
|
|
224
|
-
return { allowed: false, reason: `Tool ${toolName} is denied by local policy`, risk: 'forbidden' };
|
|
225
|
-
}
|
|
226
|
-
if (!this.allowedTools.includes('*') && !this.allowedTools.includes(toolName)) {
|
|
227
|
-
return { allowed: false, reason: `Tool ${toolName} not allowed on current tier`, risk: 'forbidden' };
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// 2. Path scoping.
|
|
231
|
-
// Tools do not agree on what to call their path argument: MultiEdit uses
|
|
232
|
-
// file_path, the Blender/Godot automators use filepath and directory, the
|
|
233
|
-
// media tools use outputPath. Checking only `path` let all of those write
|
|
234
|
-
// outside the workspace unchallenged.
|
|
235
|
-
// fs_read_skill parameters (`skill_id`, `file_path`) identify bundled or
|
|
236
|
-
// user-skill resources bounded strictly by skillResourceSafety.ts rather
|
|
237
|
-
// than workspace filesystem paths.
|
|
238
|
-
const safeArgs = args && typeof args === 'object' ? args : {};
|
|
239
|
-
const pathsToCheck = [];
|
|
240
|
-
if (canonicalToolName !== 'fs_read_skill') {
|
|
241
|
-
const PATH_ARGUMENTS = [
|
|
242
|
-
'path', 'searchPath', 'cwd', 'source', 'destination',
|
|
243
|
-
'file_path', 'filePath', 'filepath', 'directory',
|
|
244
|
-
'targetFile', 'outputFile', 'outputPath'
|
|
245
|
-
];
|
|
246
|
-
for (const field of PATH_ARGUMENTS) {
|
|
247
|
-
if (safeArgs[field]) pathsToCheck.push(safeArgs[field]);
|
|
248
|
-
}
|
|
249
|
-
if (Array.isArray(safeArgs.target_directories)) {
|
|
250
|
-
for (const dir of safeArgs.target_directories) {
|
|
251
|
-
if (typeof dir === 'string' && dir.trim()) pathsToCheck.push(dir);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
for (const p of pathsToCheck) {
|
|
257
|
-
if (typeof p === 'string' && !this.isPathAllowed(p)) {
|
|
258
|
-
return { allowed: false, reason: `Path outside allowed workspace: ${p}`, risk: 'dangerous' };
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// L4: classify credential material in an explicitly selected workspace as
|
|
263
|
-
// extreme. The approval policy interprets that signal by autonomy mode.
|
|
264
|
-
for (const p of pathsToCheck) {
|
|
265
|
-
if (typeof p === 'string' && isCredentialPath(p)) {
|
|
266
|
-
return { allowed: true, risk: 'extreme', reason: `Touches credential material: ${p}` };
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 3. Command classification (for terminal tools).
|
|
271
|
-
// terminal_persistent_shell runs arbitrary commands exactly like sysRun does
|
|
272
|
-
// and must go through the same classifier — it previously bypassed it.
|
|
273
|
-
if (toolName === 'sysRun' || toolName === 'sysRunBg' || toolName === 'terminal_persistent_shell') {
|
|
274
|
-
const command = args.command || args.input;
|
|
275
|
-
if (command) {
|
|
276
|
-
const risk = this.classifyCommandRisk(command);
|
|
277
|
-
if (risk === 'forbidden') {
|
|
278
|
-
return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
|
|
279
|
-
}
|
|
280
|
-
return { allowed: true, risk };
|
|
281
|
-
}
|
|
282
|
-
return { allowed: true, risk: 'moderate' };
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (toolName === 'gitOp') {
|
|
286
|
-
const command = String(args.command || '');
|
|
287
|
-
const risk = this.classifyCommandRisk(`git ${command}`);
|
|
288
|
-
if (risk === 'forbidden') {
|
|
289
|
-
return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
|
|
290
|
-
}
|
|
291
|
-
return { allowed: true, risk: /\bbranch\s+-D\b/.test(command) ? 'dangerous' : risk };
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// 4. SSRF protection (for web fetch)
|
|
295
|
-
if (toolName === 'web_fetch' && args.url) {
|
|
296
|
-
if (this.isInternalUrl(args.url)) {
|
|
297
|
-
return { allowed: false, reason: 'Cannot access internal/local network URLs (SSRF Protection)', risk: 'forbidden' };
|
|
298
|
-
}
|
|
299
|
-
if (args.outputFile) {
|
|
300
|
-
return { allowed: true, risk: 'extreme', reason: 'Downloads network content to disk' };
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (toolName === 'browser_act') {
|
|
305
|
-
return validateBrowserActSandbox(
|
|
306
|
-
args,
|
|
307
|
-
this.workspacePaths[0],
|
|
308
|
-
url => this.isInternalUrl(url, { allowLoopback: true }),
|
|
309
|
-
targetPath => this.isPathAllowed(targetPath)
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (toolName === 'creative_apps') {
|
|
314
|
-
const isReadOnly =
|
|
315
|
-
args.action === 'status' ||
|
|
316
|
-
args.action === 'verify_bridge' ||
|
|
317
|
-
(args.action === 'live_bridge' && args.liveOperation === 'inspect_active');
|
|
318
|
-
return { allowed: true, risk: isReadOnly ? 'safe' : 'dangerous' };
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (toolName === 'native_engine') {
|
|
322
|
-
if (args.action === 'install') {
|
|
323
|
-
return { allowed: true, risk: 'extreme', reason: 'Downloads and installs a native engine binary' };
|
|
324
|
-
}
|
|
325
|
-
const readOnly = ['status', 'catalog', 'describe', 'inspect', 'probe'];
|
|
326
|
-
return { allowed: true, risk: readOnly.includes(args.action) ? 'safe' : 'dangerous' };
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (toolName === 'game_asset_fetch' && args.action === 'download_asset') {
|
|
330
|
-
if (!args.url || this.isInternalUrl(args.url)) {
|
|
331
|
-
return { allowed: false, reason: 'Cannot download from an internal or invalid URL', risk: 'forbidden' };
|
|
332
|
-
}
|
|
333
|
-
return { allowed: true, risk: 'extreme', reason: 'Downloads a third-party asset to disk' };
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// Keep downloads classified as extreme for supervised modes and auditing.
|
|
337
|
-
// Mode C approval is decided separately by the TypeScript approval policy.
|
|
338
|
-
if (toolName === 'manage_local_dependencies') {
|
|
339
|
-
// grant_capability installs third-party packages into the user's home
|
|
340
|
-
// directory. Classification remains visible even when Mode C proceeds.
|
|
341
|
-
const heavyActions = ['pipInst', 'grant_capability', 'grant_mcp_server'];
|
|
342
|
-
if (heavyActions.includes(args.action)) {
|
|
343
|
-
return { allowed: true, risk: 'extreme' };
|
|
344
|
-
}
|
|
345
|
-
return { allowed: true, risk: 'moderate' };
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// Plugins are code extensions. Keep their risk classification visible to
|
|
349
|
-
// supervised modes and audit logs; Mode C still uses workspace and hard
|
|
350
|
-
// policy checks before execution.
|
|
351
|
-
if (toolName === 'plugin_manager') {
|
|
352
|
-
return ['create', 'enable'].includes(args.action)
|
|
353
|
-
? { allowed: true, risk: 'extreme', reason: 'Creates or trusts executable plugin code' }
|
|
354
|
-
: { allowed: true, risk: 'safe' };
|
|
355
|
-
}
|
|
356
|
-
if (toolName.startsWith('plugin__')) {
|
|
357
|
-
return { allowed: true, risk: 'extreme', reason: 'Executes an enabled local plugin' };
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Tools that overwrite or delete are inherently dangerous.
|
|
361
|
-
// These comparisons used the dotted schema names (`fs.delete`, `proc.term`,
|
|
362
|
-
// `fs.write`) while validate() is always called with the canonical wire name
|
|
363
|
-
// (`fs_delete`, ...), so none of them ever matched: the Human-in-the-Loop
|
|
364
|
-
// approval gate for destructive operations had never once fired.
|
|
365
|
-
if (toolName === 'fs_delete') {
|
|
366
|
-
// If wiping an entire directory tree, flag as extreme
|
|
367
|
-
if (args.path && !args.path.includes('.')) {
|
|
368
|
-
return { allowed: true, risk: 'extreme' };
|
|
369
|
-
}
|
|
370
|
-
return { allowed: true, risk: 'dangerous' };
|
|
371
|
-
}
|
|
372
|
-
if (toolName === 'proc_term') {
|
|
373
|
-
return { allowed: true, risk: 'dangerous' };
|
|
374
|
-
}
|
|
375
|
-
// Desktop interaction reaches applications the user is signed into.
|
|
376
|
-
// Keep the extreme risk signal for supervised modes and auditing; Mode C
|
|
377
|
-
// follows the owner's autonomous approval policy after hard checks.
|
|
378
|
-
if (toolName === 'desktop_act' || toolName === 'computer_use') {
|
|
379
|
-
return { allowed: true, risk: 'extreme' };
|
|
380
|
-
}
|
|
381
|
-
if (toolName === 'ui_forge' || toolName === 'document_forge') {
|
|
382
|
-
return { allowed: true, risk: 'safe' };
|
|
383
|
-
}
|
|
384
|
-
if (toolName === 'fs_write' || toolName === 'fs_move' || toolName === 'fs_edit' || toolName === 'MultiEdit') {
|
|
385
|
-
return { allowed: true, risk: 'moderate' };
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return { allowed: true, risk: 'safe' };
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
isPathAllowed(targetPath) {
|
|
392
|
-
if (typeof targetPath !== 'string' || targetPath.length === 0) return false;
|
|
393
|
-
const expand = (value) => {
|
|
394
|
-
if (value === '~') return os.homedir();
|
|
395
|
-
if (value.startsWith('~/') || value.startsWith('~\\')) {
|
|
396
|
-
return path.join(os.homedir(), value.slice(2));
|
|
397
|
-
}
|
|
398
|
-
return value;
|
|
399
|
-
};
|
|
400
|
-
const workspaces = Array.isArray(this.workspacePaths)
|
|
401
|
-
? this.workspacePaths.filter(item => typeof item === 'string').map(expand) : [];
|
|
402
|
-
const baseDir = workspaces[0] ? path.resolve(workspaces[0]) : process.cwd();
|
|
403
|
-
const expandedTarget = expand(targetPath);
|
|
404
|
-
const resolvedTarget = path.isAbsolute(expandedTarget)
|
|
405
|
-
? expandedTarget
|
|
406
|
-
: path.resolve(baseDir, expandedTarget);
|
|
407
|
-
// Resolve physical ancestors, including symlinks, before checking the scope.
|
|
408
|
-
// Missing destination files remain possible inside a valid workspace.
|
|
409
|
-
return isPhysicalPathAllowed(resolvedTarget, workspaces, this.grantAllAccess === true);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
isInternalUrl(urlString, { allowLoopback = false } = {}) {
|
|
413
|
-
try {
|
|
414
|
-
const url = new URL(urlString);
|
|
415
|
-
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) return true;
|
|
416
|
-
const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
417
|
-
const isLoopback = host === 'localhost' || host.endsWith('.localhost') || /^127\.\d+\.\d+\.\d+$/.test(host) || host === '::1';
|
|
418
|
-
if (allowLoopback && isLoopback) return false;
|
|
419
|
-
if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.local') || host.endsWith('.internal')) return true;
|
|
420
|
-
|
|
421
|
-
// Block localhost, private IPs, cloud metadata
|
|
422
|
-
const blockedRegex = /^(localhost|0\.\d+\.\d+\.\d+|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+|169\.254\.\d+\.\d+|192\.168\.\d+\.\d+|192\.0\.(0|2)\.\d+|192\.88\.99\.\d+|198\.(18|19)\.\d+\.\d+|198\.51\.100\.\d+|203\.0\.113\.\d+|(22[4-9]|23\d|24\d|25[0-5])\.\d+\.\d+\.\d+)$/;
|
|
423
|
-
if (blockedRegex.test(host)) return true;
|
|
424
|
-
if (host === 'metadata.google.internal') return true;
|
|
425
|
-
if (isIP(host) === 6) {
|
|
426
|
-
const normalized = host.split('%')[0];
|
|
427
|
-
if (normalized === '::' || normalized === '::1' || /^(fc|fd|fe8|fe9|fea|feb|fec|fed|fee|fef|ff|2001:db8:|64:ff9b:)/.test(normalized)) return true;
|
|
428
|
-
if (normalized.startsWith('::ffff:')) return true;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
return false;
|
|
432
|
-
} catch(e) {
|
|
433
|
-
return true; // If URL is unparseable, block it to be safe
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
classifyCommandRisk(command) {
|
|
438
|
-
if (!command) return 'safe';
|
|
439
|
-
const normalized = command.trim().toLowerCase();
|
|
440
|
-
|
|
441
|
-
// FORBIDDEN — absolute blocklist (Technical + Ethical Safety Net Layer 3)
|
|
442
|
-
const FORBIDDEN_PATTERNS = [
|
|
443
|
-
/:\(\)\s*\{\s*:\|:&\s*\};/,
|
|
444
|
-
/curl\s+.*\|\s*(sh|bash)/,
|
|
445
|
-
/wget\s+.*\|\s*(sh|bash)/,
|
|
446
|
-
// Process substitution — `bash <(curl …)` / `sh <(wget …)` fetch-and-run,
|
|
447
|
-
// the pipe-to-shell trick's twin that the `| sh` patterns above miss.
|
|
448
|
-
/<\(\s*(curl|wget)\b/,
|
|
449
|
-
/>\s*\/dev\/sda/,
|
|
450
|
-
// Ethical Safety Gate: Offensive security attack tools & ransomware patterns
|
|
451
|
-
/nmap\s+-s[STUVFN]/i,
|
|
452
|
-
/sqlmap/i,
|
|
453
|
-
/metasploit|msfconsole|msfvenom/i,
|
|
454
|
-
/hydra\s+/i,
|
|
455
|
-
/john\s+/i,
|
|
456
|
-
/hashcat/i,
|
|
457
|
-
/aircrack|airmon|aireplay/i,
|
|
458
|
-
/ettercap|arpspoof|bettercap/i,
|
|
459
|
-
/nikto/i,
|
|
460
|
-
/xmrig|cpuminer|minerd/i,
|
|
461
|
-
/ransomware|encrypt.*ransom/i
|
|
462
|
-
];
|
|
463
|
-
|
|
464
|
-
// FORBIDDEN is matched against the WHOLE line, never against segments:
|
|
465
|
-
// several of these patterns deliberately span shell separators (the fork
|
|
466
|
-
// bomb contains ; and |, the pipe-to-shell patterns contain |), so
|
|
467
|
-
// splitting first would stop them matching at all.
|
|
468
|
-
const analyzed = analyzeShellCommand(command);
|
|
469
|
-
for (const pattern of FORBIDDEN_PATTERNS) {
|
|
470
|
-
if (pattern.test(normalized)) return 'forbidden';
|
|
471
|
-
for (const rawUnit of analyzed.allRawUnits) {
|
|
472
|
-
if (pattern.test(rawUnit.toLowerCase())) return 'forbidden';
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
if (isFetchAndExecPipeline(analyzed.normalizedPipelines)) return 'forbidden';
|
|
476
|
-
|
|
477
|
-
// Everything below judges what the shell will actually execute.
|
|
478
|
-
const masked = analyzed.maskedTopLevel;
|
|
479
|
-
|
|
480
|
-
// L3 (local-path audit): classify the redirection / tee write target, not just the verb.
|
|
481
|
-
// Tool argument validation enforces boundaries on named arguments, but
|
|
482
|
-
// shell redirection targets appended via operators (>> or >) or `tee` require independent
|
|
483
|
-
// audit — including quoted targets, `$HOME` expansions, and command substitutions.
|
|
484
|
-
if (
|
|
485
|
-
redirectsIntoSensitiveTarget(masked) ||
|
|
486
|
-
analyzed.writeTargets.some(target => isSensitiveWriteTarget(target))
|
|
487
|
-
) {
|
|
488
|
-
return 'extreme';
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
const executesQuotedText = analyzed.allMaskedUnits.some(unit => INTERPRETER_INVOCATION.test(unit));
|
|
492
|
-
const scanUnits = executesQuotedText
|
|
493
|
-
? analyzed.allRawUnits.map(u => u.toLowerCase())
|
|
494
|
-
: analyzed.allMaskedUnits;
|
|
495
|
-
|
|
496
|
-
const EXTREME_PATTERNS = [
|
|
497
|
-
/rm\s+(-rf|-fr)\s+[\/~]/,
|
|
498
|
-
/rm\s+(-rf|-fr)\s+\*/,
|
|
499
|
-
/mkfs/,
|
|
500
|
-
/dd\s+if=/,
|
|
501
|
-
/shutdown|reboot|init\s+[06]/,
|
|
502
|
-
/passwd|useradd|userdel/,
|
|
503
|
-
/iptables|ufw\s+delete/,
|
|
504
|
-
/format\s+[a-z]:/i,
|
|
505
|
-
/diskpart/i
|
|
506
|
-
];
|
|
507
|
-
|
|
508
|
-
for (const unit of scanUnits) {
|
|
509
|
-
for (const pattern of EXTREME_PATTERNS) {
|
|
510
|
-
if (pattern.test(unit)) return 'extreme';
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
for (const seg of analyzed.normalizedSegments) {
|
|
514
|
-
if (isExtremeRemovalSegment(seg)) return 'extreme';
|
|
515
|
-
}
|
|
516
|
-
for (const seg of analyzed.unwrappedRawSegments) {
|
|
517
|
-
if (isExtremeRemovalSegment(seg)) return 'extreme';
|
|
115
|
+
config;
|
|
116
|
+
workspacePaths;
|
|
117
|
+
grantAllAccess;
|
|
118
|
+
allowedTools;
|
|
119
|
+
deniedTools;
|
|
120
|
+
constructor(options) {
|
|
121
|
+
const safeOptions = options && typeof options === 'object' ? options : {};
|
|
122
|
+
const candidateRoot = typeof safeOptions.workspaceRoot === 'string' && safeOptions.workspaceRoot.trim()
|
|
123
|
+
? safeOptions.workspaceRoot.trim()
|
|
124
|
+
: process.cwd();
|
|
125
|
+
this.config = loadConfig();
|
|
126
|
+
this.workspacePaths = isBlockedWorkspaceRoot(candidateRoot) ? [] : [path.resolve(candidateRoot)];
|
|
127
|
+
const devMode = isDevEmulator(this.config);
|
|
128
|
+
this.grantAllAccess = devMode ? true : (this.config.grantAllAccess || false);
|
|
129
|
+
const rawAllowed = devMode ? ['*'] : (Array.isArray(this.config.allowedTools) ? this.config.allowedTools : ['*']);
|
|
130
|
+
this.allowedTools = rawAllowed.map((name) => String(name).replace(/\./g, '_'));
|
|
131
|
+
this.deniedTools = new Set((devMode ? [] : (this.config.deniedTools || []))
|
|
132
|
+
.map((name) => String(name).replace(/\./g, '_')));
|
|
133
|
+
}
|
|
134
|
+
updateWorkspacePaths(newPaths) {
|
|
135
|
+
if (Array.isArray(newPaths) && newPaths.length > 0) {
|
|
136
|
+
const seen = new Set();
|
|
137
|
+
const safePaths = [];
|
|
138
|
+
for (const p of newPaths) {
|
|
139
|
+
if (typeof p !== 'string' || p.includes('\0') || !p.trim() || isBlockedWorkspaceRoot(p))
|
|
140
|
+
continue;
|
|
141
|
+
const resolved = path.resolve(p.trim());
|
|
142
|
+
if (!seen.has(resolved)) {
|
|
143
|
+
seen.add(resolved);
|
|
144
|
+
safePaths.push(resolved);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (safePaths.length > 0) {
|
|
148
|
+
this.workspacePaths = safePaths;
|
|
149
|
+
return { success: true, paths: this.workspacePaths };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { success: false, reason: 'Invalid or blocked paths provided' };
|
|
518
153
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
];
|
|
529
|
-
|
|
530
|
-
// Prefix rules are evaluated per normalized segment (including env-prefixed,
|
|
531
|
-
// wrapper-prefixed, absolute-path, and `$(...)`/backtick substituted commands).
|
|
532
|
-
// Highest risk across all segments wins.
|
|
533
|
-
for (const seg of analyzed.normalizedSegments) {
|
|
534
|
-
if (seg.isReadOnlyLookup) continue;
|
|
535
|
-
if (seg.executable === 'su') return 'dangerous';
|
|
536
|
-
for (const prefix of DANGEROUS_PREFIXES) {
|
|
537
|
-
if (seg.normalized.startsWith(prefix) && !isReadOnlyInvocation(seg.normalized)) {
|
|
538
|
-
return 'dangerous';
|
|
539
|
-
}
|
|
540
|
-
}
|
|
154
|
+
addWorkspacePath(newPath) {
|
|
155
|
+
if (typeof newPath !== 'string' || newPath.includes('\0') || !newPath.trim() || isBlockedWorkspaceRoot(newPath)) {
|
|
156
|
+
return this.workspacePaths;
|
|
157
|
+
}
|
|
158
|
+
const resolved = path.resolve(newPath.trim());
|
|
159
|
+
if (!this.workspacePaths.includes(resolved)) {
|
|
160
|
+
this.workspacePaths.push(resolved);
|
|
161
|
+
}
|
|
162
|
+
return this.workspacePaths;
|
|
541
163
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
164
|
+
validate(toolName, args) {
|
|
165
|
+
const canonicalToolName = String(toolName || '').replace(/\./g, '_');
|
|
166
|
+
if (this.deniedTools.has(canonicalToolName)) {
|
|
167
|
+
return { allowed: false, reason: `Tool ${toolName} is denied by local policy`, risk: 'forbidden' };
|
|
168
|
+
}
|
|
169
|
+
if (!this.allowedTools.includes('*') && !this.allowedTools.includes(canonicalToolName)) {
|
|
170
|
+
return { allowed: false, reason: `Tool ${toolName} not allowed on current tier`, risk: 'forbidden' };
|
|
171
|
+
}
|
|
172
|
+
const safeArgs = args && typeof args === 'object' ? args : {};
|
|
173
|
+
const pathsToCheck = [];
|
|
174
|
+
if (canonicalToolName !== 'fs_read_skill') {
|
|
175
|
+
const PATH_ARGUMENTS = [
|
|
176
|
+
'path', 'searchPath', 'cwd', 'workdir', 'dir', 'source', 'destination',
|
|
177
|
+
'file_path', 'filePath', 'filepath', 'directory', 'inputPath', 'targetPath',
|
|
178
|
+
'targetFile', 'outputFile', 'outputPath', 'outFile', 'outputDir', 'previewFile'
|
|
179
|
+
];
|
|
180
|
+
for (const field of PATH_ARGUMENTS) {
|
|
181
|
+
if (safeArgs[field])
|
|
182
|
+
pathsToCheck.push(safeArgs[field]);
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(safeArgs.target_directories)) {
|
|
185
|
+
for (const dir of safeArgs.target_directories) {
|
|
186
|
+
if (typeof dir === 'string' && dir.trim())
|
|
187
|
+
pathsToCheck.push(dir);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(safeArgs.files)) {
|
|
191
|
+
for (const entry of safeArgs.files) {
|
|
192
|
+
if (typeof entry === 'string' && entry.trim())
|
|
193
|
+
pathsToCheck.push(entry);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const p of pathsToCheck) {
|
|
198
|
+
if (typeof p === 'string' && !this.isPathAllowed(p)) {
|
|
199
|
+
return { allowed: false, reason: `Path outside allowed workspace: ${p}`, risk: 'dangerous' };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const baseWorkspace = this.workspacePaths[0] || process.cwd();
|
|
203
|
+
let credentialPathHit = null;
|
|
204
|
+
for (const p of pathsToCheck) {
|
|
205
|
+
if (typeof p !== 'string')
|
|
206
|
+
continue;
|
|
207
|
+
if (isCredentialPath(p)) {
|
|
208
|
+
credentialPathHit = p;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
const expanded = p === '~'
|
|
212
|
+
? os.homedir()
|
|
213
|
+
: (p.startsWith('~/') || p.startsWith('~\\') ? path.join(os.homedir(), p.slice(2)) : p);
|
|
214
|
+
const resolvedCandidate = path.isAbsolute(expanded) ? expanded : path.resolve(baseWorkspace, expanded);
|
|
215
|
+
const real = physicalPath(resolvedCandidate);
|
|
216
|
+
if (real && isCredentialPath(real)) {
|
|
217
|
+
credentialPathHit = p;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const withCredentialEscalation = (verdict) => {
|
|
222
|
+
if (!verdict.allowed || !credentialPathHit)
|
|
223
|
+
return verdict;
|
|
224
|
+
return {
|
|
225
|
+
allowed: true,
|
|
226
|
+
risk: 'extreme',
|
|
227
|
+
reason: verdict.reason
|
|
228
|
+
? `${verdict.reason} (touches credential material: ${credentialPathHit})`
|
|
229
|
+
: `Touches credential material: ${credentialPathHit}`
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
if (canonicalToolName === 'sysRun' || canonicalToolName === 'sysRunBg' || canonicalToolName === 'terminal_persistent_shell') {
|
|
233
|
+
const command = safeArgs.command || safeArgs.input || safeArgs.cmd;
|
|
234
|
+
if (command) {
|
|
235
|
+
const risk = this.classifyCommandRisk(command);
|
|
236
|
+
if (risk === 'forbidden') {
|
|
237
|
+
return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
|
|
238
|
+
}
|
|
239
|
+
return withCredentialEscalation({ allowed: true, risk });
|
|
240
|
+
}
|
|
241
|
+
return withCredentialEscalation({ allowed: true, risk: 'moderate' });
|
|
242
|
+
}
|
|
243
|
+
if (canonicalToolName === 'gitOp') {
|
|
244
|
+
const command = String(safeArgs.command ?? safeArgs.action ?? '');
|
|
245
|
+
const risk = this.classifyCommandRisk(`git ${command}`);
|
|
246
|
+
if (risk === 'forbidden') {
|
|
247
|
+
return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
|
|
248
|
+
}
|
|
249
|
+
const destructiveGit = /\b(?:branch\s+-D|clean\s+-[a-zA-Z]*f|reset\s+--hard|push\s+(?:--force|-f)\b)/.test(command);
|
|
250
|
+
return withCredentialEscalation({
|
|
251
|
+
allowed: true,
|
|
252
|
+
risk: risk === 'extreme' ? 'extreme' : (destructiveGit ? 'dangerous' : risk)
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (canonicalToolName === 'web_fetch' && safeArgs.url) {
|
|
256
|
+
if (this.isInternalUrl(safeArgs.url)) {
|
|
257
|
+
return { allowed: false, reason: 'Cannot access internal/local network URLs (SSRF Protection)', risk: 'forbidden' };
|
|
258
|
+
}
|
|
259
|
+
if (safeArgs.outputFile) {
|
|
260
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme', reason: 'Downloads network content to disk' });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (canonicalToolName === 'browser_act') {
|
|
264
|
+
return withCredentialEscalation(validateBrowserActSandbox(safeArgs, this.workspacePaths[0] || process.cwd(), url => this.isInternalUrl(url, { allowLoopback: true }), targetPath => this.isPathAllowed(targetPath)));
|
|
265
|
+
}
|
|
266
|
+
if (canonicalToolName === 'creative_apps') {
|
|
267
|
+
const isReadOnly = safeArgs.action === 'status' ||
|
|
268
|
+
safeArgs.action === 'verify_bridge' ||
|
|
269
|
+
(safeArgs.action === 'live_bridge' && safeArgs.liveOperation === 'inspect_active');
|
|
270
|
+
return withCredentialEscalation({ allowed: true, risk: isReadOnly ? 'safe' : 'dangerous' });
|
|
271
|
+
}
|
|
272
|
+
if (canonicalToolName === 'native_engine') {
|
|
273
|
+
if (safeArgs.action === 'install') {
|
|
274
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme', reason: 'Downloads and installs a native engine binary' });
|
|
275
|
+
}
|
|
276
|
+
const readOnly = ['status', 'catalog', 'describe', 'inspect', 'probe'];
|
|
277
|
+
return withCredentialEscalation({ allowed: true, risk: readOnly.includes(String(safeArgs.action ?? '')) ? 'safe' : 'dangerous' });
|
|
278
|
+
}
|
|
279
|
+
if (canonicalToolName === 'game_asset_fetch' && safeArgs.action === 'download_asset') {
|
|
280
|
+
if (!safeArgs.url || this.isInternalUrl(safeArgs.url)) {
|
|
281
|
+
return { allowed: false, reason: 'Cannot download from an internal or invalid URL', risk: 'forbidden' };
|
|
282
|
+
}
|
|
283
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme', reason: 'Downloads a third-party asset to disk' });
|
|
284
|
+
}
|
|
285
|
+
if (canonicalToolName === 'manage_local_dependencies') {
|
|
286
|
+
const heavyActions = ['pipInst', 'grant_capability', 'grant_mcp_server'];
|
|
287
|
+
if (heavyActions.includes(String(safeArgs.action ?? ''))) {
|
|
288
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme' });
|
|
289
|
+
}
|
|
290
|
+
return withCredentialEscalation({ allowed: true, risk: 'moderate' });
|
|
291
|
+
}
|
|
292
|
+
if (canonicalToolName === 'plugin_manager') {
|
|
293
|
+
return withCredentialEscalation(['create', 'enable'].includes(String(safeArgs.action ?? ''))
|
|
294
|
+
? { allowed: true, risk: 'extreme', reason: 'Creates or trusts executable plugin code' }
|
|
295
|
+
: { allowed: true, risk: 'safe' });
|
|
296
|
+
}
|
|
297
|
+
if (canonicalToolName.startsWith('plugin__')) {
|
|
298
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme', reason: 'Executes an enabled local plugin' });
|
|
299
|
+
}
|
|
300
|
+
if (canonicalToolName === 'fs_delete') {
|
|
301
|
+
if (typeof safeArgs.path === 'string' && safeArgs.path.trim()) {
|
|
302
|
+
const baseDir = this.workspacePaths[0] || process.cwd();
|
|
303
|
+
const candidate = path.isAbsolute(safeArgs.path)
|
|
304
|
+
? safeArgs.path
|
|
305
|
+
: path.resolve(baseDir, safeArgs.path);
|
|
306
|
+
try {
|
|
307
|
+
if (fs.lstatSync(candidate).isDirectory()) {
|
|
308
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme' });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
if (!path.basename(safeArgs.path).includes('.')) {
|
|
313
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme' });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return withCredentialEscalation({ allowed: true, risk: 'dangerous' });
|
|
318
|
+
}
|
|
319
|
+
if (canonicalToolName === 'proc_term') {
|
|
320
|
+
return withCredentialEscalation({ allowed: true, risk: 'dangerous' });
|
|
321
|
+
}
|
|
322
|
+
if (canonicalToolName === 'desktop_act' || canonicalToolName === 'computer_use') {
|
|
323
|
+
return withCredentialEscalation({ allowed: true, risk: 'extreme' });
|
|
324
|
+
}
|
|
325
|
+
if (canonicalToolName === 'ui_forge' || canonicalToolName === 'document_forge') {
|
|
326
|
+
return withCredentialEscalation({ allowed: true, risk: 'safe' });
|
|
327
|
+
}
|
|
328
|
+
if (canonicalToolName === 'fs_write' || canonicalToolName === 'fs_move' || canonicalToolName === 'fs_edit' || canonicalToolName === 'MultiEdit') {
|
|
329
|
+
return withCredentialEscalation({ allowed: true, risk: 'moderate' });
|
|
330
|
+
}
|
|
331
|
+
return withCredentialEscalation({ allowed: true, risk: 'safe' });
|
|
332
|
+
}
|
|
333
|
+
isPathAllowed(targetPath) {
|
|
334
|
+
if (typeof targetPath !== 'string' || targetPath.trim().length === 0 || targetPath.includes('\0'))
|
|
335
|
+
return false;
|
|
336
|
+
const expand = (value) => {
|
|
337
|
+
if (value === '~')
|
|
338
|
+
return os.homedir();
|
|
339
|
+
if (value.startsWith('~/') || value.startsWith('~\\')) {
|
|
340
|
+
return path.join(os.homedir(), value.slice(2));
|
|
341
|
+
}
|
|
342
|
+
return value;
|
|
343
|
+
};
|
|
344
|
+
const workspaces = Array.isArray(this.workspacePaths)
|
|
345
|
+
? this.workspacePaths.filter(item => typeof item === 'string').map(expand) : [];
|
|
346
|
+
const baseDir = workspaces[0] ? path.resolve(workspaces[0]) : process.cwd();
|
|
347
|
+
const expandedTarget = expand(targetPath);
|
|
348
|
+
const resolvedTarget = path.isAbsolute(expandedTarget)
|
|
349
|
+
? expandedTarget
|
|
350
|
+
: path.resolve(baseDir, expandedTarget);
|
|
351
|
+
return isPhysicalPathAllowed(resolvedTarget, workspaces, this.grantAllAccess === true);
|
|
352
|
+
}
|
|
353
|
+
isInternalUrl(urlString, { allowLoopback = false } = {}) {
|
|
354
|
+
if (typeof urlString !== 'string' || !urlString.trim() || /[\r\n\0]/.test(urlString)) {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
const url = new URL(urlString.trim());
|
|
359
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
|
|
360
|
+
return true;
|
|
361
|
+
const rawHost = url.hostname.toLowerCase().replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
362
|
+
const host = rawHost.split('%')[0] || '';
|
|
363
|
+
if (!host)
|
|
364
|
+
return true;
|
|
365
|
+
const ipv6OnlyZerosAndOne = host.includes(':') && /^(?:0+:){0,7}0*1$/.test(host);
|
|
366
|
+
const ipv6AllZeros = host.includes(':') && /^(?:0*:)+0*$/.test(host);
|
|
367
|
+
const isLoopback = host === 'localhost'
|
|
368
|
+
|| host.endsWith('.localhost')
|
|
369
|
+
|| /^127\.\d+\.\d+\.\d+$/.test(host)
|
|
370
|
+
|| host === '::1'
|
|
371
|
+
|| ipv6OnlyZerosAndOne;
|
|
372
|
+
if (allowLoopback && isLoopback)
|
|
373
|
+
return false;
|
|
374
|
+
if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.local') || host.endsWith('.internal'))
|
|
375
|
+
return true;
|
|
376
|
+
const blockedRegex = /^(localhost|0\.\d+\.\d+\.\d+|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+|169\.254\.\d+\.\d+|192\.168\.\d+\.\d+|192\.0\.(0|2)\.\d+|192\.88\.99\.\d+|198\.(18|19)\.\d+\.\d+|198\.51\.100\.\d+|203\.0\.113\.\d+|(22[4-9]|23\d|24\d|25[0-5])\.\d+\.\d+\.\d+)$/;
|
|
377
|
+
if (blockedRegex.test(host))
|
|
378
|
+
return true;
|
|
379
|
+
if (host === 'metadata.google.internal')
|
|
380
|
+
return true;
|
|
381
|
+
if (isIP(host) === 6) {
|
|
382
|
+
if (host === '::' || host === '::1' || ipv6AllZeros || ipv6OnlyZerosAndOne)
|
|
383
|
+
return true;
|
|
384
|
+
if (/^(fc|fd|fe8|fe9|fea|feb|fec|fed|fee|fef|ff|2001:db8:|64:ff9b:|100::)/.test(host))
|
|
385
|
+
return true;
|
|
386
|
+
if (host.startsWith('::ffff:') || host.startsWith('0:0:0:0:0:ffff:'))
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
553
394
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
395
|
+
classifyCommandRisk(command) {
|
|
396
|
+
if (!command || typeof command !== 'string')
|
|
397
|
+
return 'safe';
|
|
398
|
+
if (command.length > 200_000)
|
|
399
|
+
return 'extreme';
|
|
400
|
+
const normalized = command.trim().toLowerCase();
|
|
401
|
+
const FORBIDDEN_PATTERNS = [
|
|
402
|
+
/:\(\)\s*\{\s*:\|:&\s*\};/,
|
|
403
|
+
/<\(\s*(curl|wget)\b/,
|
|
404
|
+
/>\s*\/dev\/sda/,
|
|
405
|
+
/nmap\s+-s[STUVFN]/i,
|
|
406
|
+
/sqlmap/i,
|
|
407
|
+
/metasploit|msfconsole|msfvenom/i,
|
|
408
|
+
/hydra\s+/i,
|
|
409
|
+
/john\s+/i,
|
|
410
|
+
/hashcat/i,
|
|
411
|
+
/aircrack|airmon|aireplay/i,
|
|
412
|
+
/ettercap|arpspoof|bettercap/i,
|
|
413
|
+
/nikto/i,
|
|
414
|
+
/xmrig|cpuminer|minerd/i
|
|
415
|
+
];
|
|
416
|
+
const analyzed = analyzeShellCommand(command);
|
|
417
|
+
if (hasLinearPipeToShell(normalized) || hasRansomwareKeyword(normalized))
|
|
418
|
+
return 'forbidden';
|
|
419
|
+
for (const rawUnit of analyzed.allRawUnits) {
|
|
420
|
+
const lowerUnit = rawUnit.toLowerCase();
|
|
421
|
+
if (hasLinearPipeToShell(lowerUnit) || hasRansomwareKeyword(lowerUnit))
|
|
422
|
+
return 'forbidden';
|
|
423
|
+
}
|
|
424
|
+
for (const pattern of FORBIDDEN_PATTERNS) {
|
|
425
|
+
if (pattern.test(normalized))
|
|
426
|
+
return 'forbidden';
|
|
427
|
+
for (const rawUnit of analyzed.allRawUnits) {
|
|
428
|
+
if (pattern.test(rawUnit.toLowerCase()))
|
|
429
|
+
return 'forbidden';
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (isFetchAndExecPipeline(analyzed.normalizedPipelines))
|
|
433
|
+
return 'forbidden';
|
|
434
|
+
const masked = analyzed.maskedTopLevel;
|
|
435
|
+
if (redirectsIntoSensitiveTarget(masked) ||
|
|
436
|
+
analyzed.writeTargets.some(target => isSensitiveWriteTarget(target))) {
|
|
437
|
+
return 'extreme';
|
|
438
|
+
}
|
|
439
|
+
const executesQuotedText = analyzed.allMaskedUnits.some(unit => INTERPRETER_INVOCATION.test(unit));
|
|
440
|
+
const scanUnits = executesQuotedText
|
|
441
|
+
? analyzed.allRawUnits.map(u => u.toLowerCase())
|
|
442
|
+
: analyzed.allMaskedUnits;
|
|
443
|
+
const EXTREME_PATTERNS = [
|
|
444
|
+
/rm\s+(-rf|-fr)\s+[\/~]/,
|
|
445
|
+
/rm\s+(-rf|-fr)\s+\*/,
|
|
446
|
+
/mkfs/,
|
|
447
|
+
/dd\s+if=/,
|
|
448
|
+
/shutdown|reboot|init\s+[06]/,
|
|
449
|
+
/passwd|useradd|userdel/,
|
|
450
|
+
/iptables|ufw\s+delete/,
|
|
451
|
+
/format\s+[a-z]:/i,
|
|
452
|
+
/diskpart/i
|
|
453
|
+
];
|
|
454
|
+
for (const unit of scanUnits) {
|
|
455
|
+
for (const pattern of EXTREME_PATTERNS) {
|
|
456
|
+
if (pattern.test(unit))
|
|
457
|
+
return 'extreme';
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
for (const seg of analyzed.normalizedSegments) {
|
|
461
|
+
if (isExtremeRemovalSegment(seg))
|
|
462
|
+
return 'extreme';
|
|
463
|
+
}
|
|
464
|
+
for (const seg of analyzed.unwrappedRawSegments) {
|
|
465
|
+
if (isExtremeRemovalSegment(seg))
|
|
466
|
+
return 'extreme';
|
|
467
|
+
}
|
|
468
|
+
const DANGEROUS_PREFIXES = [
|
|
469
|
+
'rm ', 'sudo ', 'su ', 'doas ', 'pkexec ', 'chmod ', 'chown ',
|
|
470
|
+
'apt ', 'apt-get ', 'brew ', 'yum ', 'dnf ',
|
|
471
|
+
'git reset', 'git push --force', 'git push -f', 'git rebase',
|
|
472
|
+
'kill ', 'pkill ', 'killall ',
|
|
473
|
+
'ssh ', 'scp ', 'rsync ',
|
|
474
|
+
'mv ', 'crontab ', 'systemctl ', 'service '
|
|
475
|
+
];
|
|
476
|
+
for (const seg of analyzed.normalizedSegments) {
|
|
477
|
+
if (seg.isReadOnlyLookup)
|
|
478
|
+
continue;
|
|
479
|
+
if (seg.executable === 'su')
|
|
480
|
+
return 'dangerous';
|
|
481
|
+
for (const prefix of DANGEROUS_PREFIXES) {
|
|
482
|
+
if (seg.normalized.startsWith(prefix) && !isReadOnlyInvocation(seg.normalized)) {
|
|
483
|
+
return 'dangerous';
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
for (const unit of scanUnits) {
|
|
488
|
+
if (hasDangerousFindAction(unit))
|
|
489
|
+
return 'dangerous';
|
|
490
|
+
}
|
|
491
|
+
const MODERATE_PREFIXES = [
|
|
492
|
+
'npm i', 'npm run', 'npx ', 'yarn ', 'pnpm ',
|
|
493
|
+
'pip install', 'pip uninstall', 'pip3 ',
|
|
494
|
+
'python', 'python3', 'node ', 'deno ', 'bun ',
|
|
495
|
+
'perl ', 'ruby ', 'awk ', 'gawk ', 'php ', 'lua ', 'tclsh ', 'rscript ',
|
|
496
|
+
'pwsh ', 'powershell ',
|
|
497
|
+
'git add', 'git commit', 'git push', 'git pull', 'git checkout',
|
|
498
|
+
'git merge', 'git branch', 'git tag',
|
|
499
|
+
'mkdir', 'touch', 'cp ',
|
|
500
|
+
'cargo ', 'go ', 'make', 'cmake', 'gcc', 'g++',
|
|
501
|
+
'docker ', 'docker-compose ', 'podman ',
|
|
502
|
+
'code ', 'open ', 'xdg-open ',
|
|
503
|
+
'curl ', 'wget '
|
|
504
|
+
];
|
|
505
|
+
for (const seg of analyzed.normalizedSegments) {
|
|
506
|
+
if (seg.isReadOnlyLookup)
|
|
507
|
+
continue;
|
|
508
|
+
for (const prefix of MODERATE_PREFIXES) {
|
|
509
|
+
if (seg.normalized.startsWith(prefix))
|
|
510
|
+
return 'moderate';
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return 'safe';
|
|
576
514
|
}
|
|
577
|
-
|
|
578
|
-
return 'safe';
|
|
579
|
-
}
|
|
580
515
|
}
|