@agenshield/interceptor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @agenshield/interceptor
2
+
3
+ Node.js runtime interception via ESM loader and CJS preload. It instruments selected Node APIs to apply AgenShield policy checks and (in some cases) route traffic through the broker.
4
+
5
+ ## Purpose
6
+ - Enforce policy checks inside a Node process without changing application code.
7
+ - Provide a quick on-ramp for CLI tools (npm, curl wrappers, etc.).
8
+ - Emit local audit events to the broker.
9
+
10
+ ## Installation
11
+ ```bash
12
+ npm install @agenshield/interceptor
13
+ ```
14
+
15
+ ## Usage
16
+ ### ESM loader (recommended)
17
+ ```bash
18
+ node --import @agenshield/interceptor/register app.js
19
+ ```
20
+
21
+ ### CommonJS preload
22
+ ```bash
23
+ node -r @agenshield/interceptor/require app.js
24
+ ```
25
+
26
+ ### Programmatic
27
+ ```ts
28
+ import { installInterceptors, uninstallInterceptors } from '@agenshield/interceptor';
29
+
30
+ installInterceptors({
31
+ socketPath: '/var/run/agenshield.sock',
32
+ failOpen: false,
33
+ });
34
+
35
+ // ... your app ...
36
+
37
+ uninstallInterceptors();
38
+ ```
39
+
40
+ ## What Gets Intercepted
41
+ - `fetch` (global)
42
+ - `http` / `https` (`request`, `get`)
43
+ - `WebSocket` (global, if present)
44
+ - `fs`, `fs/promises` (read/write/list)
45
+ - `child_process` (`exec`, `spawn`, `execSync`, etc.)
46
+
47
+ ## Configuration
48
+ `createConfig()` reads environment variables (or you can pass overrides to `installInterceptors()`):
49
+
50
+ - `AGENSHIELD_SOCKET` - Unix socket path.
51
+ - `AGENSHIELD_HOST` - HTTP fallback host.
52
+ - `AGENSHIELD_PORT` - HTTP fallback port.
53
+ - `AGENSHIELD_FAIL_OPEN` - `true` to allow operations if broker is unreachable.
54
+ - `AGENSHIELD_LOG_LEVEL` - `debug|info|warn|error`.
55
+ - `AGENSHIELD_INTERCEPT_FETCH` - enable/disable fetch interception.
56
+ - `AGENSHIELD_INTERCEPT_HTTP` - enable/disable http/https interception.
57
+ - `AGENSHIELD_INTERCEPT_WS` - enable/disable WebSocket interception.
58
+ - `AGENSHIELD_INTERCEPT_FS` - enable/disable fs interception.
59
+ - `AGENSHIELD_INTERCEPT_EXEC` - enable/disable child_process interception.
60
+ - `AGENSHIELD_TIMEOUT` - broker request timeout (ms).
61
+ - `AGENSHIELD_POLICY_CACHE_TTL` - policy cache TTL (ms).
62
+
63
+ ## Behavior Details (Important)
64
+ - `fetch` requests are proxied through the broker (`http_request`) and return a synthetic `Response`.
65
+ - `http`/`https` requests are NOT proxied; a policy check runs asynchronously and may destroy the request if denied.
66
+ - `fs` async APIs perform a policy check, then call the original local method (no broker proxy).
67
+ - `fs` sync APIs perform a synchronous policy check via `SyncClient`, then call the original local method.
68
+ - `child_process.exec` performs an async policy check and returns a dummy process immediately; the actual command is executed only after policy approval.
69
+ - `child_process.spawn` and `execFile` perform async policy checks but still start the process immediately.
70
+ - `WebSocket` interception closes connections post-hoc if denied.
71
+
72
+ ## Limitations and Caveats
73
+ - Only `fetch` is truly proxied through the broker; other interceptors are policy checks around local calls.
74
+ - Async HTTP and process interceptors cannot fully block before the underlying operation starts.
75
+ - Sync interceptors (`fs`, `execSync`, `spawnSync`) use a hardcoded broker socket/host/port (`/var/run/agenshield.sock`, `localhost:5200`) and ignore config overrides.
76
+ - Broker URL bypass checks are hardcoded to `localhost:5200`; non-default ports can lead to interception recursion.
77
+ - WebSocket interception requires `globalThis.WebSocket` to exist (not always true in Node without a polyfill).
78
+ - Native modules or direct syscalls that bypass Node APIs are not intercepted.
79
+
80
+ ## Roadmap (Ideas)
81
+ - Use config overrides for sync clients.
82
+ - Full proxying for http/https and child_process where possible.
83
+ - Safer broker URL detection for non-default ports.
84
+ - Comprehensive test suite around interception edge cases.
85
+
86
+ ## Development
87
+ ```bash
88
+ # Build
89
+ npx nx build shield-interceptor
90
+ ```
91
+
92
+ ## Contribution Guide
93
+ - Keep interceptors isolated and reversible (always restore originals).
94
+ - Add new interceptors in `src/interceptors/` and register in `src/installer.ts`.
95
+ - Extend `@agenshield/ipc` if new operation types are introduced.
96
+
97
+ ## Agent Notes
98
+ - `src/installer.ts` is the authoritative install/uninstall sequence.
99
+ - `src/interceptors/base.ts` handles policy checks and fail-open behavior.
100
+ - `src/client/http-client.ts` is async (socket then HTTP), while `src/client/sync-client.ts` uses a subprocess for sync calls.
101
+ - When adjusting policy checks, update `PolicyEvaluator` caching semantics in `src/policy/`.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Async HTTP Client
3
+ *
4
+ * Async client for communicating with the broker daemon.
5
+ */
6
+ export interface AsyncClientOptions {
7
+ socketPath: string;
8
+ httpHost: string;
9
+ httpPort: number;
10
+ timeout: number;
11
+ }
12
+ export interface BrokerRequest {
13
+ jsonrpc: '2.0';
14
+ id: string;
15
+ method: string;
16
+ params: Record<string, unknown>;
17
+ }
18
+ export interface BrokerResponse {
19
+ jsonrpc: '2.0';
20
+ id: string;
21
+ result?: unknown;
22
+ error?: {
23
+ code: number;
24
+ message: string;
25
+ };
26
+ }
27
+ export declare class AsyncClient {
28
+ private socketPath;
29
+ private httpHost;
30
+ private httpPort;
31
+ private timeout;
32
+ constructor(options: AsyncClientOptions);
33
+ /**
34
+ * Send a request to the broker
35
+ */
36
+ request<T>(method: string, params: Record<string, unknown>): Promise<T>;
37
+ /**
38
+ * Send request via Unix socket
39
+ */
40
+ private socketRequest;
41
+ /**
42
+ * Send request via HTTP
43
+ */
44
+ private httpRequest;
45
+ /**
46
+ * Check if broker is available
47
+ */
48
+ ping(): Promise<boolean>;
49
+ }
50
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/client/http-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,kBAAkB;IAOvC;;OAEG;IACG,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC;IAgBb;;OAEG;YACW,aAAa;IA0D3B;;OAEG;YACW,WAAW;IAiDzB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;CAQ/B"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Sync Client
3
+ *
4
+ * Synchronous client for intercepting sync operations like execSync.
5
+ * Uses a subprocess to make async calls synchronously.
6
+ */
7
+ export interface SyncClientOptions {
8
+ socketPath: string;
9
+ httpHost: string;
10
+ httpPort: number;
11
+ timeout: number;
12
+ }
13
+ export declare class SyncClient {
14
+ private socketPath;
15
+ private httpHost;
16
+ private httpPort;
17
+ private timeout;
18
+ constructor(options: SyncClientOptions);
19
+ /**
20
+ * Send a synchronous request to the broker
21
+ */
22
+ request<T>(method: string, params: Record<string, unknown>): T;
23
+ /**
24
+ * Synchronous socket request
25
+ *
26
+ * This uses a blocking approach with a temporary file for the response.
27
+ */
28
+ private socketRequestSync;
29
+ /**
30
+ * Synchronous HTTP request using curl
31
+ */
32
+ private httpRequestSync;
33
+ /**
34
+ * Check if broker is available
35
+ */
36
+ ping(): boolean;
37
+ }
38
+ //# sourceMappingURL=sync-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../../src/client/sync-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,iBAAiB;IAOtC;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC;IAU9D;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IA6EzB;;OAEG;IACH,OAAO,CAAC,eAAe;IAoCvB;;OAEG;IACH,IAAI,IAAI,OAAO;CAQhB"}
package/config.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Interceptor Configuration
3
+ *
4
+ * Configuration management for the interceptor.
5
+ */
6
+ export interface InterceptorConfig {
7
+ /** Unix socket path for broker communication */
8
+ socketPath: string;
9
+ /** HTTP fallback host */
10
+ httpHost: string;
11
+ /** HTTP fallback port */
12
+ httpPort: number;
13
+ /** Whether to fail open if broker is unavailable */
14
+ failOpen: boolean;
15
+ /** Log level */
16
+ logLevel: 'debug' | 'info' | 'warn' | 'error';
17
+ /** Enable fetch interception */
18
+ interceptFetch: boolean;
19
+ /** Enable http/https module interception */
20
+ interceptHttp: boolean;
21
+ /** Enable WebSocket interception */
22
+ interceptWs: boolean;
23
+ /** Enable fs module interception */
24
+ interceptFs: boolean;
25
+ /** Enable child_process interception */
26
+ interceptExec: boolean;
27
+ /** Request timeout in milliseconds */
28
+ timeout: number;
29
+ }
30
+ /**
31
+ * Create configuration from environment variables
32
+ */
33
+ export declare function createConfig(overrides?: Partial<InterceptorConfig>): InterceptorConfig;
34
+ /**
35
+ * Default configuration
36
+ */
37
+ export declare const defaultConfig: InterceptorConfig;
38
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IAEnB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IAEjB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IAEjB,oDAAoD;IACpD,QAAQ,EAAE,OAAO,CAAC;IAElB,gBAAgB;IAChB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAE9C,gCAAgC;IAChC,cAAc,EAAE,OAAO,CAAC;IAExB,4CAA4C;IAC5C,aAAa,EAAE,OAAO,CAAC;IAEvB,oCAAoC;IACpC,WAAW,EAAE,OAAO,CAAC;IAErB,oCAAoC;IACpC,WAAW,EAAE,OAAO,CAAC;IAErB,wCAAwC;IACxC,aAAa,EAAE,OAAO,CAAC;IAEvB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAiBtF;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,iBAAkC,CAAC"}
package/errors.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Custom error types for the interceptor
3
+ */
4
+ /**
5
+ * Base error class for AgenShield errors
6
+ */
7
+ export declare class AgenShieldError extends Error {
8
+ readonly code: string;
9
+ readonly operation?: string;
10
+ readonly target?: string;
11
+ constructor(message: string, code: string, options?: {
12
+ operation?: string;
13
+ target?: string;
14
+ });
15
+ }
16
+ /**
17
+ * Error thrown when a policy denies an operation
18
+ */
19
+ export declare class PolicyDeniedError extends AgenShieldError {
20
+ readonly policyId?: string;
21
+ constructor(message: string, options?: {
22
+ operation?: string;
23
+ target?: string;
24
+ policyId?: string;
25
+ });
26
+ }
27
+ /**
28
+ * Error thrown when broker is unavailable
29
+ */
30
+ export declare class BrokerUnavailableError extends AgenShieldError {
31
+ constructor(message?: string);
32
+ }
33
+ /**
34
+ * Error thrown when request times out
35
+ */
36
+ export declare class TimeoutError extends AgenShieldError {
37
+ constructor(message?: string);
38
+ }
39
+ /**
40
+ * Error thrown for invalid operations
41
+ */
42
+ export declare class InvalidOperationError extends AgenShieldError {
43
+ constructor(message: string, operation?: string);
44
+ }
45
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAG9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAWpD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAGhC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;CAMvE;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,eAAe;gBAC7C,OAAO,GAAE,MAA2C;CAIjE;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,eAAe;gBACnC,OAAO,GAAE,MAA4B;CAIlD;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,eAAe;gBAC5C,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAIhD"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Event Reporter
3
+ *
4
+ * Reports interceptor events to the broker.
5
+ */
6
+ import type { AsyncClient } from '../client/http-client.js';
7
+ export interface EventReporterOptions {
8
+ client: AsyncClient;
9
+ logLevel: 'debug' | 'info' | 'warn' | 'error';
10
+ }
11
+ export interface InterceptorEvent {
12
+ type: 'intercept' | 'allow' | 'deny' | 'error';
13
+ operation: string;
14
+ target: string;
15
+ timestamp: Date;
16
+ duration?: number;
17
+ policyId?: string;
18
+ error?: string;
19
+ }
20
+ export declare class EventReporter {
21
+ private client;
22
+ private logLevel;
23
+ private queue;
24
+ private flushInterval;
25
+ private failedFlushCount;
26
+ private static readonly MAX_QUEUE_SIZE;
27
+ private static readonly MAX_RETRIES;
28
+ private readonly levelPriority;
29
+ constructor(options: EventReporterOptions);
30
+ /**
31
+ * Report an event
32
+ */
33
+ report(event: InterceptorEvent): void;
34
+ /**
35
+ * Report an interception
36
+ */
37
+ intercept(operation: string, target: string): void;
38
+ /**
39
+ * Report an allowed operation
40
+ */
41
+ allow(operation: string, target: string, policyId?: string, duration?: number): void;
42
+ /**
43
+ * Report a denied operation
44
+ */
45
+ deny(operation: string, target: string, policyId?: string, reason?: string): void;
46
+ /**
47
+ * Report an error
48
+ */
49
+ error(operation: string, target: string, error: string): void;
50
+ /**
51
+ * Flush the event queue
52
+ */
53
+ flush(): Promise<void>;
54
+ /**
55
+ * Stop the reporter
56
+ */
57
+ stop(): void;
58
+ /**
59
+ * Get the appropriate log level for an event
60
+ */
61
+ private getLogLevel;
62
+ /**
63
+ * Check if we should log at the given level
64
+ */
65
+ private shouldLog;
66
+ }
67
+ //# sourceMappingURL=reporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../../src/events/reporter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC/C;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,gBAAgB,CAAK;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAO;IAC7C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAK;IAExC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAK5B;gBAEU,OAAO,EAAE,oBAAoB;IAQzC;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAqBrC;;OAEG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IASlD;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAWpF;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAWjF;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAU7D;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAUZ;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;OAEG;IACH,OAAO,CAAC,SAAS;CAGlB"}
package/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @agenshield/interceptor
3
+ *
4
+ * Node.js runtime interception via ESM loader and CJS preload.
5
+ * Intercepts network, file system, and process operations to route
6
+ * them through the AgenShield broker daemon.
7
+ */
8
+ export { installInterceptors, uninstallInterceptors } from './installer.js';
9
+ export { InterceptorConfig, createConfig } from './config.js';
10
+ export { FetchInterceptor } from './interceptors/fetch.js';
11
+ export { HttpInterceptor } from './interceptors/http.js';
12
+ export { WebSocketInterceptor } from './interceptors/websocket.js';
13
+ export { ChildProcessInterceptor } from './interceptors/child-process.js';
14
+ export { FsInterceptor } from './interceptors/fs.js';
15
+ export { AsyncClient } from './client/http-client.js';
16
+ export { SyncClient } from './client/sync-client.js';
17
+ export { PolicyEvaluator } from './policy/evaluator.js';
18
+ export { EventReporter } from './events/reporter.js';
19
+ export { AgenShieldError, PolicyDeniedError } from './errors.js';
20
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}