@mitre/inspec-objects 0.0.9 → 0.0.12
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/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/parsers/xccdf.d.ts +1 -1
- package/lib/parsers/xccdf.js +18 -6
- package/lib/resources/automatticUpdateTemplate.json +3 -0
- package/lib/utilities/CciNistMappingData.d.ts +5100 -0
- package/lib/utilities/CciNistMappingData.js +5103 -0
- package/lib/utilities/diff.js +13 -3
- package/lib/utilities/diffMarkdown.d.ts +6 -0
- package/lib/utilities/diffMarkdown.js +32 -0
- package/lib/utilities/update.d.ts +15 -0
- package/lib/utilities/update.js +88 -0
- package/lib/utilities/xccdf.d.ts +1 -1
- package/lib/utilities/xccdf.js +18 -2
- package/mitre-inspec-objects-v0.0.11.tgz +0 -0
- package/out.json +107055 -0
- package/package-lock.json +52 -2
- package/package.json +5 -1
- package/test/sample_data/inspec/profiles/redhat-enterprise-linux-7-stig-baseline/spec/fixtures/kitchen/manifests/site.pp +0 -29
- package/test/sample_data/inspec/profiles/redhat-enterprise-linux-7-stig-baseline/spec/fixtures/kitchen/modules/garbage/.gitignore +0 -0
- package/test/sample_data/inspec/profiles/redhat-enterprise-linux-7-stig-baseline/spec/results/.gitkeep +0 -0
package/lib/utilities/diff.js
CHANGED
|
@@ -22,7 +22,15 @@ exports.removeNewlines = removeNewlines;
|
|
|
22
22
|
function simplifyDiff(diffData) {
|
|
23
23
|
return lodash_1.default.transform(diffData, (result, diffValue, key) => {
|
|
24
24
|
if (lodash_1.default.has(diffValue, '__new')) {
|
|
25
|
-
|
|
25
|
+
// Remove any trailing space
|
|
26
|
+
if (typeof lodash_1.default.get(diffValue, '__new') === 'string' && typeof lodash_1.default.get(diffValue, '__old') === 'string') {
|
|
27
|
+
if (lodash_1.default.get(diffValue, '__new').trim() !== lodash_1.default.get(diffValue, '__old').trim()) {
|
|
28
|
+
lodash_1.default.set(result, key, lodash_1.default.get(diffValue, '__new'));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
result[key] = lodash_1.default.get(diffValue, '__new');
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
else if (Array.isArray(diffValue)) {
|
|
28
36
|
result[key] = diffValue.map((value) => value[0] === '+' && value[1]).filter(value => value);
|
|
@@ -43,11 +51,13 @@ function diffProfile(fromProfile, toProfile) {
|
|
|
43
51
|
const profileDiff = {
|
|
44
52
|
addedControlIDs: [],
|
|
45
53
|
removedControlIDs: [],
|
|
54
|
+
addedControls: {},
|
|
46
55
|
changedControls: {}
|
|
47
56
|
};
|
|
48
57
|
const originalDiff = {
|
|
49
58
|
addedControlIDs: [],
|
|
50
59
|
removedControlIDs: [],
|
|
60
|
+
addedControls: {},
|
|
51
61
|
changedControls: {}
|
|
52
62
|
};
|
|
53
63
|
const fromControlIDs = fromProfile.controls.map((control) => control.id).sort();
|
|
@@ -68,8 +78,8 @@ function diffProfile(fromProfile, toProfile) {
|
|
|
68
78
|
profileDiff.addedControlIDs.forEach((addedControl) => {
|
|
69
79
|
const newControl = toProfile.controls.find((control) => addedControl === control.id);
|
|
70
80
|
if (newControl) {
|
|
71
|
-
profileDiff.
|
|
72
|
-
originalDiff.
|
|
81
|
+
profileDiff.addedControls[addedControl] = newControl;
|
|
82
|
+
originalDiff.addedControls[addedControl] = newControl;
|
|
73
83
|
}
|
|
74
84
|
});
|
|
75
85
|
// Find changed controls
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDiffMarkdown = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const mustache_1 = tslib_1.__importDefault(require("mustache"));
|
|
6
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
+
const global_1 = require("./global");
|
|
8
|
+
const xccdf_1 = require("./xccdf");
|
|
9
|
+
const automatticUpdateTemplate_json_1 = tslib_1.__importDefault(require("../resources/automatticUpdateTemplate.json"));
|
|
10
|
+
function getUpdatedCheckForId(id, profile) {
|
|
11
|
+
const foundControl = profile.controls.find((control) => control.id === id);
|
|
12
|
+
return lodash_1.default.get(foundControl === null || foundControl === void 0 ? void 0 : foundControl.descs, 'check') || 'Missing check';
|
|
13
|
+
}
|
|
14
|
+
function createDiffMarkdown(diff, updatedProfile) {
|
|
15
|
+
const renderableDiffData = {
|
|
16
|
+
addedControls: Object.values(diff.simplified.addedControls),
|
|
17
|
+
checks: [],
|
|
18
|
+
fixes: [],
|
|
19
|
+
};
|
|
20
|
+
Object.entries(diff.simplified.changedControls).forEach(([id, updatedControl]) => {
|
|
21
|
+
if (lodash_1.default.get(updatedControl, "descs.check")) {
|
|
22
|
+
console.log((0, xccdf_1.removeXMLSpecialCharacters)((0, global_1.removeNewlinePlaceholders)(getUpdatedCheckForId(id, updatedProfile))));
|
|
23
|
+
renderableDiffData.checks.push({
|
|
24
|
+
id,
|
|
25
|
+
check: (0, xccdf_1.removeXMLSpecialCharacters)((0, global_1.removeNewlinePlaceholders)(getUpdatedCheckForId(id, updatedProfile))),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
// Render output
|
|
30
|
+
return mustache_1.default.render(automatticUpdateTemplate_json_1.default.data, renderableDiffData);
|
|
31
|
+
}
|
|
32
|
+
exports.createDiffMarkdown = createDiffMarkdown;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Control from '../objects/control';
|
|
2
|
+
import Profile from '../objects/profile';
|
|
3
|
+
import { ProfileDiff } from '../types/diff';
|
|
4
|
+
import { OvalDefinitionValue } from '../types/oval';
|
|
5
|
+
export declare type UpdatedProfileReturn = {
|
|
6
|
+
profile: Profile;
|
|
7
|
+
diff: {
|
|
8
|
+
simplified: ProfileDiff;
|
|
9
|
+
originalDiff: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
markdown: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function updateControl(from: Control, update: Partial<Control>): Control;
|
|
14
|
+
export declare function updateProfile(from: Profile, using: Profile): Omit<UpdatedProfileReturn, 'markdown'>;
|
|
15
|
+
export declare function updateProfileUsingXCCDF(from: Profile, using: string, id: 'group' | 'rule' | 'version', ovalDefinitions?: Record<string, OvalDefinitionValue>): UpdatedProfileReturn;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Utilities to update a profile or control with new metadata
|
|
3
|
+
// The ultimate goal is to preserve all the metadata that is already there and only add what is new
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.updateProfileUsingXCCDF = exports.updateProfile = exports.updateControl = void 0;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
8
|
+
const profile_1 = tslib_1.__importDefault(require("../objects/profile"));
|
|
9
|
+
const xccdf_1 = require("../parsers/xccdf");
|
|
10
|
+
const diff_1 = require("./diff");
|
|
11
|
+
const diffMarkdown_1 = require("./diffMarkdown");
|
|
12
|
+
function projectValuesOntoExistingObj(dst, src, currentPath = '') {
|
|
13
|
+
for (const updatedValue in src) {
|
|
14
|
+
const existingValue = lodash_1.default.get(dst, updatedValue);
|
|
15
|
+
// We have a new value for something that already exists in dst
|
|
16
|
+
if (existingValue !== undefined) {
|
|
17
|
+
if (typeof existingValue === 'object' && existingValue !== null && !Array.isArray(existingValue)) {
|
|
18
|
+
dst[updatedValue] = projectValuesOntoExistingObj(existingValue, src[updatedValue], currentPath + updatedValue + '.');
|
|
19
|
+
}
|
|
20
|
+
else if (typeof src[updatedValue] === 'string') {
|
|
21
|
+
lodash_1.default.set(dst, updatedValue, src[updatedValue].trim());
|
|
22
|
+
}
|
|
23
|
+
else if (typeof src[updatedValue] === 'number') {
|
|
24
|
+
lodash_1.default.set(dst, updatedValue, src[updatedValue]);
|
|
25
|
+
}
|
|
26
|
+
else if (Array.isArray(src[updatedValue])) {
|
|
27
|
+
const uniqueArrayValues = [...new Set(lodash_1.default.get(dst, updatedValue, []).concat(src[updatedValue]))];
|
|
28
|
+
lodash_1.default.set(dst, updatedValue, uniqueArrayValues);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return dst;
|
|
33
|
+
}
|
|
34
|
+
function updateControl(from, update) {
|
|
35
|
+
return projectValuesOntoExistingObj(from, update);
|
|
36
|
+
}
|
|
37
|
+
exports.updateControl = updateControl;
|
|
38
|
+
function updateProfile(from, using) {
|
|
39
|
+
// Update the profile with the new metadata
|
|
40
|
+
const to = new profile_1.default(lodash_1.default.omit(from, 'controls'));
|
|
41
|
+
// Find the diff
|
|
42
|
+
const diff = (0, diff_1.diffProfile)(from, using);
|
|
43
|
+
// Add the new controls
|
|
44
|
+
diff.simplified.addedControlIDs.forEach(id => {
|
|
45
|
+
const addedControl = diff.simplified.addedControls[id];
|
|
46
|
+
if (addedControl) {
|
|
47
|
+
to.controls.push(addedControl);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("New control added but don't have the control data");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// Update the existing controls
|
|
54
|
+
for (const existingControl of from.controls) {
|
|
55
|
+
const updatedControl = using.controls.find(control => control.id === existingControl.id);
|
|
56
|
+
if (updatedControl) {
|
|
57
|
+
const controlDiff = diff.simplified.changedControls[existingControl.id];
|
|
58
|
+
if (controlDiff) {
|
|
59
|
+
to.controls.push(updateControl(existingControl, controlDiff));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
to.controls.push(existingControl);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.log("Control not updated: " + existingControl.id);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
profile: to,
|
|
71
|
+
diff,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.updateProfile = updateProfile;
|
|
75
|
+
function updateProfileUsingXCCDF(from, using, id, ovalDefinitions) {
|
|
76
|
+
// Parse the XCCDF benchmark and convert it into a Profile
|
|
77
|
+
const xccdfProfile = (0, xccdf_1.processXCCDF)(using, false, id);
|
|
78
|
+
const xccdfProfileWithNLReplacement = (0, xccdf_1.processXCCDF)(using, true, id);
|
|
79
|
+
// Update the profile and return
|
|
80
|
+
const updatedProfile = updateProfile(from, xccdfProfile);
|
|
81
|
+
// Create the markdown
|
|
82
|
+
return {
|
|
83
|
+
profile: updatedProfile.profile,
|
|
84
|
+
diff: updatedProfile.diff,
|
|
85
|
+
markdown: (0, diffMarkdown_1.createDiffMarkdown)(updatedProfile.diff, xccdfProfileWithNLReplacement)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
exports.updateProfileUsingXCCDF = updateProfileUsingXCCDF;
|
package/lib/utilities/xccdf.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DecodedDescription } from '../types/xccdf';
|
|
2
2
|
export declare function convertEncodedXmlIntoJson(encodedXml: string): any;
|
|
3
|
-
export declare function removeXMLSpecialCharacters(
|
|
3
|
+
export declare function removeXMLSpecialCharacters(str: string): string;
|
|
4
4
|
export declare function severityStringToImpact(string: string, id: string): number;
|
|
5
5
|
export declare function impactNumberToSeverityString(impact: number): string;
|
|
6
6
|
export declare function convertEncodedHTMLIntoJson(encodedHTML?: string): DecodedDescription;
|
package/lib/utilities/xccdf.js
CHANGED
|
@@ -5,6 +5,21 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const fast_xml_parser_1 = tslib_1.__importDefault(require("fast-xml-parser"));
|
|
6
6
|
const htmlparser = tslib_1.__importStar(require("htmlparser2"));
|
|
7
7
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
8
|
+
const he_1 = tslib_1.__importDefault(require("he"));
|
|
9
|
+
var htmlEntities = {
|
|
10
|
+
nbsp: ' ',
|
|
11
|
+
cent: '¢',
|
|
12
|
+
pound: '£',
|
|
13
|
+
yen: '¥',
|
|
14
|
+
euro: '€',
|
|
15
|
+
copy: '©',
|
|
16
|
+
reg: '®',
|
|
17
|
+
lt: '<',
|
|
18
|
+
gt: '>',
|
|
19
|
+
quot: '"',
|
|
20
|
+
amp: '&',
|
|
21
|
+
apos: '\''
|
|
22
|
+
};
|
|
8
23
|
function convertEncodedXmlIntoJson(encodedXml) {
|
|
9
24
|
return fast_xml_parser_1.default.parse(encodedXml, {
|
|
10
25
|
ignoreAttributes: false,
|
|
@@ -14,10 +29,11 @@ function convertEncodedXmlIntoJson(encodedXml) {
|
|
|
14
29
|
});
|
|
15
30
|
}
|
|
16
31
|
exports.convertEncodedXmlIntoJson = convertEncodedXmlIntoJson;
|
|
17
|
-
function removeXMLSpecialCharacters(
|
|
18
|
-
return
|
|
32
|
+
function removeXMLSpecialCharacters(str) {
|
|
33
|
+
return he_1.default.decode(str);
|
|
19
34
|
}
|
|
20
35
|
exports.removeXMLSpecialCharacters = removeXMLSpecialCharacters;
|
|
36
|
+
;
|
|
21
37
|
function severityStringToImpact(string, id) {
|
|
22
38
|
var _a, _b, _c, _d, _e;
|
|
23
39
|
if ((_a = string.match(/none|na|n\/a|not[\s()*_|]?applicable/i)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
Binary file
|