atabey 0.0.15 → 0.0.16
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/LICENSE +672 -21
- package/README.md +20 -11
- package/dist/framework-mcp/src/index.js +69 -10
- package/dist/framework-mcp/src/index.js.map +1 -1
- package/dist/framework-mcp/src/tools/control_plane/registry.d.ts +1 -1
- package/dist/framework-mcp/src/tools/control_plane/registry.js +52 -4
- package/dist/framework-mcp/src/tools/control_plane/registry.js.map +1 -1
- package/dist/framework-mcp/src/tools/definitions.js +1 -1
- package/dist/framework-mcp/src/tools/file_system/read_file.js +5 -0
- package/dist/framework-mcp/src/tools/file_system/read_file.js.map +1 -1
- package/dist/framework-mcp/src/tools/messaging/approve_operation.d.ts +2 -0
- package/dist/framework-mcp/src/tools/messaging/approve_operation.js +1 -1
- package/dist/framework-mcp/src/tools/messaging/approve_operation.js.map +1 -1
- package/dist/framework-mcp/src/tools/messaging/send_message.js +19 -3
- package/dist/framework-mcp/src/tools/messaging/send_message.js.map +1 -1
- package/dist/framework-mcp/src/tools/schemas.d.ts +4 -4
- package/dist/framework-mcp/src/tools/search/grep_search.js +11 -4
- package/dist/framework-mcp/src/tools/search/grep_search.js.map +1 -1
- package/dist/framework-mcp/src/tools/search/list_dir.js +3 -0
- package/dist/framework-mcp/src/tools/search/list_dir.js.map +1 -1
- package/dist/framework-mcp/src/tools/shell/run_command.js +47 -1
- package/dist/framework-mcp/src/tools/shell/run_command.js.map +1 -1
- package/dist/framework-mcp/src/utils/auth.d.ts +26 -2
- package/dist/framework-mcp/src/utils/auth.js +71 -4
- package/dist/framework-mcp/src/utils/auth.js.map +1 -1
- package/dist/framework-mcp/src/utils/compliance.js +45 -13
- package/dist/framework-mcp/src/utils/compliance.js.map +1 -1
- package/dist/framework-mcp/src/utils/discipline.d.ts +1 -0
- package/dist/framework-mcp/src/utils/discipline.js +41 -2
- package/dist/framework-mcp/src/utils/discipline.js.map +1 -1
- package/dist/framework-mcp/src/utils/human-in-loop.d.ts +35 -2
- package/dist/framework-mcp/src/utils/human-in-loop.js +113 -9
- package/dist/framework-mcp/src/utils/human-in-loop.js.map +1 -1
- package/dist/framework-mcp/src/utils/permissions.d.ts +67 -3
- package/dist/framework-mcp/src/utils/permissions.js +179 -43
- package/dist/framework-mcp/src/utils/permissions.js.map +1 -1
- package/dist/framework-mcp/src/utils/prompt-injection.d.ts +20 -0
- package/dist/framework-mcp/src/utils/prompt-injection.js +64 -0
- package/dist/framework-mcp/src/utils/prompt-injection.js.map +1 -0
- package/dist/framework-mcp/tests/tools/file_system/permissions.test.js +174 -71
- package/dist/framework-mcp/tests/tools/file_system/permissions.test.js.map +1 -1
- package/dist/framework-mcp/tests/tools/messaging/send_message.test.js +36 -30
- package/dist/framework-mcp/tests/tools/messaging/send_message.test.js.map +1 -1
- package/dist/framework-mcp/tests/utils/human-in-loop.test.js +152 -4
- package/dist/framework-mcp/tests/utils/human-in-loop.test.js.map +1 -1
- package/dist/framework-mcp/tests/utils/loop-detector.test.js +0 -2
- package/dist/framework-mcp/tests/utils/loop-detector.test.js.map +1 -1
- package/dist/framework-mcp/tests/utils/prompt-injection.test.d.ts +1 -0
- package/dist/framework-mcp/tests/utils/prompt-injection.test.js +43 -0
- package/dist/framework-mcp/tests/utils/prompt-injection.test.js.map +1 -0
- package/dist/src/cli/commands/dashboard.js +167 -2
- package/dist/src/cli/commands/dashboard.js.map +1 -1
- package/dist/src/cli/commands/init/scaffold-standards.js +1 -1
- package/dist/src/cli/commands/init/scaffold-standards.js.map +1 -1
- package/dist/src/cli/commands/log.js +8 -5
- package/dist/src/cli/commands/log.js.map +1 -1
- package/dist/src/cli/commands/orchestrate.d.ts +4 -4
- package/dist/src/cli/commands/orchestrate.js +14 -2
- package/dist/src/cli/commands/orchestrate.js.map +1 -1
- package/dist/src/cli/commands/status.js +21 -1
- package/dist/src/cli/commands/status.js.map +1 -1
- package/dist/src/cli/utils/memory.js +6 -5
- package/dist/src/cli/utils/memory.js.map +1 -1
- package/dist/src/cli/utils/schemas.d.ts +2 -2
- package/dist/src/contracts/tasks.d.ts +4 -4
- package/dist/src/modules/contracts/api.d.ts +6 -6
- package/dist/src/modules/engines/agent-executor.js +30 -19
- package/dist/src/modules/engines/agent-executor.js.map +1 -1
- package/dist/src/modules/engines/evaluation-engine.d.ts +0 -3
- package/dist/src/modules/engines/evaluation-engine.js +17 -16
- package/dist/src/modules/engines/evaluation-engine.js.map +1 -1
- package/dist/src/modules/engines/quality-gate.js +4 -2
- package/dist/src/modules/engines/quality-gate.js.map +1 -1
- package/dist/src/modules/engines/risk-engine.d.ts +17 -1
- package/dist/src/modules/engines/risk-engine.js +98 -3
- package/dist/src/modules/engines/risk-engine.js.map +1 -1
- package/dist/src/modules/engines/routing-engine.d.ts +26 -1
- package/dist/src/modules/engines/routing-engine.js +97 -1
- package/dist/src/modules/engines/routing-engine.js.map +1 -1
- package/dist/src/modules/providers/shared.js +2 -3
- package/dist/src/modules/providers/shared.js.map +1 -1
- package/dist/src/shared/storage.d.ts +17 -0
- package/dist/src/shared/storage.js +76 -2
- package/dist/src/shared/storage.js.map +1 -1
- package/dist/tests/cli/commands/dashboard-coverage.test.js +3 -1
- package/dist/tests/cli/commands/dashboard-coverage.test.js.map +1 -1
- package/dist/tests/modules/engines/evaluation-engine.test.js +2 -2
- package/dist/tests/modules/engines/evaluation-engine.test.js.map +1 -1
- package/dist/tests/status-cost.test.js +2 -0
- package/dist/tests/status-cost.test.js.map +1 -1
- package/dist/tests/storage-operations.test.js +31 -4
- package/dist/tests/storage-operations.test.js.map +1 -1
- package/dist/vitest.config.js +6 -4
- package/dist/vitest.config.js.map +1 -1
- package/framework-mcp/README.md +18 -32
- package/framework-mcp/dist/dashboard/assets/index-B-Eu7_J9.js +1260 -0
- package/framework-mcp/dist/dashboard/index.html +1 -1
- package/framework-mcp/dist/framework-mcp/src/index.js +69 -10
- package/framework-mcp/dist/framework-mcp/src/tools/control_plane/registry.js +52 -4
- package/framework-mcp/dist/framework-mcp/src/tools/definitions.js +1 -1
- package/framework-mcp/dist/framework-mcp/src/tools/file_system/read_file.js +5 -0
- package/framework-mcp/dist/framework-mcp/src/tools/messaging/approve_operation.js +1 -1
- package/framework-mcp/dist/framework-mcp/src/tools/messaging/send_message.js +19 -3
- package/framework-mcp/dist/framework-mcp/src/tools/search/grep_search.js +11 -4
- package/framework-mcp/dist/framework-mcp/src/tools/search/list_dir.js +3 -0
- package/framework-mcp/dist/framework-mcp/src/tools/shell/run_command.js +47 -1
- package/framework-mcp/dist/framework-mcp/src/utils/auth.js +71 -4
- package/framework-mcp/dist/framework-mcp/src/utils/compliance.js +45 -13
- package/framework-mcp/dist/framework-mcp/src/utils/discipline.js +41 -2
- package/framework-mcp/dist/framework-mcp/src/utils/human-in-loop.js +113 -9
- package/framework-mcp/dist/framework-mcp/src/utils/permissions.js +179 -43
- package/framework-mcp/dist/framework-mcp/src/utils/prompt-injection.js +63 -0
- package/framework-mcp/dist/src/cli/utils/memory.js +6 -5
- package/framework-mcp/dist/src/modules/engines/evaluation-engine.js +17 -16
- package/framework-mcp/dist/src/modules/engines/quality-gate.js +4 -2
- package/framework-mcp/dist/src/modules/engines/risk-engine.js +98 -3
- package/framework-mcp/dist/src/modules/engines/routing-engine.js +97 -1
- package/framework-mcp/dist/src/modules/providers/shared.js +2 -3
- package/framework-mcp/dist/src/shared/storage.js +76 -2
- package/framework-mcp/package.json +21 -18
- package/package.json +3 -3
- package/framework-mcp/dist/dashboard/assets/index-B_rK57vi.js +0 -1221
|
@@ -1,6 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ─── RBAC PERMISSION MATRIX ───────────────────────────────────────────────
|
|
3
|
+
*
|
|
4
|
+
* Enforces agent-scoped file system permissions at the MCP tool layer.
|
|
5
|
+
* This is the file-level RBAC enforcement point for:
|
|
6
|
+
* - Claude Code (calls write_file / read_file via MCP sub-agents)
|
|
7
|
+
* - Gemini CLI (calls write_file / read_file via MCP server)
|
|
8
|
+
* - Cursor (calls write_file / read_file via MCP rules)
|
|
9
|
+
* - Codex CLI (calls write_file / read_file via agent allowed-tools)
|
|
10
|
+
* - Antigravity (calls write_file / read_file via customAgentSpec tools)
|
|
11
|
+
*
|
|
12
|
+
* Permission matrix is stored in `.atabey/permission-matrix.json`:
|
|
13
|
+
* {
|
|
14
|
+
* "@frontend": { "write": ["apps/web/**"], "read": ["apps/web/**", "docs/**"] },
|
|
15
|
+
* "@backend": { "write": ["apps/backend/**"], "read": ["apps/backend/**", "apps/web/types/**"] }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* Agent Tier enforcement:
|
|
19
|
+
* supreme (@manager, @security) — no write/read restrictions (omnipotent)
|
|
20
|
+
* core (@backend, @frontend, ...) — matrix-enforced
|
|
21
|
+
* recon (@explorer, @git, @analyst, @native) — read-only by default,
|
|
22
|
+
* write requires explicit matrix entry
|
|
23
|
+
*/
|
|
1
24
|
import fs from "fs";
|
|
2
25
|
import path from "path";
|
|
3
26
|
import { resolveFrameworkDir } from "./security.js";
|
|
27
|
+
// ─── Tier hierarchy ─────────────────────────────────────────────────────────
|
|
28
|
+
/** Well-known tier for agents defined in the built-in registry */
|
|
29
|
+
const AGENT_TIER_MAP = {
|
|
30
|
+
"@manager": "supreme",
|
|
31
|
+
"@security": "supreme",
|
|
32
|
+
"@backend": "core",
|
|
33
|
+
"@frontend": "core",
|
|
34
|
+
"@mobile": "core",
|
|
35
|
+
"@quality": "core",
|
|
36
|
+
"@database": "core",
|
|
37
|
+
"@devops": "core",
|
|
38
|
+
"@architect": "core",
|
|
39
|
+
"@explorer": "recon",
|
|
40
|
+
"@git": "recon",
|
|
41
|
+
"@analyst": "recon",
|
|
42
|
+
"@native": "recon",
|
|
43
|
+
};
|
|
44
|
+
export function getAgentTier(agentName) {
|
|
45
|
+
return AGENT_TIER_MAP[agentName] ?? "core"; // unknown agents default to core
|
|
46
|
+
}
|
|
47
|
+
// ─── Glob → RegExp ──────────────────────────────────────────────────────────
|
|
4
48
|
function globToRegex(glob) {
|
|
5
49
|
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
6
50
|
const step1 = escaped.replace(/\*\*/g, "__DBL_STR__");
|
|
@@ -8,65 +52,157 @@ function globToRegex(glob) {
|
|
|
8
52
|
const regexStr = "^" + step2.replace(/__DBL_STR__/g, ".*") + "$";
|
|
9
53
|
return new RegExp(regexStr);
|
|
10
54
|
}
|
|
55
|
+
// ─── Active Agent Resolution ─────────────────────────────────────────────────
|
|
11
56
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
57
|
+
* Resolves the active agent for the current operation.
|
|
58
|
+
*
|
|
59
|
+
* Priority order:
|
|
60
|
+
* 1. ATABEY_ACTIVE_AGENT env var (set by AgentLoop per-invocation — most reliable)
|
|
61
|
+
* 2. `.atabey/memory/status.json` first EXECUTING agent (legacy fallback)
|
|
62
|
+
*
|
|
63
|
+
* Note: The traceId-scoped approach is preferred when AgentLoop sets
|
|
64
|
+
* ATABEY_ACTIVE_AGENT before spawning the MCP tool call.
|
|
15
65
|
*/
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const matrixPath = path.join(absoluteFrameworkPath, "permission-matrix.json");
|
|
22
|
-
// If no permission matrix exists, skip enforcement (default allow)
|
|
23
|
-
if (!fs.existsSync(matrixPath)) {
|
|
24
|
-
return;
|
|
66
|
+
export function resolveActiveAgent(frameworkDir) {
|
|
67
|
+
// 1. Env var (highest reliability — set by orchestration layer)
|
|
68
|
+
const envAgent = process.env.ATABEY_ACTIVE_AGENT?.trim();
|
|
69
|
+
if (envAgent) {
|
|
70
|
+
return envAgent.startsWith("@") ? envAgent : `@${envAgent}`;
|
|
25
71
|
}
|
|
26
|
-
|
|
72
|
+
// 2. status.json fallback
|
|
73
|
+
const statusPath = path.join(frameworkDir, "memory", "status.json");
|
|
74
|
+
if (!fs.existsSync(statusPath))
|
|
75
|
+
return null;
|
|
27
76
|
try {
|
|
28
|
-
|
|
77
|
+
const status = JSON.parse(fs.readFileSync(statusPath, "utf8"));
|
|
78
|
+
for (const [agentName, info] of Object.entries(status)) {
|
|
79
|
+
if (info.state === "EXECUTING") {
|
|
80
|
+
return agentName.startsWith("@") ? agentName : `@${agentName}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
process.stderr.write(`[Permissions] Warning: Failed to read status.json: ${String(e)}\n`);
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
// ─── Matrix Loader ───────────────────────────────────────────────────────────
|
|
90
|
+
function loadMatrix(frameworkDir) {
|
|
91
|
+
const matrixPath = path.join(frameworkDir, "permission-matrix.json");
|
|
92
|
+
if (!fs.existsSync(matrixPath))
|
|
93
|
+
return null;
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse(fs.readFileSync(matrixPath, "utf8"));
|
|
29
96
|
}
|
|
30
97
|
catch (e) {
|
|
31
98
|
throw new Error(`Failed to parse permission-matrix.json: ${String(e)}`, { cause: e });
|
|
32
99
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Internal enforcement logic for both read and write operations.
|
|
103
|
+
*
|
|
104
|
+
* Enforcement logic per tier:
|
|
105
|
+
* - supreme: always allowed (no matrix needed)
|
|
106
|
+
* - core: enforced by matrix; if no rule defined → default-allow
|
|
107
|
+
* - recon: write → always denied unless explicit matrix allow
|
|
108
|
+
* read → allowed by default (recon agents must be able to explore)
|
|
109
|
+
*/
|
|
110
|
+
function enforcePermission(projectRoot, targetFilePath, accessType) {
|
|
111
|
+
const frameworkDir = resolveFrameworkDir(projectRoot);
|
|
112
|
+
const absoluteFrameworkPath = path.isAbsolute(frameworkDir)
|
|
113
|
+
? frameworkDir
|
|
114
|
+
: path.resolve(projectRoot, frameworkDir);
|
|
115
|
+
const activeAgent = resolveActiveAgent(absoluteFrameworkPath);
|
|
116
|
+
// No active agent identified → default-allow (non-agent call, e.g. CLI tools)
|
|
117
|
+
if (!activeAgent)
|
|
118
|
+
return;
|
|
119
|
+
const tier = getAgentTier(activeAgent);
|
|
120
|
+
// Supreme agents are omnipotent — no matrix enforcement
|
|
121
|
+
if (tier === "supreme")
|
|
122
|
+
return;
|
|
123
|
+
// Recon agents: block writes unless explicitly allowed in matrix
|
|
124
|
+
if (tier === "recon" && accessType === "write") {
|
|
125
|
+
const matrix = loadMatrix(absoluteFrameworkPath);
|
|
126
|
+
if (!matrix) {
|
|
127
|
+
throw new Error(`Permission Denied: Agent ${activeAgent} (tier: recon) cannot write files. ` +
|
|
128
|
+
"Recon agents (@explorer, @git, @analyst, @native) are read-only by default. " +
|
|
129
|
+
"Add an explicit write rule to permission-matrix.json to grant write access.");
|
|
47
130
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
131
|
+
const agentRules = matrix[activeAgent];
|
|
132
|
+
if (!agentRules?.write?.length) {
|
|
133
|
+
throw new Error(`Permission Denied: Agent ${activeAgent} (tier: recon) has no write rules in permission-matrix.json. ` +
|
|
134
|
+
"Recon agents are read-only by default.");
|
|
51
135
|
}
|
|
136
|
+
// Fall through to glob check below
|
|
52
137
|
}
|
|
53
|
-
|
|
54
|
-
|
|
138
|
+
const matrix = loadMatrix(absoluteFrameworkPath);
|
|
139
|
+
// No matrix file → default-allow (matrix is opt-in)
|
|
140
|
+
if (!matrix)
|
|
55
141
|
return;
|
|
56
|
-
}
|
|
57
142
|
const agentRules = matrix[activeAgent];
|
|
58
|
-
//
|
|
59
|
-
if (!agentRules
|
|
143
|
+
// No rules for this agent → default-allow
|
|
144
|
+
if (!agentRules)
|
|
145
|
+
return;
|
|
146
|
+
const rules = accessType === "write" ? agentRules.write : (agentRules.read ?? null);
|
|
147
|
+
// No rule for this access type → default-allow
|
|
148
|
+
if (!rules)
|
|
60
149
|
return;
|
|
61
|
-
}
|
|
62
|
-
// Resolve target path relative to project root for glob matching
|
|
63
150
|
const relativeTargetPath = path.relative(projectRoot, path.resolve(projectRoot, targetFilePath));
|
|
64
|
-
const allowed =
|
|
65
|
-
const regex = globToRegex(glob);
|
|
66
|
-
return regex.test(relativeTargetPath);
|
|
67
|
-
});
|
|
151
|
+
const allowed = rules.some(glob => globToRegex(glob).test(relativeTargetPath));
|
|
68
152
|
if (!allowed) {
|
|
69
|
-
throw new Error(`Permission Denied: Agent ${activeAgent}
|
|
153
|
+
throw new Error(`Permission Denied: Agent ${activeAgent} (tier: ${tier}) is not authorized to ` +
|
|
154
|
+
`${accessType} "${relativeTargetPath}". ` +
|
|
155
|
+
`Matrix rules restrict ${accessType} to: [${rules.join(", ")}].`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
159
|
+
/**
|
|
160
|
+
* Verifies that the active agent has WRITE permission for the target file.
|
|
161
|
+
* Called by: write_file, replace_text, batch_surgical_edit, patch_file
|
|
162
|
+
*
|
|
163
|
+
* Throws a descriptive error if permission is denied.
|
|
164
|
+
*/
|
|
165
|
+
export function verifyWritePermission(projectRoot, targetFilePath) {
|
|
166
|
+
enforcePermission(projectRoot, targetFilePath, "write");
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Verifies that the active agent has READ permission for the target file.
|
|
170
|
+
* Called by: read_file, view_file (alias)
|
|
171
|
+
*
|
|
172
|
+
* Throws a descriptive error if permission is denied.
|
|
173
|
+
* Note: read enforcement is SOFTER than write — recon agents can read freely
|
|
174
|
+
* unless an explicit read matrix restriction is defined.
|
|
175
|
+
*/
|
|
176
|
+
export function verifyReadPermission(projectRoot, targetFilePath) {
|
|
177
|
+
enforcePermission(projectRoot, targetFilePath, "read");
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Verifies that the sender agent is allowed to send messages to the target agent
|
|
181
|
+
* based on the AgentTier hierarchy.
|
|
182
|
+
*
|
|
183
|
+
* Messaging rules (AI IDE governance layer):
|
|
184
|
+
* - Any tier → supreme: allowed (escalation always permitted)
|
|
185
|
+
* - core → core: allowed
|
|
186
|
+
* - recon → core: allowed (recon can delegate up)
|
|
187
|
+
* - recon → supreme: allowed
|
|
188
|
+
* - core → recon: BLOCKED (core agents should not delegate down to recon)
|
|
189
|
+
* - supreme → any: allowed
|
|
190
|
+
*
|
|
191
|
+
* Rationale: Recon agents (@explorer, @git) are information-gatherers.
|
|
192
|
+
* If a core agent delegates to a recon agent, it bypasses the quality gate
|
|
193
|
+
* and risk engine — a potential governance gap.
|
|
194
|
+
*/
|
|
195
|
+
export function verifyMessagingPermission(fromAgent, toAgent) {
|
|
196
|
+
const fromTier = getAgentTier(fromAgent);
|
|
197
|
+
const toTier = getAgentTier(toAgent);
|
|
198
|
+
// supreme senders: unrestricted
|
|
199
|
+
if (fromTier === "supreme")
|
|
200
|
+
return;
|
|
201
|
+
// core → recon: block (prevents quality-gate bypass via recon delegation)
|
|
202
|
+
if (fromTier === "core" && toTier === "recon") {
|
|
203
|
+
throw new Error(`[RBAC] Messaging violation: Agent ${fromAgent} (tier: core) cannot delegate to ` +
|
|
204
|
+
`${toAgent} (tier: recon). Core agents must delegate up to @manager or peer core agents. ` +
|
|
205
|
+
"Recon agents are read-only information gatherers and cannot execute delegated tasks.");
|
|
70
206
|
}
|
|
71
207
|
}
|
|
72
208
|
//# sourceMappingURL=permissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../../framework-mcp/src/utils/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,mBAAm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EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAmB,EAAE,cAAsB;IAC5E,iBAAiB,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,yBAAyB,CAAC,SAAiB,EAAE,OAAe;IACxE,MAAM,QAAQ,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IACzC,MAAM,MAAM,GAAK,YAAY,CAAC,OAAO,CAAC,CAAC;IAEvC,gCAAgC;IAChC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO;IAEnC,0EAA0E;IAC1E,IAAI,QAAQ,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACX,qCAAqC,SAAS,mCAAmC;YACjF,GAAG,OAAO,gFAAgF;YAC1F,sFAAsF,CACzF,CAAC;IACN,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ─── PROMPT INJECTION PROTECTION ENGINE ────────────────────────────
|
|
3
|
+
*
|
|
4
|
+
* Scans, detects, and neutralizes prompt injection payloads in tool outputs
|
|
5
|
+
* before they are returned to the AI assistant's context.
|
|
6
|
+
*
|
|
7
|
+
* This prevents malicious files, code comments, or external resources from
|
|
8
|
+
* hijacking the AI client (e.g., instructing it to delete files or ignore safety).
|
|
9
|
+
*/
|
|
10
|
+
export declare class PromptInjectionProtection {
|
|
11
|
+
/**
|
|
12
|
+
* Scan tool response text for injection patterns.
|
|
13
|
+
* Replaces any matches with a redirection block and logs it.
|
|
14
|
+
*/
|
|
15
|
+
static sanitizeResponse(text: string): {
|
|
16
|
+
sanitized: string;
|
|
17
|
+
detected: boolean;
|
|
18
|
+
patterns: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ─── PROMPT INJECTION PROTECTION ENGINE ────────────────────────────
|
|
3
|
+
*
|
|
4
|
+
* Scans, detects, and neutralizes prompt injection payloads in tool outputs
|
|
5
|
+
* before they are returned to the AI assistant's context.
|
|
6
|
+
*
|
|
7
|
+
* This prevents malicious files, code comments, or external resources from
|
|
8
|
+
* hijacking the AI client (e.g., instructing it to delete files or ignore safety).
|
|
9
|
+
*/
|
|
10
|
+
import { logger } from "../../../src/shared/logger.js";
|
|
11
|
+
// Common prompt injection signatures
|
|
12
|
+
const INJECTION_PATTERNS = [
|
|
13
|
+
/ignore\s+(?:all\s+)?instructions/gi,
|
|
14
|
+
/system\s+override/gi,
|
|
15
|
+
/you\s+must\s+now/gi,
|
|
16
|
+
/you\s+are\s+now/gi,
|
|
17
|
+
/bypass\s+governance/gi,
|
|
18
|
+
/bypass\s+safety/gi,
|
|
19
|
+
/bypass\s+atabey/gi,
|
|
20
|
+
/dan\s+mode/gi,
|
|
21
|
+
/developer\s+mode/gi,
|
|
22
|
+
/override\s+system\s+instructions/gi,
|
|
23
|
+
/ignore\s+safety\s+rules/gi,
|
|
24
|
+
/\[system\s+prompt\]/gi,
|
|
25
|
+
/<system_prompt>/gi,
|
|
26
|
+
/disable\s+restrictions/gi
|
|
27
|
+
];
|
|
28
|
+
export class PromptInjectionProtection {
|
|
29
|
+
/**
|
|
30
|
+
* Scan tool response text for injection patterns.
|
|
31
|
+
* Replaces any matches with a redirection block and logs it.
|
|
32
|
+
*/
|
|
33
|
+
static sanitizeResponse(text) {
|
|
34
|
+
if (!text) {
|
|
35
|
+
return { sanitized: text, detected: false, patterns: [] };
|
|
36
|
+
}
|
|
37
|
+
let detected = false;
|
|
38
|
+
const patternsMatched = [];
|
|
39
|
+
let sanitized = text;
|
|
40
|
+
for (const pattern of INJECTION_PATTERNS) {
|
|
41
|
+
if (pattern.test(sanitized)) {
|
|
42
|
+
detected = true;
|
|
43
|
+
const matches = text.match(pattern);
|
|
44
|
+
if (matches) {
|
|
45
|
+
matches.forEach(m => {
|
|
46
|
+
if (!patternsMatched.includes(m)) {
|
|
47
|
+
patternsMatched.push(m);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
sanitized = sanitized.replace(pattern, "[REDACTED PROMPT INJECTION]");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (detected) {
|
|
55
|
+
logger.warn(`[INJECTION PROTECTION] Blocked prompt injection pattern in tool response: ${patternsMatched.join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
sanitized,
|
|
59
|
+
detected,
|
|
60
|
+
patterns: patternsMatched
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=prompt-injection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-injection.js","sourceRoot":"","sources":["../../../../framework-mcp/src/utils/prompt-injection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAEvD,qCAAqC;AACrC,MAAM,kBAAkB,GAAG;IACvB,oCAAoC;IACpC,qBAAqB;IACrB,oBAAoB;IACpB,mBAAmB;IACnB,uBAAuB;IACvB,mBAAmB;IACnB,mBAAmB;IACnB,cAAc;IACd,oBAAoB;IACpB,oCAAoC;IACpC,2BAA2B;IAC3B,uBAAuB;IACvB,mBAAmB;IACnB,0BAA0B;CAC7B,CAAC;AAEF,MAAM,OAAO,yBAAyB;IAClC;;;OAGG;IACI,MAAM,CAAC,gBAAgB,CAAC,IAAY;QAKvC,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QAC9D,CAAC;QAED,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,eAAe,GAAa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