Skip to content

Commit 3fbd213

Browse files
authored
Create br_quarantine_risky_attachments.js
1 parent d961e5b commit 3fbd213

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Business Rule: Quarantine risky attachments by type or size
2+
// Table: sys_attachment | When: before insert
3+
4+
(function executeRule(current, previous /*null*/) {
5+
try {
6+
// Config
7+
var BLOCKED_EXTS = ['exe', 'bat', 'cmd', 'ps1', 'js'];
8+
var MAX_SIZE_MB = 25; // quarantine files larger than this
9+
var QUARANTINE_TABLE = 'incident'; // replace with your quarantine table if available
10+
var ASSIGNMENT_GROUP_SYSID = ''; // optional triage group
11+
12+
// Skip non-file or missing metadata
13+
if (!current.table_name || !current.file_name) return;
14+
15+
var utils = new QuarantineAttachmentUtils();
16+
var ext = utils.getExt(current.file_name);
17+
var sizeBytes = Number(current.size_bytes || 0);
18+
var isBlocked = BLOCKED_EXTS.indexOf(ext) !== -1;
19+
var isTooLarge = sizeBytes > (MAX_SIZE_MB * 1024 * 1024);
20+
21+
if (!(isBlocked || isTooLarge)) return;
22+
23+
var reason = isBlocked ? ('blocked extension .' + ext) : ('size ' + sizeBytes + ' bytes exceeds ' + MAX_SIZE_MB + ' MB');
24+
25+
// Create quarantine record
26+
var quarantineId = utils.ensureQuarantineRecord(QUARANTINE_TABLE, current.file_name, reason, ASSIGNMENT_GROUP_SYSID);
27+
28+
// Copy attachment to quarantine and delete original
29+
utils.copyAndDelete(current.table_name, current.table_sys_id, QUARANTINE_TABLE, quarantineId, current.sys_id);
30+
31+
gs.info('[ATTACHMENT-QUARANTINE] file=' + current.file_name +
32+
' ext=' + ext +
33+
' size=' + sizeBytes +
34+
' reason=' + reason +
35+
' quarantined_to=' + QUARANTINE_TABLE + ':' + quarantineId);
36+
} catch (e) {
37+
gs.error('Attachment quarantine failed: ' + e.message);
38+
}
39+
})(current, previous);

0 commit comments

Comments
 (0)