@securecode-ai/mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/api/client.d.ts +22 -0
- package/dist/api/client.js +141 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/types.d.ts +129 -0
- package/dist/api/types.js +3 -0
- package/dist/api/types.js.map +1 -0
- package/dist/approval/auditLog.d.ts +3 -0
- package/dist/approval/auditLog.js +67 -0
- package/dist/approval/auditLog.js.map +1 -0
- package/dist/approval/broker.d.ts +11 -0
- package/dist/approval/broker.js +252 -0
- package/dist/approval/broker.js.map +1 -0
- package/dist/approval/types.d.ts +26 -0
- package/dist/approval/types.js +58 -0
- package/dist/approval/types.js.map +1 -0
- package/dist/attack/agentLoop.d.ts +21 -0
- package/dist/attack/agentLoop.js +148 -0
- package/dist/attack/agentLoop.js.map +1 -0
- package/dist/attack/executor.d.ts +17 -0
- package/dist/attack/executor.js +162 -0
- package/dist/attack/executor.js.map +1 -0
- package/dist/attack/policy.d.ts +26 -0
- package/dist/attack/policy.js +73 -0
- package/dist/attack/policy.js.map +1 -0
- package/dist/attack/protocol.d.ts +64 -0
- package/dist/attack/protocol.js +3 -0
- package/dist/attack/protocol.js.map +1 -0
- package/dist/attack/report.d.ts +16 -0
- package/dist/attack/report.js +54 -0
- package/dist/attack/report.js.map +1 -0
- package/dist/auth/credentialStore.d.ts +20 -0
- package/dist/auth/credentialStore.js +148 -0
- package/dist/auth/credentialStore.js.map +1 -0
- package/dist/auth/keychain.d.ts +14 -0
- package/dist/auth/keychain.js +267 -0
- package/dist/auth/keychain.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +170 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +183 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +2 -0
- package/dist/mcp/tools.js +120 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/types.d.ts +26 -0
- package/dist/mcp/types.js +3 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/project-map/astHelpers.d.ts +89 -0
- package/dist/project-map/astHelpers.js +468 -0
- package/dist/project-map/astHelpers.js.map +1 -0
- package/dist/project-map/cache.d.ts +11 -0
- package/dist/project-map/cache.js +86 -0
- package/dist/project-map/cache.js.map +1 -0
- package/dist/project-map/confidence.d.ts +50 -0
- package/dist/project-map/confidence.js +87 -0
- package/dist/project-map/confidence.js.map +1 -0
- package/dist/project-map/crossFile.d.ts +73 -0
- package/dist/project-map/crossFile.js +33 -0
- package/dist/project-map/crossFile.js.map +1 -0
- package/dist/project-map/detectors.d.ts +83 -0
- package/dist/project-map/detectors.js +376 -0
- package/dist/project-map/detectors.js.map +1 -0
- package/dist/project-map/layer1.d.ts +74 -0
- package/dist/project-map/layer1.js +928 -0
- package/dist/project-map/layer1.js.map +1 -0
- package/dist/project-map/layer2.d.ts +30 -0
- package/dist/project-map/layer2.js +249 -0
- package/dist/project-map/layer2.js.map +1 -0
- package/dist/project-map/mapBuilder.d.ts +17 -0
- package/dist/project-map/mapBuilder.js +164 -0
- package/dist/project-map/mapBuilder.js.map +1 -0
- package/dist/project-map/parserLoader.d.ts +61 -0
- package/dist/project-map/parserLoader.js +175 -0
- package/dist/project-map/parserLoader.js.map +1 -0
- package/dist/project-map/schemas.d.ts +28 -0
- package/dist/project-map/schemas.js +131 -0
- package/dist/project-map/schemas.js.map +1 -0
- package/dist/project-map/types.d.ts +232 -0
- package/dist/project-map/types.js +61 -0
- package/dist/project-map/types.js.map +1 -0
- package/dist/tools/attack.d.ts +2 -0
- package/dist/tools/attack.js +80 -0
- package/dist/tools/attack.js.map +1 -0
- package/dist/tools/fix.d.ts +2 -0
- package/dist/tools/fix.js +60 -0
- package/dist/tools/fix.js.map +1 -0
- package/dist/tools/map.d.ts +2 -0
- package/dist/tools/map.js +46 -0
- package/dist/tools/map.js.map +1 -0
- package/dist/tools/scan.d.ts +2 -0
- package/dist/tools/scan.js +55 -0
- package/dist/tools/scan.js.map +1 -0
- package/dist/utils/files.d.ts +8 -0
- package/dist/utils/files.js +79 -0
- package/dist/utils/files.js.map +1 -0
- package/package.json +53 -0
- package/resources/tree-sitter/tree-sitter-javascript.wasm +0 -0
- package/resources/tree-sitter/tree-sitter-python.wasm +0 -0
- package/resources/tree-sitter/tree-sitter-tsx.wasm +0 -0
- package/resources/tree-sitter/tree-sitter-typescript.wasm +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ApprovalBroker = void 0;
|
|
37
|
+
const http = __importStar(require("http"));
|
|
38
|
+
const child_process_1 = require("child_process");
|
|
39
|
+
const types_1 = require("./types");
|
|
40
|
+
const auditLog_1 = require("./auditLog");
|
|
41
|
+
const APPROVAL_PAGE_HTML = `<!DOCTYPE html>
|
|
42
|
+
<html>
|
|
43
|
+
<head>
|
|
44
|
+
<meta charset="utf-8">
|
|
45
|
+
<title>SecureCode MCP — Approval Required</title>
|
|
46
|
+
<style>
|
|
47
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; max-width: 600px; margin: 60px auto; padding: 20px; color: #1a1a1a; }
|
|
48
|
+
h1 { font-size: 20px; margin-bottom: 8px; }
|
|
49
|
+
.summary { background: #f4f4f4; padding: 16px; border-radius: 8px; margin: 16px 0; font-family: monospace; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
|
|
50
|
+
.meta { color: #666; font-size: 13px; margin-bottom: 16px; }
|
|
51
|
+
.buttons { display: flex; gap: 12px; margin-top: 24px; }
|
|
52
|
+
button { padding: 10px 24px; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; font-weight: 600; }
|
|
53
|
+
.approve { background: #16a34a; color: white; }
|
|
54
|
+
.deny { background: #dc2626; color: white; }
|
|
55
|
+
.result { margin-top: 24px; font-size: 16px; font-weight: 600; }
|
|
56
|
+
.timeout { color: #d97706; }
|
|
57
|
+
.expired { display: none; color: #dc2626; }
|
|
58
|
+
</style>
|
|
59
|
+
</head>
|
|
60
|
+
<body>
|
|
61
|
+
<h1>SecureCode MCP — Approval Required</h1>
|
|
62
|
+
<div class="meta">Tool: <span id="tool"></span> | Hash: <span id="hash"></span></div>
|
|
63
|
+
<div class="summary" id="summary"></div>
|
|
64
|
+
<div class="buttons" id="buttons">
|
|
65
|
+
<button class="approve" onclick="respond(true)">Approve</button>
|
|
66
|
+
<button class="deny" onclick="respond(false)">Deny</button>
|
|
67
|
+
</div>
|
|
68
|
+
<div class="result" id="result"></div>
|
|
69
|
+
<div class="expired" id="expired">This request has expired. You can close this page.</div>
|
|
70
|
+
<script>
|
|
71
|
+
const params = new URLSearchParams(window.location.search);
|
|
72
|
+
const reqId = params.get('id');
|
|
73
|
+
document.getElementById('tool').textContent = params.get('tool') || '';
|
|
74
|
+
document.getElementById('hash').textContent = params.get('hash') || '';
|
|
75
|
+
document.getElementById('summary').textContent = decodeURIComponent(params.get('summary') || '');
|
|
76
|
+
|
|
77
|
+
async function respond(approved) {
|
|
78
|
+
document.getElementById('buttons').style.display = 'none';
|
|
79
|
+
const res = document.getElementById('result');
|
|
80
|
+
try {
|
|
81
|
+
const r = await fetch('/decide', {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: {'Content-Type': 'application/json'},
|
|
84
|
+
body: JSON.stringify({ id: reqId, approved })
|
|
85
|
+
});
|
|
86
|
+
const data = await r.json();
|
|
87
|
+
if (data.ok) {
|
|
88
|
+
res.textContent = approved ? 'Approved. You can close this page.' : 'Denied. You can close this page.';
|
|
89
|
+
res.style.color = approved ? '#16a34a' : '#dc2626';
|
|
90
|
+
} else {
|
|
91
|
+
res.textContent = 'Error: ' + (data.error || 'unknown');
|
|
92
|
+
res.style.color = '#dc2626';
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {
|
|
95
|
+
res.textContent = 'Error: ' + e.message;
|
|
96
|
+
res.style.color = '#dc2626';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const expiresAt = parseInt(params.get('exp') || '0');
|
|
101
|
+
if (expiresAt && Date.now() > expiresAt) {
|
|
102
|
+
document.getElementById('buttons').style.display = 'none';
|
|
103
|
+
document.getElementById('expired').style.display = 'block';
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
</body>
|
|
107
|
+
</html>`;
|
|
108
|
+
function openBrowser(url) {
|
|
109
|
+
const platform = process.platform;
|
|
110
|
+
try {
|
|
111
|
+
if (platform === 'darwin') {
|
|
112
|
+
(0, child_process_1.exec)(`open "${url}"`);
|
|
113
|
+
}
|
|
114
|
+
else if (platform === 'win32') {
|
|
115
|
+
(0, child_process_1.exec)(`start "" "${url}"`);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
(0, child_process_1.exec)(`xdg-open "${url}"`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// If browser open fails, the user can copy the URL from stdout
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class ApprovalBroker {
|
|
126
|
+
server = null;
|
|
127
|
+
port = 0;
|
|
128
|
+
pending = new Map();
|
|
129
|
+
async start() {
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
this.server = http.createServer((req, res) => this.handle(req, res));
|
|
132
|
+
this.server.listen(0, '127.0.0.1', () => {
|
|
133
|
+
const addr = this.server.address();
|
|
134
|
+
this.port = addr.port;
|
|
135
|
+
resolve(this.port);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async stop() {
|
|
140
|
+
return new Promise((resolve) => {
|
|
141
|
+
if (this.server) {
|
|
142
|
+
this.server.close(() => resolve());
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
resolve();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
getPort() {
|
|
150
|
+
return this.port;
|
|
151
|
+
}
|
|
152
|
+
requestApproval(tool, summary, operationParts, timeoutMs = 60_000) {
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
|
+
const req = (0, types_1.createApprovalRequest)(tool, summary, operationParts, timeoutMs);
|
|
155
|
+
const startTime = Date.now();
|
|
156
|
+
this.pending.set(req.id, { req, resolve });
|
|
157
|
+
const url = `http://127.0.0.1:${this.port}/?id=${req.id}&tool=${encodeURIComponent(tool)}&hash=${req.operationHash}&summary=${encodeURIComponent(summary)}&exp=${req.expiresAt}`;
|
|
158
|
+
console.error(`[securecode] Approval required for ${tool}. Open: ${url}`);
|
|
159
|
+
openBrowser(url);
|
|
160
|
+
const timer = setTimeout(() => {
|
|
161
|
+
const entry = this.pending.get(req.id);
|
|
162
|
+
if (entry) {
|
|
163
|
+
this.pending.delete(req.id);
|
|
164
|
+
const result = {
|
|
165
|
+
approved: false,
|
|
166
|
+
reason: 'Request timed out',
|
|
167
|
+
requestId: req.id,
|
|
168
|
+
duration: Date.now() - startTime,
|
|
169
|
+
};
|
|
170
|
+
(0, auditLog_1.appendAudit)({
|
|
171
|
+
timestamp: new Date().toISOString(),
|
|
172
|
+
requestId: req.id,
|
|
173
|
+
tool: req.tool,
|
|
174
|
+
operationHash: req.operationHash,
|
|
175
|
+
approved: false,
|
|
176
|
+
reason: 'timeout',
|
|
177
|
+
durationMs: result.duration,
|
|
178
|
+
});
|
|
179
|
+
resolve(result);
|
|
180
|
+
}
|
|
181
|
+
}, timeoutMs + 5000);
|
|
182
|
+
const origResolve = resolve;
|
|
183
|
+
this.pending.set(req.id, {
|
|
184
|
+
req,
|
|
185
|
+
resolve: (r) => {
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
origResolve(r);
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
handle(req, res) {
|
|
193
|
+
const url = req.url || '/';
|
|
194
|
+
if (req.method === 'GET' && (url === '/' || url.startsWith('/?'))) {
|
|
195
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
196
|
+
res.end(APPROVAL_PAGE_HTML);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (req.method === 'POST' && req.url === '/decide') {
|
|
200
|
+
let body = '';
|
|
201
|
+
req.on('data', (c) => { body += c; });
|
|
202
|
+
req.on('end', () => {
|
|
203
|
+
try {
|
|
204
|
+
const data = JSON.parse(body);
|
|
205
|
+
const requestId = data.id;
|
|
206
|
+
const entry = requestId ? this.pending.get(requestId) : undefined;
|
|
207
|
+
if (!entry || !requestId) {
|
|
208
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
209
|
+
res.end(JSON.stringify({ ok: false, error: 'Request not found or already answered' }));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if ((0, types_1.isExpired)(entry.req)) {
|
|
213
|
+
this.pending.delete(requestId);
|
|
214
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
215
|
+
res.end(JSON.stringify({ ok: false, error: 'Request expired' }));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.pending.delete(requestId);
|
|
219
|
+
const approved = data.approved === true;
|
|
220
|
+
const startTime = entry.req.createdAt;
|
|
221
|
+
const result = {
|
|
222
|
+
approved,
|
|
223
|
+
reason: approved ? 'User approved' : 'User denied',
|
|
224
|
+
requestId: entry.req.id,
|
|
225
|
+
duration: Date.now() - startTime,
|
|
226
|
+
};
|
|
227
|
+
(0, auditLog_1.appendAudit)({
|
|
228
|
+
timestamp: new Date().toISOString(),
|
|
229
|
+
requestId: entry.req.id,
|
|
230
|
+
tool: entry.req.tool,
|
|
231
|
+
operationHash: entry.req.operationHash,
|
|
232
|
+
approved,
|
|
233
|
+
reason: approved ? 'approved' : 'denied',
|
|
234
|
+
durationMs: result.duration,
|
|
235
|
+
});
|
|
236
|
+
entry.resolve(result);
|
|
237
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
238
|
+
res.end(JSON.stringify({ ok: true }));
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
242
|
+
res.end(JSON.stringify({ ok: false, error: 'Invalid request body' }));
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
res.writeHead(404);
|
|
248
|
+
res.end('Not found');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.ApprovalBroker = ApprovalBroker;
|
|
252
|
+
//# sourceMappingURL=broker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/approval/broker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAE7B,iDAAqC;AACrC,mCAAsG;AACtG,yCAAyC;AAEzC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAkEnB,CAAC;AAET,SAAS,WAAW,CAAC,GAAW;IAC5B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,IAAI,CAAC;QACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAA,oBAAI,EAAC,SAAS,GAAG,GAAG,CAAC,CAAC;QAC1B,CAAC;aAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC9B,IAAA,oBAAI,EAAC,aAAa,GAAG,GAAG,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACJ,IAAA,oBAAI,EAAC,aAAa,GAAG,GAAG,CAAC,CAAC;QAC9B,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACL,+DAA+D;IACnE,CAAC;AACL,CAAC;AAED,MAAa,cAAc;IACf,MAAM,GAAuB,IAAI,CAAC;IAClC,IAAI,GAAG,CAAC,CAAC;IACT,OAAO,GAAgF,IAAI,GAAG,EAAE,CAAC;IAEzG,KAAK,CAAC,KAAK;QACP,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YA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AAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ;wBACxC,UAAU,EAAE,MAAM,CAAC,QAAQ;qBAC9B,CAAC,CAAC;oBAEH,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBAEtB,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;oBAC3D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAC1C,CAAC;gBAAC,MAAM,CAAC;oBACL,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;oBAC3D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC;gBAC1E,CAAC;YACL,CAAC,CAAC,CAAC;YACH,OAAO;QACX,CAAC;QAED,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACnB,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,CAAC;CACJ;AAjJD,wCAiJC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ApprovalRequest {
|
|
2
|
+
id: string;
|
|
3
|
+
tool: string;
|
|
4
|
+
summary: string;
|
|
5
|
+
operationHash: string;
|
|
6
|
+
createdAt: number;
|
|
7
|
+
expiresAt: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ApprovalResult {
|
|
10
|
+
approved: boolean;
|
|
11
|
+
reason: string;
|
|
12
|
+
requestId: string;
|
|
13
|
+
duration: number;
|
|
14
|
+
}
|
|
15
|
+
export interface AuditEntry {
|
|
16
|
+
timestamp: string;
|
|
17
|
+
requestId: string;
|
|
18
|
+
tool: string;
|
|
19
|
+
operationHash: string;
|
|
20
|
+
approved: boolean;
|
|
21
|
+
reason: string;
|
|
22
|
+
durationMs: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function hashOperation(tool: string, ...parts: unknown[]): string;
|
|
25
|
+
export declare function createApprovalRequest(tool: string, summary: string, operationParts: unknown[], timeoutMs?: number): ApprovalRequest;
|
|
26
|
+
export declare function isExpired(req: ApprovalRequest, now?: number): boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.hashOperation = hashOperation;
|
|
37
|
+
exports.createApprovalRequest = createApprovalRequest;
|
|
38
|
+
exports.isExpired = isExpired;
|
|
39
|
+
const crypto = __importStar(require("crypto"));
|
|
40
|
+
function hashOperation(tool, ...parts) {
|
|
41
|
+
const data = JSON.stringify({ tool, parts });
|
|
42
|
+
return crypto.createHash('sha256').update(data).digest('hex').substring(0, 16);
|
|
43
|
+
}
|
|
44
|
+
function createApprovalRequest(tool, summary, operationParts, timeoutMs = 60_000) {
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
return {
|
|
47
|
+
id: crypto.randomUUID(),
|
|
48
|
+
tool,
|
|
49
|
+
summary,
|
|
50
|
+
operationHash: hashOperation(tool, ...operationParts),
|
|
51
|
+
createdAt: now,
|
|
52
|
+
expiresAt: now + timeoutMs,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isExpired(req, now = Date.now()) {
|
|
56
|
+
return now > req.expiresAt;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/approval/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,sCAGC;AAED,sDAeC;AAED,8BAEC;AApDD,+CAAiC;AA4BjC,SAAgB,aAAa,CAAC,IAAY,EAAE,GAAG,KAAgB;IAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACnF,CAAC;AAED,SAAgB,qBAAqB,CACjC,IAAY,EACZ,OAAe,EACf,cAAyB,EACzB,YAAoB,MAAM;IAE1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,OAAO;QACH,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE;QACvB,IAAI;QACJ,OAAO;QACP,aAAa,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC;QACrD,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,GAAG,GAAG,SAAS;KAC7B,CAAC;AACN,CAAC;AAED,SAAgB,SAAS,CAAC,GAAoB,EAAE,MAAc,IAAI,CAAC,GAAG,EAAE;IACpE,OAAO,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ServerContext } from '../mcp/types';
|
|
2
|
+
import { type AttackBudget } from './policy';
|
|
3
|
+
import { type AttackReport } from './report';
|
|
4
|
+
import type { AgentRunStatus } from './protocol';
|
|
5
|
+
export interface AttackOptions {
|
|
6
|
+
targetPort: number;
|
|
7
|
+
targetHost?: string;
|
|
8
|
+
budget?: Partial<AttackBudget>;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export interface AttackResult {
|
|
12
|
+
status: AgentRunStatus;
|
|
13
|
+
report?: AttackReport;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function runAttack(ctx: ServerContext, endpoint: {
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
sourceFile: string;
|
|
20
|
+
handlerName: string;
|
|
21
|
+
}, code: string, language: string, options: AttackOptions): Promise<AttackResult>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAttack = runAttack;
|
|
4
|
+
const client_1 = require("../api/client");
|
|
5
|
+
const executor_1 = require("./executor");
|
|
6
|
+
const policy_1 = require("./policy");
|
|
7
|
+
const report_1 = require("./report");
|
|
8
|
+
async function runAttack(ctx, endpoint, code, language, options) {
|
|
9
|
+
const client = new client_1.ApiClient({ baseUrl: ctx.apiUrl, token: ctx.apiToken });
|
|
10
|
+
const budget = { ...policy_1.DEFAULT_BUDGET, ...options.budget };
|
|
11
|
+
const target = {
|
|
12
|
+
host: options.targetHost || '127.0.0.1',
|
|
13
|
+
port: options.targetPort,
|
|
14
|
+
path: endpoint.path,
|
|
15
|
+
};
|
|
16
|
+
(0, policy_1.validateTarget)(target);
|
|
17
|
+
const startTime = Date.now();
|
|
18
|
+
let stepsTaken = 0;
|
|
19
|
+
let requestsMade = 0;
|
|
20
|
+
const state = { stepsTaken, requestsMade, startTime };
|
|
21
|
+
try {
|
|
22
|
+
const scanResp = await client.postJson('/scan', {
|
|
23
|
+
code,
|
|
24
|
+
language,
|
|
25
|
+
filePath: endpoint.sourceFile,
|
|
26
|
+
scanDepth: 'auto',
|
|
27
|
+
});
|
|
28
|
+
const findings = (scanResp.scanType === 'advanced' && scanResp.finalFindings)
|
|
29
|
+
? scanResp.finalFindings
|
|
30
|
+
: (scanResp.findings || []);
|
|
31
|
+
const attackable = findings.filter((f) => {
|
|
32
|
+
const type = f.type || f.check_id;
|
|
33
|
+
return type && f.source !== 'dependency';
|
|
34
|
+
});
|
|
35
|
+
if (attackable.length === 0) {
|
|
36
|
+
return { status: 'completed', error: 'No attackable vulnerability found in scan results.' };
|
|
37
|
+
}
|
|
38
|
+
const finding = attackable[0];
|
|
39
|
+
const loc = finding.location || {
|
|
40
|
+
line_start: finding.start?.line,
|
|
41
|
+
line_end: finding.end?.line ?? finding.start?.line,
|
|
42
|
+
};
|
|
43
|
+
const fixResp = await client.postJson('/fix', {
|
|
44
|
+
code,
|
|
45
|
+
language,
|
|
46
|
+
vulnerability: {
|
|
47
|
+
type: finding.type || finding.check_id,
|
|
48
|
+
line_start: loc.line_start ?? 1,
|
|
49
|
+
line_end: loc.line_end ?? loc.line_start ?? 1,
|
|
50
|
+
evidence_snippet: finding.evidence_snippet || '',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
if (!fixResp.fixed_code || fixResp.fixed_code.length === 0) {
|
|
54
|
+
return { status: 'completed', error: 'Fixer returned no patch — nothing to attack.' };
|
|
55
|
+
}
|
|
56
|
+
const startResp = await client.postJson('/attack/agent/start', {});
|
|
57
|
+
const runId = startResp.runId;
|
|
58
|
+
const endpointContext = {
|
|
59
|
+
method: endpoint.method,
|
|
60
|
+
path: endpoint.path,
|
|
61
|
+
handlerName: endpoint.handlerName,
|
|
62
|
+
sourceFile: endpoint.sourceFile,
|
|
63
|
+
line: 0,
|
|
64
|
+
middleware: [],
|
|
65
|
+
params: [],
|
|
66
|
+
authScheme: 'unknown',
|
|
67
|
+
dataLayer: 'unknown',
|
|
68
|
+
validatorLibrary: 'unknown',
|
|
69
|
+
callGraph: [],
|
|
70
|
+
responseShape: 'unknown',
|
|
71
|
+
confidence: 0,
|
|
72
|
+
runtimeConfirmed: false,
|
|
73
|
+
};
|
|
74
|
+
const transcript = [];
|
|
75
|
+
while (true) {
|
|
76
|
+
const budgetCheck = (0, policy_1.checkBudget)(budget, state);
|
|
77
|
+
if (budgetCheck.exhausted) {
|
|
78
|
+
return {
|
|
79
|
+
status: 'capped',
|
|
80
|
+
report: (0, report_1.buildReport)('capped', [], transcript, stepsTaken, 0, budgetCheck.reason),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (options.signal?.aborted) {
|
|
84
|
+
return {
|
|
85
|
+
status: 'cancelled',
|
|
86
|
+
report: (0, report_1.buildReport)('cancelled', [], transcript, stepsTaken, 0, 'Cancelled by user'),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const stepResp = await client.postJson('/attack/agent/step', {
|
|
90
|
+
runId,
|
|
91
|
+
endpointContext,
|
|
92
|
+
language,
|
|
93
|
+
handlerSource: code,
|
|
94
|
+
transcript,
|
|
95
|
+
budget: {
|
|
96
|
+
stepsRemaining: budget.maxSteps - stepsTaken,
|
|
97
|
+
costSpentUsd: 0,
|
|
98
|
+
costCapUsd: 0,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
if (!stepResp.next) {
|
|
102
|
+
return {
|
|
103
|
+
status: stepResp.costCapped ? 'capped' : (stepResp.degraded ? 'degraded' : 'completed'),
|
|
104
|
+
report: (0, report_1.buildReport)(stepResp.costCapped ? 'capped' : 'completed', [], transcript, stepsTaken, stepResp.costUsd || 0),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const action = stepResp.next;
|
|
108
|
+
stepsTaken++;
|
|
109
|
+
state.stepsTaken = stepsTaken;
|
|
110
|
+
if (action.type === 'finish') {
|
|
111
|
+
return {
|
|
112
|
+
status: 'completed',
|
|
113
|
+
report: (0, report_1.buildReport)('completed', action.findings || [], transcript, stepsTaken, stepResp.costUsd || 0, action.summary),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (action.type === 'http_request') {
|
|
117
|
+
requestsMade++;
|
|
118
|
+
state.requestsMade = requestsMade;
|
|
119
|
+
const execResp = await (0, executor_1.executeHttpRequest)({
|
|
120
|
+
method: action.method,
|
|
121
|
+
path: action.path,
|
|
122
|
+
host: target.host,
|
|
123
|
+
port: target.port,
|
|
124
|
+
headers: action.headers,
|
|
125
|
+
body: action.body,
|
|
126
|
+
}, budget, options.signal);
|
|
127
|
+
transcript.push({
|
|
128
|
+
action,
|
|
129
|
+
observation: {
|
|
130
|
+
statusCode: execResp.statusCode,
|
|
131
|
+
headers: execResp.headers,
|
|
132
|
+
body: (0, report_1.redactText)(execResp.body).slice(0, 10_000),
|
|
133
|
+
latencyMs: execResp.latencyMs,
|
|
134
|
+
error: execResp.error,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
return {
|
|
142
|
+
status: 'spawn_failed',
|
|
143
|
+
error: err.message || String(err),
|
|
144
|
+
report: (0, report_1.buildReport)('spawn_failed', [], [], stepsTaken, 0, err.message),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=agentLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentLoop.js","sourceRoot":"","sources":["../../src/attack/agentLoop.ts"],"names":[],"mappings":";;AAsBA,8BAgLC;AAtMD,0CAA0C;AAI1C,yCAAgD;AAChD,qCAA0F;AAC1F,qCAAsE;AAgB/D,KAAK,UAAU,SAAS,CAC3B,GAAkB,EAClB,QAAmF,EACnF,IAAY,EACZ,QAAgB,EAChB,OAAsB;IAEtB,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,EAAE,GAAG,uBAAc,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACxD,MAAM,MAAM,GAAG;QACX,IAAI,EAAE,OAAO,CAAC,UAAU,IAAI,WAAW;QACvC,IAAI,EAAE,OAAO,CAAC,UAAU;QACxB,IAAI,EAAE,QAAQ,CAAC,IAAI;KACtB,CAAC;IAEF,IAAA,uBAAc,EAAC,MAAM,CAAC,CAAC;IAEvB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,MAAM,KAAK,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IAEtD,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAe,OAAO,EAAE;YAC1D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@@
|
|
|
1
|
+
import type { AttackBudget } from './policy';
|
|
2
|
+
export interface ExecRequest {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface ExecResponse {
|
|
11
|
+
statusCode: number;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
body: string;
|
|
14
|
+
latencyMs: number;
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function executeHttpRequest(req: ExecRequest, budget: AttackBudget, signal?: AbortSignal): Promise<ExecResponse>;
|