agentic-qe 2.8.1 → 2.8.2
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/CHANGELOG.md +43 -0
- package/README.md +1 -1
- package/dist/agents/BaseAgent.d.ts +201 -0
- package/dist/agents/BaseAgent.d.ts.map +1 -1
- package/dist/agents/BaseAgent.js +401 -0
- package/dist/agents/BaseAgent.js.map +1 -1
- package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.d.ts +135 -0
- package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.d.ts.map +1 -0
- package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.js +301 -0
- package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.js.map +1 -0
- package/dist/code-intelligence/embeddings/NomicEmbedder.d.ts +78 -6
- package/dist/code-intelligence/embeddings/NomicEmbedder.d.ts.map +1 -1
- package/dist/code-intelligence/embeddings/NomicEmbedder.js +162 -21
- package/dist/code-intelligence/embeddings/NomicEmbedder.js.map +1 -1
- package/dist/code-intelligence/embeddings/backends/MemoryBackend.d.ts +59 -0
- package/dist/code-intelligence/embeddings/backends/MemoryBackend.d.ts.map +1 -0
- package/dist/code-intelligence/embeddings/backends/MemoryBackend.js +173 -0
- package/dist/code-intelligence/embeddings/backends/MemoryBackend.js.map +1 -0
- package/dist/code-intelligence/embeddings/backends/RedisBackend.d.ts +50 -0
- package/dist/code-intelligence/embeddings/backends/RedisBackend.d.ts.map +1 -0
- package/dist/code-intelligence/embeddings/backends/RedisBackend.js +279 -0
- package/dist/code-intelligence/embeddings/backends/RedisBackend.js.map +1 -0
- package/dist/code-intelligence/embeddings/backends/SQLiteBackend.d.ts +64 -0
- package/dist/code-intelligence/embeddings/backends/SQLiteBackend.d.ts.map +1 -0
- package/dist/code-intelligence/embeddings/backends/SQLiteBackend.js +314 -0
- package/dist/code-intelligence/embeddings/backends/SQLiteBackend.js.map +1 -0
- package/dist/code-intelligence/embeddings/backends/index.d.ts +16 -0
- package/dist/code-intelligence/embeddings/backends/index.d.ts.map +1 -0
- package/dist/code-intelligence/embeddings/backends/index.js +28 -0
- package/dist/code-intelligence/embeddings/backends/index.js.map +1 -0
- package/dist/code-intelligence/embeddings/backends/types.d.ts +177 -0
- package/dist/code-intelligence/embeddings/backends/types.d.ts.map +1 -0
- package/dist/code-intelligence/embeddings/backends/types.js +30 -0
- package/dist/code-intelligence/embeddings/backends/types.js.map +1 -0
- package/dist/code-intelligence/embeddings/index.d.ts +7 -0
- package/dist/code-intelligence/embeddings/index.d.ts.map +1 -1
- package/dist/code-intelligence/embeddings/index.js +16 -1
- package/dist/code-intelligence/embeddings/index.js.map +1 -1
- package/dist/core/memory/HNSWVectorMemory.js +1 -1
- package/dist/infrastructure/index.d.ts +15 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/index.js +44 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/infrastructure/network/AgentRateLimiter.d.ts +59 -0
- package/dist/infrastructure/network/AgentRateLimiter.d.ts.map +1 -0
- package/dist/infrastructure/network/AgentRateLimiter.js +186 -0
- package/dist/infrastructure/network/AgentRateLimiter.js.map +1 -0
- package/dist/infrastructure/network/AuditLogger.d.ts +102 -0
- package/dist/infrastructure/network/AuditLogger.d.ts.map +1 -0
- package/dist/infrastructure/network/AuditLogger.js +284 -0
- package/dist/infrastructure/network/AuditLogger.js.map +1 -0
- package/dist/infrastructure/network/DomainWhitelist.d.ts +111 -0
- package/dist/infrastructure/network/DomainWhitelist.d.ts.map +1 -0
- package/dist/infrastructure/network/DomainWhitelist.js +216 -0
- package/dist/infrastructure/network/DomainWhitelist.js.map +1 -0
- package/dist/infrastructure/network/NetworkPolicyManager.d.ts +97 -0
- package/dist/infrastructure/network/NetworkPolicyManager.d.ts.map +1 -0
- package/dist/infrastructure/network/NetworkPolicyManager.js +309 -0
- package/dist/infrastructure/network/NetworkPolicyManager.js.map +1 -0
- package/dist/infrastructure/network/index.d.ts +19 -0
- package/dist/infrastructure/network/index.d.ts.map +1 -0
- package/dist/infrastructure/network/index.js +46 -0
- package/dist/infrastructure/network/index.js.map +1 -0
- package/dist/infrastructure/network/policies/default-policies.d.ts +78 -0
- package/dist/infrastructure/network/policies/default-policies.d.ts.map +1 -0
- package/dist/infrastructure/network/policies/default-policies.js +312 -0
- package/dist/infrastructure/network/policies/default-policies.js.map +1 -0
- package/dist/infrastructure/network/types.d.ts +214 -0
- package/dist/infrastructure/network/types.d.ts.map +1 -0
- package/dist/infrastructure/network/types.js +25 -0
- package/dist/infrastructure/network/types.js.map +1 -0
- package/dist/infrastructure/sandbox/ResourceMonitor.d.ts +124 -0
- package/dist/infrastructure/sandbox/ResourceMonitor.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/ResourceMonitor.js +305 -0
- package/dist/infrastructure/sandbox/ResourceMonitor.js.map +1 -0
- package/dist/infrastructure/sandbox/SandboxManager.d.ts +122 -0
- package/dist/infrastructure/sandbox/SandboxManager.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/SandboxManager.js +527 -0
- package/dist/infrastructure/sandbox/SandboxManager.js.map +1 -0
- package/dist/infrastructure/sandbox/index.d.ts +18 -0
- package/dist/infrastructure/sandbox/index.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/index.js +38 -0
- package/dist/infrastructure/sandbox/index.js.map +1 -0
- package/dist/infrastructure/sandbox/profiles/agent-profiles.d.ts +53 -0
- package/dist/infrastructure/sandbox/profiles/agent-profiles.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/profiles/agent-profiles.js +433 -0
- package/dist/infrastructure/sandbox/profiles/agent-profiles.js.map +1 -0
- package/dist/infrastructure/sandbox/types.d.ts +227 -0
- package/dist/infrastructure/sandbox/types.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/types.js +63 -0
- package/dist/infrastructure/sandbox/types.js.map +1 -0
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.js +1 -1
- package/dist/persistence/SupabasePersistenceProvider.d.ts.map +1 -1
- package/dist/persistence/SupabasePersistenceProvider.js +8 -4
- package/dist/persistence/SupabasePersistenceProvider.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Rate Limiter for Network Policy Enforcement
|
|
4
|
+
*
|
|
5
|
+
* Token bucket rate limiter with per-agent tracking.
|
|
6
|
+
* Supports both per-minute and per-hour limits.
|
|
7
|
+
*
|
|
8
|
+
* @module infrastructure/network/AgentRateLimiter
|
|
9
|
+
* @see Issue #146 - Security Hardening: SP-3 Network Policy Enforcement
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AgentRateLimiter = void 0;
|
|
13
|
+
exports.createDefaultRateLimiter = createDefaultRateLimiter;
|
|
14
|
+
/**
|
|
15
|
+
* Agent rate limiter using token bucket algorithm
|
|
16
|
+
*
|
|
17
|
+
* Features:
|
|
18
|
+
* - Per-agent rate limiting
|
|
19
|
+
* - Burst allowance via token bucket
|
|
20
|
+
* - Per-minute and per-hour limits
|
|
21
|
+
* - Automatic token refill
|
|
22
|
+
*/
|
|
23
|
+
class AgentRateLimiter {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.cleanupInterval = null;
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.buckets = new Map();
|
|
28
|
+
// Cleanup stale buckets every 10 minutes
|
|
29
|
+
this.cleanupInterval = setInterval(() => this.cleanup(), 10 * 60 * 1000);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if request is allowed without consuming
|
|
33
|
+
*/
|
|
34
|
+
check(agentId) {
|
|
35
|
+
const bucket = this.getOrCreateBucket(agentId);
|
|
36
|
+
this.refillBucket(bucket);
|
|
37
|
+
this.updateWindows(bucket);
|
|
38
|
+
return this.calculateStatus(bucket, false);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Consume a request token
|
|
42
|
+
*/
|
|
43
|
+
consume(agentId) {
|
|
44
|
+
const bucket = this.getOrCreateBucket(agentId);
|
|
45
|
+
this.refillBucket(bucket);
|
|
46
|
+
this.updateWindows(bucket);
|
|
47
|
+
const status = this.calculateStatus(bucket, true);
|
|
48
|
+
if (!status.limited) {
|
|
49
|
+
// Consume token
|
|
50
|
+
bucket.tokens -= 1;
|
|
51
|
+
bucket.minuteCount += 1;
|
|
52
|
+
bucket.hourCount += 1;
|
|
53
|
+
}
|
|
54
|
+
return status;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reset rate limit for an agent
|
|
58
|
+
*/
|
|
59
|
+
reset(agentId) {
|
|
60
|
+
this.buckets.delete(agentId);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get current status for agent
|
|
64
|
+
*/
|
|
65
|
+
getStatus(agentId) {
|
|
66
|
+
return this.check(agentId);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get all agent IDs being tracked
|
|
70
|
+
*/
|
|
71
|
+
getTrackedAgents() {
|
|
72
|
+
return Array.from(this.buckets.keys());
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stop the cleanup interval
|
|
76
|
+
*/
|
|
77
|
+
close() {
|
|
78
|
+
if (this.cleanupInterval) {
|
|
79
|
+
clearInterval(this.cleanupInterval);
|
|
80
|
+
this.cleanupInterval = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// ============================================
|
|
84
|
+
// Private Methods
|
|
85
|
+
// ============================================
|
|
86
|
+
getOrCreateBucket(agentId) {
|
|
87
|
+
let bucket = this.buckets.get(agentId);
|
|
88
|
+
if (!bucket) {
|
|
89
|
+
const now = Date.now();
|
|
90
|
+
bucket = {
|
|
91
|
+
tokens: this.config.burstSize,
|
|
92
|
+
lastRefill: now,
|
|
93
|
+
minuteCount: 0,
|
|
94
|
+
minuteWindowStart: now,
|
|
95
|
+
hourCount: 0,
|
|
96
|
+
hourWindowStart: now,
|
|
97
|
+
};
|
|
98
|
+
this.buckets.set(agentId, bucket);
|
|
99
|
+
}
|
|
100
|
+
return bucket;
|
|
101
|
+
}
|
|
102
|
+
refillBucket(bucket) {
|
|
103
|
+
const now = Date.now();
|
|
104
|
+
const elapsed = now - bucket.lastRefill;
|
|
105
|
+
// Refill rate: requests per minute / 60 seconds
|
|
106
|
+
const refillRate = this.config.requestsPerMinute / 60;
|
|
107
|
+
const refillAmount = (elapsed / 1000) * refillRate;
|
|
108
|
+
bucket.tokens = Math.min(this.config.burstSize, bucket.tokens + refillAmount);
|
|
109
|
+
bucket.lastRefill = now;
|
|
110
|
+
}
|
|
111
|
+
updateWindows(bucket) {
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
// Reset minute window
|
|
114
|
+
if (now - bucket.minuteWindowStart >= 60000) {
|
|
115
|
+
bucket.minuteCount = 0;
|
|
116
|
+
bucket.minuteWindowStart = now;
|
|
117
|
+
}
|
|
118
|
+
// Reset hour window
|
|
119
|
+
if (now - bucket.hourWindowStart >= 3600000) {
|
|
120
|
+
bucket.hourCount = 0;
|
|
121
|
+
bucket.hourWindowStart = now;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
calculateStatus(bucket, forConsume) {
|
|
125
|
+
const now = Date.now();
|
|
126
|
+
// Check per-minute limit
|
|
127
|
+
const minuteRemaining = this.config.requestsPerMinute - bucket.minuteCount;
|
|
128
|
+
const minuteResetIn = 60000 - (now - bucket.minuteWindowStart);
|
|
129
|
+
// Check per-hour limit
|
|
130
|
+
const hourRemaining = this.config.requestsPerHour - bucket.hourCount;
|
|
131
|
+
const hourResetIn = 3600000 - (now - bucket.hourWindowStart);
|
|
132
|
+
// Check token bucket
|
|
133
|
+
const tokensAvailable = bucket.tokens >= 1;
|
|
134
|
+
// Determine if limited
|
|
135
|
+
// For check(): report if we're AT the limit (next request would fail)
|
|
136
|
+
// For consume(): report if we're OVER the limit (this request fails)
|
|
137
|
+
let limited = false;
|
|
138
|
+
let retryAfter = 0;
|
|
139
|
+
// Check minute limit
|
|
140
|
+
if (bucket.minuteCount >= this.config.requestsPerMinute) {
|
|
141
|
+
limited = true;
|
|
142
|
+
retryAfter = Math.max(retryAfter, minuteResetIn);
|
|
143
|
+
}
|
|
144
|
+
// Check hour limit
|
|
145
|
+
if (bucket.hourCount >= this.config.requestsPerHour) {
|
|
146
|
+
limited = true;
|
|
147
|
+
retryAfter = Math.max(retryAfter, hourResetIn);
|
|
148
|
+
}
|
|
149
|
+
// Check token bucket (only for consume to allow burst)
|
|
150
|
+
if (forConsume && !tokensAvailable) {
|
|
151
|
+
limited = true;
|
|
152
|
+
// Estimate time to refill one token
|
|
153
|
+
const refillRate = this.config.requestsPerMinute / 60;
|
|
154
|
+
retryAfter = Math.max(retryAfter, Math.ceil(1000 / refillRate));
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
limited,
|
|
158
|
+
currentRate: bucket.minuteCount,
|
|
159
|
+
remaining: Math.min(minuteRemaining, hourRemaining, Math.floor(bucket.tokens)),
|
|
160
|
+
resetIn: Math.min(minuteResetIn, hourResetIn),
|
|
161
|
+
retryAfter: limited ? retryAfter : undefined,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
cleanup() {
|
|
165
|
+
const now = Date.now();
|
|
166
|
+
const staleThreshold = 3600000; // 1 hour
|
|
167
|
+
for (const [agentId, bucket] of this.buckets) {
|
|
168
|
+
// Remove buckets that haven't been used in an hour
|
|
169
|
+
if (now - bucket.lastRefill > staleThreshold) {
|
|
170
|
+
this.buckets.delete(agentId);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.AgentRateLimiter = AgentRateLimiter;
|
|
176
|
+
/**
|
|
177
|
+
* Create a rate limiter with default configuration
|
|
178
|
+
*/
|
|
179
|
+
function createDefaultRateLimiter() {
|
|
180
|
+
return new AgentRateLimiter({
|
|
181
|
+
requestsPerMinute: 60,
|
|
182
|
+
requestsPerHour: 1000,
|
|
183
|
+
burstSize: 10,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=AgentRateLimiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRateLimiter.js","sourceRoot":"","sources":["../../../src/infrastructure/network/AgentRateLimiter.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAmOH,4DAMC;AA9MD;;;;;;;;GAQG;AACH,MAAa,gBAAgB;IAK3B,YAAY,MAAuB;QAF3B,oBAAe,GAA0C,IAAI,CAAC;QAGpE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QAEzB,yCAAyC;QACzC,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAe;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,OAAe;QACrB,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAE3B,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAElD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CA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AE,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9E,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,WAAW,CAAC;YAC7C,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;SAC7C,CAAC;IACJ,CAAC;IAEO,OAAO;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,SAAS;QAEzC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7C,mDAAmD;YACnD,IAAI,GAAG,GAAG,MAAM,CAAC,UAAU,GAAG,cAAc,EAAE,CAAC;gBAC7C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA1LD,4CA0LC;AAED;;GAEG;AACH,SAAgB,wBAAwB;IACtC,OAAO,IAAI,gBAAgB,CAAC;QAC1B,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,IAAI;QACrB,SAAS,EAAE,EAAE;KACd,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Logger for Network Policy Enforcement
|
|
3
|
+
*
|
|
4
|
+
* Logs all network requests with configurable retention and querying.
|
|
5
|
+
* Supports both in-memory and persistent storage.
|
|
6
|
+
*
|
|
7
|
+
* @module infrastructure/network/AuditLogger
|
|
8
|
+
* @see Issue #146 - Security Hardening: SP-3 Network Policy Enforcement
|
|
9
|
+
*/
|
|
10
|
+
import type { AuditEntry, AuditQueryFilter, AuditStats } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Audit logger configuration
|
|
13
|
+
*/
|
|
14
|
+
export interface AuditLoggerConfig {
|
|
15
|
+
/** Maximum entries to keep in memory */
|
|
16
|
+
maxEntries: number;
|
|
17
|
+
/** Persist to file */
|
|
18
|
+
persistToFile: boolean;
|
|
19
|
+
/** File path for persistence */
|
|
20
|
+
filePath?: string;
|
|
21
|
+
/** Auto-save interval in ms (0 to disable) */
|
|
22
|
+
autoSaveIntervalMs: number;
|
|
23
|
+
/** Enable debug logging */
|
|
24
|
+
debug: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Audit logger for network requests
|
|
28
|
+
*
|
|
29
|
+
* Features:
|
|
30
|
+
* - In-memory circular buffer
|
|
31
|
+
* - Query by agent, domain, action, time range
|
|
32
|
+
* - Statistics aggregation
|
|
33
|
+
* - JSON export
|
|
34
|
+
* - Optional file persistence
|
|
35
|
+
*/
|
|
36
|
+
export declare class AuditLogger {
|
|
37
|
+
private entries;
|
|
38
|
+
private config;
|
|
39
|
+
private saveInterval;
|
|
40
|
+
private dirty;
|
|
41
|
+
constructor(config?: Partial<AuditLoggerConfig>);
|
|
42
|
+
/**
|
|
43
|
+
* Log a network request
|
|
44
|
+
*/
|
|
45
|
+
log(entry: Omit<AuditEntry, 'id' | 'timestamp'>): Promise<AuditEntry>;
|
|
46
|
+
/**
|
|
47
|
+
* Log an allowed request
|
|
48
|
+
*/
|
|
49
|
+
logAllowed(agentId: string, agentType: string, domain: string, options?: Partial<AuditEntry>): Promise<AuditEntry>;
|
|
50
|
+
/**
|
|
51
|
+
* Log a blocked request
|
|
52
|
+
*/
|
|
53
|
+
logBlocked(agentId: string, agentType: string, domain: string, reason: string, options?: Partial<AuditEntry>): Promise<AuditEntry>;
|
|
54
|
+
/**
|
|
55
|
+
* Log a rate-limited request
|
|
56
|
+
*/
|
|
57
|
+
logRateLimited(agentId: string, agentType: string, domain: string, options?: Partial<AuditEntry>): Promise<AuditEntry>;
|
|
58
|
+
/**
|
|
59
|
+
* Query audit entries
|
|
60
|
+
*/
|
|
61
|
+
query(filter: AuditQueryFilter): Promise<AuditEntry[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get audit statistics
|
|
64
|
+
*/
|
|
65
|
+
getStats(since?: Date): Promise<AuditStats>;
|
|
66
|
+
/**
|
|
67
|
+
* Export entries to JSON file
|
|
68
|
+
*/
|
|
69
|
+
exportToJson(filepath: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Import entries from JSON file
|
|
72
|
+
*/
|
|
73
|
+
importFromJson(filepath: string): Promise<number>;
|
|
74
|
+
/**
|
|
75
|
+
* Save to configured file
|
|
76
|
+
*/
|
|
77
|
+
save(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Load from configured file
|
|
80
|
+
*/
|
|
81
|
+
load(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Clear all entries
|
|
84
|
+
*/
|
|
85
|
+
clear(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get entry count
|
|
88
|
+
*/
|
|
89
|
+
size(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Get recent entries
|
|
92
|
+
*/
|
|
93
|
+
getRecent(count?: number): AuditEntry[];
|
|
94
|
+
/**
|
|
95
|
+
* Close and cleanup
|
|
96
|
+
*/
|
|
97
|
+
close(): Promise<void>;
|
|
98
|
+
private startAutoSave;
|
|
99
|
+
private stopAutoSave;
|
|
100
|
+
private debug;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=AuditLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuditLogger.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/network/AuditLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAe,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IAEnB,sBAAsB;IACtB,aAAa,EAAE,OAAO,CAAC;IAEvB,gCAAgC;I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AAC,IAAI,CAAC;IAOnD;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBvD;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAa3B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,SAAS,CAAC,KAAK,GAAE,MAAW,GAAG,UAAU,EAAE;IAI3C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,KAAK;CAKd"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Audit Logger for Network Policy Enforcement
|
|
4
|
+
*
|
|
5
|
+
* Logs all network requests with configurable retention and querying.
|
|
6
|
+
* Supports both in-memory and persistent storage.
|
|
7
|
+
*
|
|
8
|
+
* @module infrastructure/network/AuditLogger
|
|
9
|
+
* @see Issue #146 - Security Hardening: SP-3 Network Policy Enforcement
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuditLogger = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const promises_1 = require("fs/promises");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
/**
|
|
17
|
+
* Default audit logger configuration
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_CONFIG = {
|
|
20
|
+
maxEntries: 10000,
|
|
21
|
+
persistToFile: false,
|
|
22
|
+
autoSaveIntervalMs: 0,
|
|
23
|
+
debug: false,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Audit logger for network requests
|
|
27
|
+
*
|
|
28
|
+
* Features:
|
|
29
|
+
* - In-memory circular buffer
|
|
30
|
+
* - Query by agent, domain, action, time range
|
|
31
|
+
* - Statistics aggregation
|
|
32
|
+
* - JSON export
|
|
33
|
+
* - Optional file persistence
|
|
34
|
+
*/
|
|
35
|
+
class AuditLogger {
|
|
36
|
+
constructor(config = {}) {
|
|
37
|
+
this.saveInterval = null;
|
|
38
|
+
this.dirty = false;
|
|
39
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
40
|
+
this.entries = [];
|
|
41
|
+
if (this.config.persistToFile && this.config.autoSaveIntervalMs > 0) {
|
|
42
|
+
this.startAutoSave();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Log a network request
|
|
47
|
+
*/
|
|
48
|
+
async log(entry) {
|
|
49
|
+
const fullEntry = {
|
|
50
|
+
id: (0, crypto_1.randomUUID)(),
|
|
51
|
+
timestamp: new Date(),
|
|
52
|
+
...entry,
|
|
53
|
+
};
|
|
54
|
+
this.entries.push(fullEntry);
|
|
55
|
+
this.dirty = true;
|
|
56
|
+
// Evict oldest if over limit
|
|
57
|
+
if (this.entries.length > this.config.maxEntries) {
|
|
58
|
+
this.entries.shift();
|
|
59
|
+
}
|
|
60
|
+
this.debug(`Logged: ${entry.action} ${entry.domain} for ${entry.agentType}`);
|
|
61
|
+
return fullEntry;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Log an allowed request
|
|
65
|
+
*/
|
|
66
|
+
async logAllowed(agentId, agentType, domain, options = {}) {
|
|
67
|
+
return this.log({
|
|
68
|
+
agentId,
|
|
69
|
+
agentType,
|
|
70
|
+
domain,
|
|
71
|
+
action: 'allowed',
|
|
72
|
+
...options,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Log a blocked request
|
|
77
|
+
*/
|
|
78
|
+
async logBlocked(agentId, agentType, domain, reason, options = {}) {
|
|
79
|
+
return this.log({
|
|
80
|
+
agentId,
|
|
81
|
+
agentType,
|
|
82
|
+
domain,
|
|
83
|
+
action: 'blocked',
|
|
84
|
+
reason,
|
|
85
|
+
...options,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Log a rate-limited request
|
|
90
|
+
*/
|
|
91
|
+
async logRateLimited(agentId, agentType, domain, options = {}) {
|
|
92
|
+
return this.log({
|
|
93
|
+
agentId,
|
|
94
|
+
agentType,
|
|
95
|
+
domain,
|
|
96
|
+
action: 'rate_limited',
|
|
97
|
+
reason: 'Rate limit exceeded',
|
|
98
|
+
...options,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Query audit entries
|
|
103
|
+
*/
|
|
104
|
+
async query(filter) {
|
|
105
|
+
let results = [...this.entries];
|
|
106
|
+
// Apply filters
|
|
107
|
+
if (filter.agentId) {
|
|
108
|
+
results = results.filter((e) => e.agentId === filter.agentId);
|
|
109
|
+
}
|
|
110
|
+
if (filter.agentType) {
|
|
111
|
+
results = results.filter((e) => e.agentType === filter.agentType);
|
|
112
|
+
}
|
|
113
|
+
if (filter.domain) {
|
|
114
|
+
results = results.filter((e) => e.domain === filter.domain);
|
|
115
|
+
}
|
|
116
|
+
if (filter.action) {
|
|
117
|
+
results = results.filter((e) => e.action === filter.action);
|
|
118
|
+
}
|
|
119
|
+
if (filter.since) {
|
|
120
|
+
results = results.filter((e) => e.timestamp >= filter.since);
|
|
121
|
+
}
|
|
122
|
+
if (filter.until) {
|
|
123
|
+
results = results.filter((e) => e.timestamp <= filter.until);
|
|
124
|
+
}
|
|
125
|
+
// Apply pagination
|
|
126
|
+
if (filter.offset) {
|
|
127
|
+
results = results.slice(filter.offset);
|
|
128
|
+
}
|
|
129
|
+
if (filter.limit) {
|
|
130
|
+
results = results.slice(0, filter.limit);
|
|
131
|
+
}
|
|
132
|
+
return results;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get audit statistics
|
|
136
|
+
*/
|
|
137
|
+
async getStats(since) {
|
|
138
|
+
const sinceDate = since || new Date(Date.now() - 24 * 60 * 60 * 1000); // Default: last 24h
|
|
139
|
+
const filtered = this.entries.filter((e) => e.timestamp >= sinceDate);
|
|
140
|
+
const byDomain = {};
|
|
141
|
+
const byAgentType = {};
|
|
142
|
+
let totalResponseTime = 0;
|
|
143
|
+
let responseTimeCount = 0;
|
|
144
|
+
let allowedRequests = 0;
|
|
145
|
+
let blockedRequests = 0;
|
|
146
|
+
let rateLimitedRequests = 0;
|
|
147
|
+
for (const entry of filtered) {
|
|
148
|
+
// Count by domain
|
|
149
|
+
byDomain[entry.domain] = (byDomain[entry.domain] || 0) + 1;
|
|
150
|
+
// Count by agent type
|
|
151
|
+
byAgentType[entry.agentType] = (byAgentType[entry.agentType] || 0) + 1;
|
|
152
|
+
// Count by action
|
|
153
|
+
switch (entry.action) {
|
|
154
|
+
case 'allowed':
|
|
155
|
+
allowedRequests++;
|
|
156
|
+
break;
|
|
157
|
+
case 'blocked':
|
|
158
|
+
blockedRequests++;
|
|
159
|
+
break;
|
|
160
|
+
case 'rate_limited':
|
|
161
|
+
rateLimitedRequests++;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
// Sum response times
|
|
165
|
+
if (entry.responseTimeMs !== undefined) {
|
|
166
|
+
totalResponseTime += entry.responseTimeMs;
|
|
167
|
+
responseTimeCount++;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
totalRequests: filtered.length,
|
|
172
|
+
allowedRequests,
|
|
173
|
+
blockedRequests,
|
|
174
|
+
rateLimitedRequests,
|
|
175
|
+
byDomain,
|
|
176
|
+
byAgentType,
|
|
177
|
+
avgResponseTimeMs: responseTimeCount > 0 ? totalResponseTime / responseTimeCount : 0,
|
|
178
|
+
since: sinceDate,
|
|
179
|
+
timestamp: new Date(),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Export entries to JSON file
|
|
184
|
+
*/
|
|
185
|
+
async exportToJson(filepath) {
|
|
186
|
+
const data = JSON.stringify(this.entries, null, 2);
|
|
187
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(filepath), { recursive: true });
|
|
188
|
+
await (0, promises_1.writeFile)(filepath, data, 'utf-8');
|
|
189
|
+
this.debug(`Exported ${this.entries.length} entries to ${filepath}`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Import entries from JSON file
|
|
193
|
+
*/
|
|
194
|
+
async importFromJson(filepath) {
|
|
195
|
+
try {
|
|
196
|
+
const data = await (0, promises_1.readFile)(filepath, 'utf-8');
|
|
197
|
+
const entries = JSON.parse(data);
|
|
198
|
+
// Convert timestamp strings to Date objects
|
|
199
|
+
for (const entry of entries) {
|
|
200
|
+
entry.timestamp = new Date(entry.timestamp);
|
|
201
|
+
}
|
|
202
|
+
this.entries = entries;
|
|
203
|
+
this.dirty = false;
|
|
204
|
+
this.debug(`Imported ${entries.length} entries from ${filepath}`);
|
|
205
|
+
return entries.length;
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
this.debug(`Failed to import: ${error.message}`);
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Save to configured file
|
|
214
|
+
*/
|
|
215
|
+
async save() {
|
|
216
|
+
if (!this.config.persistToFile || !this.config.filePath) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (!this.dirty) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
await this.exportToJson(this.config.filePath);
|
|
223
|
+
this.dirty = false;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Load from configured file
|
|
227
|
+
*/
|
|
228
|
+
async load() {
|
|
229
|
+
if (!this.config.persistToFile || !this.config.filePath) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
await this.importFromJson(this.config.filePath);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Clear all entries
|
|
236
|
+
*/
|
|
237
|
+
clear() {
|
|
238
|
+
this.entries = [];
|
|
239
|
+
this.dirty = true;
|
|
240
|
+
this.debug('Cleared all entries');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get entry count
|
|
244
|
+
*/
|
|
245
|
+
size() {
|
|
246
|
+
return this.entries.length;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get recent entries
|
|
250
|
+
*/
|
|
251
|
+
getRecent(count = 10) {
|
|
252
|
+
return this.entries.slice(-count);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Close and cleanup
|
|
256
|
+
*/
|
|
257
|
+
async close() {
|
|
258
|
+
this.stopAutoSave();
|
|
259
|
+
await this.save();
|
|
260
|
+
}
|
|
261
|
+
// ============================================
|
|
262
|
+
// Private Methods
|
|
263
|
+
// ============================================
|
|
264
|
+
startAutoSave() {
|
|
265
|
+
if (this.saveInterval)
|
|
266
|
+
return;
|
|
267
|
+
this.saveInterval = setInterval(async () => {
|
|
268
|
+
await this.save();
|
|
269
|
+
}, this.config.autoSaveIntervalMs);
|
|
270
|
+
}
|
|
271
|
+
stopAutoSave() {
|
|
272
|
+
if (this.saveInterval) {
|
|
273
|
+
clearInterval(this.saveInterval);
|
|
274
|
+
this.saveInterval = null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
debug(message) {
|
|
278
|
+
if (this.config.debug) {
|
|
279
|
+
console.log(`[AuditLogger] ${message}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.AuditLogger = AuditLogger;
|
|
284
|
+
//# sourceMappingURL=AuditLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuditLogger.js","sourceRoot":"","sources":["../../../src/infrastructure/network/AuditLogger.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,mCAAoC;AACpC,0CAAyD;AACzD,+BAA+B;AAuB/B;;GAEG;AACH,MAAM,cA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