@kortix/agent-tunnel 0.1.2 → 0.1.4

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.
@@ -0,0 +1,140 @@
1
+ interface TunnelConfig {
2
+ token: string;
3
+ tunnelId: string;
4
+ apiUrl: string;
5
+ wsPath: string;
6
+ maxFileSize: number;
7
+ allowedPaths: string[];
8
+ allowedCommands: string[];
9
+ blockedCommands: string[];
10
+ blockedPaths: string[];
11
+ workingDir: string;
12
+ shellTimeout: number;
13
+ shellMaxTimeout: number;
14
+ shellMaxOutputSize: number;
15
+ shellEnvPassthrough: string[];
16
+ }
17
+ declare function loadConfig(overrides?: Partial<TunnelConfig>): TunnelConfig;
18
+
19
+ /**
20
+ * Capability Registry — extensible registry for tunnel capabilities.
21
+ *
22
+ * Each capability (filesystem, shell, network, etc.) registers its
23
+ * RPC method handlers here. The TunnelAgent dispatches incoming
24
+ * JSON-RPC requests to the matching handler.
25
+ */
26
+ type RpcHandler = (params: Record<string, unknown>) => Promise<unknown>;
27
+ interface Capability {
28
+ name: string;
29
+ methods: Map<string, RpcHandler>;
30
+ }
31
+ declare class CapabilityRegistry {
32
+ private capabilities;
33
+ register(capability: Capability): void;
34
+ unregister(name: string): void;
35
+ getHandler(method: string): RpcHandler | null;
36
+ getCapabilityNames(): string[];
37
+ has(name: string): boolean;
38
+ }
39
+
40
+ declare class TunnelAgent {
41
+ private ws;
42
+ private registry;
43
+ private permissionGuard;
44
+ private config;
45
+ private reconnectAttempts;
46
+ private maxReconnectDelay;
47
+ private baseReconnectDelay;
48
+ private reconnectTimer;
49
+ private isShuttingDown;
50
+ private uptime;
51
+ private uptimeInterval;
52
+ private signingKey;
53
+ private lastNonce;
54
+ private responseNonce;
55
+ constructor(config: TunnelConfig, registry: CapabilityRegistry);
56
+ connect(): void;
57
+ disconnect(): void;
58
+ isConnected(): boolean;
59
+ private setupWsHandlers;
60
+ private handleMessage;
61
+ /**
62
+ * Verify HMAC signature on incoming messages (excluding pings).
63
+ */
64
+ private verifyIncomingSignature;
65
+ private handleRpcRequest;
66
+ /** Send HMAC-signed RPC result. */
67
+ private sendSignedResult;
68
+ /** Send HMAC-signed RPC error. */
69
+ private sendSignedError;
70
+ private sendSigned;
71
+ private send;
72
+ private sendPong;
73
+ private scheduleReconnect;
74
+ private buildWsUrl;
75
+ }
76
+
77
+ /**
78
+ * Filesystem Capability — handles fs.read, fs.write, fs.list, fs.stat, fs.delete.
79
+ *
80
+ * All operations go through local-side path validation (defense in depth)
81
+ * even though the server already validates permissions.
82
+ */
83
+
84
+ declare function createFilesystemCapability(config: TunnelConfig): Capability;
85
+
86
+ /**
87
+ * Shell Capability — handles shell.exec for running commands on the local machine.
88
+ *
89
+ * Security:
90
+ * - Commands are executed as array args (no shell interpolation)
91
+ * - First arg (executable) is validated against allowedCommands / blockedCommands
92
+ * - Working directory is validated against allowedPaths / blockedPaths
93
+ * - Timeout enforcement
94
+ */
95
+
96
+ declare function createShellCapability(config: TunnelConfig): Capability;
97
+
98
+ declare function createDesktopCapability(): Capability;
99
+
100
+ /**
101
+ * Permission Guard — local-side permission enforcement (defense in depth).
102
+ *
103
+ * Even though the server validates permissions before relaying RPCs,
104
+ * the local agent also checks permissions as a second layer of defense.
105
+ * This prevents a compromised server from bypassing permission controls.
106
+ *
107
+ * After the initial permission sync, unknown permissionIds are denied.
108
+ * Before sync, unknown IDs are also denied (fail-closed).
109
+ */
110
+ interface LocalPermission {
111
+ permissionId: string;
112
+ capability: string;
113
+ scope: Record<string, unknown>;
114
+ expiresAt?: string;
115
+ }
116
+ declare class PermissionGuard {
117
+ private permissions;
118
+ private hasSynced;
119
+ /** Bulk-load permissions from server sync notification. */
120
+ syncPermissions(permissions: LocalPermission[]): void;
121
+ addPermission(permission: LocalPermission): void;
122
+ revokePermission(permissionId: string): void;
123
+ checkPermission(permissionId: string | undefined): boolean;
124
+ clear(): void;
125
+ }
126
+
127
+ declare function validateCommand(command: string, allowedCommands: string[], blockedCommands: string[]): void;
128
+
129
+ /**
130
+ * Path Validator — defense-in-depth path traversal prevention.
131
+ *
132
+ * Validates that requested paths:
133
+ * 1. Are absolute
134
+ * 2. Resolve to an absolute path (follows symlinks)
135
+ * 3. Fall within allowed directories
136
+ * 4. Don't hit blocked paths (configurable)
137
+ */
138
+ declare function validatePath(path: string, allowedPaths: string[], blockedPaths?: string[]): void;
139
+
140
+ export { type Capability, CapabilityRegistry, type LocalPermission, PermissionGuard, type RpcHandler, TunnelAgent, type TunnelConfig, createDesktopCapability, createFilesystemCapability, createShellCapability, loadConfig, validateCommand, validatePath };
@@ -0,0 +1,21 @@
1
+ import { TunnelAgent } from "./agent";
2
+ import { loadConfig } from "./config";
3
+ import { CapabilityRegistry } from "./capabilities/index";
4
+ import { createFilesystemCapability } from "./capabilities/filesystem";
5
+ import { createShellCapability } from "./capabilities/shell";
6
+ import { createDesktopCapability } from "./capabilities/desktop";
7
+ import { PermissionGuard } from "./security/permission-guard";
8
+ import { validateCommand } from "./security/command-validator";
9
+ import { validatePath } from "./security/path-validator";
10
+ export {
11
+ CapabilityRegistry,
12
+ PermissionGuard,
13
+ TunnelAgent,
14
+ createDesktopCapability,
15
+ createFilesystemCapability,
16
+ createShellCapability,
17
+ loadConfig,
18
+ validateCommand,
19
+ validatePath
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/agent/index.ts"],"sourcesContent":["export { TunnelAgent } from './agent';\nexport { loadConfig, type TunnelConfig } from './config';\nexport { CapabilityRegistry } from './capabilities/index';\nexport type { Capability, RpcHandler } from './capabilities/index';\nexport { createFilesystemCapability } from './capabilities/filesystem';\nexport { createShellCapability } from './capabilities/shell';\nexport { createDesktopCapability } from './capabilities/desktop';\nexport { PermissionGuard } from './security/permission-guard';\nexport type { LocalPermission } from './security/permission-guard';\nexport { validateCommand } from './security/command-validator';\nexport { validatePath } from './security/path-validator';\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,kBAAqC;AAC9C,SAAS,0BAA0B;AAEnC,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAEhC,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;","names":[]}