feat: ACN Application Security Standard V7.30 compliance (19/23 items)
CRITICAL — Authentication & Access: - TOTP MFA: otpauth-based, QR setup UI, sign-in flow integration, admin disable override, /account/security self-service page - Session Timeouts: 8h absolute (maxAge), 30min idle (updateAge) - Failed Auth Logging: Pino warn for invalid password/user/totp, info for successful login, audit entries for all auth events - Concurrent Session Limit: ActiveSession model, oldest-kick strategy, max 3 per user (configurable in SystemSettings) CRITICAL — HTTP Security: - HSTS: max-age=31536000; includeSubDomains - CSP: script/style/img/font/connect-src with Gemini/OpenAI whitelist - X-XSS-Protection: 0 (CSP replaces legacy) - Auth page cache: no-store, no-cache, must-revalidate - Rate Limiting: 100/15min general API, 5/15min auth (Map-based) Data Protection: - XSS Sanitization: DOMPurify on comment bodies - autocomplete="new-password" on all password/secret fields - SameSite=Strict on all cookies (Credentials-only, no OAuth) - File Upload Magic Bytes validation (PNG/JPEG/WebP/GIF/BMP/TIFF) Logging & Monitoring: - Login/Logout audit entries (Auth entityType) - External API call logging with timing (OpenAI, Gemini) - Input validation failure logging at warn level - Concurrent session tracking in ActiveSession table Documentation: - docs/security-architecture.md (11 sections) - docs/sdlc.md (CI pipeline, security gates, incident response) - .gitea/PULL_REQUEST_TEMPLATE.md (security checklist) Schema: User.totpSecret/totpEnabled, SystemSettings.sessionMaxAge/ sessionIdleTimeout/maxConcurrentSessions, ActiveSession model Tests: 310 engine + 37 staffing pass. TypeScript clean. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { logger } from "./lib/logger.js";
|
||||
|
||||
type GeminiSettings = {
|
||||
geminiApiKey?: string | null;
|
||||
geminiModel?: string | null;
|
||||
@@ -18,6 +20,7 @@ export async function generateGeminiImage(
|
||||
model = "gemini-2.5-flash-image",
|
||||
): Promise<string> {
|
||||
const fullPrompt = `Generate a professional, cinematic cover image for a 3D production project. ${prompt}`;
|
||||
const start = performance.now();
|
||||
|
||||
const response = await fetch(
|
||||
`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`,
|
||||
@@ -32,6 +35,7 @@ export async function generateGeminiImage(
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const responseTimeMs = Math.round(performance.now() - start);
|
||||
const body = await response.text();
|
||||
let msg = body;
|
||||
try {
|
||||
@@ -40,6 +44,7 @@ export async function generateGeminiImage(
|
||||
} catch {
|
||||
/* keep raw */
|
||||
}
|
||||
logger.warn({ provider: "gemini", model, promptLength: fullPrompt.length, responseTimeMs, status: response.status }, "External API call failed");
|
||||
throw new Error(`HTTP ${response.status}: ${msg}`);
|
||||
}
|
||||
|
||||
@@ -62,6 +67,9 @@ export async function generateGeminiImage(
|
||||
throw new Error("No image data returned from Gemini");
|
||||
}
|
||||
|
||||
const responseTimeMs = Math.round(performance.now() - start);
|
||||
logger.info({ provider: "gemini", model, promptLength: fullPrompt.length, responseTimeMs }, "External API call");
|
||||
|
||||
const base64 = imagePart.inlineData.data;
|
||||
const mimeType = imagePart.inlineData.mimeType ?? "image/png";
|
||||
return `data:${mimeType};base64,${base64}`;
|
||||
|
||||
Reference in New Issue
Block a user