@mitre/inspec-objects 0.0.5 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/objects/control.d.ts +8 -2
- package/lib/objects/control.js +12 -0
- package/lib/parsers/json.js +3 -3
- package/lib/parsers/xccdf.js +1 -8
- package/lib/utilities/diff.d.ts +1 -0
- package/lib/utilities/diff.js +23 -12
- package/package.json +1 -1
- package/lib/utilities/CciNistMappingData.d.ts +0 -5100
- package/lib/utilities/CciNistMappingData.js +0 -5103
- package/mitre-inspec-objects-v0.0.3.tgz +0 -0
- package/mitre-inspec-objects-v0.0.5.tgz +0 -0
package/lib/objects/control.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { ExecJSON } from "inspecjs";
|
|
2
|
+
export declare function objectifyDescriptions(descs: ExecJSON.ControlDescription[] | {
|
|
3
|
+
[key: string]: string | undefined;
|
|
4
|
+
} | null | undefined): {
|
|
5
|
+
[key: string]: string | undefined;
|
|
6
|
+
} | null | undefined;
|
|
2
7
|
export default class Control {
|
|
3
8
|
id?: string | null;
|
|
4
9
|
title?: string | null;
|
|
5
10
|
code?: string | null;
|
|
6
11
|
desc?: string | null;
|
|
7
|
-
descs?:
|
|
12
|
+
descs?: {
|
|
8
13
|
[key: string]: string | undefined;
|
|
9
14
|
} | null;
|
|
10
15
|
impact?: number;
|
|
@@ -16,14 +21,15 @@ export default class Control {
|
|
|
16
21
|
})[];
|
|
17
22
|
tags: {
|
|
18
23
|
check?: string;
|
|
24
|
+
check_id?: string;
|
|
19
25
|
fix?: string;
|
|
26
|
+
fix_id?: string | null;
|
|
20
27
|
severity?: string;
|
|
21
28
|
gtitle?: string;
|
|
22
29
|
gid?: string;
|
|
23
30
|
satisfies?: string[];
|
|
24
31
|
rid?: string;
|
|
25
32
|
stig_id?: string;
|
|
26
|
-
fix_id?: string | null;
|
|
27
33
|
cci?: string[];
|
|
28
34
|
cis_controls?: Record<string, string[]>[];
|
|
29
35
|
nist?: string[];
|
package/lib/objects/control.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectifyDescriptions = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
5
6
|
const flat_1 = require("flat");
|
|
6
7
|
const global_1 = require("../utilities/global");
|
|
8
|
+
function objectifyDescriptions(descs) {
|
|
9
|
+
if (Array.isArray(descs)) {
|
|
10
|
+
const descriptions = {};
|
|
11
|
+
descs.forEach((description) => {
|
|
12
|
+
descriptions[description.label] = description.data;
|
|
13
|
+
});
|
|
14
|
+
return descriptions;
|
|
15
|
+
}
|
|
16
|
+
return descs;
|
|
17
|
+
}
|
|
18
|
+
exports.objectifyDescriptions = objectifyDescriptions;
|
|
7
19
|
class Control {
|
|
8
20
|
constructor(data) {
|
|
9
21
|
this.tags = {};
|
package/lib/parsers/json.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.processJSON = exports.processExecJSON = exports.processProfileJSON = exp
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const inspecjs_1 = require("inspecjs");
|
|
6
6
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
-
const control_1 = tslib_1.
|
|
7
|
+
const control_1 = tslib_1.__importStar(require("../objects/control"));
|
|
8
8
|
const profile_1 = tslib_1.__importDefault(require("../objects/profile"));
|
|
9
9
|
function processEvaluation(evaluationInput) {
|
|
10
10
|
const topLevelProfile = evaluationInput.contains[0];
|
|
@@ -25,7 +25,7 @@ function processEvaluation(evaluationInput) {
|
|
|
25
25
|
title: control.data.title,
|
|
26
26
|
impact: control.data.impact,
|
|
27
27
|
desc: control.data.desc,
|
|
28
|
-
descs: control.hdf.wraps.descriptions,
|
|
28
|
+
descs: (0, control_1.objectifyDescriptions)(control.hdf.wraps.descriptions),
|
|
29
29
|
tags: control.hdf.wraps.tags,
|
|
30
30
|
}));
|
|
31
31
|
});
|
|
@@ -52,7 +52,7 @@ function processProfileJSON(profileInput) {
|
|
|
52
52
|
impact: control.impact,
|
|
53
53
|
code: control.code,
|
|
54
54
|
tags: control.tags,
|
|
55
|
-
descs: control.descriptions,
|
|
55
|
+
descs: (0, control_1.objectifyDescriptions)(control.descriptions),
|
|
56
56
|
}));
|
|
57
57
|
});
|
|
58
58
|
return profile;
|
package/lib/parsers/xccdf.js
CHANGED
|
@@ -43,13 +43,12 @@ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
|
|
|
43
43
|
extractedDescription = (0, xccdf_1.convertEncodedHTMLIntoJson)(rule.description);
|
|
44
44
|
}
|
|
45
45
|
const control = new control_1.default();
|
|
46
|
-
control.id = rule['@_id'];
|
|
47
46
|
switch (useRuleId) {
|
|
48
47
|
case 'group':
|
|
49
48
|
control.id = rule.group['@_id'];
|
|
50
49
|
break;
|
|
51
50
|
case 'rule':
|
|
52
|
-
control.id = rule['@_id'];
|
|
51
|
+
control.id = rule['@_id'].split('r')[0];
|
|
53
52
|
break;
|
|
54
53
|
case 'version':
|
|
55
54
|
control.id = rule.version;
|
|
@@ -126,15 +125,9 @@ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
|
|
|
126
125
|
if (rule['fix'] && rule['fix'].length > 0) {
|
|
127
126
|
control.tags.fix_id = rule['fix'][0]['@_id'];
|
|
128
127
|
}
|
|
129
|
-
else {
|
|
130
|
-
control.tags.fix_id = null;
|
|
131
|
-
}
|
|
132
128
|
if (rule['rationale']) {
|
|
133
129
|
control.tags.rationale = rule['rationale'][0]['#text'];
|
|
134
130
|
}
|
|
135
|
-
else {
|
|
136
|
-
control.tags.rationale = null;
|
|
137
|
-
}
|
|
138
131
|
if (typeof extractedDescription === 'object') {
|
|
139
132
|
control.tags.satisfies = ((_c = extractedDescription.VulnDiscussion) === null || _c === void 0 ? void 0 : _c.includes('Satisfies: ')) && extractedDescription.VulnDiscussion.split('Satisfies: ').length >= 1 ? extractedDescription.VulnDiscussion.split('Satisfies: ')[1].split(',').map(satisfaction => satisfaction.trim()) : undefined;
|
|
140
133
|
control.tags.false_negatives = extractedDescription.FalseNegatives || undefined;
|
package/lib/utilities/diff.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Profile from '../objects/profile';
|
|
2
2
|
import { ProfileDiff } from '../types/diff';
|
|
3
3
|
export declare function removeNewlines(control?: Record<string, unknown>): Record<string, unknown>;
|
|
4
|
+
export declare function simplifyDiff(diffData: Record<string, unknown>): Record<string, unknown>;
|
|
4
5
|
export declare function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDiff;
|
package/lib/utilities/diff.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diffProfile = exports.removeNewlines = void 0;
|
|
3
|
+
exports.diffProfile = exports.simplifyDiff = exports.removeNewlines = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const json_diff_1 = require("json-diff");
|
|
6
6
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
@@ -19,6 +19,26 @@ function removeNewlines(control) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
exports.removeNewlines = removeNewlines;
|
|
22
|
+
function simplifyDiff(diffData) {
|
|
23
|
+
return lodash_1.default.transform(diffData, (result, diffValue, key) => {
|
|
24
|
+
if (lodash_1.default.has(diffValue, '__new')) {
|
|
25
|
+
result[key] = lodash_1.default.get(diffValue, '__new');
|
|
26
|
+
}
|
|
27
|
+
else if (Array.isArray(diffValue)) {
|
|
28
|
+
result[key] = diffValue.map((value) => value[0] === '+' && value[1]).filter(value => value);
|
|
29
|
+
}
|
|
30
|
+
else if (typeof diffValue === 'object') {
|
|
31
|
+
result[key] = simplifyDiff(diffValue);
|
|
32
|
+
}
|
|
33
|
+
else if (key.endsWith('__deleted')) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
result[key] = diffValue;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.simplifyDiff = simplifyDiff;
|
|
22
42
|
function diffProfile(fromProfile, toProfile) {
|
|
23
43
|
const profileDiff = {
|
|
24
44
|
addedControlIDs: [],
|
|
@@ -48,18 +68,9 @@ function diffProfile(fromProfile, toProfile) {
|
|
|
48
68
|
for (const fromControl of fromProfile.controls) {
|
|
49
69
|
const toControl = toProfile.controls.find((control) => control.id === fromControl.id);
|
|
50
70
|
if (toControl) {
|
|
51
|
-
const controlDiff = (0, json_diff_1.diff)(fromControl, toControl);
|
|
71
|
+
const controlDiff = lodash_1.default.omit((0, json_diff_1.diff)(fromControl, toControl), 'code__deleted');
|
|
52
72
|
if (controlDiff) {
|
|
53
|
-
|
|
54
|
-
if (lodash_1.default.has(value, '__new')) {
|
|
55
|
-
lodash_1.default.set(profileDiff, 'changedControls.' + fromControl.id + '.' + key.replace('.', '\\.'), lodash_1.default.get(controlDiff, key + '.__new'));
|
|
56
|
-
}
|
|
57
|
-
else if (typeof value === 'object') {
|
|
58
|
-
Object.entries(value).forEach(([subKey]) => {
|
|
59
|
-
lodash_1.default.set(profileDiff, 'changedControls.' + fromControl.id + '.' + key.replace('.', '\\.') + '.' + subKey.replace('.', '\\.'), lodash_1.default.get(controlDiff, key + '.' + subKey + '.__new'));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
73
|
+
profileDiff.changedControls[toControl.id] = simplifyDiff(controlDiff);
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
}
|