Skip to content

Commit

Permalink
Fix for 620 - issues loading layers v10 and earlier (#621)
Browse files Browse the repository at this point in the history
* restore

* bug fix 620

* bump version

* update changelog

* autoformatter
  • Loading branch information
clemiller authored Feb 27, 2024
1 parent b2927a0 commit cd997c2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
This will patch the version number appropriately and create the correct tag on the current commit.
The creation of the tag can be disabled with the --no-git-tag-version if desired.
-->

# 4.9.3 - 27 February 2024

## Fixes
- Fixed a bug with loading Navigator layers on ATT&CK v10 or earlier. See issue [#620](https://github.com/mitre-attack/attack-navigator/issues/620).

# 4.9.2 - 26 February 2024

## Fixes
Expand Down
4 changes: 2 additions & 2 deletions nav-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nav-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/mitre-attack/attack-navigator.git"
},
"version": "4.9.2",
"version": "4.9.3",
"license": "Apache-2.0",
"scripts": {
"ng": "ng",
Expand Down
2 changes: 0 additions & 2 deletions nav-app/src/app/classes/stix/technique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export class Technique extends StixObject {
public readonly subtechniques: Technique[]; // subtechniques under this technique
public readonly datasources: string; // data sources of the technique
public parent: Technique = null; // parent technique. Only present if it's a sub-technique
public readonly x_mitre_domains: string[];
public get isSubtechnique() {
return this.parent != null;
}
Expand All @@ -22,7 +21,6 @@ export class Technique extends StixObject {
super(stixSDO, dataService);
this.platforms = stixSDO.x_mitre_platforms ? stixSDO.x_mitre_platforms.map((platform) => platform.trim()) : undefined;
this.datasources = stixSDO.x_mitre_data_sources ? stixSDO.x_mitre_data_sources.toString() : '';
this.x_mitre_domains = stixSDO.x_mitre_domains;
if (!this.revoked && !this.deprecated) {
this.tactics = stixSDO.kill_chain_phases.map((phase) => phase.phase_name);
}
Expand Down
67 changes: 38 additions & 29 deletions nav-app/src/app/services/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export class DataService {
*/
public parseBundle(domain: Domain, stixBundles: any[]): void {
let platforms = new Set<string>();
let matricesList: any[] = [];
let tacticsList: any[] = [];
let seenIDs = new Set<string>();
let matrixSDOs = [];
let idToTacticSDO = new Map<string, any>();
let matrixToTechniqueSDOs = new Map<string, any[]>();
for (let bundle of stixBundles) {
let techniqueSDOs = [];
let matrixSDOs = [];
let bundleMatrices = [];
let idToTechniqueSDO = new Map<string, any>();
let idToTacticSDO = new Map<string, any>();
for (let sdo of bundle.objects) {
// iterate through stix domain objects in the bundle
// Filter out object not included in this domain if domains field is available
Expand All @@ -63,9 +63,12 @@ export class DataService {
continue;
}

// filter out duplicates
if (seenIDs.has(sdo.id)) continue;
seenIDs.add(sdo.id);
// filter out duplicates, except for matrices
// which are needed to properly build the datatables
if (sdo.type != 'x-mitre-matrix') {
if (seenIDs.has(sdo.id)) continue;
seenIDs.add(sdo.id);
}

// parse according to type
switch (sdo.type) {
Expand Down Expand Up @@ -105,6 +108,7 @@ export class DataService {
break;
case 'x-mitre-matrix':
matrixSDOs.push(sdo);
bundleMatrices.push(sdo);
break;
case 'note':
domain.notes.push(new Note(sdo));
Expand All @@ -115,21 +119,21 @@ export class DataService {
// create techniques
this.createTechniques(techniqueSDOs, idToTechniqueSDO, domain);

// parse platforms
this.parsePlatforms(domain).forEach(platforms.add, platforms);

// create a list of matrix and tactic SDOs
for (let matrixSDO of matrixSDOs) {
if (matrixSDO.x_mitre_deprecated) {
continue;
// create map of matrices to techniques
for (let matrixSDO of bundleMatrices) {
if (!matrixToTechniqueSDOs.get(matrixSDO.id)) {
matrixToTechniqueSDOs.set(matrixSDO.id, techniqueSDOs);
} else {
matrixToTechniqueSDOs.get(matrixSDO.id).push(...techniqueSDOs);
}
matricesList.push(matrixSDO);
tacticsList.push(idToTacticSDO);
}

// parse platforms
this.parsePlatforms(domain).forEach(platforms.add, platforms);
}

// create matrices
this.createMatrices(matricesList, tacticsList, domain);
this.createMatrices(matrixSDOs, idToTacticSDO, matrixToTechniqueSDOs, domain);

domain.platforms = Array.from(platforms); // convert to array

Expand Down Expand Up @@ -169,18 +173,23 @@ export class DataService {
* @param tacticsList list of tactic SDOs
* @param domain the domain to add the matrix/tactics to
*/
public createMatrices(matricesList: any[], tacticsList: any[], domain: Domain): void {
for (let i = 0; i < matricesList.length; i++) {
let techniquesList = [];
if (matricesList[i].x_mitre_deprecated) {
continue;
}
for (let technique of domain.techniques) {
if (technique.x_mitre_domains.includes(matricesList[i].external_references[0].external_id)) {
techniquesList.push(technique);
}
}
domain.matrices.push(new Matrix(matricesList[i], tacticsList[i], techniquesList, this));
public createMatrices(matrixSDOs: any[], idToTacticSDO: Map<string, any>, matrixToTechniqueSDOs, domain: Domain): void {
let createdMatrixIDs = [];
for (let matrixSDO of matrixSDOs) {
// check if matrix was already created
if (createdMatrixIDs.includes(matrixSDO.id)) continue;

// check if matrix is deprecated
if (matrixSDO.x_mitre_deprecated) continue;

// retrieve relevant matrix techniques
let techniqueSDOs = matrixToTechniqueSDOs.get(matrixSDO.id);
let techniqueIDs = techniqueSDOs.map((t) => t.id);
let techniques = domain.techniques.filter((t) => techniqueIDs.includes(t.id));
domain.matrices.push(new Matrix(matrixSDO, idToTacticSDO, techniques, this));

// add to list of created matrices
createdMatrixIDs.push(matrixSDO.id);
}
}

Expand Down

0 comments on commit cd997c2

Please sign in to comment.