-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProcessorService.js
58 lines (47 loc) · 1.46 KB
/
ProcessorService.js
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
/**
* Service for Scanning Submissions
*/
const Joi = require('joi')
const logger = require('../common/logger')
const helper = require('../common/helper')
/**
* Process Scan request event
* @param {Object} message the message
*/
function * processScan (message) {
message.timestamp = (new Date()).toISOString()
message.payload.status = 'scanned'
const downloadedFile = yield helper.downloadFile(message.payload.url);
// Scan the file using ClamAV
const [isZipBomb, errorCode, errorMessage] = helper.isZipBomb(downloadedFile);
if (isZipBomb) {
message.isInfected = true;
logger.warn(`File at ${message.payload.url} is a ZipBomb. ${errorCode}: ${errorMessage}`);
yield helper.postToBusAPI(message)
return message;
}
const isInfected = yield helper.scanWithClamAV(downloadedFile)
// Update Scanning results
message.payload.isInfected = isInfected
yield helper.postToBusAPI(message)
return message
}
processScan.schema = {
message: Joi.object().keys({
topic: Joi.string().required(),
originator: Joi.string().required(),
timestamp: Joi.date().required(),
'mime-type': Joi.string().required(),
payload: Joi.object().keys({
submissionId: Joi.string().required(),
url: Joi.string().required(),
fileName: Joi.string().required(),
status: Joi.string().required()
}).unknown(true).required()
}).required()
}
// Exports
module.exports = {
processScan
}
logger.buildService(module.exports)