After correcting the issue for bonus fund credit for BEP204
This commit is contained in:
parent
9a2c88862e
commit
d0fae94d61
@ -66,6 +66,25 @@ export async function findById(id: string): Promise<SecurityAlert | null> {
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
/** True if an open FIM alert already exists for the same root/path/issue (stops alert storms). */
|
||||
export async function hasOpenFileIntegrityAlert(input: {
|
||||
rootKey: string;
|
||||
relativePath: string;
|
||||
issue: string;
|
||||
}): Promise<boolean> {
|
||||
const rows = await query<{ id: string }[]>(
|
||||
`SELECT id FROM security_alerts
|
||||
WHERE status = 'open'
|
||||
AND alert_type = 'file_integrity_violation'
|
||||
AND metadata->>'rootKey' = $1
|
||||
AND metadata->>'relativePath' = $2
|
||||
AND metadata->>'issue' = $3
|
||||
LIMIT 1`,
|
||||
[input.rootKey, input.relativePath, input.issue]
|
||||
);
|
||||
return Boolean(rows[0]);
|
||||
}
|
||||
|
||||
export async function updateAlertStatus(
|
||||
id: string,
|
||||
status: SecurityAlertStatus,
|
||||
|
||||
@ -7,6 +7,7 @@ import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import * as fileIntegrityRepository from '../repositories/fileIntegrityRepository';
|
||||
import * as securityAlertRepository from '../repositories/securityAlertRepository';
|
||||
import * as auditLogRepository from '../repositories/auditLogRepository';
|
||||
import { raiseAlert } from './securityService';
|
||||
import { ensureFaqUploadDir } from '../middleware/faqUpload';
|
||||
@ -134,18 +135,32 @@ export async function runFileIntegrityCheck(): Promise<FileIntegrityIssue[]> {
|
||||
allIssues.push(...suspicious);
|
||||
|
||||
for (const issue of suspicious) {
|
||||
await auditLogRepository.create({
|
||||
action: 'file_integrity_violation',
|
||||
resourceType: 'file',
|
||||
metadata: issue,
|
||||
});
|
||||
await raiseAlert({
|
||||
severity: 'high',
|
||||
alertType: 'file_integrity_violation',
|
||||
title: `Upload file integrity violation (${issue.issue})`,
|
||||
details: `${issue.rootKey}/${issue.relativePath} — expected baseline mismatch or deletion.`,
|
||||
metadata: issue,
|
||||
const alreadyOpen = await securityAlertRepository.hasOpenFileIntegrityAlert({
|
||||
rootKey: issue.rootKey,
|
||||
relativePath: issue.relativePath,
|
||||
issue: issue.issue,
|
||||
});
|
||||
|
||||
if (!alreadyOpen) {
|
||||
await auditLogRepository.create({
|
||||
action: 'file_integrity_violation',
|
||||
resourceType: 'file',
|
||||
metadata: issue,
|
||||
});
|
||||
await raiseAlert({
|
||||
severity: 'high',
|
||||
alertType: 'file_integrity_violation',
|
||||
title: `Upload file integrity violation (${issue.issue})`,
|
||||
details: `${issue.rootKey}/${issue.relativePath} — expected baseline mismatch or deletion.`,
|
||||
metadata: issue,
|
||||
});
|
||||
}
|
||||
|
||||
// File is gone: drop baseline so the 5‑min monitor does not re-alert forever.
|
||||
// (Common when upload dir is ephemeral Docker storage without a volume.)
|
||||
if (issue.issue === 'deleted') {
|
||||
await fileIntegrityRepository.deleteSnapshot(issue.rootKey, issue.relativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -217,6 +217,9 @@ services:
|
||||
ENGINE_ENABLED: "false"
|
||||
WS_ENABLED: "false"
|
||||
command: ["sh", "-c", "if [ \"${RUN_MIGRATE_ON_START:-0}\" = \"1\" ]; then node dist/db/migrate.js || exit 1; fi; exec node dist/apps/api.js"]
|
||||
# Persist support/FAQ uploads — without this, FIM baselines outlive files and spam "deleted" alerts.
|
||||
volumes:
|
||||
- upload_data:/app/data
|
||||
expose:
|
||||
- "4000"
|
||||
healthcheck:
|
||||
@ -482,5 +485,6 @@ networks:
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
upload_data:
|
||||
letsencrypt:
|
||||
certbot-www:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user