-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclamav.ts
More file actions
75 lines (64 loc) · 2.08 KB
/
clamav.ts
File metadata and controls
75 lines (64 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import axios from 'axios';
import FormData from 'form-data';
import fs from 'fs';
// Use external ClamAV REST API service (no local daemon needed)
const CLAMAV_API_URL = process.env.CLAMAV_API_URL || 'https://api.clamav.net/scan';
const USE_EXTERNAL_CLAMAV = process.env.USE_EXTERNAL_CLAMAV === 'true';
export async function initClamAV(): Promise<void> {
if (USE_EXTERNAL_CLAMAV) {
console.log('✓ ClamAV configured to use external API (on-demand scanning)');
} else {
console.log('⚠️ ClamAV disabled - using VirusTotal only');
}
}
export interface ClamAVResult {
infected: boolean;
virus?: string;
scannedAt: number;
}
export async function scanFileWithClamAV(filePath: string): Promise<ClamAVResult> {
if (!USE_EXTERNAL_CLAMAV) {
// ClamAV disabled, return clean result (VirusTotal will be used instead)
return {
infected: false,
virus: undefined,
scannedAt: Date.now(),
};
}
try {
// Use external ClamAV API for on-demand scanning
const form = new FormData();
form.append('file', fs.createReadStream(filePath));
const response = await axios.post(CLAMAV_API_URL, form, {
headers: form.getHeaders(),
timeout: 60000, // 1 minute timeout
});
const isInfected = response.data.infected || false;
const virus = response.data.virus || undefined;
return {
infected: isInfected,
virus: virus,
scannedAt: Date.now(),
};
} catch (error: any) {
console.error('External ClamAV scan error:', error.message);
// On error, return clean and let VirusTotal handle it
return {
infected: false,
virus: undefined,
scannedAt: Date.now(),
};
}
}
export async function scanStreamWithClamAV(stream: NodeJS.ReadableStream): Promise<ClamAVResult> {
// Stream scanning not supported with external API
// Return clean result, VirusTotal will handle it
return {
infected: false,
virus: undefined,
scannedAt: Date.now(),
};
}
export async function updateClamAVSignatures(): Promise<void> {
console.log('Using external ClamAV API - signatures managed externally');
}