@nxuss/lemma 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 +21 -0
- package/README.md +311 -0
- package/dist/cloud/KeyManager.d.ts +29 -0
- package/dist/cloud/KeyManager.d.ts.map +1 -0
- package/dist/cloud/KeyManager.js +142 -0
- package/dist/cloud/KeyManager.js.map +1 -0
- package/dist/cloud/TenantCache.d.ts +29 -0
- package/dist/cloud/TenantCache.d.ts.map +1 -0
- package/dist/cloud/TenantCache.js +162 -0
- package/dist/cloud/TenantCache.js.map +1 -0
- package/dist/cloud/index.d.ts +4 -0
- package/dist/cloud/index.d.ts.map +1 -0
- package/dist/cloud/index.js +23 -0
- package/dist/cloud/index.js.map +1 -0
- package/dist/cloud/server.d.ts +17 -0
- package/dist/cloud/server.d.ts.map +1 -0
- package/dist/cloud/server.js +189 -0
- package/dist/cloud/server.js.map +1 -0
- package/dist/cloud/types.d.ts +35 -0
- package/dist/cloud/types.d.ts.map +1 -0
- package/dist/cloud/types.js +14 -0
- package/dist/cloud/types.js.map +1 -0
- package/dist/config/index.d.ts +44 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +161 -0
- package/dist/config/index.js.map +1 -0
- package/dist/consensus/ConsensusEngine.d.ts +119 -0
- package/dist/consensus/ConsensusEngine.d.ts.map +1 -0
- package/dist/consensus/ConsensusEngine.js +314 -0
- package/dist/consensus/ConsensusEngine.js.map +1 -0
- package/dist/consensus/ModelPool.d.ts +103 -0
- package/dist/consensus/ModelPool.d.ts.map +1 -0
- package/dist/consensus/ModelPool.js +276 -0
- package/dist/consensus/ModelPool.js.map +1 -0
- package/dist/consensus/index.d.ts +8 -0
- package/dist/consensus/index.d.ts.map +1 -0
- package/dist/consensus/index.js +13 -0
- package/dist/consensus/index.js.map +1 -0
- package/dist/core/AgentRegistry.d.ts +89 -0
- package/dist/core/AgentRegistry.d.ts.map +1 -0
- package/dist/core/AgentRegistry.js +264 -0
- package/dist/core/AgentRegistry.js.map +1 -0
- package/dist/core/DashboardBroadcaster.d.ts +67 -0
- package/dist/core/DashboardBroadcaster.d.ts.map +1 -0
- package/dist/core/DashboardBroadcaster.js +264 -0
- package/dist/core/DashboardBroadcaster.js.map +1 -0
- package/dist/core/OrchestrationEngine.d.ts +84 -0
- package/dist/core/OrchestrationEngine.d.ts.map +1 -0
- package/dist/core/OrchestrationEngine.js +455 -0
- package/dist/core/OrchestrationEngine.js.map +1 -0
- package/dist/core/SubconsciousEngine.d.ts +53 -0
- package/dist/core/SubconsciousEngine.d.ts.map +1 -0
- package/dist/core/SubconsciousEngine.js +273 -0
- package/dist/core/SubconsciousEngine.js.map +1 -0
- package/dist/core/WebSocketServer.d.ts +89 -0
- package/dist/core/WebSocketServer.d.ts.map +1 -0
- package/dist/core/WebSocketServer.js +416 -0
- package/dist/core/WebSocketServer.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +24 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/router.d.ts +105 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/router.js +420 -0
- package/dist/core/router.js.map +1 -0
- package/dist/embed/index.d.ts +153 -0
- package/dist/embed/index.d.ts.map +1 -0
- package/dist/embed/index.js +408 -0
- package/dist/embed/index.js.map +1 -0
- package/dist/embed.d.ts +11 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +19 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +176 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/flows.d.ts +126 -0
- package/dist/protocol/flows.d.ts.map +1 -0
- package/dist/protocol/flows.js +347 -0
- package/dist/protocol/flows.js.map +1 -0
- package/dist/protocol/iap.d.ts +54 -0
- package/dist/protocol/iap.d.ts.map +1 -0
- package/dist/protocol/iap.js +108 -0
- package/dist/protocol/iap.js.map +1 -0
- package/dist/protocol/index.d.ts +23 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +45 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/types.d.ts +332 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +57 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/utils.d.ts +130 -0
- package/dist/protocol/utils.d.ts.map +1 -0
- package/dist/protocol/utils.js +292 -0
- package/dist/protocol/utils.js.map +1 -0
- package/dist/protocol/validators.d.ts +54 -0
- package/dist/protocol/validators.d.ts.map +1 -0
- package/dist/protocol/validators.js +344 -0
- package/dist/protocol/validators.js.map +1 -0
- package/dist/security/AuthManager.d.ts +73 -0
- package/dist/security/AuthManager.d.ts.map +1 -0
- package/dist/security/AuthManager.js +102 -0
- package/dist/security/AuthManager.js.map +1 -0
- package/dist/security/MessageSanitizer.d.ts +51 -0
- package/dist/security/MessageSanitizer.d.ts.map +1 -0
- package/dist/security/MessageSanitizer.js +166 -0
- package/dist/security/MessageSanitizer.js.map +1 -0
- package/dist/security/RateLimiter.d.ts +46 -0
- package/dist/security/RateLimiter.d.ts.map +1 -0
- package/dist/security/RateLimiter.js +133 -0
- package/dist/security/RateLimiter.js.map +1 -0
- package/dist/security/SecurityMiddleware.d.ts +88 -0
- package/dist/security/SecurityMiddleware.d.ts.map +1 -0
- package/dist/security/SecurityMiddleware.js +146 -0
- package/dist/security/SecurityMiddleware.js.map +1 -0
- package/dist/security/index.d.ts +35 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +42 -0
- package/dist/security/index.js.map +1 -0
- package/dist/speculative/PredictionEngine.d.ts +99 -0
- package/dist/speculative/PredictionEngine.d.ts.map +1 -0
- package/dist/speculative/PredictionEngine.js +291 -0
- package/dist/speculative/PredictionEngine.js.map +1 -0
- package/dist/speculative/SpeculativeCache.d.ts +117 -0
- package/dist/speculative/SpeculativeCache.d.ts.map +1 -0
- package/dist/speculative/SpeculativeCache.js +292 -0
- package/dist/speculative/SpeculativeCache.js.map +1 -0
- package/dist/speculative/SpeculativeEngine.d.ts +114 -0
- package/dist/speculative/SpeculativeEngine.d.ts.map +1 -0
- package/dist/speculative/SpeculativeEngine.js +244 -0
- package/dist/speculative/SpeculativeEngine.js.map +1 -0
- package/dist/speculative/WorkerPool.d.ts +109 -0
- package/dist/speculative/WorkerPool.d.ts.map +1 -0
- package/dist/speculative/WorkerPool.js +327 -0
- package/dist/speculative/WorkerPool.js.map +1 -0
- package/dist/speculative/index.d.ts +10 -0
- package/dist/speculative/index.d.ts.map +1 -0
- package/dist/speculative/index.js +17 -0
- package/dist/speculative/index.js.map +1 -0
- package/dist/subconscious/EmbeddingService.d.ts +73 -0
- package/dist/subconscious/EmbeddingService.d.ts.map +1 -0
- package/dist/subconscious/EmbeddingService.js +196 -0
- package/dist/subconscious/EmbeddingService.js.map +1 -0
- package/dist/subconscious/SemanticCache.d.ts +82 -0
- package/dist/subconscious/SemanticCache.d.ts.map +1 -0
- package/dist/subconscious/SemanticCache.js +164 -0
- package/dist/subconscious/SemanticCache.js.map +1 -0
- package/dist/subconscious/SubconsciousEngine.d.ts +121 -0
- package/dist/subconscious/SubconsciousEngine.d.ts.map +1 -0
- package/dist/subconscious/SubconsciousEngine.js +241 -0
- package/dist/subconscious/SubconsciousEngine.js.map +1 -0
- package/dist/subconscious/VectorStore.d.ts +54 -0
- package/dist/subconscious/VectorStore.d.ts.map +1 -0
- package/dist/subconscious/VectorStore.js +168 -0
- package/dist/subconscious/VectorStore.js.map +1 -0
- package/dist/subconscious/cache.d.ts +34 -0
- package/dist/subconscious/cache.d.ts.map +1 -0
- package/dist/subconscious/cache.js +156 -0
- package/dist/subconscious/cache.js.map +1 -0
- package/dist/subconscious/embeddings.d.ts +25 -0
- package/dist/subconscious/embeddings.d.ts.map +1 -0
- package/dist/subconscious/embeddings.js +65 -0
- package/dist/subconscious/embeddings.js.map +1 -0
- package/dist/subconscious/index.d.ts +12 -0
- package/dist/subconscious/index.d.ts.map +1 -0
- package/dist/subconscious/index.js +19 -0
- package/dist/subconscious/index.js.map +1 -0
- package/dist/types/index.d.ts +286 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +43 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +63 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +126 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Message Sanitizer
|
|
4
|
+
* Validates and sanitizes incoming messages to prevent injection attacks
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MessageSanitizer = void 0;
|
|
8
|
+
class MessageSanitizer {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.maxStringLength = options?.maxStringLength || 10000;
|
|
11
|
+
this.maxArrayLength = options?.maxArrayLength || 1000;
|
|
12
|
+
this.maxObjectDepth = options?.maxObjectDepth || 10;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Sanitize a message
|
|
16
|
+
*/
|
|
17
|
+
sanitize(message) {
|
|
18
|
+
const errors = [];
|
|
19
|
+
try {
|
|
20
|
+
const sanitized = this.sanitizeValue(message, 0, errors);
|
|
21
|
+
if (errors.length > 0) {
|
|
22
|
+
return { valid: false, errors };
|
|
23
|
+
}
|
|
24
|
+
return { valid: true, sanitized };
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return {
|
|
28
|
+
valid: false,
|
|
29
|
+
errors: [`Sanitization error: ${error.message}`],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sanitize a value recursively
|
|
35
|
+
*/
|
|
36
|
+
sanitizeValue(value, depth, errors) {
|
|
37
|
+
// Check depth
|
|
38
|
+
if (depth > this.maxObjectDepth) {
|
|
39
|
+
errors.push(`Maximum object depth (${this.maxObjectDepth}) exceeded`);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
// Handle null/undefined
|
|
43
|
+
if (value === null || value === undefined) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
// Handle strings
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
return this.sanitizeString(value, errors);
|
|
49
|
+
}
|
|
50
|
+
// Handle numbers
|
|
51
|
+
if (typeof value === 'number') {
|
|
52
|
+
if (!Number.isFinite(value)) {
|
|
53
|
+
errors.push('Invalid number (NaN or Infinity)');
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
// Handle booleans
|
|
59
|
+
if (typeof value === 'boolean') {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
// Handle arrays
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
return this.sanitizeArray(value, depth, errors);
|
|
65
|
+
}
|
|
66
|
+
// Handle objects
|
|
67
|
+
if (typeof value === 'object') {
|
|
68
|
+
return this.sanitizeObject(value, depth, errors);
|
|
69
|
+
}
|
|
70
|
+
// Reject functions, symbols, etc.
|
|
71
|
+
errors.push(`Invalid type: ${typeof value}`);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sanitize a string
|
|
76
|
+
*/
|
|
77
|
+
sanitizeString(str, errors) {
|
|
78
|
+
// Check length
|
|
79
|
+
if (str.length > this.maxStringLength) {
|
|
80
|
+
errors.push(`String too long (${str.length} > ${this.maxStringLength})`);
|
|
81
|
+
return str.substring(0, this.maxStringLength);
|
|
82
|
+
}
|
|
83
|
+
// Remove null bytes
|
|
84
|
+
str = str.replace(/\0/g, '');
|
|
85
|
+
// Remove control characters (except newline, tab, carriage return)
|
|
86
|
+
str = str.replace(/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/g, '');
|
|
87
|
+
return str;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Sanitize an array
|
|
91
|
+
*/
|
|
92
|
+
sanitizeArray(arr, depth, errors) {
|
|
93
|
+
// Check length
|
|
94
|
+
if (arr.length > this.maxArrayLength) {
|
|
95
|
+
errors.push(`Array too long (${arr.length} > ${this.maxArrayLength})`);
|
|
96
|
+
arr = arr.slice(0, this.maxArrayLength);
|
|
97
|
+
}
|
|
98
|
+
return arr.map((item) => this.sanitizeValue(item, depth + 1, errors));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sanitize an object
|
|
102
|
+
*/
|
|
103
|
+
sanitizeObject(obj, depth, errors) {
|
|
104
|
+
const sanitized = {};
|
|
105
|
+
for (const key in obj) {
|
|
106
|
+
if (obj.hasOwnProperty(key)) {
|
|
107
|
+
// Sanitize key
|
|
108
|
+
const sanitizedKey = this.sanitizeString(key, errors);
|
|
109
|
+
// Sanitize value
|
|
110
|
+
sanitized[sanitizedKey] = this.sanitizeValue(obj[key], depth + 1, errors);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return sanitized;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Validate message structure
|
|
117
|
+
*/
|
|
118
|
+
validateMessageStructure(message) {
|
|
119
|
+
const errors = [];
|
|
120
|
+
// Check if message is an object
|
|
121
|
+
if (typeof message !== 'object' || message === null) {
|
|
122
|
+
errors.push('Message must be an object');
|
|
123
|
+
return { valid: false, errors };
|
|
124
|
+
}
|
|
125
|
+
// Check required fields
|
|
126
|
+
if (!message.type) {
|
|
127
|
+
errors.push('Message must have a "type" field');
|
|
128
|
+
}
|
|
129
|
+
if (!message.id) {
|
|
130
|
+
errors.push('Message must have an "id" field');
|
|
131
|
+
}
|
|
132
|
+
if (!message.timestamp) {
|
|
133
|
+
errors.push('Message must have a "timestamp" field');
|
|
134
|
+
}
|
|
135
|
+
// Validate timestamp
|
|
136
|
+
if (message.timestamp) {
|
|
137
|
+
const now = Date.now();
|
|
138
|
+
const diff = Math.abs(now - message.timestamp);
|
|
139
|
+
// Allow 5 minutes clock skew
|
|
140
|
+
if (diff > 5 * 60 * 1000) {
|
|
141
|
+
errors.push('Message timestamp too far from current time');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
valid: errors.length === 0,
|
|
146
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Sanitize and validate a message
|
|
151
|
+
*/
|
|
152
|
+
sanitizeAndValidate(message) {
|
|
153
|
+
// First validate structure
|
|
154
|
+
const structureValidation = this.validateMessageStructure(message);
|
|
155
|
+
if (!structureValidation.valid) {
|
|
156
|
+
return {
|
|
157
|
+
valid: false,
|
|
158
|
+
errors: structureValidation.errors,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
// Then sanitize
|
|
162
|
+
return this.sanitize(message);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.MessageSanitizer = MessageSanitizer;
|
|
166
|
+
//# sourceMappingURL=MessageSanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageSanitizer.js","sourceRoot":"","sources":["../../src/security/MessageSanitizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,MAAa,gBAAgB;IAK3B,YAAY,OAIX;QACC,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,KAAK,CAAC;QACzD,IAAI,CAAC,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,IAAI,CAAC;QACtD,IAAI,CAAC,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,EAAE,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,OAAY;QACnB,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,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
+
requestsPerHour: number;
|
|
8
|
+
blockDuration?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class RateLimiter {
|
|
11
|
+
private limits;
|
|
12
|
+
private cleanupInterval;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Check if request is allowed
|
|
16
|
+
*/
|
|
17
|
+
checkLimit(identifier: string, config: RateLimitConfig): {
|
|
18
|
+
allowed: boolean;
|
|
19
|
+
remaining: {
|
|
20
|
+
perMinute: number;
|
|
21
|
+
perHour: number;
|
|
22
|
+
};
|
|
23
|
+
resetAt?: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Reset limits for an identifier
|
|
27
|
+
*/
|
|
28
|
+
reset(identifier: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get current usage for an identifier
|
|
31
|
+
*/
|
|
32
|
+
getUsage(identifier: string): {
|
|
33
|
+
minuteRequests: number;
|
|
34
|
+
hourRequests: number;
|
|
35
|
+
blockedUntil?: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Cleanup old entries
|
|
39
|
+
*/
|
|
40
|
+
private cleanup;
|
|
41
|
+
/**
|
|
42
|
+
* Destroy rate limiter
|
|
43
|
+
*/
|
|
44
|
+
destroy(): void;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=RateLimiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RateLimiter.d.ts","sourceRoot":"","sources":["../../src/security/RateLimiter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAQD,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,eAAe,CAAiB;;IASxC;;OAEG;IACH,UAAU,CACR,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,GACtB;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,EAAE;YACT,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;IA6ED;;OAEG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG;QAC5B,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;IAuBD;;OAEG;IACH,OAAO,CAAC,OAAO;IAgBf;;OAEG;IACH,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Rate Limiter
|
|
4
|
+
* Prevents abuse by limiting requests per agent
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RateLimiter = void 0;
|
|
8
|
+
class RateLimiter {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.limits = new Map();
|
|
11
|
+
// Cleanup old entries every 5 minutes
|
|
12
|
+
this.cleanupInterval = setInterval(() => {
|
|
13
|
+
this.cleanup();
|
|
14
|
+
}, 5 * 60 * 1000);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if request is allowed
|
|
18
|
+
*/
|
|
19
|
+
checkLimit(identifier, config) {
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
let entry = this.limits.get(identifier);
|
|
22
|
+
if (!entry) {
|
|
23
|
+
entry = {
|
|
24
|
+
minuteRequests: [],
|
|
25
|
+
hourRequests: [],
|
|
26
|
+
};
|
|
27
|
+
this.limits.set(identifier, entry);
|
|
28
|
+
}
|
|
29
|
+
// Check if blocked
|
|
30
|
+
if (entry.blockedUntil && now < entry.blockedUntil) {
|
|
31
|
+
return {
|
|
32
|
+
allowed: false,
|
|
33
|
+
remaining: { perMinute: 0, perHour: 0 },
|
|
34
|
+
resetAt: entry.blockedUntil,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Clean old requests
|
|
38
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
39
|
+
const oneHourAgo = now - 60 * 60 * 1000;
|
|
40
|
+
entry.minuteRequests = entry.minuteRequests.filter((t) => t > oneMinuteAgo);
|
|
41
|
+
entry.hourRequests = entry.hourRequests.filter((t) => t > oneHourAgo);
|
|
42
|
+
// Check limits
|
|
43
|
+
const minuteCount = entry.minuteRequests.length;
|
|
44
|
+
const hourCount = entry.hourRequests.length;
|
|
45
|
+
if (minuteCount >= config.requestsPerMinute) {
|
|
46
|
+
// Block if configured
|
|
47
|
+
if (config.blockDuration) {
|
|
48
|
+
entry.blockedUntil = now + config.blockDuration;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
allowed: false,
|
|
52
|
+
remaining: {
|
|
53
|
+
perMinute: 0,
|
|
54
|
+
perHour: Math.max(0, config.requestsPerHour - hourCount),
|
|
55
|
+
},
|
|
56
|
+
resetAt: entry.minuteRequests[0] + 60 * 1000,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (hourCount >= config.requestsPerHour) {
|
|
60
|
+
// Block if configured
|
|
61
|
+
if (config.blockDuration) {
|
|
62
|
+
entry.blockedUntil = now + config.blockDuration;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
allowed: false,
|
|
66
|
+
remaining: {
|
|
67
|
+
perMinute: Math.max(0, config.requestsPerMinute - minuteCount),
|
|
68
|
+
perHour: 0,
|
|
69
|
+
},
|
|
70
|
+
resetAt: entry.hourRequests[0] + 60 * 60 * 1000,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Record request
|
|
74
|
+
entry.minuteRequests.push(now);
|
|
75
|
+
entry.hourRequests.push(now);
|
|
76
|
+
return {
|
|
77
|
+
allowed: true,
|
|
78
|
+
remaining: {
|
|
79
|
+
perMinute: config.requestsPerMinute - minuteCount - 1,
|
|
80
|
+
perHour: config.requestsPerHour - hourCount - 1,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reset limits for an identifier
|
|
86
|
+
*/
|
|
87
|
+
reset(identifier) {
|
|
88
|
+
this.limits.delete(identifier);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get current usage for an identifier
|
|
92
|
+
*/
|
|
93
|
+
getUsage(identifier) {
|
|
94
|
+
const entry = this.limits.get(identifier);
|
|
95
|
+
if (!entry) {
|
|
96
|
+
return { minuteRequests: 0, hourRequests: 0 };
|
|
97
|
+
}
|
|
98
|
+
const now = Date.now();
|
|
99
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
100
|
+
const oneHourAgo = now - 60 * 60 * 1000;
|
|
101
|
+
const minuteRequests = entry.minuteRequests.filter((t) => t > oneMinuteAgo).length;
|
|
102
|
+
const hourRequests = entry.hourRequests.filter((t) => t > oneHourAgo).length;
|
|
103
|
+
return {
|
|
104
|
+
minuteRequests,
|
|
105
|
+
hourRequests,
|
|
106
|
+
blockedUntil: entry.blockedUntil,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Cleanup old entries
|
|
111
|
+
*/
|
|
112
|
+
cleanup() {
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
const oneHourAgo = now - 60 * 60 * 1000;
|
|
115
|
+
for (const [identifier, entry] of this.limits.entries()) {
|
|
116
|
+
// Remove if no recent requests and not blocked
|
|
117
|
+
if (entry.hourRequests.length === 0 ||
|
|
118
|
+
(entry.hourRequests[entry.hourRequests.length - 1] < oneHourAgo &&
|
|
119
|
+
(!entry.blockedUntil || now > entry.blockedUntil))) {
|
|
120
|
+
this.limits.delete(identifier);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Destroy rate limiter
|
|
126
|
+
*/
|
|
127
|
+
destroy() {
|
|
128
|
+
clearInterval(this.cleanupInterval);
|
|
129
|
+
this.limits.clear();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.RateLimiter = RateLimiter;
|
|
133
|
+
//# sourceMappingURL=RateLimiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RateLimiter.js","sourceRoot":"","sources":["../../src/security/RateLimiter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAcH,MAAa,WAAW;IAItB;QAHQ,WAAM,GAAgC,IAAI,GAAG,EAAE,CAAC;QAItD,sCAAsC;QACtC,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE;YACtC,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,UAAU,CACR,UAAkB,EAClB,MAAuB;QASvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAExC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG;gBACN,cAAc,EAAE,EAAE;gBAClB,YAAY,EAAE,EAAE;aACjB,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;QAED,mBAAmB;QACnB,IAAI,KAAK,CAAC,YAAY,IAAI,GAAG,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC;YACnD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;gBACvC,OAAO,EAAE,KAAK,CAAC,YAAY;aAC5B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AC,CAAC,GAAG,YAAY,CACxB,CAAC,MAAM,CAAC;QACT,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,MAAM,CAAC;QAE7E,OAAO;YACL,cAAc;YACd,YAAY;YACZ,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,OAAO;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAExC,KAAK,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACxD,+CAA+C;YAC/C,IACE,KAAK,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC;gBAC/B,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,UAAU;oBAC7D,CAAC,CAAC,KAAK,CAAC,YAAY,IAAI,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,EACpD,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AApKD,kCAoKC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ApiKey } from './AuthManager';
|
|
2
|
+
/**
|
|
3
|
+
* Security Middleware
|
|
4
|
+
* Integrates all security features into a single middleware
|
|
5
|
+
*/
|
|
6
|
+
export interface SecurityConfig {
|
|
7
|
+
auth: {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
requireApiKey: boolean;
|
|
10
|
+
allowedOrigins?: string[];
|
|
11
|
+
defaultRateLimit?: {
|
|
12
|
+
requestsPerMinute: number;
|
|
13
|
+
requestsPerHour: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
rateLimit: {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
requestsPerMinute: number;
|
|
19
|
+
requestsPerHour: number;
|
|
20
|
+
blockDuration?: number;
|
|
21
|
+
};
|
|
22
|
+
sanitization: {
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
maxStringLength?: number;
|
|
25
|
+
maxArrayLength?: number;
|
|
26
|
+
maxObjectDepth?: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface SecurityCheckResult {
|
|
30
|
+
allowed: boolean;
|
|
31
|
+
reason?: string;
|
|
32
|
+
apiKey?: ApiKey;
|
|
33
|
+
rateLimit?: {
|
|
34
|
+
remaining: {
|
|
35
|
+
perMinute: number;
|
|
36
|
+
perHour: number;
|
|
37
|
+
};
|
|
38
|
+
resetAt?: number;
|
|
39
|
+
};
|
|
40
|
+
sanitizedMessage?: any;
|
|
41
|
+
}
|
|
42
|
+
export declare class SecurityMiddleware {
|
|
43
|
+
private authManager;
|
|
44
|
+
private rateLimiter;
|
|
45
|
+
private sanitizer;
|
|
46
|
+
private config;
|
|
47
|
+
constructor(config: SecurityConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Check if a request is allowed
|
|
50
|
+
*/
|
|
51
|
+
checkRequest(apiKey: string | undefined, origin: string | undefined, message: any, identifier: string): SecurityCheckResult;
|
|
52
|
+
/**
|
|
53
|
+
* Generate a new API key
|
|
54
|
+
*/
|
|
55
|
+
generateApiKey(agentId: string, name: string, options?: {
|
|
56
|
+
expiresIn?: number;
|
|
57
|
+
permissions?: string[];
|
|
58
|
+
rateLimit?: {
|
|
59
|
+
requestsPerMinute: number;
|
|
60
|
+
requestsPerHour: number;
|
|
61
|
+
};
|
|
62
|
+
}): string;
|
|
63
|
+
/**
|
|
64
|
+
* Revoke an API key
|
|
65
|
+
*/
|
|
66
|
+
revokeApiKey(key: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* List API keys
|
|
69
|
+
*/
|
|
70
|
+
listApiKeys(agentId?: string): ApiKey[];
|
|
71
|
+
/**
|
|
72
|
+
* Get rate limit usage
|
|
73
|
+
*/
|
|
74
|
+
getRateLimitUsage(identifier: string): {
|
|
75
|
+
minuteRequests: number;
|
|
76
|
+
hourRequests: number;
|
|
77
|
+
blockedUntil?: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Reset rate limit for an identifier
|
|
81
|
+
*/
|
|
82
|
+
resetRateLimit(identifier: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Destroy security middleware
|
|
85
|
+
*/
|
|
86
|
+
destroy(): void;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=SecurityMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityMiddleware.d.ts","sourceRoot":"","sources":["../../src/security/SecurityMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,eAAe,CAAC;AAIpD;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE;QACJ,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1B,gBAAgB,CAAC,EAAE;YACjB,iBAAiB,EAAE,MAAM,CAAC;YAC1B,eAAe,EAAE,MAAM,CAAC;SACzB,CAAC;KACH,CAAC;IACF,SAAS,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,YAAY,EAAE;QACZ,OAAO,EAAE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OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG;QACrC,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;IAID;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAIxC;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecurityMiddleware = void 0;
|
|
4
|
+
const AuthManager_1 = require("./AuthManager");
|
|
5
|
+
const RateLimiter_1 = require("./RateLimiter");
|
|
6
|
+
const MessageSanitizer_1 = require("./MessageSanitizer");
|
|
7
|
+
class SecurityMiddleware {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.authManager = new AuthManager_1.AuthManager(config.auth);
|
|
11
|
+
this.rateLimiter = new RateLimiter_1.RateLimiter();
|
|
12
|
+
this.sanitizer = new MessageSanitizer_1.MessageSanitizer(config.sanitization);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if a request is allowed
|
|
16
|
+
*/
|
|
17
|
+
checkRequest(apiKey, origin, message, identifier) {
|
|
18
|
+
// 1. Check authentication
|
|
19
|
+
if (this.config.auth.enabled) {
|
|
20
|
+
const authResult = this.authManager.validateApiKey(apiKey || '');
|
|
21
|
+
if (!authResult.valid) {
|
|
22
|
+
return {
|
|
23
|
+
allowed: false,
|
|
24
|
+
reason: authResult.reason || 'Authentication failed',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Check origin (CORS)
|
|
28
|
+
if (origin && !this.authManager.validateOrigin(origin)) {
|
|
29
|
+
return {
|
|
30
|
+
allowed: false,
|
|
31
|
+
reason: 'Origin not allowed',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// 2. Check rate limit
|
|
35
|
+
if (this.config.rateLimit.enabled && authResult.apiKey) {
|
|
36
|
+
const rateLimit = this.authManager.getRateLimit(authResult.apiKey);
|
|
37
|
+
const rateLimitResult = this.rateLimiter.checkLimit(identifier, {
|
|
38
|
+
...rateLimit,
|
|
39
|
+
blockDuration: this.config.rateLimit.blockDuration,
|
|
40
|
+
});
|
|
41
|
+
if (!rateLimitResult.allowed) {
|
|
42
|
+
return {
|
|
43
|
+
allowed: false,
|
|
44
|
+
reason: 'Rate limit exceeded',
|
|
45
|
+
rateLimit: {
|
|
46
|
+
remaining: rateLimitResult.remaining,
|
|
47
|
+
resetAt: rateLimitResult.resetAt,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// 3. Sanitize message
|
|
52
|
+
let sanitizedMessage = message;
|
|
53
|
+
if (this.config.sanitization.enabled) {
|
|
54
|
+
const sanitizationResult = this.sanitizer.sanitizeAndValidate(message);
|
|
55
|
+
if (!sanitizationResult.valid) {
|
|
56
|
+
return {
|
|
57
|
+
allowed: false,
|
|
58
|
+
reason: `Message validation failed: ${sanitizationResult.errors?.join(', ')}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
sanitizedMessage = sanitizationResult.sanitized;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
allowed: true,
|
|
65
|
+
apiKey: authResult.apiKey,
|
|
66
|
+
rateLimit: {
|
|
67
|
+
remaining: rateLimitResult.remaining,
|
|
68
|
+
},
|
|
69
|
+
sanitizedMessage,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// If auth is disabled, still check rate limit and sanitization
|
|
74
|
+
if (this.config.rateLimit.enabled) {
|
|
75
|
+
const rateLimitResult = this.rateLimiter.checkLimit(identifier, {
|
|
76
|
+
requestsPerMinute: this.config.rateLimit.requestsPerMinute,
|
|
77
|
+
requestsPerHour: this.config.rateLimit.requestsPerHour,
|
|
78
|
+
blockDuration: this.config.rateLimit.blockDuration,
|
|
79
|
+
});
|
|
80
|
+
if (!rateLimitResult.allowed) {
|
|
81
|
+
return {
|
|
82
|
+
allowed: false,
|
|
83
|
+
reason: 'Rate limit exceeded',
|
|
84
|
+
rateLimit: {
|
|
85
|
+
remaining: rateLimitResult.remaining,
|
|
86
|
+
resetAt: rateLimitResult.resetAt,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Sanitize message
|
|
92
|
+
let sanitizedMessage = message;
|
|
93
|
+
if (this.config.sanitization.enabled) {
|
|
94
|
+
const sanitizationResult = this.sanitizer.sanitizeAndValidate(message);
|
|
95
|
+
if (!sanitizationResult.valid) {
|
|
96
|
+
return {
|
|
97
|
+
allowed: false,
|
|
98
|
+
reason: `Message validation failed: ${sanitizationResult.errors?.join(', ')}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
sanitizedMessage = sanitizationResult.sanitized;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
allowed: true,
|
|
105
|
+
sanitizedMessage,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generate a new API key
|
|
110
|
+
*/
|
|
111
|
+
generateApiKey(agentId, name, options) {
|
|
112
|
+
return this.authManager.generateApiKey(agentId, name, options);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Revoke an API key
|
|
116
|
+
*/
|
|
117
|
+
revokeApiKey(key) {
|
|
118
|
+
return this.authManager.revokeApiKey(key);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* List API keys
|
|
122
|
+
*/
|
|
123
|
+
listApiKeys(agentId) {
|
|
124
|
+
return this.authManager.listApiKeys(agentId);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get rate limit usage
|
|
128
|
+
*/
|
|
129
|
+
getRateLimitUsage(identifier) {
|
|
130
|
+
return this.rateLimiter.getUsage(identifier);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reset rate limit for an identifier
|
|
134
|
+
*/
|
|
135
|
+
resetRateLimit(identifier) {
|
|
136
|
+
this.rateLimiter.reset(identifier);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Destroy security middleware
|
|
140
|
+
*/
|
|
141
|
+
destroy() {
|
|
142
|
+
this.rateLimiter.destroy();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.SecurityMiddleware = SecurityMiddleware;
|
|
146
|
+
//# sourceMappingURL=SecurityMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityMiddleware.js","sourceRoot":"","sources":["../../src/security/SecurityMiddleware.ts"],"names":[],"mappings":";;;AAAA,+CAAoD;AACpD,+CAA6D;AAC7D,yDAAsD;AA6CtD,MAAa,kBAAkB;IAM7B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,EAAE,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,IAAI,mCAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,YAAY,CACV,MAA0B,EAC1B,MAA0B,EAC1B,OAAY,EACZ,UAAkB;QAElB,0BAA0B;QAC1B,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YAEjE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,uBAAuB;iBACrD,CAAC;YACJ,CAAC;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,CAAC;YAED,gBAAgB,GAAG,kBAAkB,CAAC,SAAS,CAAC;QAClD,CAAC;QAED,OAAO;YACL,OAAO,EAAE,IAAI;YACb,gBAAgB;SACjB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,cAAc,CACZ,OAAe,EACf,IAAY,EACZ,OAIC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,GAAW;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,OAAgB;QAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,UAAkB;QAKlC,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,UAAkB;QAC/B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACF;AArLD,gDAqLC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Module
|
|
3
|
+
* Exports all security-related components
|
|
4
|
+
*/
|
|
5
|
+
export { AuthManager, ApiKey, AuthConfig } from './AuthManager';
|
|
6
|
+
export { RateLimiter, RateLimitConfig } from './RateLimiter';
|
|
7
|
+
export { MessageSanitizer, SanitizationResult } from './MessageSanitizer';
|
|
8
|
+
export { SecurityMiddleware, SecurityConfig, SecurityCheckResult } from './SecurityMiddleware';
|
|
9
|
+
/**
|
|
10
|
+
* Default security configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_SECURITY_CONFIG: {
|
|
13
|
+
auth: {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
requireApiKey: boolean;
|
|
16
|
+
allowedOrigins: string[];
|
|
17
|
+
defaultRateLimit: {
|
|
18
|
+
requestsPerMinute: number;
|
|
19
|
+
requestsPerHour: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
rateLimit: {
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
requestsPerMinute: number;
|
|
25
|
+
requestsPerHour: number;
|
|
26
|
+
blockDuration: number;
|
|
27
|
+
};
|
|
28
|
+
sanitization: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
maxStringLength: number;
|
|
31
|
+
maxArrayLength: number;
|
|
32
|
+
maxObjectDepth: number;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE/F;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CAsBnC,CAAC"}
|