-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathloadThreatsforMitigations.js
40 lines (39 loc) · 1.4 KB
/
loadThreatsforMitigations.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
var mitigationsData;
//Load the json file that contains the threat and mitigation mappings
window.onload = (event) => {
fetch('../_data/mitigations_threat_mappings.json')
.then((res) => {
if (!res.ok) {
throw new Error(`HTTP error! Status: ${res.status}`);
}
return res.json();
})
.then((json) => {
mitigationsData = json;
var mitigationTitle = document
.getElementById('mitigationTitle')
.innerHTML.replaceAll('\n', '')
.replaceAll(' ', '');
getRelatedThreats(mitigationTitle);
});
};
// Get threats mitigated by the current mitigation
function getRelatedThreats(mitigationTitle) {
var threats = [];
for (let i = 0; i < mitigationsData.mitigations.length; i++) {
if (mitigationTitle == mitigationsData.mitigations[i].id) {
for (let j = 0; j < mitigationsData.mitigations[i].threats.length; j++) {
threats.push({id: mitigationsData.mitigations[i].threats[j].id, desc: mitigationsData.mitigations[i].threats[j].text})
}
}
}
var threatsDiv = document.getElementById('relatedthreats');
if(threats.length != 0){
var threatsDiv_inner = '<h2>Mitigated Threats:</h2>';
for (var i = 0; i < threats.length; i++) {
threatsDiv_inner += "<a href='/threats/" + threats[i].id + ".html'>" + threats[i].id + "</a>" + " - "
+ threats[i].desc + "<br>"
}
threatsDiv.innerHTML = threatsDiv_inner;
}
}