Skip to content

Commit 52e1090

Browse files
Merge pull request #3 from compliance-framework/feat/add-more-alert-checks
BCH 1033: More alert checks for vulnerabilities.
2 parents a0c6cdb + ee27af0 commit 52e1090

28 files changed

+3796
-2505
lines changed

examples/dismissed.json

Lines changed: 626 additions & 0 deletions
Large diffs are not rendered by default.

examples/full.json

Lines changed: 2205 additions & 2159 deletions
Large diffs are not rendered by default.

examples/redacted.json

Lines changed: 298 additions & 252 deletions
Large diffs are not rendered by default.

policies/critical_vulnerabilities.rego

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package critical_vulnerabilities_count
2+
3+
import future.keywords.in
4+
5+
violation[{}] if {
6+
# Build a set of alerts that are open and with a critical severity.
7+
open_alerts := [alert |
8+
some alert in input.alerts
9+
alert.state == "open"
10+
alert.security_vulnerability.severity == "critical"
11+
]
12+
13+
# If there are 2 or more such alerts, then deny.
14+
count(open_alerts) >= 2
15+
}
16+
17+
title := "Limit amount of critical vulnerabilities"
18+
description := `
19+
Critical severity vulnerabilities should be kept within
20+
reasonable limits to avoid a wide footprint of risk
21+
`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package critical_vulnerabilities_count_test
2+
3+
import data.critical_vulnerabilities_count
4+
5+
test_too_many_critical_vulnerabilities_fail if {
6+
count(critical_vulnerabilities_count.violation) == 1 with input as {"alerts": [
7+
{
8+
"state": "open",
9+
"security_vulnerability": {"severity": "critical"},
10+
},
11+
{
12+
"state": "open",
13+
"security_vulnerability": {"severity": "critical"},
14+
},
15+
]}
16+
}
17+
18+
test_few_critical_vulnerabilities_pass if {
19+
count(critical_vulnerabilities_count.violation) == 0 with input as {"alerts": [{
20+
"state": "open",
21+
"security_vulnerability": {"severity": "medium"},
22+
}]}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package critical_vulnerabilities_dismissal
2+
3+
import data.utils.time_ext
4+
5+
violation[{}] if {
6+
working_day_now_ns := time_ext.reduce_day_ns(time.now_ns())
7+
seven_days_ago := working_day_now_ns - (7 * time_ext.one_day_ns)
8+
9+
# Check there exists 1 or more critical alerts that have been open for more than 5 working days.
10+
some alert in input.alerts
11+
12+
alert.state == "open"
13+
alert.security_vulnerability.severity == "critical"
14+
time.parse_rfc3339_ns(alert.created_at) < seven_days_ago
15+
}
16+
17+
title := "Limit amount of critical vulnerabilities within 5 working days"
18+
description := `
19+
Critical severity vulnerabilities should be dealt with within
20+
five working days to avoid a wide footprint of risk`
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package critical_vulnerabilities_dismissal_test
2+
3+
import data.critical_vulnerabilities_dismissal
4+
5+
test_over_five_days_violation if {
6+
now := time.parse_rfc3339_ns("2025-06-20T09:00:00Z")
7+
count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{
8+
"state": "open",
9+
"created_at": "2025-06-03T09:00:00Z",
10+
"security_vulnerability": {"severity": "critical"},
11+
}]}
12+
with time.now_ns as now
13+
}
14+
15+
test_one_day_ok if {
16+
now := time.parse_rfc3339_ns("2025-06-04T09:00:00Z")
17+
count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{
18+
"state": "open",
19+
"created_at": "2025-06-03T09:00:00Z", # one week earlier
20+
"security_vulnerability": {"severity": "critical"},
21+
}]}
22+
with time.now_ns as now
23+
}
24+
25+
test_five_days_over_weekend_ok if {
26+
now := time.parse_rfc3339_ns("2025-09-22T09:00:00Z")
27+
count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{
28+
"state": "open",
29+
"created_at": "2025-09-15T09:00:00Z",
30+
"security_vulnerability": {"severity": "critical"},
31+
}]}
32+
with time.now_ns as now
33+
}
34+
35+
test_just_more_than_five_days_violation if {
36+
now := time.parse_rfc3339_ns("2025-09-22T09:00:00Z")
37+
count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{
38+
"state": "open",
39+
"created_at": "2025-09-15T08:59:59Z",
40+
"security_vulnerability": {"severity": "critical"},
41+
}]}
42+
with time.now_ns as now
43+
}
44+
45+
test_alert_over_weekend_ok if {
46+
now := time.parse_rfc3339_ns("2025-09-29T09:00:00Z")
47+
count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{
48+
"state": "open",
49+
"created_at": "2025-09-26T09:00:00Z",
50+
"security_vulnerability": {"severity": "critical"},
51+
}]}
52+
with time.now_ns as now
53+
}
54+
55+
test_alert_over_weekend_marginal_ok if {
56+
now := time.parse_rfc3339_ns("2025-09-27T09:00:00Z")
57+
count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{
58+
"state": "open",
59+
"created_at": "2025-09-21T09:00:00Z",
60+
"security_vulnerability": {"severity": "critical"},
61+
}]}
62+
with time.now_ns as now
63+
}
64+
65+
test_alert_over_weekend_violation if {
66+
now := time.parse_rfc3339_ns("2025-09-27T09:00:00Z")
67+
count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{
68+
"state": "open",
69+
"created_at": "2025-09-18T09:00:00Z",
70+
"security_vulnerability": {"severity": "critical"},
71+
}]}
72+
with time.now_ns as now
73+
}
74+
75+
test_alert_over_weekend_marginal_violation if {
76+
now := time.parse_rfc3339_ns("2025-09-27T09:00:00Z")
77+
count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{
78+
"state": "open",
79+
"created_at": "2025-09-19T06:00:00Z",
80+
"security_vulnerability": {"severity": "critical"},
81+
}]}
82+
with time.now_ns as now
83+
}

policies/critical_vulnerabilities_test.rego

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package high_vulnerabilities_dismissal
2+
3+
import data.utils.time_ext
4+
5+
violation[{}] if {
6+
working_day_now_ns := time_ext.reduce_day_ns(time.now_ns())
7+
two_weeks_ago := working_day_now_ns - (14 * time_ext.one_day_ns)
8+
9+
some alert in input.alerts
10+
alert.state == "open"
11+
alert.security_vulnerability.severity == "high"
12+
time.parse_rfc3339_ns(alert.created_at) < two_weeks_ago
13+
}
14+
15+
title := "Limit amount of 'high' vulnerabilities that have not been dismissed within 10 working days"
16+
description := `
17+
'High' severity vulnerabilities should be dismissed within two weeks (10 working days)
18+
to avoid a wide footprint of risk
19+
`

0 commit comments

Comments
 (0)