@secureai-sdk/sdk 1.2.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/README.md +131 -0
- package/dist/bin/mcp-proxy.d.ts +3 -0
- package/dist/bin/mcp-proxy.d.ts.map +1 -0
- package/dist/bin/mcp-proxy.js +27 -0
- package/dist/bin/mcp-proxy.js.map +1 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +145 -0
- package/dist/client.js.map +1 -0
- package/dist/grok-bot.d.ts +28 -0
- package/dist/grok-bot.d.ts.map +1 -0
- package/dist/grok-bot.js +109 -0
- package/dist/grok-bot.js.map +1 -0
- package/dist/guard.d.ts +10 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +115 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-proxy.d.ts +8 -0
- package/dist/mcp-proxy.d.ts.map +1 -0
- package/dist/mcp-proxy.js +111 -0
- package/dist/mcp-proxy.js.map +1 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/vault.d.ts +7 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +45 -0
- package/dist/vault.js.map +1 -0
- package/package.json +46 -0
- package/src/bin/mcp-proxy.ts +27 -0
- package/src/client.ts +177 -0
- package/src/grok-bot.ts +129 -0
- package/src/guard.ts +119 -0
- package/src/index.ts +12 -0
- package/src/mcp-proxy.ts +94 -0
- package/src/types.ts +124 -0
- package/src/vault.ts +47 -0
- package/tsconfig.json +18 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @secureai/sdk
|
|
3
|
+
* Enterprise AI Security, GrokBot Firewall, Agent Action Armor & Reversible PII Vault
|
|
4
|
+
* Powered by AcadmyAI (https://secure.acadmyai.com)
|
|
5
|
+
*/
|
|
6
|
+
export * from "./types";
|
|
7
|
+
export * from "./guard";
|
|
8
|
+
export * from "./vault";
|
|
9
|
+
export * from "./grok-bot";
|
|
10
|
+
export * from "./client";
|
|
11
|
+
export * from "./mcp-proxy";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @secureai/sdk
|
|
4
|
+
* Enterprise AI Security, GrokBot Firewall, Agent Action Armor & Reversible PII Vault
|
|
5
|
+
* Powered by AcadmyAI (https://secure.acadmyai.com)
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./guard"), exports);
|
|
24
|
+
__exportStar(require("./vault"), exports);
|
|
25
|
+
__exportStar(require("./grok-bot"), exports);
|
|
26
|
+
__exportStar(require("./client"), exports);
|
|
27
|
+
__exportStar(require("./mcp-proxy"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB;AACzB,8CAA4B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface MCPProxyOptions {
|
|
2
|
+
targetCommand: string;
|
|
3
|
+
targetArgs: string[];
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
policy?: "read-only-strict" | "standard" | "developer";
|
|
6
|
+
}
|
|
7
|
+
export declare function startMCPProxy(options: MCPProxyOptions): void;
|
|
8
|
+
//# sourceMappingURL=mcp-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-proxy.d.ts","sourceRoot":"","sources":["../src/mcp-proxy.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,kBAAkB,GAAG,UAAU,GAAG,WAAW,CAAC;CACxD;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAgF5D"}
|
|
@@ -0,0 +1,111 @@
|
|
|
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.startMCPProxy = startMCPProxy;
|
|
37
|
+
const child_process_1 = require("child_process");
|
|
38
|
+
const readline = __importStar(require("readline"));
|
|
39
|
+
const SQLI_REGEX = /(?:union\s+select|drop\s+table|delete\s+from|insert\s+into|truncate\s+table|--|\bwaitfor\s+delay\b)/i;
|
|
40
|
+
const TRAVERSAL_REGEX = /(?:\.\.\/|\.\.\\|\/\.env|id_rsa|credentials)/i;
|
|
41
|
+
function startMCPProxy(options) {
|
|
42
|
+
const apiKey = options.apiKey || process.env.SECUREAI_API_KEY;
|
|
43
|
+
if (!apiKey) {
|
|
44
|
+
process.stderr.write("[SecureAI MCP Proxy ERROR]: SECUREAI_API_KEY environment variable is required.\n" +
|
|
45
|
+
"Generate an API key at https://secure.acadmyai.com/console/apikeys\n");
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
process.stderr.write(`[SecureAI MCP Proxy]: Zero-Trust interceptor active for '${options.targetCommand} ${options.targetArgs.join(" ")}'\n`);
|
|
49
|
+
const targetProcess = (0, child_process_1.spawn)(options.targetCommand, options.targetArgs, {
|
|
50
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
51
|
+
env: process.env
|
|
52
|
+
});
|
|
53
|
+
// Intercept Agent -> MCP Target (stdin)
|
|
54
|
+
const rlStdin = readline.createInterface({
|
|
55
|
+
input: process.stdin,
|
|
56
|
+
output: process.stdout,
|
|
57
|
+
terminal: false
|
|
58
|
+
});
|
|
59
|
+
rlStdin.on("line", (line) => {
|
|
60
|
+
if (!line.trim())
|
|
61
|
+
return;
|
|
62
|
+
try {
|
|
63
|
+
const msg = JSON.parse(line);
|
|
64
|
+
if (msg.method === "tools/call") {
|
|
65
|
+
const toolName = msg.params?.name || "";
|
|
66
|
+
const argsStr = JSON.stringify(msg.params?.arguments || {});
|
|
67
|
+
// 1. SQL Injection Parameter Check
|
|
68
|
+
if (SQLI_REGEX.test(argsStr)) {
|
|
69
|
+
process.stderr.write(`[SecureAI MCP BLOCKED]: SQL Injection detected in tool '${toolName}' arguments.\n`);
|
|
70
|
+
const blockedResp = {
|
|
71
|
+
jsonrpc: "2.0",
|
|
72
|
+
id: msg.id,
|
|
73
|
+
error: {
|
|
74
|
+
code: -32000,
|
|
75
|
+
message: `SecureAI Policy Block: SQL Injection signature detected in parameters for tool '${toolName}'.`
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
process.stdout.write(JSON.stringify(blockedResp) + "\n");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// 2. Path Traversal & Sensitive File Access Check
|
|
82
|
+
if (TRAVERSAL_REGEX.test(argsStr)) {
|
|
83
|
+
process.stderr.write(`[SecureAI MCP BLOCKED]: Path traversal or secret file access detected in tool '${toolName}'.\n`);
|
|
84
|
+
const blockedResp = {
|
|
85
|
+
jsonrpc: "2.0",
|
|
86
|
+
id: msg.id,
|
|
87
|
+
error: {
|
|
88
|
+
code: -32000,
|
|
89
|
+
message: `SecureAI Policy Block: Path traversal or unauthorized secret access forbidden in tool '${toolName}'.`
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
process.stdout.write(JSON.stringify(blockedResp) + "\n");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Forward sanitized command to target
|
|
97
|
+
targetProcess.stdin.write(line + "\n");
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
targetProcess.stdin.write(line + "\n");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
// Forward Target MCP -> Agent (stdout)
|
|
104
|
+
targetProcess.stdout.on("data", (chunk) => {
|
|
105
|
+
process.stdout.write(chunk);
|
|
106
|
+
});
|
|
107
|
+
targetProcess.on("exit", (code) => {
|
|
108
|
+
process.exit(code ?? 0);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=mcp-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-proxy.js","sourceRoot":"","sources":["../src/mcp-proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,sCAgFC;AA7FD,iDAAsC;AACtC,mDAAqC;AAErC,MAAM,UAAU,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AAC;QACzC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,uCAAuC;IACvC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAsB,EAAE,EAAE;QACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAmB,EAAE,EAAE;QAC/C,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SecureAI TypeScript SDK Types
|
|
3
|
+
* Enterprise AI Security, GrokBot Firewall, Agent Action Armor & Reversible PII Vault
|
|
4
|
+
*/
|
|
5
|
+
export type ThreatSeverity = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | "INFO";
|
|
6
|
+
export type SecurityAction = "ALLOW" | "BLOCK" | "REWRITE_SAFE" | "STEP_UP_HITL" | "ALLOW_WITH_TOKENIZATION";
|
|
7
|
+
export interface UserSecurityContext {
|
|
8
|
+
userId?: string;
|
|
9
|
+
role?: "admin" | "analyst" | "developer" | "guest";
|
|
10
|
+
department?: string;
|
|
11
|
+
clearanceLevel?: 1 | 2 | 3 | 4 | 5;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PromptInspectionResult {
|
|
15
|
+
isSafe: boolean;
|
|
16
|
+
action: SecurityAction;
|
|
17
|
+
riskScore: number;
|
|
18
|
+
threatDetected?: string | null;
|
|
19
|
+
matchedPatterns: string[];
|
|
20
|
+
sanitizedText: string;
|
|
21
|
+
latencyMs: number;
|
|
22
|
+
quota?: {
|
|
23
|
+
tier: string;
|
|
24
|
+
used: number;
|
|
25
|
+
limit: number;
|
|
26
|
+
remaining: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface BotIngressResult {
|
|
30
|
+
isSafe: boolean;
|
|
31
|
+
sanitizedText: string;
|
|
32
|
+
threatDetected?: string | null;
|
|
33
|
+
riskScore: number;
|
|
34
|
+
latencyMs: number;
|
|
35
|
+
matchedPatterns: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface BotToolResult {
|
|
38
|
+
allowed: boolean;
|
|
39
|
+
toolName: string;
|
|
40
|
+
requiredClearance: number;
|
|
41
|
+
botClearance: number;
|
|
42
|
+
syntheticError?: string | null;
|
|
43
|
+
reason?: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface BotEgressResult {
|
|
46
|
+
isSafe: boolean;
|
|
47
|
+
sanitizedText: string;
|
|
48
|
+
leaksRedacted: number;
|
|
49
|
+
redactedTypes: string[];
|
|
50
|
+
latencyMs: number;
|
|
51
|
+
}
|
|
52
|
+
export interface AgentActionPayload {
|
|
53
|
+
actionType: "EXECUTE_SHELL" | "WRITE_FILE" | "READ_FILE" | "NETWORK_EGRESS";
|
|
54
|
+
target: string;
|
|
55
|
+
command?: string;
|
|
56
|
+
userContext?: UserSecurityContext;
|
|
57
|
+
}
|
|
58
|
+
export interface AgentActionVerdict {
|
|
59
|
+
verdict: SecurityAction;
|
|
60
|
+
isAllowed: boolean;
|
|
61
|
+
riskScore: number;
|
|
62
|
+
threatsDetected: string[];
|
|
63
|
+
rewrittenCommand?: string | null;
|
|
64
|
+
explanation?: string;
|
|
65
|
+
tamperProofSignature?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface PIIVaultResult {
|
|
68
|
+
sanitizedText: string;
|
|
69
|
+
redactedCount: number;
|
|
70
|
+
tokenMap: Record<string, string>;
|
|
71
|
+
}
|
|
72
|
+
export interface ModelScanResult {
|
|
73
|
+
isSafe: boolean;
|
|
74
|
+
verdict: "SAFE" | "BLOCKED" | "MALICIOUS";
|
|
75
|
+
riskScore: number;
|
|
76
|
+
maliciousOpcodes: string[];
|
|
77
|
+
formatDetected: string;
|
|
78
|
+
explanation: string;
|
|
79
|
+
}
|
|
80
|
+
export interface ServiceConfigItem {
|
|
81
|
+
enabled: boolean;
|
|
82
|
+
mode?: string;
|
|
83
|
+
threshold?: number;
|
|
84
|
+
clearanceLevel?: number;
|
|
85
|
+
description?: string;
|
|
86
|
+
[key: string]: any;
|
|
87
|
+
}
|
|
88
|
+
export interface ServicesConfig {
|
|
89
|
+
prompt_injection_guard?: ServiceConfigItem;
|
|
90
|
+
pii_vault?: ServiceConfigItem;
|
|
91
|
+
agent_action_firewall?: ServiceConfigItem;
|
|
92
|
+
mcp_gateway?: ServiceConfigItem;
|
|
93
|
+
bot_firewall?: ServiceConfigItem;
|
|
94
|
+
rag_context_guard?: ServiceConfigItem;
|
|
95
|
+
grounding_scorer?: ServiceConfigItem;
|
|
96
|
+
model_scanner?: ServiceConfigItem;
|
|
97
|
+
canary_vault?: ServiceConfigItem;
|
|
98
|
+
toxicity_filter?: ServiceConfigItem;
|
|
99
|
+
semantic_cache?: ServiceConfigItem;
|
|
100
|
+
redteam_simulator?: ServiceConfigItem;
|
|
101
|
+
aspm_engine?: ServiceConfigItem;
|
|
102
|
+
aibom_generator?: ServiceConfigItem;
|
|
103
|
+
[key: string]: ServiceConfigItem | undefined;
|
|
104
|
+
}
|
|
105
|
+
export interface SecureAIClientOptions {
|
|
106
|
+
apiKey?: string;
|
|
107
|
+
baseUrl?: string;
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
services?: ServicesConfig;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7E,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,cAAc,G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MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,sBAAsB,CAAC,EAAE,iBAAiB,CAAC;IAC3C,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;IAC1C,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,eAAe,CAAC,EAAE,iBAAiB,CAAC;IACpC,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,eAAe,CAAC,EAAE,iBAAiB,CAAC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;CAC9C;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/dist/vault.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PIIVaultResult } from "./types";
|
|
2
|
+
export declare class PIIVault {
|
|
3
|
+
tokenize(text: string): PIIVaultResult;
|
|
4
|
+
detokenize(text: string, tokenMap: Record<string, string>): string;
|
|
5
|
+
}
|
|
6
|
+
export declare const defaultVault: PIIVault;
|
|
7
|
+
//# sourceMappingURL=vault.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAUzC,qBAAa,QAAQ;IACZ,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc;IAyBtC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM;CAQ1E;AAED,eAAO,MAAM,YAAY,UAAiB,CAAC"}
|
package/dist/vault.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultVault = exports.PIIVault = void 0;
|
|
4
|
+
const PII_PATTERNS = [
|
|
5
|
+
{ type: "SSN", regex: /\b\d{3}-\d{2}-\d{4}\b/g },
|
|
6
|
+
{ type: "CREDIT_CARD", regex: /\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})\b/g },
|
|
7
|
+
{ type: "EMAIL", regex: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g },
|
|
8
|
+
{ type: "PHONE", regex: /\b(?:\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g },
|
|
9
|
+
{ type: "API_KEY", regex: /\b(?:sk-[a-zA-Z0-9]{20,}|sec_live_[a-zA-Z0-9]{16,}|ghp_[a-zA-Z0-9]{36,})\b/g }
|
|
10
|
+
];
|
|
11
|
+
class PIIVault {
|
|
12
|
+
tokenize(text) {
|
|
13
|
+
if (!text) {
|
|
14
|
+
return { sanitizedText: "", redactedCount: 0, tokenMap: {} };
|
|
15
|
+
}
|
|
16
|
+
let sanitized = text;
|
|
17
|
+
const tokenMap = {};
|
|
18
|
+
let count = 0;
|
|
19
|
+
for (const { type, regex } of PII_PATTERNS) {
|
|
20
|
+
sanitized = sanitized.replace(regex, (match) => {
|
|
21
|
+
count++;
|
|
22
|
+
const token = `[SEC_${type}_${Math.random().toString(36).substring(2, 8).toUpperCase()}]`;
|
|
23
|
+
tokenMap[token] = match;
|
|
24
|
+
return token;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
sanitizedText: sanitized,
|
|
29
|
+
redactedCount: count,
|
|
30
|
+
tokenMap
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
detokenize(text, tokenMap) {
|
|
34
|
+
if (!text || !tokenMap)
|
|
35
|
+
return text;
|
|
36
|
+
let restored = text;
|
|
37
|
+
for (const [token, original] of Object.entries(tokenMap)) {
|
|
38
|
+
restored = restored.split(token).join(original);
|
|
39
|
+
}
|
|
40
|
+
return restored;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.PIIVault = PIIVault;
|
|
44
|
+
exports.defaultVault = new PIIVault();
|
|
45
|
+
//# sourceMappingURL=vault.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAA2C;IAC3D,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,wBAAwB,EAAE;IAChD,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,iEAAiE,EAAE;IACjG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,sDAAsD,EAAE;IAChF,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gEAAgE,EAAE;IAC1F,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,6EAA6E,EAAE;CAC1G,CAAC;AAEF,MAAa,Q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CACF;AAlCD,4BAkCC;AAEY,QAAA,YAAY,GAAG,IAAI,QAAQ,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@secureai-sdk/sdk",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Enterprise AI Security, GrokBot & Agent Runtime Firewall, In-Process Guardrails, Zero-Trust MCP Proxy & Reversible PII Vault SDK by AcadmyAI",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"secureai-mcp-proxy": "dist/bin/mcp-proxy.js",
|
|
9
|
+
"secureai-guard": "dist/bin/mcp-proxy.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"clean": "rm -rf dist",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"ai-security",
|
|
18
|
+
"guardrails",
|
|
19
|
+
"prompt-injection",
|
|
20
|
+
"grok-bot",
|
|
21
|
+
"agent-firewall",
|
|
22
|
+
"mcp-proxy",
|
|
23
|
+
"model-context-protocol",
|
|
24
|
+
"pii-vault",
|
|
25
|
+
"claude-code",
|
|
26
|
+
"cursor-ai"
|
|
27
|
+
],
|
|
28
|
+
"author": "AcadmyAI <acadmyaiorg@gmail.com>",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/nickmudit/secure_acadmyai.git",
|
|
33
|
+
"directory": "sdk/typescript"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://secure.acadmyai.com",
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.4.0",
|
|
44
|
+
"@types/node": "^20.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { startMCPProxy } from "../mcp-proxy";
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
|
|
7
|
+
// Split at '--' if present
|
|
8
|
+
const separatorIndex = args.indexOf("--");
|
|
9
|
+
let targetCommand = "";
|
|
10
|
+
let targetArgs: string[] = [];
|
|
11
|
+
|
|
12
|
+
if (separatorIndex !== -1 && separatorIndex < args.length - 1) {
|
|
13
|
+
targetCommand = args[separatorIndex + 1];
|
|
14
|
+
targetArgs = args.slice(separatorIndex + 2);
|
|
15
|
+
} else if (args.length > 0) {
|
|
16
|
+
targetCommand = args[0];
|
|
17
|
+
targetArgs = args.slice(1);
|
|
18
|
+
} else {
|
|
19
|
+
console.error("Usage: secureai-mcp-proxy -- <command> [args...]");
|
|
20
|
+
console.error("Example: secureai-mcp-proxy -- npx -y @modelcontextprotocol/server-postgres postgresql://...");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
startMCPProxy({
|
|
25
|
+
targetCommand,
|
|
26
|
+
targetArgs
|
|
27
|
+
});
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PromptInspectionResult,
|
|
3
|
+
AgentActionVerdict,
|
|
4
|
+
PIIVaultResult,
|
|
5
|
+
ModelScanResult,
|
|
6
|
+
ServicesConfig,
|
|
7
|
+
SecureAIClientOptions,
|
|
8
|
+
UserSecurityContext
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
export class SecureAI {
|
|
12
|
+
private apiKey: string;
|
|
13
|
+
private baseUrl: string;
|
|
14
|
+
private timeoutMs: number;
|
|
15
|
+
|
|
16
|
+
constructor(options: SecureAIClientOptions = {}) {
|
|
17
|
+
this.apiKey = options.apiKey || process.env.SECUREAI_API_KEY || "";
|
|
18
|
+
if (!this.apiKey) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"SecureAI Authentication Required: No API key provided. " +
|
|
21
|
+
"Pass { apiKey: 'sec_live_...' } or set SECUREAI_API_KEY environment variable. " +
|
|
22
|
+
"Create a key at https://secure.acadmyai.com/console/apikeys"
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
this.baseUrl = (options.baseUrl || process.env.SECUREAI_BASE_URL || "https://secure.acadmyai.com/v1").replace(/\/$/, "");
|
|
26
|
+
this.timeoutMs = options.timeoutMs || 10000;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
|
|
30
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
31
|
+
const controller = new AbortController();
|
|
32
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetch(url, {
|
|
36
|
+
...options,
|
|
37
|
+
signal: controller.signal,
|
|
38
|
+
headers: {
|
|
39
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"User-Agent": "@secureai/sdk-node/1.2.0",
|
|
42
|
+
...(options.headers || {})
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (response.status === 401) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"SecureAI Authentication Error (401): Invalid or unauthorized API key. " +
|
|
49
|
+
"Generate a valid key at https://secure.acadmyai.com/console/apikeys"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (response.status === 429) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"SecureAI Rate/Quota Error (429): Monthly gateway scan limit reached. " +
|
|
56
|
+
"Upgrade your plan at https://secure.acadmyai.com/console/billing"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const errorText = await response.text();
|
|
62
|
+
throw new Error(`SecureAI Gateway Error (${response.status}): ${errorText}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (await response.json()) as T;
|
|
66
|
+
} finally {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Inspects prompt for injections, jailbreaks, and toxicity.
|
|
73
|
+
*/
|
|
74
|
+
public async inspect(prompt: string, context?: UserSecurityContext): Promise<PromptInspectionResult> {
|
|
75
|
+
return this.request<PromptInspectionResult>("/guard/inspect", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
prompt,
|
|
79
|
+
user_id: context?.userId,
|
|
80
|
+
role: context?.role,
|
|
81
|
+
department: context?.department,
|
|
82
|
+
clearance_level: context?.clearanceLevel
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Intercepts agent shell commands and actions with safe auto-rewriting.
|
|
89
|
+
*/
|
|
90
|
+
public async interceptAgentAction(
|
|
91
|
+
actionType: "EXECUTE_SHELL" | "WRITE_FILE" | "READ_FILE" | "NETWORK_EGRESS",
|
|
92
|
+
target: string,
|
|
93
|
+
command?: string,
|
|
94
|
+
context?: UserSecurityContext
|
|
95
|
+
): Promise<AgentActionVerdict> {
|
|
96
|
+
return this.request<AgentActionVerdict>("/firewall/agent/intercept", {
|
|
97
|
+
method: "POST",
|
|
98
|
+
body: JSON.stringify({
|
|
99
|
+
action_type: actionType,
|
|
100
|
+
target,
|
|
101
|
+
command,
|
|
102
|
+
user_id: context?.userId,
|
|
103
|
+
role: context?.role,
|
|
104
|
+
clearance_level: context?.clearanceLevel
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Scans serialized ML model weights (.pkl, .pt, .onnx) for remote code execution opcodes.
|
|
111
|
+
*/
|
|
112
|
+
public async scanModel(filename: string, fileContentBase64: string): Promise<ModelScanResult> {
|
|
113
|
+
return this.request<ModelScanResult>("/scanner/model", {
|
|
114
|
+
method: "POST",
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
filename,
|
|
117
|
+
file_content_base64: fileContentBase64
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Tokenizes PII into synthetic surrogate tokens.
|
|
124
|
+
*/
|
|
125
|
+
public async tokenizePII(text: string): Promise<PIIVaultResult> {
|
|
126
|
+
const res = await this.request<{ sanitized_text: string; redacted_count: number; token_map: Record<string, string> }>(
|
|
127
|
+
"/vault/tokenize",
|
|
128
|
+
{
|
|
129
|
+
method: "POST",
|
|
130
|
+
body: JSON.stringify({ text })
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
return {
|
|
134
|
+
sanitizedText: res.sanitized_text,
|
|
135
|
+
redactedCount: res.redacted_count,
|
|
136
|
+
tokenMap: res.token_map
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Detokenizes synthetic surrogate tokens back to original values.
|
|
142
|
+
*/
|
|
143
|
+
public async detokenizePII(text: string, tokenMap: Record<string, string>): Promise<string> {
|
|
144
|
+
const res = await this.request<{ detokenized_text: string }>("/vault/detokenize", {
|
|
145
|
+
method: "POST",
|
|
146
|
+
body: JSON.stringify({ text, token_map: tokenMap })
|
|
147
|
+
});
|
|
148
|
+
return res.detokenized_text;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Retrieves current Service Capability & Capacity Configuration (SCCM).
|
|
153
|
+
*/
|
|
154
|
+
public async getServicesConfig(): Promise<{ organizationId: string; services: ServicesConfig }> {
|
|
155
|
+
const res = await this.request<{ organization_id: string; services: ServicesConfig }>("/services/config", {
|
|
156
|
+
method: "GET"
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
organizationId: res.organization_id,
|
|
160
|
+
services: res.services
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Updates Service Capability & Capacity Configuration (SCCM).
|
|
166
|
+
*/
|
|
167
|
+
public async updateServicesConfig(services: ServicesConfig): Promise<{ organizationId: string; services: ServicesConfig }> {
|
|
168
|
+
const res = await this.request<{ organization_id: string; services: ServicesConfig }>("/services/config", {
|
|
169
|
+
method: "POST",
|
|
170
|
+
body: JSON.stringify({ services })
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
organizationId: res.organization_id,
|
|
174
|
+
services: res.services
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|