Skip to content

Commit

Permalink
Update XCCDF mapper as per NIST to CCI, CCI to NIST, and proper defau…
Browse files Browse the repository at this point in the history
…lt NIST and CCI tags discussion

Signed-off-by: Joyce Quach <jquach@mitre.org>
  • Loading branch information
jtquach1 committed Nov 15, 2024
1 parent 3451cdc commit 635b270
Show file tree
Hide file tree
Showing 10 changed files with 16,960 additions and 16,232 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,962 changes: 1,481 additions & 1,481 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel7-hdf.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3,474 changes: 1,737 additions & 1,737 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel8-hdf.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,920 changes: 1,460 additions & 1,460 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel7-hdf.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3,474 changes: 1,737 additions & 1,737 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel8-hdf.json

Large diffs are not rendered by default.

57 changes: 40 additions & 17 deletions libs/hdf-converters/src/xccdf-results-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
parseXml
} from './base-converter';
import {conditionallyProvideAttribute} from './utils/global';
import {DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS} from './mappings/CciNistMappingData';
import {CCI2NIST} from './mappings/CciNistMapping';
import {CCI2NIST, NIST2CCI} from './mappings/CciNistMapping';

const IMPACT_MAPPING: Map<string, number> = new Map([
['critical', 0.9],
Expand All @@ -20,6 +19,15 @@ const IMPACT_MAPPING: Map<string, number> = new Map([
['low', 0.3]
]);

const DEFAULT_CCI_TAGS = [
'CCI-000707',
'CCI-000710',
'CCI-000711',
'CCI-000366'
];

const DEFAULT_NIST_TAGS = CCI2NIST(DEFAULT_CCI_TAGS, []);

function asArray<T>(arg: T | T[]): T[] {
if (Array.isArray(arg)) {
return arg;
Expand Down Expand Up @@ -161,16 +169,34 @@ function extractNist(input: IIdent | IIdent[]): string[] {
.flatMap((c) => c.canonize() || []);
}

function nistTag(input: IIdent | IIdent[]): string[] {
// The XCCDF results input file might already contain some NIST tags.
function cciAndNistTags(input: IIdent | IIdent[]): {
cci: string[];
nist: string[];
} {
const output: {
cci: string[];
nist: string[];
} = {cci: [], nist: []};
// The XCCDF results input file might already contain NIST and CCI tags.
const existingCcis = extractCci(input);
const existingNists = extractNist(input);

// It might also have CCI tags adjacent to the NIST tags.
const ccis = extractCci(input);
const nistsFromMappedCcis = CCI2NIST(ccis, []);
if (existingCcis.length > 0) {
const nistsFromMappedCcis = CCI2NIST(existingCcis, []);
output.nist.push(...nistsFromMappedCcis);
output.cci.push(...existingCcis);
return output;
}
if (existingNists.length > 0) {
const ccisFromMappedNists = NIST2CCI(existingNists);
output.nist.push(...existingNists);
output.cci.push(...ccisFromMappedNists);
return output;
}

const nists = _.uniq([...existingNists, ...nistsFromMappedCcis]);
return nists.length > 0 ? nists : DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS;
output.nist.push(...DEFAULT_NIST_TAGS);
output.cci.push(...DEFAULT_CCI_TAGS);
return output;
}

/**
Expand Down Expand Up @@ -325,14 +351,6 @@ export class XCCDFResultsMapper extends BaseConverter {
pathTransform: getRulesInBenchmark,
key: 'id',
tags: {
cci: {
path: ['ident', 'reference'],
transformer: extractCci
},
nist: {
path: ['ident', 'reference'], // WIP: figure out why reference isn't being pulled
transformer: nistTag
},
severity: {path: 'severity'},
description: {
path: ['description.text', 'description'],
Expand Down Expand Up @@ -429,6 +447,11 @@ export class XCCDFResultsMapper extends BaseConverter {
'version',
_.get(data, 'version.text'),
_.has(data, 'version.text')
),
...cciAndNistTags(
['ident', 'reference'].flatMap(
(path) => _.get(data, path, []) as IIdent[]
)
)
})
},
Expand Down

0 comments on commit 635b270

Please sign in to comment.