-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
files.js
98 lines (93 loc) · 3.45 KB
/
files.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const NodeClam = require('clamscan');
const { Readable } = require('stream');
Parse.Cloud.beforeSave(Parse.File, async (request) => {
const { file, user } = request;
try {
const fileData = Buffer.from(await file.getData(), 'base64').toString();
// Get instance by resolving ClamScan promise object
const clamscan = await new NodeClam().init({
clamdscan: {
host: 'scan', // IP of host to connect to TCP interface
port: 3310,
}
});
const stream = new Readable();
stream.push(fileData);
stream.push(null);
const { isInfected, viruses } = await clamscan.scanStream(stream);
if (isInfected) {
throw `********* Virus or malware detected! This file was not uploaded. Viruses detected: (${viruses.join(',')}) *********`;
}
return file;
} catch(error) {
// Handle any errors raised by the code in the try block
throw `Error scanning for virus or malware ${error}`;
}
});
Parse.Cloud.define("setTestSchema", async (request) => {
const { params, headers, log } = request;
const clp = {
get: { requiresAuthentication: true },
find: { requiresAuthentication: true },
create: { requiresAuthentication: true },
update: { requiresAuthentication: true },
delete: { requiresAuthentication: true },
addField: {},
protectedFields: {}
};
const testSchema = new Parse.Schema('Test');
try {
await testSchema.get();
} catch {
try {
await testSchema.addFile('textFile')
.setCLP(clp)
.save();
console.log("*** Success: Test class created with default fields. Ignore any previous errors about this class ***");
} catch(error) {
throw error;
}
}
});
Parse.Cloud.job("testSaveFile", async (request) => {
const { params, headers, log, message } = request;
const normal_file_url = 'https://github.com/netreconlab/parse-hipaa/blob/main/README.md';
await Parse.Cloud.run("setTestSchema");
const object = new Parse.Object('Test');
const file = new Parse.File("README.md", { uri: normal_file_url });
object.set('textFile', file);
try {
await object.save(null, { useMasterKey: true });
message("Saved file");
} catch(error) {
throw error;
}
});
Parse.Cloud.job("testDontSaveUnauthenticatedFile", async (request) => {
const { params, headers, log, message } = request;
const normal_file_url = 'https://github.com/netreconlab/parse-hipaa/blob/main/README.md';
await Parse.Cloud.run("setTestSchema");
const object = new Parse.Object('Test');
const file = new Parse.File("README.md", { uri: normal_file_url });
object.set('textFile', file);
try {
await object.save();
message("Saved file");
} catch(error) {
throw error;
}
});
Parse.Cloud.job("testDontSaveVirusFile", async (request) => {
const { params, headers, log, message } = request;
const fake_virus_url = 'https://secure.eicar.org/eicar.com';
await Parse.Cloud.run("setTestSchema");
const object = new Parse.Object('Test');
const file = new Parse.File("eicar.com", { uri: fake_virus_url });
object.set('textFile', file);
try {
await object.save(null, { useMasterKey: true });
message("Saved file");
} catch(error) {
throw error;
}
});