@solongate/proxy 0.47.7 → 0.48.1
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/dist/cli-utils.d.ts +27 -0
- package/dist/config.d.ts +105 -0
- package/dist/core/capability-token.d.ts +46 -0
- package/dist/core/constants.d.ts +47 -0
- package/dist/core/context-boundary.d.ts +19 -0
- package/dist/core/context.d.ts +24 -0
- package/dist/core/errors.d.ts +51 -0
- package/dist/core/execution.d.ts +35 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/input-guard.d.ts +66 -0
- package/dist/core/mcp-types.d.ts +35 -0
- package/dist/core/permissions.d.ts +27 -0
- package/dist/core/policy.d.ts +399 -0
- package/dist/core/response-scanner.d.ts +27 -0
- package/dist/core/schema-validator.d.ts +33 -0
- package/dist/core/tool.d.ts +23 -0
- package/dist/core/trust.d.ts +28 -0
- package/dist/create.d.ts +13 -0
- package/dist/global-install.d.ts +17 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +211 -158
- package/dist/init.d.ts +18 -0
- package/dist/init.js +0 -0
- package/dist/inject.d.ts +19 -0
- package/dist/lib.d.ts +18 -0
- package/dist/lib.js +103 -48
- package/dist/login.d.ts +2 -0
- package/dist/policy-engine/command-matcher.d.ts +34 -0
- package/dist/policy-engine/defaults.d.ts +23 -0
- package/dist/policy-engine/engine.d.ts +30 -0
- package/dist/policy-engine/evaluator.d.ts +13 -0
- package/dist/policy-engine/filename-matcher.d.ts +20 -0
- package/dist/policy-engine/index.d.ts +12 -0
- package/dist/policy-engine/matcher.d.ts +18 -0
- package/dist/policy-engine/opa/index.d.ts +4 -0
- package/dist/policy-engine/opa/json-to-rego.d.ts +2 -0
- package/dist/policy-engine/opa/opa-evaluator.d.ts +10 -0
- package/dist/policy-engine/opa/rego-compiler.d.ts +2 -0
- package/dist/policy-engine/opa/request-adapter.d.ts +17 -0
- package/dist/policy-engine/path-matcher.d.ts +41 -0
- package/dist/policy-engine/policy-store.d.ts +66 -0
- package/dist/policy-engine/url-matcher.d.ts +29 -0
- package/dist/policy-engine/validator.d.ts +7 -0
- package/dist/policy-engine/warnings.d.ts +10 -0
- package/dist/proxy.d.ts +89 -0
- package/dist/pull-push.d.ts +17 -0
- package/dist/sdk/config.d.ts +26 -0
- package/dist/sdk/expiring-set.d.ts +18 -0
- package/dist/sdk/index.d.ts +10 -0
- package/dist/sdk/interceptor.d.ts +45 -0
- package/dist/sdk/logger.d.ts +16 -0
- package/dist/sdk/rate-limiter.d.ts +59 -0
- package/dist/sdk/secure-server.d.ts +68 -0
- package/dist/sdk/server-verifier.d.ts +53 -0
- package/dist/sdk/solongate.d.ts +105 -0
- package/dist/sdk/token-issuer.d.ts +37 -0
- package/dist/sync.d.ts +82 -0
- package/hooks/audit.mjs +3 -1
- package/hooks/guard.bundled.mjs +63 -7
- package/hooks/guard.mjs +75 -14
- package/package.json +15 -13
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared CLI utilities for SolonGate proxy CLI commands.
|
|
3
|
+
* Consolidates banner art, ANSI colors, and log helpers used by init, inject, and create.
|
|
4
|
+
*/
|
|
5
|
+
export declare const c: {
|
|
6
|
+
reset: string;
|
|
7
|
+
bold: string;
|
|
8
|
+
dim: string;
|
|
9
|
+
italic: string;
|
|
10
|
+
white: string;
|
|
11
|
+
gray: string;
|
|
12
|
+
blue1: string;
|
|
13
|
+
blue2: string;
|
|
14
|
+
blue3: string;
|
|
15
|
+
blue4: string;
|
|
16
|
+
blue5: string;
|
|
17
|
+
blue6: string;
|
|
18
|
+
green: string;
|
|
19
|
+
red: string;
|
|
20
|
+
cyan: string;
|
|
21
|
+
yellow: string;
|
|
22
|
+
bgBlue: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function log(msg: string): void;
|
|
25
|
+
export declare const BANNER_FULL: string[];
|
|
26
|
+
export declare const BANNER_COLORS: string[];
|
|
27
|
+
export declare function printBanner(subtitle: string): void;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { PolicySet } from './core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Upstream MCP server connection config.
|
|
4
|
+
*
|
|
5
|
+
* Two modes:
|
|
6
|
+
* - stdio: spawn a child process (command + args)
|
|
7
|
+
* - sse/http: connect to a remote URL
|
|
8
|
+
*/
|
|
9
|
+
export interface UpstreamConfig {
|
|
10
|
+
/** Transport type: stdio (default), sse, or http (StreamableHTTP) */
|
|
11
|
+
transport?: 'stdio' | 'sse' | 'http';
|
|
12
|
+
/** Command to spawn the upstream MCP server (stdio mode) */
|
|
13
|
+
command: string;
|
|
14
|
+
/** Arguments for the command (stdio mode) */
|
|
15
|
+
args?: string[];
|
|
16
|
+
/** Environment variables for the upstream process (stdio mode) */
|
|
17
|
+
env?: Record<string, string>;
|
|
18
|
+
/** Working directory for the upstream process (stdio mode) */
|
|
19
|
+
cwd?: string;
|
|
20
|
+
/** URL of the upstream MCP server (sse/http mode) */
|
|
21
|
+
url?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SolonGate Proxy configuration.
|
|
25
|
+
*/
|
|
26
|
+
export interface ProxyConfig {
|
|
27
|
+
/** Upstream MCP server to protect */
|
|
28
|
+
upstream: UpstreamConfig;
|
|
29
|
+
/** Policy set to enforce (inline or file path) */
|
|
30
|
+
policy: PolicySet;
|
|
31
|
+
/** Proxy display name */
|
|
32
|
+
name?: string;
|
|
33
|
+
/** Enable verbose error messages */
|
|
34
|
+
verbose?: boolean;
|
|
35
|
+
/** Per-tool rate limit (calls per minute) */
|
|
36
|
+
rateLimitPerTool?: number;
|
|
37
|
+
/** Global rate limit (calls per minute) */
|
|
38
|
+
globalRateLimit?: number;
|
|
39
|
+
/** SolonGate Cloud API key for policy sync and audit forwarding */
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
/** SolonGate Cloud API URL (default: https://api.solongate.com) */
|
|
42
|
+
apiUrl?: string;
|
|
43
|
+
/** Port to serve on via HTTP (StreamableHTTP). If omitted, serves on stdio. */
|
|
44
|
+
port?: number;
|
|
45
|
+
/** Resolved absolute path to the policy JSON file (null if cloud-only) */
|
|
46
|
+
policyPath?: string;
|
|
47
|
+
/** Cloud policy ID to fetch (if not set, auto-selects first policy) */
|
|
48
|
+
policyId?: string;
|
|
49
|
+
/** Agent name for trust map identification (from --agent-name flag) */
|
|
50
|
+
agentName?: string;
|
|
51
|
+
}
|
|
52
|
+
export declare const DEFAULT_API_URL = "https://api.solongate.com";
|
|
53
|
+
/**
|
|
54
|
+
* Fetch policy from SolonGate Cloud API.
|
|
55
|
+
* TODO: extract cloud policy parsing to shared module with packages/sdk-ts/src/solongate.ts
|
|
56
|
+
*/
|
|
57
|
+
export declare function fetchCloudPolicy(apiKey: string, apiUrl: string, policyId?: string): Promise<PolicySet>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch a policy's compiled OPA WASM bundle from the cloud. The cloud API
|
|
60
|
+
* compiles every policy version to WASM on save; the proxy evaluates with it
|
|
61
|
+
* (OPA is the sole evaluator — same engine as the airgap product).
|
|
62
|
+
* Returns the WASM bundle bytes, or null if none is available yet.
|
|
63
|
+
*/
|
|
64
|
+
export declare function fetchCloudPolicyWasm(apiKey: string, apiUrl: string, policyId: string): Promise<Uint8Array | null>;
|
|
65
|
+
export interface AuditLogEntry {
|
|
66
|
+
tool: string;
|
|
67
|
+
arguments: Record<string, unknown>;
|
|
68
|
+
decision: 'ALLOW' | 'DENY';
|
|
69
|
+
reason: string;
|
|
70
|
+
permission?: string;
|
|
71
|
+
matchedRule?: string;
|
|
72
|
+
evaluationTimeMs: number;
|
|
73
|
+
/** Agent identity for trust map */
|
|
74
|
+
agent_id?: string;
|
|
75
|
+
agent_name?: string;
|
|
76
|
+
/** Sub-agent identity (within same MCP connection) */
|
|
77
|
+
sub_agent_id?: string;
|
|
78
|
+
sub_agent_name?: string;
|
|
79
|
+
}
|
|
80
|
+
export declare function sendAuditLog(apiKey: string, apiUrl: string, entry: AuditLogEntry): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Load policy from a JSON file path or inline object.
|
|
83
|
+
*/
|
|
84
|
+
export declare function loadPolicy(source: string | PolicySet): PolicySet;
|
|
85
|
+
/**
|
|
86
|
+
* Parse CLI arguments into a ProxyConfig.
|
|
87
|
+
*
|
|
88
|
+
* Usage:
|
|
89
|
+
* solongate-proxy [options] -- <command> [args...]
|
|
90
|
+
*
|
|
91
|
+
* Options:
|
|
92
|
+
* --policy <file> Policy JSON file (default: policy.json or cloud fetch)
|
|
93
|
+
* --name <name> Proxy name (default: solongate-proxy)
|
|
94
|
+
* --verbose Enable verbose errors
|
|
95
|
+
* --rate-limit <n> Per-tool rate limit (calls/min)
|
|
96
|
+
* --global-rate-limit <n> Global rate limit (calls/min)
|
|
97
|
+
* --config <file> Load config from JSON file
|
|
98
|
+
* --api-key <key> SolonGate Cloud API key (enables cloud policy + audit)
|
|
99
|
+
* --api-url <url> SolonGate Cloud API URL (default: https://api.solongate.com)
|
|
100
|
+
* --upstream-url <url> Connect to upstream via URL (SSE or HTTP) instead of stdio
|
|
101
|
+
* --upstream-transport <type> Transport type: stdio (default), sse, http
|
|
102
|
+
* --port <n> Serve downstream on HTTP port (default: stdio)
|
|
103
|
+
* --policy-id <id> Cloud policy ID to use (default: auto-select first)
|
|
104
|
+
*/
|
|
105
|
+
export declare function parseArgs(argv: string[]): ProxyConfig;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Permission } from './permissions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Capability Token: a signed, short-lived, single-use token
|
|
4
|
+
* that authorizes execution of specific tools within specific scopes.
|
|
5
|
+
*
|
|
6
|
+
* Security properties:
|
|
7
|
+
* - Short-lived: TTL defaults to 30 seconds
|
|
8
|
+
* - Single-use: nonce prevents replay attacks
|
|
9
|
+
* - Scoped: limited to specific tools and servers
|
|
10
|
+
* - Signed: HMAC-SHA256 prevents forgery
|
|
11
|
+
*/
|
|
12
|
+
export interface CapabilityToken {
|
|
13
|
+
readonly jti: string;
|
|
14
|
+
readonly iss: string;
|
|
15
|
+
readonly sub: string;
|
|
16
|
+
readonly iat: number;
|
|
17
|
+
readonly exp: number;
|
|
18
|
+
readonly permissions: readonly Permission[];
|
|
19
|
+
readonly toolScope: readonly string[];
|
|
20
|
+
readonly serverScope: readonly string[];
|
|
21
|
+
readonly pathScope?: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for token issuance.
|
|
25
|
+
*/
|
|
26
|
+
export interface TokenConfig {
|
|
27
|
+
readonly secret: string;
|
|
28
|
+
readonly ttlSeconds: number;
|
|
29
|
+
readonly algorithm: 'HS256';
|
|
30
|
+
readonly issuer: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Default token configuration.
|
|
34
|
+
* Secret must be provided - no default.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_TOKEN_TTL_SECONDS = 30;
|
|
37
|
+
export declare const TOKEN_ALGORITHM: "HS256";
|
|
38
|
+
export declare const MIN_SECRET_LENGTH = 32;
|
|
39
|
+
/**
|
|
40
|
+
* Result of token verification.
|
|
41
|
+
*/
|
|
42
|
+
export interface TokenVerificationResult {
|
|
43
|
+
readonly valid: boolean;
|
|
44
|
+
readonly payload?: CapabilityToken;
|
|
45
|
+
readonly reason?: string;
|
|
46
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Default policy effect when no rule matches: DENY */
|
|
2
|
+
export declare const DEFAULT_POLICY_EFFECT: "DENY";
|
|
3
|
+
/** Maximum number of rules in a single PolicySet */
|
|
4
|
+
export declare const MAX_RULES_PER_POLICY_SET = 1000;
|
|
5
|
+
/** Maximum depth for nested argument validation */
|
|
6
|
+
export declare const MAX_ARGUMENT_DEPTH = 10;
|
|
7
|
+
/** Maximum size of tool arguments in bytes */
|
|
8
|
+
export declare const MAX_ARGUMENTS_SIZE_BYTES = 1048576;
|
|
9
|
+
/** Maximum length of a tool name */
|
|
10
|
+
export declare const MAX_TOOL_NAME_LENGTH = 256;
|
|
11
|
+
/** Maximum length of a server name */
|
|
12
|
+
export declare const MAX_SERVER_NAME_LENGTH = 256;
|
|
13
|
+
/** Default rate limit per tool per minute */
|
|
14
|
+
export declare const DEFAULT_RATE_LIMIT_PER_MINUTE = 60;
|
|
15
|
+
/** Maximum rate limit per tool per minute */
|
|
16
|
+
export declare const MAX_RATE_LIMIT_PER_MINUTE = 10000;
|
|
17
|
+
/** Security context timeout in milliseconds (5 minutes) */
|
|
18
|
+
export declare const SECURITY_CONTEXT_TIMEOUT_MS: number;
|
|
19
|
+
/** Policy evaluation timeout in milliseconds (100ms) */
|
|
20
|
+
export declare const POLICY_EVALUATION_TIMEOUT_MS = 100;
|
|
21
|
+
/** Default maximum length per string argument */
|
|
22
|
+
export declare const INPUT_GUARD_MAX_LENGTH = 4096;
|
|
23
|
+
/** Shannon entropy threshold for encoded payload detection */
|
|
24
|
+
export declare const INPUT_GUARD_ENTROPY_THRESHOLD = 4.5;
|
|
25
|
+
/** Minimum string length before entropy check applies */
|
|
26
|
+
export declare const INPUT_GUARD_MIN_ENTROPY_LENGTH = 32;
|
|
27
|
+
/** Maximum wildcards allowed per value */
|
|
28
|
+
export declare const INPUT_GUARD_MAX_WILDCARDS = 3;
|
|
29
|
+
/** Default capability token TTL in seconds */
|
|
30
|
+
export declare const TOKEN_DEFAULT_TTL_SECONDS = 30;
|
|
31
|
+
/** Minimum secret key length for HMAC signing */
|
|
32
|
+
export declare const TOKEN_MIN_SECRET_LENGTH = 32;
|
|
33
|
+
/** Maximum token age before forced expiry (5 minutes) */
|
|
34
|
+
export declare const TOKEN_MAX_AGE_SECONDS = 300;
|
|
35
|
+
/** Default sliding window size in milliseconds (1 minute) */
|
|
36
|
+
export declare const RATE_LIMIT_WINDOW_MS = 60000;
|
|
37
|
+
/** Maximum entries to keep per tool before cleanup */
|
|
38
|
+
export declare const RATE_LIMIT_MAX_ENTRIES = 10000;
|
|
39
|
+
/** Warning messages for unsafe configurations. */
|
|
40
|
+
export declare const UNSAFE_CONFIGURATION_WARNINGS: {
|
|
41
|
+
readonly WILDCARD_ALLOW: "Wildcard ALLOW rules grant permission to ALL tools. This bypasses the default-deny model.";
|
|
42
|
+
readonly TRUSTED_LEVEL_EXTERNAL: "Setting trust level to TRUSTED for external requests bypasses all security checks.";
|
|
43
|
+
readonly WRITE_WITHOUT_READ: "Granting WRITE without READ is unusual and may indicate a misconfiguration.";
|
|
44
|
+
readonly EXECUTE_WITHOUT_REVIEW: "EXECUTE permission allows tools to perform arbitrary actions. Review carefully.";
|
|
45
|
+
readonly RATE_LIMIT_ZERO: "A rate limit of 0 means unlimited calls. This removes protection against runaway loops.";
|
|
46
|
+
readonly DISABLED_VALIDATION: "Disabling schema validation removes input sanitization protections.";
|
|
47
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Boundary Tagging: wraps user-provided tool arguments with
|
|
3
|
+
* boundary markers so the LLM can distinguish user input from system data.
|
|
4
|
+
*
|
|
5
|
+
* This prevents confusion attacks where adversarial input is treated
|
|
6
|
+
* as trusted system instructions.
|
|
7
|
+
*/
|
|
8
|
+
export type TaggedArguments = Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Wraps all string values in the arguments with context boundary markers.
|
|
11
|
+
* Non-string values are passed through unchanged.
|
|
12
|
+
* Objects and arrays are recursively tagged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function tagUserInput(args: Record<string, unknown>): TaggedArguments;
|
|
15
|
+
/**
|
|
16
|
+
* Strips all boundary tags from a string (e.g. from tool responses before
|
|
17
|
+
* returning to client).
|
|
18
|
+
*/
|
|
19
|
+
export declare function stripBoundaryTags(text: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TrustLevel } from './trust.js';
|
|
2
|
+
import type { PermissionSet } from './permissions.js';
|
|
3
|
+
/**
|
|
4
|
+
* SecurityContext represents the security state of a single request.
|
|
5
|
+
* Created fresh for each MCP request and NEVER reused.
|
|
6
|
+
* All fields are readonly - state transitions create new contexts.
|
|
7
|
+
*/
|
|
8
|
+
export interface SecurityContext {
|
|
9
|
+
readonly requestId: string;
|
|
10
|
+
readonly trustLevel: TrustLevel;
|
|
11
|
+
readonly grantedPermissions: PermissionSet;
|
|
12
|
+
readonly sessionId: string | null;
|
|
13
|
+
readonly createdAt: string;
|
|
14
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
15
|
+
readonly capabilityToken?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Extends SecurityContext with tool-specific execution information. */
|
|
18
|
+
export interface ExecutionContext extends SecurityContext {
|
|
19
|
+
readonly toolName: string;
|
|
20
|
+
readonly serverName: string;
|
|
21
|
+
readonly arguments: Readonly<Record<string, unknown>>;
|
|
22
|
+
}
|
|
23
|
+
/** Creates a new SecurityContext with default-deny settings. */
|
|
24
|
+
export declare function createSecurityContext(params: Pick<SecurityContext, 'requestId'> & Partial<Omit<SecurityContext, 'requestId' | 'createdAt' | 'trustLevel' | 'grantedPermissions'>>): SecurityContext;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all SolonGate security errors.
|
|
3
|
+
* Every error includes a machine-readable code for programmatic handling.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SolonGateError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly timestamp: string;
|
|
8
|
+
readonly details: Record<string, unknown>;
|
|
9
|
+
constructor(message: string, code: string, details?: Record<string, unknown>);
|
|
10
|
+
/**
|
|
11
|
+
* Serializable representation for logging and API responses.
|
|
12
|
+
* Never includes stack traces (information leakage prevention).
|
|
13
|
+
*/
|
|
14
|
+
toJSON(): Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/** Thrown when a tool call is denied by policy. */
|
|
17
|
+
export declare class PolicyDeniedError extends SolonGateError {
|
|
18
|
+
constructor(toolName: string, reason: string, details?: Record<string, unknown>);
|
|
19
|
+
}
|
|
20
|
+
/** Thrown when a trust level escalation is attempted illegally. */
|
|
21
|
+
export declare class TrustEscalationError extends SolonGateError {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
/** Thrown when tool input fails schema validation. */
|
|
25
|
+
export declare class SchemaValidationError extends SolonGateError {
|
|
26
|
+
constructor(toolName: string, validationErrors: readonly string[]);
|
|
27
|
+
}
|
|
28
|
+
/** Thrown when a tool exceeds its rate limit. */
|
|
29
|
+
export declare class RateLimitError extends SolonGateError {
|
|
30
|
+
constructor(toolName: string, limitPerMinute: number);
|
|
31
|
+
}
|
|
32
|
+
/** Thrown when a tool is not found in the registry. */
|
|
33
|
+
export declare class ToolNotFoundError extends SolonGateError {
|
|
34
|
+
constructor(toolName: string, serverName: string);
|
|
35
|
+
}
|
|
36
|
+
/** Thrown when an unsafe configuration is detected. */
|
|
37
|
+
export declare class UnsafeConfigurationError extends SolonGateError {
|
|
38
|
+
constructor(message: string, field: string);
|
|
39
|
+
}
|
|
40
|
+
/** Thrown when input guard detects dangerous patterns. */
|
|
41
|
+
export declare class InputGuardError extends SolonGateError {
|
|
42
|
+
constructor(toolName: string, threats: readonly {
|
|
43
|
+
type: string;
|
|
44
|
+
field: string;
|
|
45
|
+
description: string;
|
|
46
|
+
}[]);
|
|
47
|
+
}
|
|
48
|
+
/** Thrown when a network operation fails (API calls, cloud sync, etc.). */
|
|
49
|
+
export declare class NetworkError extends SolonGateError {
|
|
50
|
+
constructor(operation: string, statusCode?: number, details?: Record<string, unknown>);
|
|
51
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SecurityContext } from './context.js';
|
|
2
|
+
import type { Permission } from './permissions.js';
|
|
3
|
+
import type { PolicyDecision } from './policy.js';
|
|
4
|
+
import type { SolonGateError } from './errors.js';
|
|
5
|
+
/** An execution request represents a tool call that needs security evaluation. */
|
|
6
|
+
export interface ExecutionRequest {
|
|
7
|
+
readonly context: SecurityContext;
|
|
8
|
+
readonly toolName: string;
|
|
9
|
+
readonly serverName: string;
|
|
10
|
+
readonly arguments: Readonly<Record<string, unknown>>;
|
|
11
|
+
readonly requiredPermission: Permission;
|
|
12
|
+
readonly timestamp: string;
|
|
13
|
+
}
|
|
14
|
+
/** Discriminated union on `status` for exhaustive matching. */
|
|
15
|
+
export type ExecutionResult = ExecutionResultAllowed | ExecutionResultDenied | ExecutionResultError;
|
|
16
|
+
export interface ExecutionResultAllowed {
|
|
17
|
+
readonly status: 'ALLOWED';
|
|
18
|
+
readonly request: ExecutionRequest;
|
|
19
|
+
readonly decision: PolicyDecision;
|
|
20
|
+
readonly toolResult: unknown;
|
|
21
|
+
readonly durationMs: number;
|
|
22
|
+
readonly timestamp: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ExecutionResultDenied {
|
|
25
|
+
readonly status: 'DENIED';
|
|
26
|
+
readonly request: ExecutionRequest;
|
|
27
|
+
readonly decision: PolicyDecision;
|
|
28
|
+
readonly timestamp: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ExecutionResultError {
|
|
31
|
+
readonly status: 'ERROR';
|
|
32
|
+
readonly request: ExecutionRequest;
|
|
33
|
+
readonly error: SolonGateError;
|
|
34
|
+
readonly timestamp: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { TrustLevel, isValidTrustLevel, assertValidTransition } from './trust.js';
|
|
2
|
+
export { Permission, PermissionSchema, type PermissionSet, createPermissionSet, hasPermission, hasAllPermissions, permissionForMethod, guessPermission, NO_PERMISSIONS, READ_ONLY, } from './permissions.js';
|
|
3
|
+
export { PolicyEffect, type PolicyRule, type PolicySet, type PolicyDecision, PolicyRuleSchema, PolicySetSchema, } from './policy.js';
|
|
4
|
+
export { type ToolCapability, createToolCapability, } from './tool.js';
|
|
5
|
+
export { type SecurityContext, type ExecutionContext, createSecurityContext, } from './context.js';
|
|
6
|
+
export { type ExecutionRequest, type ExecutionResult, type ExecutionResultAllowed, type ExecutionResultDenied, type ExecutionResultError, } from './execution.js';
|
|
7
|
+
export { SolonGateError, PolicyDeniedError, TrustEscalationError, SchemaValidationError, RateLimitError, ToolNotFoundError, UnsafeConfigurationError, InputGuardError, NetworkError, } from './errors.js';
|
|
8
|
+
export * from './constants.js';
|
|
9
|
+
export { type McpToolDefinition, type McpCallToolParams, type McpCallToolResult, type McpToolResultContent, createDeniedToolResult, } from './mcp-types.js';
|
|
10
|
+
export { validateToolInput, createStrictSchema, type SchemaValidationResult, type SchemaValidatorOptions, } from './schema-validator.js';
|
|
11
|
+
export { detectPathTraversal, detectShellInjection, detectWildcardAbuse, detectSSRF, detectSQLInjection, detectExfiltration, detectBoundaryEscape, checkLengthLimits, checkEntropyLimits, sanitizeInput, sanitizeInputAsync, DEFAULT_INPUT_GUARD_CONFIG, BOUNDARY_PREFIX, BOUNDARY_SUFFIX, type ThreatType, type DetectedThreat, type SanitizationResult, type AsyncSanitizationResult, type InputGuardConfig, } from './input-guard.js';
|
|
12
|
+
export { scanResponse, RESPONSE_WARNING_MARKER, DEFAULT_RESPONSE_SCAN_CONFIG, type ResponseThreatType, type ResponseThreat, type ResponseScanResult, type ResponseScanConfig, } from './response-scanner.js';
|
|
13
|
+
export { tagUserInput, stripBoundaryTags, type TaggedArguments, } from './context-boundary.js';
|
|
14
|
+
export { type CapabilityToken, type TokenConfig, type TokenVerificationResult, DEFAULT_TOKEN_TTL_SECONDS, TOKEN_ALGORITHM, MIN_SECRET_LENGTH, } from './capability-token.js';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Guard: detects and blocks dangerous patterns in tool arguments.
|
|
3
|
+
*
|
|
4
|
+
* Prevents physical execution of injected instructions by checking for:
|
|
5
|
+
* - Path traversal attacks (../, ..\, encoded variants)
|
|
6
|
+
* - Shell injection (;, |, &, `, $(), etc.)
|
|
7
|
+
* - Wildcard abuse (**, recursive globs)
|
|
8
|
+
* - Excessive length
|
|
9
|
+
* - High-entropy payloads (potential encoded exploits)
|
|
10
|
+
*/
|
|
11
|
+
/** Threat type detected by input guard. */
|
|
12
|
+
export type ThreatType = 'PATH_TRAVERSAL' | 'SHELL_INJECTION' | 'WILDCARD_ABUSE' | 'LENGTH_EXCEEDED' | 'HIGH_ENTROPY' | 'SSRF' | 'SQL_INJECTION' | 'PROMPT_INJECTION' | 'EXFILTRATION' | 'BOUNDARY_ESCAPE';
|
|
13
|
+
/** A detected threat with details. */
|
|
14
|
+
export interface DetectedThreat {
|
|
15
|
+
readonly type: ThreatType;
|
|
16
|
+
readonly field: string;
|
|
17
|
+
readonly value: string;
|
|
18
|
+
readonly description: string;
|
|
19
|
+
}
|
|
20
|
+
/** Result of sanitization check. */
|
|
21
|
+
export interface SanitizationResult {
|
|
22
|
+
readonly safe: boolean;
|
|
23
|
+
readonly threats: readonly DetectedThreat[];
|
|
24
|
+
}
|
|
25
|
+
/** Configuration for input guard checks. */
|
|
26
|
+
export interface InputGuardConfig {
|
|
27
|
+
readonly pathTraversal: boolean;
|
|
28
|
+
readonly shellInjection: boolean;
|
|
29
|
+
readonly wildcardAbuse: boolean;
|
|
30
|
+
readonly lengthLimit: number;
|
|
31
|
+
readonly entropyLimit: boolean;
|
|
32
|
+
readonly ssrf: boolean;
|
|
33
|
+
readonly sqlInjection: boolean;
|
|
34
|
+
readonly exfiltration: boolean;
|
|
35
|
+
readonly boundaryEscape: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const DEFAULT_INPUT_GUARD_CONFIG: Readonly<InputGuardConfig>;
|
|
38
|
+
export declare function detectPathTraversal(value: string): boolean;
|
|
39
|
+
export declare function detectShellInjection(value: string): boolean;
|
|
40
|
+
export declare function detectWildcardAbuse(value: string): boolean;
|
|
41
|
+
export declare function detectSSRF(value: string): boolean;
|
|
42
|
+
export declare function detectSQLInjection(value: string): boolean;
|
|
43
|
+
export declare function detectExfiltration(value: string): boolean;
|
|
44
|
+
/** Context boundary markers used by SolonGate. */
|
|
45
|
+
export declare const BOUNDARY_PREFIX = "[USER_INPUT_START]";
|
|
46
|
+
export declare const BOUNDARY_SUFFIX = "[USER_INPUT_END]";
|
|
47
|
+
export declare function detectBoundaryEscape(value: string): boolean;
|
|
48
|
+
export declare function checkLengthLimits(value: string, maxLength?: number): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Detects high-entropy strings that may indicate encoded payloads.
|
|
51
|
+
* Uses Shannon entropy calculation.
|
|
52
|
+
* Threshold: 4.5 bits per character (base64 encoded data is ~6.0).
|
|
53
|
+
*/
|
|
54
|
+
export declare function checkEntropyLimits(value: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Runs all input guard checks on a value.
|
|
57
|
+
* Returns structured result with all detected threats.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sanitizeInput(field: string, value: unknown, config?: InputGuardConfig): SanitizationResult;
|
|
60
|
+
/** Async result shape (kept for API compatibility; same as the sync result). */
|
|
61
|
+
export type AsyncSanitizationResult = SanitizationResult;
|
|
62
|
+
/**
|
|
63
|
+
* Async wrapper around sanitizeInput(). Kept async so callers (the proxy) can
|
|
64
|
+
* await it uniformly; the deterministic checks run synchronously.
|
|
65
|
+
*/
|
|
66
|
+
export declare function sanitizeInputAsync(field: string, value: unknown, config?: InputGuardConfig): Promise<AsyncSanitizationResult>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types that bridge between the MCP protocol and SolonGate's type system.
|
|
3
|
+
* Adapts MCP SDK types without creating a hard dependency.
|
|
4
|
+
*/
|
|
5
|
+
export interface McpToolDefinition {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly description?: string;
|
|
8
|
+
readonly inputSchema: {
|
|
9
|
+
readonly type: 'object';
|
|
10
|
+
readonly properties?: Record<string, unknown>;
|
|
11
|
+
readonly required?: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface McpCallToolParams {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly arguments?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface McpCallToolResult {
|
|
19
|
+
readonly content: readonly McpToolResultContent[];
|
|
20
|
+
readonly isError?: boolean;
|
|
21
|
+
readonly structuredContent?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export type McpToolResultContent = {
|
|
24
|
+
readonly type: 'text';
|
|
25
|
+
readonly text: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: 'image';
|
|
28
|
+
readonly data: string;
|
|
29
|
+
readonly mimeType: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly type: 'resource';
|
|
32
|
+
readonly resource: unknown;
|
|
33
|
+
};
|
|
34
|
+
/** Wraps denied tool calls in MCP error responses. */
|
|
35
|
+
export declare function createDeniedToolResult(reason: string): McpCallToolResult;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Permission types are ALWAYS evaluated independently.
|
|
4
|
+
* Having READ does NOT imply WRITE or EXECUTE.
|
|
5
|
+
*/
|
|
6
|
+
export declare const Permission: {
|
|
7
|
+
readonly READ: "READ";
|
|
8
|
+
readonly WRITE: "WRITE";
|
|
9
|
+
readonly EXECUTE: "EXECUTE";
|
|
10
|
+
readonly NETWORK: "NETWORK";
|
|
11
|
+
};
|
|
12
|
+
export type Permission = (typeof Permission)[keyof typeof Permission];
|
|
13
|
+
export declare const PermissionSchema: z.ZodEnum<["READ", "WRITE", "EXECUTE", "NETWORK"]>;
|
|
14
|
+
/** Guess the permission type from a tool name. */
|
|
15
|
+
export declare function guessPermission(toolName: string): Permission;
|
|
16
|
+
/** Immutable set of permissions granted to a specific scope. */
|
|
17
|
+
export type PermissionSet = ReadonlySet<Permission>;
|
|
18
|
+
/** Creates an immutable permission set from an array. */
|
|
19
|
+
export declare function createPermissionSet(permissions: Permission[]): PermissionSet;
|
|
20
|
+
/** Empty permission set - the default for all new tools (default-deny). */
|
|
21
|
+
export declare const NO_PERMISSIONS: PermissionSet;
|
|
22
|
+
/** Read-only permission set - the maximum default for new tools. */
|
|
23
|
+
export declare const READ_ONLY: PermissionSet;
|
|
24
|
+
export declare function hasPermission(permissions: PermissionSet, required: Permission): boolean;
|
|
25
|
+
export declare function hasAllPermissions(permissions: PermissionSet, required: Permission[]): boolean;
|
|
26
|
+
/** Maps MCP protocol methods to SolonGate permission types. */
|
|
27
|
+
export declare function permissionForMethod(method: string): Permission;
|