fullcourtdefense 1.0.4 → 1.7.27
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 +28 -1
- package/dist/cli/api.d.ts +14 -0
- package/dist/cli/api.js +4 -1
- package/dist/cli/commands/agentCi.d.ts +15 -0
- package/dist/cli/commands/agentCi.js +418 -0
- package/dist/cli/commands/autoProtect.d.ts +10 -0
- package/dist/cli/commands/autoProtect.js +150 -0
- package/dist/cli/commands/configure.d.ts +4 -1
- package/dist/cli/commands/configure.js +78 -7
- package/dist/cli/commands/deterministicGuard.d.ts +30 -0
- package/dist/cli/commands/deterministicGuard.js +507 -0
- package/dist/cli/commands/discover.d.ts +70 -0
- package/dist/cli/commands/discover.js +818 -0
- package/dist/cli/commands/discoverAgentFiles.d.ts +15 -0
- package/dist/cli/commands/discoverAgentFiles.js +204 -0
- package/dist/cli/commands/discoverBlastRadius.d.ts +30 -0
- package/dist/cli/commands/discoverBlastRadius.js +139 -0
- package/dist/cli/commands/discoverPaths.d.ts +18 -0
- package/dist/cli/commands/discoverPaths.js +200 -0
- package/dist/cli/commands/discoverProxy.d.ts +42 -0
- package/dist/cli/commands/discoverProxy.js +266 -0
- package/dist/cli/commands/discoverSchedule.d.ts +8 -0
- package/dist/cli/commands/discoverSchedule.js +169 -0
- package/dist/cli/commands/discoverSecrets.d.ts +24 -0
- package/dist/cli/commands/discoverSecrets.js +286 -0
- package/dist/cli/commands/flushSpool.d.ts +13 -0
- package/dist/cli/commands/flushSpool.js +28 -0
- package/dist/cli/commands/hook.d.ts +35 -0
- package/dist/cli/commands/hook.js +840 -0
- package/dist/cli/commands/installAll.d.ts +18 -0
- package/dist/cli/commands/installAll.js +114 -0
- package/dist/cli/commands/installClaudeHook.d.ts +27 -0
- package/dist/cli/commands/installClaudeHook.js +201 -0
- package/dist/cli/commands/installCursorHook.d.ts +12 -0
- package/dist/cli/commands/installCursorHook.js +198 -0
- package/dist/cli/commands/knownMcpServers.d.ts +8 -0
- package/dist/cli/commands/knownMcpServers.js +68 -0
- package/dist/cli/commands/local-scan.d.ts +3 -0
- package/dist/cli/commands/local-scan.js +1630 -14
- package/dist/cli/commands/login.d.ts +15 -0
- package/dist/cli/commands/login.js +61 -0
- package/dist/cli/commands/mcpGateway.d.ts +74 -0
- package/dist/cli/commands/mcpGateway.js +1706 -0
- package/dist/cli/commands/restartNotice.d.ts +2 -0
- package/dist/cli/commands/restartNotice.js +14 -0
- package/dist/cli/commands/scan.d.ts +3 -0
- package/dist/cli/commands/scan.js +3 -0
- package/dist/cli/commands/taintLedger.d.ts +58 -0
- package/dist/cli/commands/taintLedger.js +370 -0
- package/dist/cli/config.d.ts +26 -0
- package/dist/cli/config.js +99 -16
- package/dist/cli/index.js +463 -14
- package/dist/cli/localSafetySnapshot.d.ts +18 -0
- package/dist/cli/localSafetySnapshot.js +130 -0
- package/dist/cli/machineIdentity.d.ts +23 -0
- package/dist/cli/machineIdentity.js +147 -0
- package/dist/cli/runtimeConfig.d.ts +43 -0
- package/dist/cli/runtimeConfig.js +115 -0
- package/dist/cli/telemetry.d.ts +43 -0
- package/dist/cli/telemetry.js +177 -0
- package/dist/cli/version.json +3 -0
- package/dist/client.d.ts +33 -2
- package/dist/client.js +440 -87
- package/dist/types.d.ts +87 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -543,10 +543,37 @@ const fcd = new FullCourtDefense({
|
|
|
543
543
|
shieldKey: 'shsk_...', // Required only for shields locked with an API key
|
|
544
544
|
apiKey: 'your-llm-key', // Only needed for LLM gateway use cases (7–11)
|
|
545
545
|
apiUrl: 'https://...', // Optional — defaults to api.fullcourtdefense.ai
|
|
546
|
-
timeout: 120000, // Optional — ms (default: 120000)
|
|
546
|
+
timeout: 120000, // Optional — ms for gateway chat / approval polling (default: 120000)
|
|
547
|
+
monitorMode: 'auto', // Optional — 'auto' (default) | 'off'. See below.
|
|
548
|
+
failOpen: true, // Optional — default true. Backend down = allow, never throw.
|
|
549
|
+
scanTimeoutMs: 5000, // Optional — bounded timeout for sync verdict calls (default: 5000)
|
|
547
550
|
});
|
|
548
551
|
```
|
|
549
552
|
|
|
553
|
+
### Monitor mode (zero-latency detection)
|
|
554
|
+
|
|
555
|
+
With `monitorMode: 'auto'` (the default) the SDK follows the shield's mode set in
|
|
556
|
+
the console:
|
|
557
|
+
|
|
558
|
+
- **Shield in `monitor` mode** — `scan()`, `scanGenerated()`, `scanToolResponse()`,
|
|
559
|
+
`scanChunks()`, `checkToolCall()`, `guardToolCall()` and `checkContext()` return
|
|
560
|
+
"allowed" **instantly** (no verdict wait, zero added latency) and report the
|
|
561
|
+
event fire-and-forget. The full detection pipeline runs server-side and logs
|
|
562
|
+
"would have blocked" events in your console — same detection, same data, no
|
|
563
|
+
agent impact. Results carry `analysis: 'async'`.
|
|
564
|
+
- **Shield in `block` mode** — synchronous verdict path: attacks are blocked
|
|
565
|
+
before they reach your bot/LLM.
|
|
566
|
+
|
|
567
|
+
The mode is cached for 60s, so flipping monitor → block in the console takes
|
|
568
|
+
effect within a minute without redeploying your agent.
|
|
569
|
+
|
|
570
|
+
### Fail-open guarantee
|
|
571
|
+
|
|
572
|
+
With `failOpen: true` (the default), FullCourtDefense being unreachable, slow, or
|
|
573
|
+
erroring can NEVER block or break your agent: scan/check calls return an allowed
|
|
574
|
+
result with `degraded: true` instead of throwing. No connection = no blocking.
|
|
575
|
+
Set `failOpen: false` to restore strict throwing.
|
|
576
|
+
|
|
550
577
|
### Method reference
|
|
551
578
|
|
|
552
579
|
| Method | Hits | Use it for |
|
package/dist/cli/api.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export interface ScanResult {
|
|
|
69
69
|
};
|
|
70
70
|
agentDescription: string;
|
|
71
71
|
createdAt: string;
|
|
72
|
+
reportUrl?: string;
|
|
72
73
|
}
|
|
73
74
|
export interface AsyncJobResponse {
|
|
74
75
|
jobId: string;
|
|
@@ -90,6 +91,14 @@ export interface ApiError {
|
|
|
90
91
|
code?: string;
|
|
91
92
|
remaining?: number;
|
|
92
93
|
}
|
|
94
|
+
export interface SetupValidationResponse {
|
|
95
|
+
organizationId: string;
|
|
96
|
+
organizationName: string;
|
|
97
|
+
shieldId: string;
|
|
98
|
+
shieldName: string;
|
|
99
|
+
shieldKeyRequired: boolean;
|
|
100
|
+
gatewayMode: boolean;
|
|
101
|
+
}
|
|
93
102
|
export declare class BotGuardApi {
|
|
94
103
|
private apiUrl;
|
|
95
104
|
private apiKey;
|
|
@@ -99,4 +108,9 @@ export declare class BotGuardApi {
|
|
|
99
108
|
getScanStatus(jobId: string): Promise<AsyncJobResponse>;
|
|
100
109
|
pollUntilDone(jobId: string, intervalMs?: number, maxWaitMs?: number): Promise<ScanResult>;
|
|
101
110
|
getCredits(): Promise<CreditsResponse>;
|
|
111
|
+
validateSetup(input: {
|
|
112
|
+
organizationId?: string;
|
|
113
|
+
shieldId: string;
|
|
114
|
+
shieldKey?: string;
|
|
115
|
+
}): Promise<SetupValidationResponse>;
|
|
102
116
|
}
|
package/dist/cli/api.js
CHANGED
|
@@ -22,7 +22,7 @@ class BotGuardApi {
|
|
|
22
22
|
const data = await resp.json();
|
|
23
23
|
if (!resp.ok || data.success === false) {
|
|
24
24
|
const err = data;
|
|
25
|
-
const msg = err.error || `API error (${resp.status})
|
|
25
|
+
const msg = err.code ? `${err.error} (${err.code})` : (err.error || `API error (${resp.status})`);
|
|
26
26
|
if (err.code === 'CREDITS_EXHAUSTED') {
|
|
27
27
|
throw new Error(`No scan credits remaining this month. Upgrade your plan at https://fullcourtdefense.ai/pricing`);
|
|
28
28
|
}
|
|
@@ -58,5 +58,8 @@ class BotGuardApi {
|
|
|
58
58
|
async getCredits() {
|
|
59
59
|
return this.request('GET', '/api/cicd/credits');
|
|
60
60
|
}
|
|
61
|
+
async validateSetup(input) {
|
|
62
|
+
return this.request('POST', '/api/cicd/setup/validate', input);
|
|
63
|
+
}
|
|
61
64
|
}
|
|
62
65
|
exports.BotGuardApi = BotGuardApi;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BotGuardConfig } from '../config';
|
|
2
|
+
export interface AgentCiArgs {
|
|
3
|
+
failOn?: string;
|
|
4
|
+
format?: string;
|
|
5
|
+
upload?: string;
|
|
6
|
+
requireUpload?: string;
|
|
7
|
+
requireGateway?: string;
|
|
8
|
+
requireApprovalFor?: string;
|
|
9
|
+
changedOnly?: string;
|
|
10
|
+
changedFiles?: string;
|
|
11
|
+
extraPath?: string;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
apiUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function agentCiCommand(args: AgentCiArgs, config: BotGuardConfig): Promise<void>;
|
|
@@ -0,0 +1,418 @@
|
|
|
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.agentCiCommand = agentCiCommand;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
const child_process_1 = require("child_process");
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const config_1 = require("../config");
|
|
42
|
+
const discoverPaths_1 = require("./discoverPaths");
|
|
43
|
+
const discoverAgentFiles_1 = require("./discoverAgentFiles");
|
|
44
|
+
const discoverSecrets_1 = require("./discoverSecrets");
|
|
45
|
+
const discover_1 = require("./discover");
|
|
46
|
+
const SEVERITY_RANK = { low: 0, medium: 1, high: 2, critical: 3 };
|
|
47
|
+
function stableId(parts) {
|
|
48
|
+
return crypto.createHash('sha256').update(parts.join('|')).digest('hex').slice(0, 16);
|
|
49
|
+
}
|
|
50
|
+
function parseJsonFile(filePath) {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function parseTomlMcpServers(content) {
|
|
59
|
+
const servers = {};
|
|
60
|
+
const lines = content.split(/\r?\n/);
|
|
61
|
+
let current = null;
|
|
62
|
+
for (const raw of lines) {
|
|
63
|
+
const line = raw.trim();
|
|
64
|
+
const section = line.match(/^\[mcp_servers\.([^\]]+)\]$/);
|
|
65
|
+
if (section) {
|
|
66
|
+
current = section[1].replace(/^["']|["']$/g, '');
|
|
67
|
+
servers[current] = {};
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (!current || !line || line.startsWith('#'))
|
|
71
|
+
continue;
|
|
72
|
+
const match = line.match(/^([A-Za-z0-9_-]+)\s*=\s*(.+)$/);
|
|
73
|
+
if (!match)
|
|
74
|
+
continue;
|
|
75
|
+
const key = match[1];
|
|
76
|
+
const rawValue = match[2].trim().replace(/,$/, '');
|
|
77
|
+
if (rawValue.startsWith('[')) {
|
|
78
|
+
servers[current][key] = rawValue
|
|
79
|
+
.replace(/^\[|\]$/g, '')
|
|
80
|
+
.split(',')
|
|
81
|
+
.map(part => part.trim().replace(/^["']|["']$/g, ''))
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
servers[current][key] = rawValue.replace(/^["']|["']$/g, '');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return servers;
|
|
89
|
+
}
|
|
90
|
+
function extractServerMap(parsed) {
|
|
91
|
+
if (!parsed || typeof parsed !== 'object')
|
|
92
|
+
return {};
|
|
93
|
+
if (parsed.mcpServers && typeof parsed.mcpServers === 'object')
|
|
94
|
+
return parsed.mcpServers;
|
|
95
|
+
if (parsed.servers && typeof parsed.servers === 'object')
|
|
96
|
+
return parsed.servers;
|
|
97
|
+
if (parsed.mcp?.servers && typeof parsed.mcp.servers === 'object')
|
|
98
|
+
return parsed.mcp.servers;
|
|
99
|
+
if (parsed['mcp.servers'] && typeof parsed['mcp.servers'] === 'object')
|
|
100
|
+
return parsed['mcp.servers'];
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
function riskSignalsForServer(name, server) {
|
|
104
|
+
const text = [
|
|
105
|
+
name,
|
|
106
|
+
server?.command,
|
|
107
|
+
...(Array.isArray(server?.args) ? server.args : []),
|
|
108
|
+
server?.url,
|
|
109
|
+
].filter(Boolean).join(' ').toLowerCase();
|
|
110
|
+
const signals = [
|
|
111
|
+
[/\b(shell|exec|command|terminal|powershell|bash|cmd\.exe)\b/, 'shell'],
|
|
112
|
+
[/\b(file|filesystem|readfile|writefile|directory|path)\b/, 'filesystem'],
|
|
113
|
+
[/\b(database|postgres|mysql|mongo|sql|db)\b/, 'database'],
|
|
114
|
+
[/\b(secret|token|key|password|credential|env)\b/, 'secrets'],
|
|
115
|
+
[/\b(payment|wire|transfer|bank|iban|invoice|billing)\b/, 'payment'],
|
|
116
|
+
[/\b(customer|user|pii|ssn|email|phone|record)\b/, 'pii'],
|
|
117
|
+
[/\b(browser|web|http|fetch|request|webhook)\b/, 'network'],
|
|
118
|
+
[/\b(delete|remove|destroy|drop|wipe|purge|write|update|create)\b/, 'write'],
|
|
119
|
+
];
|
|
120
|
+
return signals.filter(([re]) => re.test(text)).map(([, signal]) => signal);
|
|
121
|
+
}
|
|
122
|
+
function discoverMcpServers(cwd, extraPath) {
|
|
123
|
+
const out = [];
|
|
124
|
+
for (const candidate of (0, discoverPaths_1.discoverScanTargets)(cwd, extraPath)) {
|
|
125
|
+
if (!fs.existsSync(candidate.path))
|
|
126
|
+
continue;
|
|
127
|
+
const isToml = candidate.path.endsWith('.toml');
|
|
128
|
+
const parsed = isToml
|
|
129
|
+
? parseTomlMcpServers(fs.readFileSync(candidate.path, 'utf8'))
|
|
130
|
+
: parseJsonFile(candidate.path);
|
|
131
|
+
const map = extractServerMap(parsed);
|
|
132
|
+
for (const [name, server] of Object.entries(map)) {
|
|
133
|
+
const cfg = server;
|
|
134
|
+
const command = typeof cfg.command === 'string' ? cfg.command : undefined;
|
|
135
|
+
const args = Array.isArray(cfg.args) ? cfg.args.map(String) : [];
|
|
136
|
+
const url = typeof cfg.url === 'string' ? cfg.url : typeof cfg.endpoint === 'string' ? cfg.endpoint : undefined;
|
|
137
|
+
const targetText = [command, ...args, url].filter(Boolean).join(' ');
|
|
138
|
+
const protectedGateway = /fullcourtdefense|agentguard|mcp-gateway|5066|fcd/i.test(targetText);
|
|
139
|
+
out.push({
|
|
140
|
+
name,
|
|
141
|
+
source: candidate.source,
|
|
142
|
+
filePath: candidate.path,
|
|
143
|
+
command,
|
|
144
|
+
args,
|
|
145
|
+
url,
|
|
146
|
+
direct: !protectedGateway,
|
|
147
|
+
protectedGateway,
|
|
148
|
+
riskSignals: riskSignalsForServer(name, cfg),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
function parseRequiredControls(value) {
|
|
155
|
+
return (value || 'payment,delete,shell,secrets')
|
|
156
|
+
.split(',')
|
|
157
|
+
.map(part => part.trim().toLowerCase())
|
|
158
|
+
.filter(Boolean);
|
|
159
|
+
}
|
|
160
|
+
function finding(input) {
|
|
161
|
+
return { ...input, id: stableId([input.category, input.title, input.filePath || '', input.detail]) };
|
|
162
|
+
}
|
|
163
|
+
function normalizeRelativePath(cwd, filePath) {
|
|
164
|
+
if (!filePath)
|
|
165
|
+
return '';
|
|
166
|
+
const absolute = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
167
|
+
return path.relative(cwd, absolute).replace(/\\/g, '/').toLowerCase();
|
|
168
|
+
}
|
|
169
|
+
function parseChangedFilesInput(raw) {
|
|
170
|
+
return (raw || '')
|
|
171
|
+
.split(/\r?\n|,/)
|
|
172
|
+
.map(item => item.trim())
|
|
173
|
+
.filter(Boolean);
|
|
174
|
+
}
|
|
175
|
+
function resolveChangedFiles(cwd, args) {
|
|
176
|
+
if (args.changedOnly !== 'true')
|
|
177
|
+
return null;
|
|
178
|
+
let files = [];
|
|
179
|
+
if (args.changedFiles) {
|
|
180
|
+
const changedFilePath = path.resolve(cwd, args.changedFiles);
|
|
181
|
+
if (fs.existsSync(changedFilePath)) {
|
|
182
|
+
files = parseChangedFilesInput(fs.readFileSync(changedFilePath, 'utf8'));
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
files = parseChangedFilesInput(args.changedFiles);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (files.length === 0)
|
|
189
|
+
files = parseChangedFilesInput(process.env.AGENTGUARD_CHANGED_FILES || process.env.FCD_CHANGED_FILES);
|
|
190
|
+
if (files.length === 0 && process.env.GITHUB_BASE_REF) {
|
|
191
|
+
try {
|
|
192
|
+
files = (0, child_process_1.execFileSync)('git', ['diff', '--name-only', `origin/${process.env.GITHUB_BASE_REF}...HEAD`], { cwd, encoding: 'utf8' })
|
|
193
|
+
.split(/\r?\n/)
|
|
194
|
+
.filter(Boolean);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// The workflow should pass --changed-files; full scan is safer if diff context is unavailable.
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (files.length === 0)
|
|
201
|
+
return null;
|
|
202
|
+
return new Set(files.map(file => normalizeRelativePath(cwd, file)));
|
|
203
|
+
}
|
|
204
|
+
function isChangedFile(cwd, changedFiles, filePath) {
|
|
205
|
+
if (!changedFiles)
|
|
206
|
+
return true;
|
|
207
|
+
return changedFiles.has(normalizeRelativePath(cwd, filePath));
|
|
208
|
+
}
|
|
209
|
+
function agentFileRemediation(tags) {
|
|
210
|
+
const fixes = [];
|
|
211
|
+
if (tags.includes('allows_shell'))
|
|
212
|
+
fixes.push('remove blanket shell/terminal permission or require an explicit command allowlist plus human approval');
|
|
213
|
+
if (tags.includes('broad_filesystem'))
|
|
214
|
+
fixes.push('limit file access to approved project paths and deny secrets/home/system paths');
|
|
215
|
+
if (tags.includes('destructive_actions'))
|
|
216
|
+
fixes.push('require an AgentGuard Action Policy for delete, payment, transfer, email, Slack, or other side-effecting actions');
|
|
217
|
+
if (tags.includes('weak_guardrails'))
|
|
218
|
+
fixes.push('delete bypass language such as always allow, never block, disable security, or skip validation');
|
|
219
|
+
if (tags.includes('embedded_secret_ref'))
|
|
220
|
+
fixes.push('remove inline secret/password/token references and use a managed secret store');
|
|
221
|
+
if (tags.includes('jailbreak_hint'))
|
|
222
|
+
fixes.push('remove jailbreak/bypass instructions and add hierarchy language that system and security policies win');
|
|
223
|
+
if (tags.includes('no_runtime_hook'))
|
|
224
|
+
fixes.push('install the Full Court Defense hook/gateway so risky tool calls are checked before execution');
|
|
225
|
+
if (fixes.length === 0)
|
|
226
|
+
return 'Review the instruction/rule and add explicit least-privilege boundaries.';
|
|
227
|
+
return `Fix this file before merge: ${fixes.join('; ')}.`;
|
|
228
|
+
}
|
|
229
|
+
function evaluateAgentGate(args) {
|
|
230
|
+
const cwd = process.cwd();
|
|
231
|
+
const changedFiles = resolveChangedFiles(cwd, args);
|
|
232
|
+
const mcpServers = discoverMcpServers(cwd, args.extraPath)
|
|
233
|
+
.filter(server => isChangedFile(cwd, changedFiles, server.filePath));
|
|
234
|
+
const agentFiles = (0, discoverAgentFiles_1.scanAgentFiles)({ cwd })
|
|
235
|
+
.filter(file => isChangedFile(cwd, changedFiles, file.filePath));
|
|
236
|
+
const secrets = (0, discoverSecrets_1.scanSecrets)({ cwd, maxEnvDepth: 3 });
|
|
237
|
+
const secretFindings = secrets.findings
|
|
238
|
+
.filter(item => isChangedFile(cwd, changedFiles, item.filePath));
|
|
239
|
+
const requireGateway = args.requireGateway !== 'false';
|
|
240
|
+
const requiredControls = parseRequiredControls(args.requireApprovalFor);
|
|
241
|
+
const findings = [];
|
|
242
|
+
for (const server of mcpServers) {
|
|
243
|
+
if (requireGateway && server.direct && server.riskSignals.length > 0) {
|
|
244
|
+
findings.push(finding({
|
|
245
|
+
severity: server.riskSignals.includes('payment') || server.riskSignals.includes('shell') || server.riskSignals.includes('secrets') ? 'critical' : 'high',
|
|
246
|
+
category: 'mcp',
|
|
247
|
+
title: `Unprotected MCP server: ${server.name}`,
|
|
248
|
+
detail: `${server.source} exposes ${server.riskSignals.join(', ')} without Full Court Defense gateway wrapping.`,
|
|
249
|
+
filePath: server.filePath,
|
|
250
|
+
remediation: 'Wrap this MCP server with fullcourtdefense protect-all or install-mcp-gateway before merging.',
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
const missingControls = server.riskSignals.filter(signal => requiredControls.includes(signal));
|
|
254
|
+
if (missingControls.length > 0 && server.direct) {
|
|
255
|
+
findings.push(finding({
|
|
256
|
+
severity: 'high',
|
|
257
|
+
category: 'policy',
|
|
258
|
+
title: `Missing approval policy evidence for ${server.name}`,
|
|
259
|
+
detail: `Risky tool signals need approval/block policy before merge: ${missingControls.join(', ')}.`,
|
|
260
|
+
filePath: server.filePath,
|
|
261
|
+
remediation: 'Add an AgentGuard action policy requiring approval/block for this tool class, then route through the gateway.',
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
for (const file of agentFiles.filter(item => item.riskTags.length > 0)) {
|
|
266
|
+
findings.push(finding({
|
|
267
|
+
severity: file.riskTags.includes('allows_shell') || file.riskTags.includes('broad_filesystem') ? 'high' : 'medium',
|
|
268
|
+
category: 'agent-file',
|
|
269
|
+
title: `Risky agent instruction: ${file.title}`,
|
|
270
|
+
detail: `${file.filePath} contains agent risk tags: ${file.riskTags.join(', ')}.`,
|
|
271
|
+
filePath: file.filePath,
|
|
272
|
+
remediation: agentFileRemediation(file.riskTags),
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
for (const secret of secretFindings.filter(item => item.severity === 'critical' || item.severity === 'high')) {
|
|
276
|
+
findings.push(finding({
|
|
277
|
+
severity: secret.severity === 'critical' ? 'critical' : 'high',
|
|
278
|
+
category: 'secret',
|
|
279
|
+
title: secret.title,
|
|
280
|
+
detail: secret.detail,
|
|
281
|
+
filePath: secret.filePath,
|
|
282
|
+
remediation: secret.remediation,
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
let score = 100;
|
|
286
|
+
for (const item of findings) {
|
|
287
|
+
score -= item.severity === 'critical' ? 25 : item.severity === 'high' ? 12 : item.severity === 'medium' ? 5 : 2;
|
|
288
|
+
}
|
|
289
|
+
return { findings: findings.sort((a, b) => SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity]), score: Math.max(0, score), mcpServers };
|
|
290
|
+
}
|
|
291
|
+
function shouldFail(findings, failOn) {
|
|
292
|
+
return findings.some(item => SEVERITY_RANK[item.severity] >= SEVERITY_RANK[failOn]);
|
|
293
|
+
}
|
|
294
|
+
function toSarif(findings) {
|
|
295
|
+
return {
|
|
296
|
+
version: '2.1.0',
|
|
297
|
+
$schema: 'https://json.schemastore.org/sarif-2.1.0.json',
|
|
298
|
+
runs: [{
|
|
299
|
+
tool: {
|
|
300
|
+
driver: {
|
|
301
|
+
name: 'Full Court Defense Agent CI Gate',
|
|
302
|
+
informationUri: 'https://fullcourtdefense.ai',
|
|
303
|
+
rules: findings.map(item => ({
|
|
304
|
+
id: item.id,
|
|
305
|
+
name: item.title,
|
|
306
|
+
shortDescription: { text: item.title },
|
|
307
|
+
fullDescription: { text: item.detail },
|
|
308
|
+
help: { text: item.remediation },
|
|
309
|
+
defaultConfiguration: {
|
|
310
|
+
level: item.severity === 'critical' || item.severity === 'high' ? 'error' : item.severity === 'medium' ? 'warning' : 'note',
|
|
311
|
+
},
|
|
312
|
+
})),
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
results: findings.map(item => ({
|
|
316
|
+
ruleId: item.id,
|
|
317
|
+
level: item.severity === 'critical' || item.severity === 'high' ? 'error' : item.severity === 'medium' ? 'warning' : 'note',
|
|
318
|
+
message: { text: `${item.title}: ${item.detail}` },
|
|
319
|
+
locations: item.filePath ? [{
|
|
320
|
+
physicalLocation: {
|
|
321
|
+
artifactLocation: { uri: path.relative(process.cwd(), item.filePath).replace(/\\/g, '/') },
|
|
322
|
+
region: { startLine: 1 },
|
|
323
|
+
},
|
|
324
|
+
}] : [],
|
|
325
|
+
})),
|
|
326
|
+
}],
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function printSummary(report, failed, failOn) {
|
|
330
|
+
console.log(`Agent CI Gate: ${failed ? 'FAIL' : 'PASS'}`);
|
|
331
|
+
console.log(`Score: ${report.score}/100`);
|
|
332
|
+
console.log(`MCP servers: ${report.mcpServers.length}`);
|
|
333
|
+
console.log(`Findings: ${report.findings.length} (fail-on: ${failOn})`);
|
|
334
|
+
for (const item of report.findings.slice(0, 20)) {
|
|
335
|
+
console.log(`- [${item.severity.toUpperCase()}] ${item.title}`);
|
|
336
|
+
console.log(` ${item.detail}`);
|
|
337
|
+
if (item.filePath)
|
|
338
|
+
console.log(` ${path.relative(process.cwd(), item.filePath)}`);
|
|
339
|
+
}
|
|
340
|
+
if (report.findings.length > 20)
|
|
341
|
+
console.log(`... and ${report.findings.length - 20} more findings`);
|
|
342
|
+
}
|
|
343
|
+
function buildCiMetadata() {
|
|
344
|
+
return {
|
|
345
|
+
provider: process.env.GITHUB_ACTIONS === 'true' ? 'github_actions' : process.env.CI ? 'ci' : undefined,
|
|
346
|
+
repository: process.env.GITHUB_REPOSITORY,
|
|
347
|
+
ref: process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || process.env.GITHUB_REF,
|
|
348
|
+
sha: process.env.GITHUB_SHA,
|
|
349
|
+
runId: process.env.GITHUB_RUN_ID,
|
|
350
|
+
runUrl: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY && process.env.GITHUB_RUN_ID
|
|
351
|
+
? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
|
|
352
|
+
: undefined,
|
|
353
|
+
workflow: process.env.GITHUB_WORKFLOW,
|
|
354
|
+
job: process.env.GITHUB_JOB,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
async function agentCiCommand(args, config) {
|
|
358
|
+
const failOn = (['critical', 'high', 'medium', 'low'].includes(String(args.failOn || '').toLowerCase())
|
|
359
|
+
? String(args.failOn).toLowerCase()
|
|
360
|
+
: 'high');
|
|
361
|
+
const format = (['summary', 'json', 'sarif'].includes(String(args.format || '').toLowerCase())
|
|
362
|
+
? String(args.format).toLowerCase()
|
|
363
|
+
: 'summary');
|
|
364
|
+
const report = evaluateAgentGate(args);
|
|
365
|
+
const failed = shouldFail(report.findings, failOn);
|
|
366
|
+
if (format === 'json') {
|
|
367
|
+
console.log(JSON.stringify({ ...report, failed, failOn }, null, 2));
|
|
368
|
+
}
|
|
369
|
+
else if (format === 'sarif') {
|
|
370
|
+
console.log(JSON.stringify(toSarif(report.findings), null, 2));
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
printSummary(report, failed, failOn);
|
|
374
|
+
}
|
|
375
|
+
const uploadRequested = args.upload === 'true' || args.requireUpload === 'true';
|
|
376
|
+
if (uploadRequested) {
|
|
377
|
+
const creds = (0, config_1.resolveCliCredentials)(config, { apiKey: args.apiKey, apiUrl: args.apiUrl });
|
|
378
|
+
if (creds.apiKey || (creds.shieldId && creds.shieldKey)) {
|
|
379
|
+
try {
|
|
380
|
+
await (0, discover_1.runDiscoverUpload)({
|
|
381
|
+
apiKey: args.apiKey,
|
|
382
|
+
apiUrl: args.apiUrl,
|
|
383
|
+
silent: true,
|
|
384
|
+
connectorName: `Agent CI Gate${process.env.GITHUB_REPOSITORY ? ` · ${process.env.GITHUB_REPOSITORY}` : ''}`,
|
|
385
|
+
agentCiGate: {
|
|
386
|
+
status: failed ? 'fail' : 'pass',
|
|
387
|
+
score: report.score,
|
|
388
|
+
failOn,
|
|
389
|
+
findings: report.findings,
|
|
390
|
+
mcpServers: report.mcpServers.map(server => ({
|
|
391
|
+
name: server.name,
|
|
392
|
+
source: server.source,
|
|
393
|
+
filePath: server.filePath,
|
|
394
|
+
direct: server.direct,
|
|
395
|
+
protectedGateway: server.protectedGateway,
|
|
396
|
+
riskSignals: server.riskSignals,
|
|
397
|
+
})),
|
|
398
|
+
uploadedAt: new Date().toISOString(),
|
|
399
|
+
ci: buildCiMetadata(),
|
|
400
|
+
},
|
|
401
|
+
}, config);
|
|
402
|
+
console.error('AgentGuard evidence upload: uploaded to AI Fleet / discovery posture inventory.');
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
console.error(`AgentGuard evidence upload: failed (${error instanceof Error ? error.message : String(error)})`);
|
|
406
|
+
if (args.requireUpload === 'true')
|
|
407
|
+
process.exit(1);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
console.error('AgentGuard evidence upload: missing credentials. Run fullcourtdefense login or pass FULLCOURTDEFENSE_API_KEY.');
|
|
412
|
+
if (args.requireUpload === 'true')
|
|
413
|
+
process.exit(1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (failed)
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BotGuardConfig } from '../config';
|
|
2
|
+
import { ProtectAllArgs } from './mcpGateway';
|
|
3
|
+
export interface AutoProtectArgs extends ProtectAllArgs {
|
|
4
|
+
install?: string;
|
|
5
|
+
uninstall?: string;
|
|
6
|
+
status?: string;
|
|
7
|
+
intervalMinutes?: string;
|
|
8
|
+
onLogon?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function autoProtectCommand(args: AutoProtectArgs, config: BotGuardConfig): Promise<void>;
|