mcp-image 0.1.0 → 0.2.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/README.md +41 -17
- package/dist/api/geminiClient.d.ts +2 -12
- package/dist/api/geminiClient.d.ts.map +1 -1
- package/dist/api/geminiClient.js +28 -56
- package/dist/api/geminiClient.js.map +1 -1
- package/dist/api/geminiTextClient.d.ts +42 -0
- package/dist/api/geminiTextClient.d.ts.map +1 -0
- package/dist/api/geminiTextClient.js +198 -0
- package/dist/api/geminiTextClient.js.map +1 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.d.ts +84 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.d.ts.map +1 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.js +100 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.js.map +1 -0
- package/dist/business/bestPracticesEngine.d.ts +149 -0
- package/dist/business/bestPracticesEngine.d.ts.map +1 -0
- package/dist/business/bestPracticesEngine.js +781 -0
- package/dist/business/bestPracticesEngine.js.map +1 -0
- package/dist/business/complexityAssessment.d.ts +132 -0
- package/dist/business/complexityAssessment.d.ts.map +1 -0
- package/dist/business/complexityAssessment.js +488 -0
- package/dist/business/complexityAssessment.js.map +1 -0
- package/dist/business/fallbackStrategies.d.ts +177 -0
- package/dist/business/fallbackStrategies.d.ts.map +1 -0
- package/dist/business/fallbackStrategies.js +368 -0
- package/dist/business/fallbackStrategies.js.map +1 -0
- package/dist/business/imageGenerator.d.ts.map +1 -1
- package/dist/business/imageGenerator.js +26 -5
- package/dist/business/imageGenerator.js.map +1 -1
- package/dist/business/multiImage/aspectRatioController.d.ts +77 -0
- package/dist/business/multiImage/aspectRatioController.d.ts.map +1 -0
- package/dist/business/multiImage/aspectRatioController.js +580 -0
- package/dist/business/multiImage/aspectRatioController.js.map +1 -0
- package/dist/business/multiImage/multiImageCoordinator.d.ts +142 -0
- package/dist/business/multiImage/multiImageCoordinator.d.ts.map +1 -0
- package/dist/business/multiImage/multiImageCoordinator.js +801 -0
- package/dist/business/multiImage/multiImageCoordinator.js.map +1 -0
- package/dist/business/pomlTemplateEngine.d.ts +206 -0
- package/dist/business/pomlTemplateEngine.d.ts.map +1 -0
- package/dist/business/pomlTemplateEngine.js +737 -0
- package/dist/business/pomlTemplateEngine.js.map +1 -0
- package/dist/business/promptOrchestrator.d.ts +173 -0
- package/dist/business/promptOrchestrator.d.ts.map +1 -0
- package/dist/business/promptOrchestrator.js +490 -0
- package/dist/business/promptOrchestrator.js.map +1 -0
- package/dist/business/responseBuilder.d.ts +2 -2
- package/dist/business/responseBuilder.d.ts.map +1 -1
- package/dist/business/responseBuilder.js +6 -1
- package/dist/business/responseBuilder.js.map +1 -1
- package/dist/business/structuredPromptGenerator.d.ts +54 -0
- package/dist/business/structuredPromptGenerator.d.ts.map +1 -0
- package/dist/business/structuredPromptGenerator.js +208 -0
- package/dist/business/structuredPromptGenerator.js.map +1 -0
- package/dist/business/templateNormalizer.d.ts +81 -0
- package/dist/business/templateNormalizer.d.ts.map +1 -0
- package/dist/business/templateNormalizer.js +659 -0
- package/dist/business/templateNormalizer.js.map +1 -0
- package/dist/documentation/apiContractValidation.d.ts +62 -0
- package/dist/documentation/apiContractValidation.d.ts.map +1 -0
- package/dist/documentation/apiContractValidation.js +305 -0
- package/dist/documentation/apiContractValidation.js.map +1 -0
- package/dist/infrastructure/concurrency/concurrencyManager.d.ts +101 -0
- package/dist/infrastructure/concurrency/concurrencyManager.d.ts.map +1 -0
- package/dist/infrastructure/concurrency/concurrencyManager.js +345 -0
- package/dist/infrastructure/concurrency/concurrencyManager.js.map +1 -0
- package/dist/infrastructure/config/secureConfigManager.d.ts +319 -0
- package/dist/infrastructure/config/secureConfigManager.d.ts.map +1 -0
- package/dist/infrastructure/config/secureConfigManager.js +600 -0
- package/dist/infrastructure/config/secureConfigManager.js.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.d.ts +229 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.d.ts.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.js +61 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.js.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.d.ts +133 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.d.ts.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.js +569 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.js.map +1 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.d.ts +19 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.d.ts.map +1 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.js +31 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.js.map +1 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.d.ts +59 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.d.ts.map +1 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.js +271 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.js.map +1 -0
- package/dist/infrastructure/metadata/generationMetadata.d.ts +72 -0
- package/dist/infrastructure/metadata/generationMetadata.d.ts.map +1 -0
- package/dist/infrastructure/metadata/generationMetadata.js +228 -0
- package/dist/infrastructure/metadata/generationMetadata.js.map +1 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.d.ts +106 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.js +456 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.js.map +1 -0
- package/dist/infrastructure/monitoring/alertingSystem.d.ts +135 -0
- package/dist/infrastructure/monitoring/alertingSystem.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/alertingSystem.js +549 -0
- package/dist/infrastructure/monitoring/alertingSystem.js.map +1 -0
- package/dist/infrastructure/optimization/performanceOptimizer.d.ts +89 -0
- package/dist/infrastructure/optimization/performanceOptimizer.d.ts.map +1 -0
- package/dist/infrastructure/optimization/performanceOptimizer.js +375 -0
- package/dist/infrastructure/optimization/performanceOptimizer.js.map +1 -0
- package/dist/infrastructure/security/AdvancedContentFilter.d.ts +99 -0
- package/dist/infrastructure/security/AdvancedContentFilter.d.ts.map +1 -0
- package/dist/infrastructure/security/AdvancedContentFilter.js +363 -0
- package/dist/infrastructure/security/AdvancedContentFilter.js.map +1 -0
- package/dist/infrastructure/security/MCPSecurityValidator.d.ts +62 -0
- package/dist/infrastructure/security/MCPSecurityValidator.d.ts.map +1 -0
- package/dist/infrastructure/security/MCPSecurityValidator.js +129 -0
- package/dist/infrastructure/security/MCPSecurityValidator.js.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.d.ts +304 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.d.ts.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.js +61 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.js.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.d.ts +62 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.d.ts.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.js +591 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.js.map +1 -0
- package/dist/infrastructure/security/SecureMCPClient.d.ts +154 -0
- package/dist/infrastructure/security/SecureMCPClient.d.ts.map +1 -0
- package/dist/infrastructure/security/SecureMCPClient.js +292 -0
- package/dist/infrastructure/security/SecureMCPClient.js.map +1 -0
- package/dist/infrastructure/security/SecurityIncidentManager.d.ts +142 -0
- package/dist/infrastructure/security/SecurityIncidentManager.d.ts.map +1 -0
- package/dist/infrastructure/security/SecurityIncidentManager.js +260 -0
- package/dist/infrastructure/security/SecurityIncidentManager.js.map +1 -0
- package/dist/infrastructure/security/apiKeyManager.d.ts +297 -0
- package/dist/infrastructure/security/apiKeyManager.d.ts.map +1 -0
- package/dist/infrastructure/security/apiKeyManager.js +254 -0
- package/dist/infrastructure/security/apiKeyManager.js.map +1 -0
- package/dist/infrastructure/security/dataSanitizer.d.ts +157 -0
- package/dist/infrastructure/security/dataSanitizer.d.ts.map +1 -0
- package/dist/infrastructure/security/dataSanitizer.js +525 -0
- package/dist/infrastructure/security/dataSanitizer.js.map +1 -0
- package/dist/infrastructure/validation/inputValidator.d.ts +54 -0
- package/dist/infrastructure/validation/inputValidator.d.ts.map +1 -0
- package/dist/infrastructure/validation/inputValidator.js +362 -0
- package/dist/infrastructure/validation/inputValidator.js.map +1 -0
- package/dist/integration/parameterOptimizer.d.ts +69 -0
- package/dist/integration/parameterOptimizer.d.ts.map +1 -0
- package/dist/integration/parameterOptimizer.js +317 -0
- package/dist/integration/parameterOptimizer.js.map +1 -0
- package/dist/integration/twoStageProcessor.d.ts +66 -0
- package/dist/integration/twoStageProcessor.d.ts.map +1 -0
- package/dist/integration/twoStageProcessor.js +348 -0
- package/dist/integration/twoStageProcessor.js.map +1 -0
- package/dist/server/handlers/structuredPromptHandler.d.ts +65 -0
- package/dist/server/handlers/structuredPromptHandler.d.ts.map +1 -0
- package/dist/server/handlers/structuredPromptHandler.js +314 -0
- package/dist/server/handlers/structuredPromptHandler.js.map +1 -0
- package/dist/server/mcpServer.d.ts +16 -35
- package/dist/server/mcpServer.d.ts.map +1 -1
- package/dist/server/mcpServer.js +111 -150
- package/dist/server/mcpServer.js.map +1 -1
- package/dist/server/mcpServerWithOrchestration.d.ts +98 -0
- package/dist/server/mcpServerWithOrchestration.d.ts.map +1 -0
- package/dist/server/mcpServerWithOrchestration.js +284 -0
- package/dist/server/mcpServerWithOrchestration.js.map +1 -0
- package/dist/types/mcpOrchestrationTypes.d.ts +135 -0
- package/dist/types/mcpOrchestrationTypes.d.ts.map +1 -0
- package/dist/types/mcpOrchestrationTypes.js +28 -0
- package/dist/types/mcpOrchestrationTypes.js.map +1 -0
- package/dist/types/multiImageTypes.d.ts +328 -0
- package/dist/types/multiImageTypes.d.ts.map +1 -0
- package/dist/types/multiImageTypes.js +27 -0
- package/dist/types/multiImageTypes.js.map +1 -0
- package/dist/types/performanceTypes.d.ts +300 -0
- package/dist/types/performanceTypes.d.ts.map +1 -0
- package/dist/types/performanceTypes.js +50 -0
- package/dist/types/performanceTypes.js.map +1 -0
- package/dist/types/twoStageTypes.d.ts +123 -0
- package/dist/types/twoStageTypes.d.ts.map +1 -0
- package/dist/types/twoStageTypes.js +7 -0
- package/dist/types/twoStageTypes.js.map +1 -0
- package/dist/utils/config.d.ts +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +1 -0
- package/dist/utils/config.js.map +1 -1
- package/package.json +11 -4
- package/vitest.config.mjs +0 -47
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Security Incident Manager
|
|
4
|
+
* Detects, tracks, and reports security anomalies in prompt orchestration
|
|
5
|
+
* Provides automatic pattern detection and incident management
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.SecurityIncidentManager = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* SecurityIncidentManager provides comprehensive security monitoring
|
|
11
|
+
* for the prompt orchestration system
|
|
12
|
+
*/
|
|
13
|
+
class SecurityIncidentManager {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.sensitiveDataPatterns = [];
|
|
16
|
+
this.errorPatternTracker = new Map();
|
|
17
|
+
this.recentIncidents = [];
|
|
18
|
+
this.currentLogLevel = 'info';
|
|
19
|
+
this.maxIncidentHistory = 100;
|
|
20
|
+
this.initializeSensitiveDataPatterns();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initialize patterns for detecting sensitive data
|
|
24
|
+
* Used for data protection in logging and incident reporting
|
|
25
|
+
*/
|
|
26
|
+
initializeSensitiveDataPatterns() {
|
|
27
|
+
this.sensitiveDataPatterns = [
|
|
28
|
+
/(?:api[_-]?key|apikey)\s*[:\=]\s*[\'""]?[a-zA-Z0-9\-_]{10,}[\'""]?/gi,
|
|
29
|
+
/(?:password|pwd|passwd)\s*[:\=]\s*[\'""]?[^\s\'"]{8,}[\'""]?/gi,
|
|
30
|
+
/(?:token|auth[_-]?token)\s*[:\=]\s*[\'""]?[a-zA-Z0-9\-_\.]{20,}[\'""]?/gi,
|
|
31
|
+
/(?:secret|client[_-]?secret)\s*[:\=]\s*[\'""]?[a-zA-Z0-9\-_]{16,}[\'""]?/gi,
|
|
32
|
+
/sk-(?:proj-)?[a-zA-Z0-9\-_]{10,}/gi, // OpenAI-style API keys (broader pattern)
|
|
33
|
+
/ghp_[a-zA-Z0-9]{36}/gi, // GitHub personal access tokens
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detect anomalies in prompt processing context
|
|
38
|
+
* Analyzes prompts and context for suspicious patterns
|
|
39
|
+
*/
|
|
40
|
+
detectAnomalies(context) {
|
|
41
|
+
let anomalyCount = 0;
|
|
42
|
+
let riskLevel = 'low';
|
|
43
|
+
const detectedAnomalies = [];
|
|
44
|
+
// Check for injection patterns
|
|
45
|
+
const injectionPatterns = [
|
|
46
|
+
/(?:script|javascript|eval|exec|system|cmd)/gi,
|
|
47
|
+
/(?:union|select|drop|delete|insert|update|alter)\s+/gi,
|
|
48
|
+
/(?:<script|<iframe|<object|<embed)/gi,
|
|
49
|
+
/(?:\.\.\/|\.\.\\|\/etc\/|c:\\)/gi,
|
|
50
|
+
];
|
|
51
|
+
for (const pattern of injectionPatterns) {
|
|
52
|
+
if (pattern.test(context.prompt)) {
|
|
53
|
+
anomalyCount++;
|
|
54
|
+
detectedAnomalies.push('potential_injection');
|
|
55
|
+
riskLevel = 'high';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Check for sensitive data exposure
|
|
59
|
+
for (const pattern of this.sensitiveDataPatterns) {
|
|
60
|
+
if (pattern.test(context.prompt)) {
|
|
61
|
+
anomalyCount++;
|
|
62
|
+
detectedAnomalies.push('sensitive_data_exposure');
|
|
63
|
+
riskLevel = riskLevel === 'low' ? 'medium' : 'critical';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Check for unusually long prompts (potential DoS)
|
|
67
|
+
if (context.prompt.length > 10000) {
|
|
68
|
+
anomalyCount++;
|
|
69
|
+
detectedAnomalies.push('excessive_prompt_length');
|
|
70
|
+
riskLevel = riskLevel === 'low' ? 'medium' : riskLevel;
|
|
71
|
+
}
|
|
72
|
+
// Check for rapid repeated processing (potential abuse)
|
|
73
|
+
const recentSimilarIncidents = this.recentIncidents.filter((incident) => incident.timestamp > new Date(Date.now() - 60000).toISOString() && // Last minute
|
|
74
|
+
incident.details['promptHash'] === this.hashPrompt(context.prompt));
|
|
75
|
+
if (recentSimilarIncidents.length > 10) {
|
|
76
|
+
anomalyCount++;
|
|
77
|
+
detectedAnomalies.push('rapid_repeated_processing');
|
|
78
|
+
riskLevel = 'high';
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
hasAnomalies: anomalyCount > 0,
|
|
82
|
+
anomalyCount,
|
|
83
|
+
riskLevel,
|
|
84
|
+
description: detectedAnomalies.length > 0
|
|
85
|
+
? `Detected anomalies: ${detectedAnomalies.join(', ')}`
|
|
86
|
+
: 'No anomalies detected',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Track error patterns and detect consecutive failures
|
|
91
|
+
* Helps identify systematic issues or potential attacks
|
|
92
|
+
*/
|
|
93
|
+
trackErrorPattern(errorType) {
|
|
94
|
+
const currentCount = this.errorPatternTracker.get(errorType) || 0;
|
|
95
|
+
const newCount = currentCount + 1;
|
|
96
|
+
this.errorPatternTracker.set(errorType, newCount);
|
|
97
|
+
// Clear other error patterns if this one is successful
|
|
98
|
+
if (errorType === 'success') {
|
|
99
|
+
this.errorPatternTracker.clear();
|
|
100
|
+
return {
|
|
101
|
+
consecutiveErrors: 0,
|
|
102
|
+
errorPattern: 'none',
|
|
103
|
+
requiresIncident: false,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const requiresIncident = newCount >= 5; // 5+ consecutive errors trigger incident
|
|
107
|
+
return {
|
|
108
|
+
consecutiveErrors: newCount,
|
|
109
|
+
errorPattern: errorType,
|
|
110
|
+
requiresIncident,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Report a security incident
|
|
115
|
+
* Creates incident record and triggers appropriate responses
|
|
116
|
+
*/
|
|
117
|
+
reportIncident(incident) {
|
|
118
|
+
const fullIncident = {
|
|
119
|
+
id: this.generateIncidentId(),
|
|
120
|
+
timestamp: new Date().toISOString(),
|
|
121
|
+
...incident,
|
|
122
|
+
};
|
|
123
|
+
// Add to incident history
|
|
124
|
+
this.recentIncidents.push(fullIncident);
|
|
125
|
+
// Maintain incident history limit
|
|
126
|
+
if (this.recentIncidents.length > this.maxIncidentHistory) {
|
|
127
|
+
this.recentIncidents.shift();
|
|
128
|
+
}
|
|
129
|
+
// Auto-adjust logging based on incident severity
|
|
130
|
+
this.adjustLogLevel(incident.riskLevel);
|
|
131
|
+
// Log incident with appropriate level
|
|
132
|
+
this.logIncident(fullIncident);
|
|
133
|
+
return fullIncident;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Automatically adjust log level based on incident severity
|
|
137
|
+
* Higher severity incidents increase logging verbosity
|
|
138
|
+
*/
|
|
139
|
+
adjustLogLevel(riskLevel) {
|
|
140
|
+
const levelMap = {
|
|
141
|
+
low: 'info',
|
|
142
|
+
medium: 'warn',
|
|
143
|
+
high: 'error',
|
|
144
|
+
critical: 'critical',
|
|
145
|
+
};
|
|
146
|
+
const newLevel = levelMap[riskLevel];
|
|
147
|
+
if (this.shouldUpgradeLogLevel(this.currentLogLevel, newLevel)) {
|
|
148
|
+
this.currentLogLevel = newLevel;
|
|
149
|
+
console.log(`Security log level adjusted to: ${newLevel} due to ${riskLevel} risk incident`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Determine if log level should be upgraded
|
|
154
|
+
*/
|
|
155
|
+
shouldUpgradeLogLevel(current, proposed) {
|
|
156
|
+
const levelPriority = {
|
|
157
|
+
debug: 0,
|
|
158
|
+
info: 1,
|
|
159
|
+
warn: 2,
|
|
160
|
+
error: 3,
|
|
161
|
+
critical: 4,
|
|
162
|
+
};
|
|
163
|
+
return levelPriority[proposed] > levelPriority[current];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Log incident with structured format and data protection
|
|
167
|
+
*/
|
|
168
|
+
logIncident(incident) {
|
|
169
|
+
const sanitizedIncident = this.sanitizeIncidentData(incident);
|
|
170
|
+
switch (incident.riskLevel) {
|
|
171
|
+
case 'critical':
|
|
172
|
+
console.error('SECURITY CRITICAL:', sanitizedIncident);
|
|
173
|
+
break;
|
|
174
|
+
case 'high':
|
|
175
|
+
console.error('SECURITY HIGH:', sanitizedIncident);
|
|
176
|
+
break;
|
|
177
|
+
case 'medium':
|
|
178
|
+
console.warn('SECURITY MEDIUM:', sanitizedIncident);
|
|
179
|
+
break;
|
|
180
|
+
case 'low':
|
|
181
|
+
console.info('SECURITY LOW:', sanitizedIncident);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Sanitize incident data to remove sensitive information
|
|
187
|
+
*/
|
|
188
|
+
sanitizeIncidentData(incident) {
|
|
189
|
+
const sanitized = JSON.parse(JSON.stringify(incident)); // Deep clone
|
|
190
|
+
// Sanitize details recursively
|
|
191
|
+
if (sanitized.details) {
|
|
192
|
+
this.sanitizeObjectRecursively(sanitized.details);
|
|
193
|
+
}
|
|
194
|
+
return sanitized;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Recursively sanitize an object to remove sensitive data
|
|
198
|
+
*/
|
|
199
|
+
sanitizeObjectRecursively(obj) {
|
|
200
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
201
|
+
if (typeof value === 'string') {
|
|
202
|
+
obj[key] = this.redactSensitiveData(value);
|
|
203
|
+
}
|
|
204
|
+
else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
205
|
+
this.sanitizeObjectRecursively(value);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Redact sensitive data from text using pattern matching
|
|
211
|
+
*/
|
|
212
|
+
redactSensitiveData(text) {
|
|
213
|
+
let sanitized = text;
|
|
214
|
+
for (const pattern of this.sensitiveDataPatterns) {
|
|
215
|
+
sanitized = sanitized.replace(pattern, '[REDACTED]');
|
|
216
|
+
}
|
|
217
|
+
return sanitized;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Generate unique incident ID
|
|
221
|
+
*/
|
|
222
|
+
generateIncidentId() {
|
|
223
|
+
return `inc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Generate hash for prompt comparison
|
|
227
|
+
*/
|
|
228
|
+
hashPrompt(prompt) {
|
|
229
|
+
// Simple hash for prompt comparison (not cryptographic)
|
|
230
|
+
let hash = 0;
|
|
231
|
+
for (let i = 0; i < prompt.length; i++) {
|
|
232
|
+
const char = prompt.charCodeAt(i);
|
|
233
|
+
hash = (hash << 5) - hash + char;
|
|
234
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
235
|
+
}
|
|
236
|
+
return hash.toString(36);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get current security status
|
|
240
|
+
*/
|
|
241
|
+
getSecurityStatus() {
|
|
242
|
+
return {
|
|
243
|
+
currentLogLevel: this.currentLogLevel,
|
|
244
|
+
recentIncidentCount: this.recentIncidents.filter((incident) => incident.timestamp > new Date(Date.now() - 3600000).toISOString() // Last hour
|
|
245
|
+
).length,
|
|
246
|
+
activeErrorPatterns: Object.fromEntries(this.errorPatternTracker),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Reset security tracking state
|
|
251
|
+
* Useful for testing or system reset scenarios
|
|
252
|
+
*/
|
|
253
|
+
reset() {
|
|
254
|
+
this.errorPatternTracker.clear();
|
|
255
|
+
this.recentIncidents.length = 0;
|
|
256
|
+
this.currentLogLevel = 'info';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.SecurityIncidentManager = SecurityIncidentManager;
|
|
260
|
+
//# sourceMappingURL=SecurityIncidentManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityIncidentManager.js","sourceRoot":"","sources":["../../../src/infrastructure/security/SecurityIncidentManager.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAiEH;;;GAGG;AACH,MAAa,uBAAuB;IAOlC;QAFQ,0BAAqB,GAAa,EAAE,CAAA;QAG1C,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAE,CAAA;QACpC,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,eAAe,GAAG,MAAM,CAAA;QAC7B,IAAI,CAAC,kBAAkB,GAAG,GAAG,CAAA;QAC7B,IAAI,CAAC,+BAA+B,EAAE,CAAA;IACxC,CAAC;IAED;;;OAGG;IACK,+BAA+B;QACrC,IAAI,CAAC,qBAAqB,GAAG;YAC3B,sEAAsE;YACtE,gEAAgE;YAChE,0EAA0E;YAC1E,4EAA4E;YAC5E,oCAAoC,EAAE,0CAA0C;YAChF,uBAAuB,EAAE,gCAAgC;SAC1D,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,OAA0B;QACxC,IAAI,YAAY,GAAG,CAAC,CAAA;QACpB,IAAI,SAAS,GAAwC,KAAK,CAAA;QAC1D,MAAM,iBAAiB,GAAa,EAAE,CAAA;QAEtC,+BAA+B;QAC/B,MAAM,iBAAiB,GAAG;YACxB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IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,YAAY;aAC7F,CAAC,MAAM;YACR,mBAAmB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC;SAClE,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAA;QAChC,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAA;QAC/B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAA;IAC/B,CAAC;CACF;AAvSD,0DAuSC"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Key Manager - Secure API key management with rotation and access control
|
|
3
|
+
* Provides separation, protection, and automated management of API keys
|
|
4
|
+
* Addresses SECURITY1 test case requirements
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Secure API key with metadata
|
|
8
|
+
*/
|
|
9
|
+
export interface SecureAPIKey {
|
|
10
|
+
key: string;
|
|
11
|
+
expiresAt: number;
|
|
12
|
+
permissions: string[];
|
|
13
|
+
usageTracking: UsageTracker;
|
|
14
|
+
keyId: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* API key access logger for security auditing
|
|
18
|
+
*/
|
|
19
|
+
export interface APIKeyAccessLogger {
|
|
20
|
+
logKeyAccess(access: KeyAccessLog): Promise<void>;
|
|
21
|
+
getAccessHistory(keyId: string, timeRange: TimeRange): Promise<KeyAccessLog[]>;
|
|
22
|
+
detectSuspiciousActivity(keyId: string): Promise<SuspiciousActivityAlert[]>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Key access log entry
|
|
26
|
+
*/
|
|
27
|
+
export interface KeyAccessLog {
|
|
28
|
+
service: string;
|
|
29
|
+
operation: string;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
keyId: string;
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
userId?: string;
|
|
34
|
+
clientId?: string;
|
|
35
|
+
success: boolean;
|
|
36
|
+
ipAddress?: string;
|
|
37
|
+
userAgent?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Time range for queries
|
|
41
|
+
*/
|
|
42
|
+
export interface TimeRange {
|
|
43
|
+
start: number;
|
|
44
|
+
end: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Suspicious activity alert
|
|
48
|
+
*/
|
|
49
|
+
export interface SuspiciousActivityAlert {
|
|
50
|
+
alertId: string;
|
|
51
|
+
keyId: string;
|
|
52
|
+
alertType: SuspiciousActivityType;
|
|
53
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
54
|
+
description: string;
|
|
55
|
+
timestamp: number;
|
|
56
|
+
evidence: Record<string, unknown>;
|
|
57
|
+
recommendedAction: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Types of suspicious activity
|
|
61
|
+
*/
|
|
62
|
+
export declare enum SuspiciousActivityType {
|
|
63
|
+
UNUSUAL_ACCESS_PATTERN = "unusual_access_pattern",
|
|
64
|
+
EXCESSIVE_USAGE = "excessive_usage",
|
|
65
|
+
UNAUTHORIZED_LOCATION = "unauthorized_location",
|
|
66
|
+
INVALID_PERMISSIONS = "invalid_permissions",
|
|
67
|
+
RAPID_SUCCESSION_REQUESTS = "rapid_succession_requests"
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Usage tracker for API key monitoring
|
|
71
|
+
*/
|
|
72
|
+
export interface UsageTracker {
|
|
73
|
+
trackUsage(operation: string, metadata?: Record<string, unknown>): void;
|
|
74
|
+
getUsageStats(timeRange: TimeRange): UsageStats;
|
|
75
|
+
resetStats(): void;
|
|
76
|
+
isRateLimited(): boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Usage statistics
|
|
80
|
+
*/
|
|
81
|
+
export interface UsageStats {
|
|
82
|
+
totalRequests: number;
|
|
83
|
+
successfulRequests: number;
|
|
84
|
+
failedRequests: number;
|
|
85
|
+
averageResponseTime: number;
|
|
86
|
+
rateLimitHits: number;
|
|
87
|
+
costEstimate: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Secure key vault for encrypted key storage
|
|
91
|
+
*/
|
|
92
|
+
export interface SecureKeyVault {
|
|
93
|
+
/**
|
|
94
|
+
* Store encrypted API key
|
|
95
|
+
*/
|
|
96
|
+
storeKey(service: string, key: string, permissions: string[], expiresAt: number): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieve decrypted API key information
|
|
99
|
+
*/
|
|
100
|
+
retrieveKey(service: string): Promise<StoredKeyInfo>;
|
|
101
|
+
/**
|
|
102
|
+
* Update existing key with new value
|
|
103
|
+
*/
|
|
104
|
+
updateKey(service: string, newKey: string, permissions: string[], expiresAt: number): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Remove key from vault
|
|
107
|
+
*/
|
|
108
|
+
removeKey(service: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* List all services with stored keys
|
|
111
|
+
*/
|
|
112
|
+
listServices(): Promise<string[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Check if key exists for service
|
|
115
|
+
*/
|
|
116
|
+
hasKey(service: string): Promise<boolean>;
|
|
117
|
+
/**
|
|
118
|
+
* Backup vault contents
|
|
119
|
+
*/
|
|
120
|
+
createBackup(): Promise<VaultBackup>;
|
|
121
|
+
/**
|
|
122
|
+
* Restore vault from backup
|
|
123
|
+
*/
|
|
124
|
+
restoreFromBackup(backup: VaultBackup): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Stored key information
|
|
128
|
+
*/
|
|
129
|
+
export interface StoredKeyInfo {
|
|
130
|
+
keyId: string;
|
|
131
|
+
key: string;
|
|
132
|
+
permissions: string[];
|
|
133
|
+
createdAt: number;
|
|
134
|
+
expiresAt: number;
|
|
135
|
+
lastUsed?: number;
|
|
136
|
+
usageCount: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Vault backup structure
|
|
140
|
+
*/
|
|
141
|
+
export interface VaultBackup {
|
|
142
|
+
backupId: string;
|
|
143
|
+
timestamp: number;
|
|
144
|
+
encryptedData: string;
|
|
145
|
+
checksum: string;
|
|
146
|
+
metadata: Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Key rotation scheduler
|
|
150
|
+
*/
|
|
151
|
+
export interface KeyRotationScheduler {
|
|
152
|
+
/**
|
|
153
|
+
* Schedule automatic key rotation
|
|
154
|
+
*/
|
|
155
|
+
scheduleRotation(service: string, intervalMs: number): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Cancel scheduled rotation
|
|
158
|
+
*/
|
|
159
|
+
cancelRotation(service: string): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Get rotation schedule for service
|
|
162
|
+
*/
|
|
163
|
+
getRotationSchedule(service: string): Promise<RotationSchedule | null>;
|
|
164
|
+
/**
|
|
165
|
+
* Manually trigger rotation
|
|
166
|
+
*/
|
|
167
|
+
triggerRotation(service: string): Promise<KeyRotationResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Get all scheduled rotations
|
|
170
|
+
*/
|
|
171
|
+
getAllSchedules(): Promise<RotationSchedule[]>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Rotation schedule configuration
|
|
175
|
+
*/
|
|
176
|
+
export interface RotationSchedule {
|
|
177
|
+
services: string[];
|
|
178
|
+
intervalMs: number;
|
|
179
|
+
nextRotationAt: number;
|
|
180
|
+
maxRetries: number;
|
|
181
|
+
notificationEnabled: boolean;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Key rotation result
|
|
185
|
+
*/
|
|
186
|
+
export interface KeyRotationResult {
|
|
187
|
+
rotations: ServiceRotationResult[];
|
|
188
|
+
overallSuccess: boolean;
|
|
189
|
+
timestamp: number;
|
|
190
|
+
errors?: string[];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Individual service rotation result
|
|
194
|
+
*/
|
|
195
|
+
export interface ServiceRotationResult {
|
|
196
|
+
service: string;
|
|
197
|
+
success: boolean;
|
|
198
|
+
newKeyId?: string;
|
|
199
|
+
rotationTimestamp?: number;
|
|
200
|
+
error?: string;
|
|
201
|
+
fallbackPeriodMs?: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Key authorization validation
|
|
205
|
+
*/
|
|
206
|
+
export interface KeyAuthorization {
|
|
207
|
+
allowed: boolean;
|
|
208
|
+
reason?: string;
|
|
209
|
+
permissions: string[];
|
|
210
|
+
restrictions: AuthorizationRestriction[];
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Authorization restrictions
|
|
214
|
+
*/
|
|
215
|
+
export interface AuthorizationRestriction {
|
|
216
|
+
type: RestrictionType;
|
|
217
|
+
value: unknown;
|
|
218
|
+
description: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Types of authorization restrictions
|
|
222
|
+
*/
|
|
223
|
+
export declare enum RestrictionType {
|
|
224
|
+
TIME_BASED = "time_based",
|
|
225
|
+
IP_BASED = "ip_based",
|
|
226
|
+
RATE_LIMIT = "rate_limit",
|
|
227
|
+
OPERATION_BASED = "operation_based",
|
|
228
|
+
USER_BASED = "user_based"
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Unauthorized API access error
|
|
232
|
+
*/
|
|
233
|
+
export declare class UnauthorizedAPIAccessError extends Error {
|
|
234
|
+
constructor(reason: string);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* API Key Manager implementation
|
|
238
|
+
*/
|
|
239
|
+
export declare class APIKeyManager {
|
|
240
|
+
private keyVault;
|
|
241
|
+
private rotationScheduler;
|
|
242
|
+
private accessLogger;
|
|
243
|
+
constructor(keyVault: SecureKeyVault, rotationScheduler: KeyRotationScheduler, accessLogger: APIKeyAccessLogger);
|
|
244
|
+
/**
|
|
245
|
+
* Get secure API key with authorization validation
|
|
246
|
+
*/
|
|
247
|
+
getAPIKey(service: string, operation: string, sessionId?: string): Promise<SecureAPIKey>;
|
|
248
|
+
/**
|
|
249
|
+
* Rotate API keys according to schedule
|
|
250
|
+
*/
|
|
251
|
+
rotateAPIKeys(schedule: RotationSchedule): Promise<KeyRotationResult>;
|
|
252
|
+
/**
|
|
253
|
+
* Validate key authorization for operation
|
|
254
|
+
*/
|
|
255
|
+
private validateKeyAuthorization;
|
|
256
|
+
/**
|
|
257
|
+
* Generate new key for service
|
|
258
|
+
*/
|
|
259
|
+
private generateNewKey;
|
|
260
|
+
/**
|
|
261
|
+
* Initiate gradual rotation with fallback period
|
|
262
|
+
*/
|
|
263
|
+
private initiateGradualRotation;
|
|
264
|
+
/**
|
|
265
|
+
* Create usage tracker for key
|
|
266
|
+
*/
|
|
267
|
+
private createUsageTracker;
|
|
268
|
+
/**
|
|
269
|
+
* Generate secure random key
|
|
270
|
+
*/
|
|
271
|
+
private generateSecureKey;
|
|
272
|
+
/**
|
|
273
|
+
* Generate unique key identifier
|
|
274
|
+
*/
|
|
275
|
+
private generateKeyId;
|
|
276
|
+
/**
|
|
277
|
+
* Get key rotation status
|
|
278
|
+
*/
|
|
279
|
+
getRotationStatus(service: string): Promise<{
|
|
280
|
+
scheduled: boolean;
|
|
281
|
+
nextRotation?: number;
|
|
282
|
+
lastRotation?: number;
|
|
283
|
+
}>;
|
|
284
|
+
/**
|
|
285
|
+
* Security audit of key usage
|
|
286
|
+
*/
|
|
287
|
+
auditKeyUsage(service: string, timeRange: TimeRange): Promise<{
|
|
288
|
+
totalAccess: number;
|
|
289
|
+
suspiciousActivity: SuspiciousActivityAlert[];
|
|
290
|
+
accessHistory: KeyAccessLog[];
|
|
291
|
+
}>;
|
|
292
|
+
/**
|
|
293
|
+
* Emergency key revocation
|
|
294
|
+
*/
|
|
295
|
+
emergencyRevocation(service: string, reason: string): Promise<void>;
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=apiKeyManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKeyManager.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/security/apiKeyManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,aAAa,EAAE,YAAY,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;IAC9E,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAA;CAC5E;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAA;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