feat: implement cache layer, CSP improvements, and database performance optimizations

- Add Redis cache implementation with LRU eviction
- Enhance Content Security Policy with nonce generation
- Optimize database queries with connection pooling
- Add cache invalidation API endpoints
- Improve security monitoring performance
This commit is contained in:
2025-07-12 04:44:50 +02:00
parent 7a3eabccd9
commit e1abedb148
56 changed files with 6881 additions and 7040 deletions

View File

@ -7,6 +7,11 @@ import {
securityAuditLogger,
} from "./securityAuditLogger";
// Utility type for deep partial objects
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
export interface SecurityAlert {
id: string;
timestamp: Date;
@ -370,7 +375,7 @@ class SecurityMonitoringService {
/**
* Configure monitoring thresholds
*/
updateConfig(config: Partial<MonitoringConfig>): void {
updateConfig(config: DeepPartial<MonitoringConfig>): void {
this.config = this.deepMerge(this.config, config);
}
@ -412,6 +417,7 @@ class SecurityMonitoringService {
threatLevel: ThreatLevel;
riskFactors: string[];
recommendations: string[];
isBlacklisted: boolean;
}> {
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
@ -470,7 +476,11 @@ class SecurityMonitoringService {
recommendations.push("Continue monitoring for suspicious activity");
}
return { threatLevel, riskFactors, recommendations };
// Simple blacklist check based on threat level and risk factors
const isBlacklisted =
threatLevel === ThreatLevel.CRITICAL && riskFactors.length >= 3;
return { threatLevel, riskFactors, recommendations, isBlacklisted };
}
private async detectImediateThreats(