feat: create security monitoring dashboard

This commit is contained in:
张翔
2026-03-24 11:27:23 +08:00
parent dea94b9955
commit 2ec4e65836
4 changed files with 479 additions and 0 deletions
+36
View File
@@ -104,4 +104,40 @@ export class SecurityLogger {
clear(): void {
this.logger.clear();
}
getStats() {
const logs = this.getRecentLogs();
const totalRequests = logs.length;
const blockedRequests = logs.filter(log =>
log.type === SecurityEventType.RATE_LIMIT_EXCEEDED ||
log.type === SecurityEventType.BLOCKED_REQUEST ||
log.type === SecurityEventType.MALICIOUS_CONTENT ||
log.type === SecurityEventType.XSS_ATTEMPT ||
log.type === SecurityEventType.SQL_INJECTION_ATTEMPT
).length;
const captchaAttempts = logs.filter(log =>
log.type === SecurityEventType.CAPTCHA_FAILED ||
log.type === SecurityEventType.CAPTCHA_EXPIRED
).length;
const rateLimitHits = logs.filter(log =>
log.type === SecurityEventType.RATE_LIMIT_EXCEEDED
).length;
const maliciousContentDetected = logs.filter(log =>
log.type === SecurityEventType.MALICIOUS_CONTENT ||
log.type === SecurityEventType.XSS_ATTEMPT ||
log.type === SecurityEventType.SQL_INJECTION_ATTEMPT
).length;
const successRate = totalRequests > 0
? ((totalRequests - blockedRequests) / totalRequests * 100).toFixed(2)
: 100;
return {
totalRequests,
blockedRequests,
captchaAttempts,
rateLimitHits,
maliciousContentDetected,
successRate: parseFloat(successRate),
};
}
}