feat(auth): enhance security and audit logging

- Integrate webhook alerts for admin login lockouts.
- Implement detailed audit logging for login, logout, and setup actions.
- Improve client revocation event tracking.
- Standardize error handling in profile updates.
- Enforce 'operator' role for event API access.
This commit is contained in:
Team Dark Devil committed 2026-11-21 00:06:55 +06:00
1 parent 5c977d6977
commit 8132087085
52 files changed
+4434 -407

No files matched your search

+14 -8
View File
@@ -1,7 +1,10 @@
import { SettingsManager } from "@/core/adminSettings/settingsManager";
import { dispatchWebhookAlertAsync } from "@/core/alerts/webhookNotifier";
import { recordAdminAuditLogAsync } from "@/core/auth/auditLog";
import { SecretVaultError } from "@/core/Security/secretVault";
import {
decryptSecret,
SecretVaultError,
} from "@/core/Security/secretVault";
import { extractClientIp, requireAdminApiSession } from "@/lib/adminAuth";
import { NextRequest, NextResponse } from "next/server";
@@ -28,17 +31,20 @@ export async function POST(req: NextRequest) {
}
try {
const savedConfig = await SettingsManager.getDecryptedWebhookConfigAsync();
const saved = await SettingsManager.getSettingsAsync();
const webhookUrl =
typeof body.webhookUrl === "string"
? body.webhookUrl.trim()
: savedConfig.webhookUrl.trim();
: saved.webhookUrl.trim();
const clearWebhookSecret = body.clearWebhookSecret === true;
const webhookSecret = clearWebhookSecret
? ""
: typeof body.webhookSecret === "string" && body.webhookSecret.trim()
const draftSecret =
typeof body.webhookSecret === "string" && body.webhookSecret.trim()
? body.webhookSecret.trim()
: savedConfig.webhookSecret;
: "";
let webhookSecret = draftSecret;
if (!webhookSecret && !clearWebhookSecret && saved.webhookSecretEnc) {
webhookSecret = decryptSecret(saved.webhookSecretEnc);
}
if (!webhookUrl) {
return NextResponse.json(
@@ -81,7 +87,7 @@ export async function POST(req: NextRequest) {
enabled: true,
webhookUrl,
webhookSecret,
cooldownSec: savedConfig.cooldownSec,
cooldownSec: saved.webhookCooldownSec,
},
{ bypassCooldown: true },
);