38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/**
|
|
* Auto-suspend user accounts when Sybil fraud score exceeds block threshold.
|
|
*/
|
|
|
|
import * as settingsRepository from '../repositories/settingsRepository';
|
|
import * as userRepository from '../repositories/userRepository';
|
|
import * as auditLogRepository from '../repositories/auditLogRepository';
|
|
import { suspendUserForSecurity } from './securityService';
|
|
import type { SybilSignal } from './referralSybilService';
|
|
|
|
export async function maybeAutoSuspendForSybilFraud(
|
|
userId: string,
|
|
sybilScore: number,
|
|
signals: SybilSignal[],
|
|
context: { referredUserId?: string; payoutId?: string } = {}
|
|
): Promise<boolean> {
|
|
const settings = await settingsRepository.getSettings();
|
|
if (!settings.sybil_auto_suspend_accounts) return false;
|
|
|
|
const user = await userRepository.findById(userId);
|
|
if (!user) return false;
|
|
if (user.withdrawals_suspended && user.under_surveillance) return false;
|
|
|
|
const reason = `Auto-suspended: Sybil fraud score ${sybilScore} (${signals.join(', ')})`;
|
|
await suspendUserForSecurity(userId, reason, 'sybil_auto_suspend', 'high');
|
|
await auditLogRepository.create({
|
|
userId,
|
|
action: 'sybil_auto_suspend',
|
|
metadata: {
|
|
sybilScore,
|
|
signals,
|
|
referredUserId: context.referredUserId ?? null,
|
|
payoutId: context.payoutId ?? null,
|
|
},
|
|
});
|
|
return true;
|
|
}
|