refactor(auth): standardize session management and security

- Centralize secret retrieval using `getAdminSessionSecret`
- Replace manual session parsing with `verifyRequestAdminSession` utility
- Tighten API validation and improve security headers handling
- Enforce environment variable security for production deployments
This commit is contained in:
Team Dark Devil committed 2026-11-18 05:18:55 +06:00
1 parent 34519c07df
commit 177ed4a844
78 files changed
+6748 -3157

No files matched your search

+36 -42
View File
@@ -14,31 +14,25 @@ datasource db {
// All collected data is strictly written to CSV files in /storage/data/{clientId}/{YYYY-MM-DD}.csv
model ClientSDK {
id String @id @default(cuid())
clientId String @unique
clientId String @id @map("client_id")
name String
secret String
rateLimit Int @default(100) // Max events per second
status String @default("active") // active | revoked
totalEvents BigInt @default(0)
lastActive DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
apiKeys ApiKey[]
token String
rateLimit Int @default(100) @map("rate_limit") // Max events per second
status String @default("active") // active | revoked
totalEvents BigInt @default(0) @map("total_events")
lastActive DateTime? @map("last_active") @db.Timestamptz(6)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
@@map("client_sdks")
}
model ApiKey {
id String @id @default(cuid())
clientId String
client ClientSDK @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
keyHash String
expiresAt DateTime?
createdAt DateTime @default(now())
model DeletedClient {
clientId String @id @map("client_id")
deletedAt DateTime @default(now()) @map("deleted_at") @db.Timestamptz(6)
@@map("api_keys")
@@map("deleted_clients")
}
model AdminUser {
@@ -46,35 +40,35 @@ model AdminUser {
email String @unique
passwordSalt Bytes @map("password_salt")
passwordHash Bytes @map("password_hash")
createdAt DateTime @default(now()) @map("created_at")
tokenVersion Int @default(1) @map("token_version")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
@@map("admin_users")
}
model AdminLoginAttempt {
keyHash String @id @map("key_hash")
windowStartedAt DateTime @map("window_started_at") @db.Timestamptz(6)
failedAttempts Int @map("failed_attempts")
blockedUntil DateTime? @map("blocked_until") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
@@map("admin_login_attempts")
}
model AdminSettings {
id String @id @default("default")
serverPort Int @default(4000)
webPort Int @default(3000)
maxEventsPerSec Int @default(100)
maxPayloadSizeKb Int @default(100)
batchFlushThreshold Int @default(500)
batchFlushIntervalMs Int @default(2000)
fileRotationMb Int @default(100)
jwtSecret String
enableIdempotency Boolean @default(true)
autoPruneDays Int @default(30)
updatedAt DateTime @updatedAt
id String @id @default("default")
serverPort Int @default(4000) @map("server_port")
webPort Int @default(3000) @map("web_port")
maxEventsPerSec Int @default(100) @map("max_events_per_sec")
maxPayloadSizeKb Int @default(100) @map("max_payload_size_kb")
batchFlushThreshold Int @default(500) @map("batch_flush_threshold")
batchFlushIntervalMs Int @default(2000) @map("batch_flush_interval_ms")
fileRotationMb Int @default(100) @map("file_rotation_mb")
jwtSecret String @map("jwt_secret")
enableIdempotency Boolean @default(true) @map("enable_idempotency")
autoPruneDays Int @default(30) @map("auto_prune_days")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
@@map("admin_settings")
}
model AuditLog {
id String @id @default(cuid())
action String
actor String
details String? // JSON string
ipAddress String?
createdAt DateTime @default(now())
@@map("audit_logs")
}