@mitre/inspec-objects 0.0.2 → 0.0.3

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.
@@ -5,4 +5,4 @@ export declare type GroupContextualizedRule = BenchmarkRule & {
5
5
  group: Omit<BenchmarkGroup, 'Rule' | 'Group'>;
6
6
  };
7
7
  export declare function extractAllRules(groups: BenchmarkGroup[]): GroupContextualizedRule[];
8
- export declare function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalDefinitionValue>): Profile;
8
+ export declare function processXCCDF(xml: string, removeNewlines?: boolean, ovalDefinitions?: Record<string, OvalDefinitionValue>): Profile;
@@ -6,7 +6,7 @@ const profile_1 = tslib_1.__importDefault(require("../objects/profile"));
6
6
  const xccdf_1 = require("../utilities/xccdf");
7
7
  const control_1 = tslib_1.__importDefault(require("../objects/control"));
8
8
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
9
- const hdf_converters_1 = require("@mitre/hdf-converters");
9
+ const CciNistMappingData_1 = require("../mappings/CciNistMappingData");
10
10
  function extractAllRules(groups) {
11
11
  const rules = [];
12
12
  groups.forEach((group) => {
@@ -25,7 +25,7 @@ function extractAllRules(groups) {
25
25
  return rules;
26
26
  }
27
27
  exports.extractAllRules = extractAllRules;
28
- function processXCCDF(xml, ovalDefinitions) {
28
+ function processXCCDF(xml, removeNewlines = false, ovalDefinitions) {
29
29
  const parsedXML = (0, xccdf_1.convertEncodedXmlIntoJson)(xml);
30
30
  const rules = extractAllRules(parsedXML.Benchmark[0].Group);
31
31
  const profile = new profile_1.default({
@@ -34,7 +34,7 @@ function processXCCDF(xml, ovalDefinitions) {
34
34
  summary: parsedXML.Benchmark[0].description[0]['#text']
35
35
  });
36
36
  rules.forEach(rule => {
37
- var _a, _b, _c;
37
+ var _a, _b, _c, _d;
38
38
  let extractedDescription;
39
39
  if (Array.isArray(rule.description)) {
40
40
  extractedDescription = rule.description[0]['#text'];
@@ -44,15 +44,29 @@ function processXCCDF(xml, ovalDefinitions) {
44
44
  }
45
45
  const control = new control_1.default();
46
46
  control.id = rule.group['@_id'];
47
- control.title = rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`;
48
- control.desc = typeof extractedDescription === 'string' ? extractedDescription : (_a = extractedDescription.VulnDiscussion) === null || _a === void 0 ? void 0 : _a.split('Satisfies: ')[0];
47
+ if (removeNewlines) {
48
+ const title = (0, xccdf_1.removeXMLSpecialCharacters)(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`);
49
+ control.title = title.replace(/\n/g, '{{{{newlineHERE}}}}');
50
+ const desc = (0, xccdf_1.removeXMLSpecialCharacters)(typeof extractedDescription === 'string' ? extractedDescription : ((_a = extractedDescription.VulnDiscussion) === null || _a === void 0 ? void 0 : _a.split('Satisfies: ')[0]) || 'Missing Description');
51
+ control.desc = desc === null || desc === void 0 ? void 0 : desc.replace(/\n/g, '{{{{newlineHERE}}}}');
52
+ }
53
+ else {
54
+ control.title = (0, xccdf_1.removeXMLSpecialCharacters)(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`);
55
+ control.desc = (0, xccdf_1.removeXMLSpecialCharacters)(typeof extractedDescription === 'string' ? extractedDescription : ((_b = extractedDescription.VulnDiscussion) === null || _b === void 0 ? void 0 : _b.split('Satisfies: ')[0]) || 'Missing Description');
56
+ }
49
57
  control.impact = (0, xccdf_1.severityStringToImpact)(rule['@_severity'] || 'critical', rule.group['@_id']);
50
58
  if (!control.descs || Array.isArray(control.descs)) {
51
59
  control.descs = {};
52
60
  }
53
61
  if (rule.check) {
54
62
  if (rule.check.some((ruleValue) => 'check-content' in ruleValue)) {
55
- control.descs.check = rule.check ? rule.check[0]['check-content'] : 'Missing description';
63
+ if (removeNewlines) {
64
+ const check = (0, xccdf_1.removeXMLSpecialCharacters)(rule.check ? rule.check[0]['check-content'] : 'Missing description');
65
+ control.descs.check = check.replace(/\n/g, '{{{{newlineHERE}}}}');
66
+ }
67
+ else {
68
+ control.descs.check = (0, xccdf_1.removeXMLSpecialCharacters)(rule.check ? rule.check[0]['check-content'] : 'Missing description');
69
+ }
56
70
  }
57
71
  else if (rule.check.some((ruleValue) => 'check-content-ref' in ruleValue) && ovalDefinitions) {
58
72
  let referenceID = null;
@@ -66,23 +80,35 @@ function processXCCDF(xml, ovalDefinitions) {
66
80
  }
67
81
  }
68
82
  if (referenceID && referenceID in ovalDefinitions) {
69
- control.descs.check = ovalDefinitions[referenceID].metadata[0].title;
83
+ if (removeNewlines) {
84
+ const check = (0, xccdf_1.removeXMLSpecialCharacters)(ovalDefinitions[referenceID].metadata[0].title);
85
+ control.descs.check = check.replace(/\n/g, '{{{{newlineHERE}}}}');
86
+ }
87
+ else {
88
+ control.descs.check = (0, xccdf_1.removeXMLSpecialCharacters)(ovalDefinitions[referenceID].metadata[0].title);
89
+ }
70
90
  }
71
91
  else if (referenceID) {
72
92
  console.warn(`Could not find OVAL definition for ${referenceID}`);
73
93
  }
74
94
  }
75
95
  }
76
- control.descs.fix = rule.fixtext ? rule.fixtext[0]['#text'] : (rule.fix ? rule.fix[0]['#text'] || 'Missing fix text' : 'Missing fix text');
96
+ if (removeNewlines) {
97
+ const fix = (0, xccdf_1.removeXMLSpecialCharacters)(rule.fixtext ? rule.fixtext[0]['#text'] : (rule.fix ? rule.fix[0]['#text'] || 'Missing fix text' : 'Missing fix text'));
98
+ control.descs.fix = fix.replace(/\n/g, '{{{{newlineHERE}}}}');
99
+ }
100
+ else {
101
+ control.descs.fix = (0, xccdf_1.removeXMLSpecialCharacters)(rule.fixtext ? rule.fixtext[0]['#text'] : (rule.fix ? rule.fix[0]['#text'] || 'Missing fix text' : 'Missing fix text'));
102
+ }
77
103
  control.tags.severity = (0, xccdf_1.impactNumberToSeverityString)((0, xccdf_1.severityStringToImpact)(rule['@_severity'] || 'critical', control.id));
78
104
  control.tags.gid = rule.group['@_id'],
79
105
  control.tags.rid = rule['@_id'];
80
106
  control.tags.stig_id = rule['version'];
81
107
  if (typeof rule.group.title === "string") {
82
- control.tags.gtitle = rule.group.title;
108
+ control.tags.gtitle = (0, xccdf_1.removeXMLSpecialCharacters)(rule.group.title);
83
109
  }
84
110
  else {
85
- control.tags.gtitle = lodash_1.default.get(rule.group, 'title[0].#text');
111
+ control.tags.gtitle = (0, xccdf_1.removeXMLSpecialCharacters)(lodash_1.default.get(rule.group, 'title[0].#text'));
86
112
  }
87
113
  if (rule['fix'] && rule['fix'].length > 0) {
88
114
  control.tags.fix_id = rule['fix'][0]['@_id'];
@@ -97,7 +123,7 @@ function processXCCDF(xml, ovalDefinitions) {
97
123
  control.tags.rationale = null;
98
124
  }
99
125
  if (typeof extractedDescription === 'object') {
100
- control.tags.satisfies = ((_b = extractedDescription.VulnDiscussion) === null || _b === void 0 ? void 0 : _b.includes('Satisfies: ')) && extractedDescription.VulnDiscussion.split('Satisfies: ').length >= 1 ? extractedDescription.VulnDiscussion.split('Satisfies: ')[1].split(',').map(satisfaction => satisfaction.trim()) : undefined;
126
+ 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;
101
127
  control.tags.false_negatives = extractedDescription.FalseNegatives || undefined;
102
128
  control.tags.false_positives = extractedDescription.FalsePositives || undefined;
103
129
  control.tags.documentable = typeof extractedDescription.Documentable === 'boolean' ? extractedDescription.Documentable : undefined;
@@ -110,7 +136,14 @@ function processXCCDF(xml, ovalDefinitions) {
110
136
  control.tags.responsibility = extractedDescription.Responsibility || undefined;
111
137
  control.tags.ia_controls = extractedDescription.IAControls || undefined;
112
138
  }
113
- control.tags = lodash_1.default.omitBy(control.tags, (value) => value === undefined);
139
+ control.tags = lodash_1.default.mapValues(lodash_1.default.omitBy(control.tags, (value) => value === undefined), (value) => {
140
+ if (typeof value === 'string') {
141
+ return (0, xccdf_1.removeXMLSpecialCharacters)(value);
142
+ }
143
+ else {
144
+ return value;
145
+ }
146
+ });
114
147
  // Get all identifiers from the rule
115
148
  if (rule.ident) {
116
149
  rule.ident.forEach((identifier) => {
@@ -143,7 +176,7 @@ function processXCCDF(xml, ovalDefinitions) {
143
176
  }
144
177
  });
145
178
  }
146
- (_c = rule.reference) === null || _c === void 0 ? void 0 : _c.forEach((reference) => {
179
+ (_d = rule.reference) === null || _d === void 0 ? void 0 : _d.forEach((reference) => {
147
180
  var _a, _b, _c, _d;
148
181
  if (lodash_1.default.get(reference, '@_href') === '') {
149
182
  (_a = control.refs) === null || _a === void 0 ? void 0 : _a.push(lodash_1.default.get(reference, '#text'));
@@ -208,8 +241,8 @@ function processXCCDF(xml, ovalDefinitions) {
208
241
  if (!('nist' in control.tags)) {
209
242
  control.tags.nist = [];
210
243
  }
211
- if (cci in hdf_converters_1.CciNistMappingData.data) {
212
- (_a = control.tags.nist) === null || _a === void 0 ? void 0 : _a.push(lodash_1.default.get(hdf_converters_1.CciNistMappingData.data, cci));
244
+ if (cci in CciNistMappingData_1.data) {
245
+ (_a = control.tags.nist) === null || _a === void 0 ? void 0 : _a.push(lodash_1.default.get(CciNistMappingData_1.data, cci));
213
246
  }
214
247
  });
215
248
  }