use crypto package instead
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
|
import crypto from 'crypto';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash a phone number for analytics purposes
|
* Hash a phone number for analytics purposes
|
||||||
* Uses a consistent hashing algorithm to create a deterministic hash
|
* Uses SHA-256 for consistent, cryptographically strong hashing
|
||||||
*/
|
*/
|
||||||
export function hashPhoneNumber(phoneNumber: string): string {
|
export function hashPhoneNumber(phoneNumber: string): string {
|
||||||
let hash = 0;
|
const hash = crypto.createHash('sha256').update(phoneNumber).digest('hex');
|
||||||
for (let i = 0; i < phoneNumber.length; i++) {
|
return `sha256_${hash}`;
|
||||||
hash = ((hash << 5) - hash) + phoneNumber.charCodeAt(i);
|
|
||||||
hash |= 0;
|
|
||||||
}
|
|
||||||
return `hash_${Math.abs(hash)}`;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,10 +210,12 @@ export class SpamShieldService {
|
|||||||
const confidence = Math.min(matches.reduce((sum, m) => sum + m.score, 0), 1.0);
|
const confidence = Math.min(matches.reduce((sum, m) => sum + m.score, 0), 1.0);
|
||||||
const decision = confidence > 0.8 ? 'BLOCK' : confidence > 0.5 ? 'FLAG' : 'ALLOW';
|
const decision = confidence > 0.8 ? 'BLOCK' : confidence > 0.5 ? 'FLAG' : 'ALLOW';
|
||||||
|
|
||||||
|
const encrypted = FieldEncryptionService.encrypt(validated);
|
||||||
|
|
||||||
const auditLog = await prisma.spamAuditLog.create({
|
const auditLog = await prisma.spamAuditLog.create({
|
||||||
data: {
|
data: {
|
||||||
userId: 'system',
|
userId: 'system',
|
||||||
phoneNumber: validated,
|
phoneNumber: encrypted,
|
||||||
decision: decision as any,
|
decision: decision as any,
|
||||||
reason: `Rule-based analysis`,
|
reason: `Rule-based analysis`,
|
||||||
ruleId: ruleMatchIds[0],
|
ruleId: ruleMatchIds[0],
|
||||||
|
|||||||
Reference in New Issue
Block a user