@mitre/inspec-objects 0.0.16 → 0.0.19

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 CHANGED
@@ -1,6 +1,7 @@
1
- export * from './objects/control';
2
- export * from './objects/profile';
3
- export * from './parsers/json';
4
- export * from './parsers/xccdf';
5
- export * from './utilities/diff';
6
- export * from './utilities/update';
1
+ export * from "./objects/control";
2
+ export * from "./objects/profile";
3
+ export * from "./parsers/json";
4
+ export * from "./parsers/oval";
5
+ export * from "./parsers/xccdf";
6
+ export * from "./utilities/diff";
7
+ export * from "./utilities/update";
package/lib/index.js CHANGED
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./objects/control"), exports);
5
5
  tslib_1.__exportStar(require("./objects/profile"), exports);
6
6
  tslib_1.__exportStar(require("./parsers/json"), exports);
7
+ tslib_1.__exportStar(require("./parsers/oval"), exports);
7
8
  tslib_1.__exportStar(require("./parsers/xccdf"), exports);
8
9
  tslib_1.__exportStar(require("./utilities/diff"), exports);
9
10
  tslib_1.__exportStar(require("./utilities/update"), exports);
@@ -1,2 +1,2 @@
1
1
  import { OvalDefinitionValue } from '../types/oval';
2
- export declare function processOVAL(oval: string): Record<string, OvalDefinitionValue>;
2
+ export declare function processOVAL(oval?: string): Record<string, OvalDefinitionValue> | undefined;
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processOVAL = void 0;
4
4
  const xccdf_1 = require("../utilities/xccdf");
5
5
  function processOVAL(oval) {
6
+ if (!oval) {
7
+ return undefined;
8
+ }
6
9
  const parsed = (0, xccdf_1.convertEncodedXmlIntoJson)(oval);
7
10
  const extractedDefinitions = {};
8
11
  for (const ovalDefinitions of parsed.oval_definitions) {
@@ -62,14 +62,21 @@ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
62
62
  control.id = rule.version;
63
63
  break;
64
64
  case 'cis':
65
- //
66
- control.id = 'CIS-PLACEHOLDER';
65
+ const controlIdRegex = /\d(\d?)(\d?)(\d?)(.\d(\d?)(\d?)(\d?))?(.\d(\d?)(\d?)(\d?))?(.\d(\d?)(\d?)(\d?))?(.\d(\d?)(\d?)(\d?))?/g;
66
+ const controlIdMatch = controlIdRegex.exec(rule['@_id']);
67
+ if (controlIdMatch) {
68
+ control.id = controlIdMatch[0];
69
+ }
70
+ else {
71
+ throw new Error(`Could not parse control ID from rule ID: ${rule['@_id']}. Expecting format: 'xccdf_org.cisecurity.benchmarks_rule_1.1.11_Rule_title_summary`);
72
+ }
67
73
  break;
68
74
  default:
69
75
  throw new Error('useRuleId must be one of "group", "rule", or "version"');
70
76
  }
71
77
  control.title = (0, xccdf_1.removeXMLSpecialCharacters)(rule['@_severity'] ? ensureDecodedXMLStringValue(rule.title) : `[[[MISSING SEVERITY FROM STIG]]] ${ensureDecodedXMLStringValue(rule.title)}`);
72
- control.desc = (0, xccdf_1.removeXMLSpecialCharacters)(typeof extractedDescription === 'string' ? extractedDescription : ((_a = extractedDescription.VulnDiscussion) === null || _a === void 0 ? void 0 : _a.split('Satisfies: ')[0]) || 'Missing Description');
78
+ const descriptionText = (typeof extractedDescription === 'object' && !Array.isArray(extractedDescription)) ? ((_a = extractedDescription.VulnDiscussion) === null || _a === void 0 ? void 0 : _a.split('Satisfies: ')[0]) || 'Missing Description' : '';
79
+ control.desc = (0, xccdf_1.removeXMLSpecialCharacters)(descriptionText);
73
80
  control.impact = (0, xccdf_1.severityStringToImpact)(rule['@_severity'] || 'medium', rule.group['@_id']);
74
81
  if (!control.descs || Array.isArray(control.descs)) {
75
82
  control.descs = {};
@@ -98,7 +105,25 @@ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
98
105
  }
99
106
  }
100
107
  }
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'));
108
+ if (lodash_1.default.get(rule.fixtext, '[0]["#text"]')) {
109
+ control.descs.fix = (0, xccdf_1.removeXMLSpecialCharacters)(rule.fixtext[0]['#text']);
110
+ }
111
+ else if (typeof rule.fixtext === 'string') {
112
+ control.descs.fix = (0, xccdf_1.removeXMLSpecialCharacters)(rule.fixtext);
113
+ }
114
+ else if (typeof rule.fixtext === 'object') {
115
+ if (Array.isArray(rule.fixtext)) {
116
+ control.descs.fix = (0, xccdf_1.removeXMLSpecialCharacters)(JSON.stringify(rule.fixtext));
117
+ }
118
+ }
119
+ else if (typeof rule.fixtext === 'undefined') {
120
+ if (rule.fix && rule.fix[0]) {
121
+ control.descs.fix = (0, xccdf_1.removeXMLSpecialCharacters)(rule.fix[0]['#text'] || 'Missing fix text');
122
+ }
123
+ }
124
+ else {
125
+ control.descs.fix = 'Missing fix text';
126
+ }
102
127
  control.tags.severity = (0, xccdf_1.impactNumberToSeverityString)((0, xccdf_1.severityStringToImpact)(rule['@_severity'] || 'critical', control.id || 'Unknown'));
103
128
  control.tags.gid = rule.group['@_id'],
104
129
  control.tags.rid = rule['@_id'];
@@ -1,6 +1,5 @@
1
1
  import { ProfileDiff } from "../types/diff";
2
- import Profile from "../objects/profile";
3
2
  export declare function createDiffMarkdown(diff: {
4
3
  simplified: ProfileDiff;
5
4
  originalDiff: any;
6
- }, updatedProfile: Profile): string;
5
+ }): string;
@@ -9,7 +9,7 @@ function getUpdatedCheckForId(id, profile) {
9
9
  const foundControl = profile.controls.find((control) => control.id === id);
10
10
  return lodash_1.default.get(foundControl === null || foundControl === void 0 ? void 0 : foundControl.descs, "check") || "Missing check";
11
11
  }
12
- function createDiffMarkdown(diff, updatedProfile) {
12
+ function createDiffMarkdown(diff) {
13
13
  const renderableDiffData = {
14
14
  addedControls: Object.values(diff.simplified.addedControls),
15
15
  hasRenamedControls: false,
@@ -14,4 +14,4 @@ export declare type UpdatedProfileReturn = {
14
14
  export declare function findUpdatedControlByAllIdentifiers(existingControl: Control, updatedControls: Control[]): Control | undefined;
15
15
  export declare function updateControl(from: Control, update: Partial<Control>, logger: winston.Logger): Control;
16
16
  export declare function updateProfile(from: Profile, using: Profile, logger: winston.Logger): Omit<UpdatedProfileReturn, 'markdown'>;
17
- export declare function updateProfileUsingXCCDF(from: Profile, using: string, id: 'group' | 'rule' | 'version', logger: winston.Logger, ovalDefinitions?: Record<string, OvalDefinitionValue>): UpdatedProfileReturn;
17
+ export declare function updateProfileUsingXCCDF(from: Profile, using: string, id: 'group' | 'rule' | 'version' | 'cis', logger: winston.Logger, ovalDefinitions?: Record<string, OvalDefinitionValue>): UpdatedProfileReturn;
@@ -37,6 +37,7 @@ function projectValuesOntoExistingObj(dst, src, currentPath = '') {
37
37
  function getExistingDescribeFromControl(control) {
38
38
  if (control.code) {
39
39
  let existingDescribeBlock = '';
40
+ let currentQuoteEscape = '';
40
41
  let inQuoteBlock = false;
41
42
  control.code.split('\n').forEach((line) => {
42
43
  const wordSplit = line.trim().split(' ');
@@ -44,7 +45,20 @@ function getExistingDescribeFromControl(control) {
44
45
  const charSplit = word.split('');
45
46
  charSplit.forEach((char, index) => {
46
47
  if (char === '"' && charSplit[index - 1] !== '\\') {
47
- inQuoteBlock = !inQuoteBlock;
48
+ if (!currentQuoteEscape) {
49
+ currentQuoteEscape = '"';
50
+ }
51
+ if (currentQuoteEscape === '"') {
52
+ inQuoteBlock = !inQuoteBlock;
53
+ }
54
+ }
55
+ else if (char === "'" && charSplit[index - 1] !== '\\') {
56
+ if (!currentQuoteEscape) {
57
+ currentQuoteEscape = "'";
58
+ }
59
+ if (currentQuoteEscape === "'") {
60
+ inQuoteBlock = !inQuoteBlock;
61
+ }
48
62
  }
49
63
  });
50
64
  });
@@ -134,17 +148,14 @@ function updateProfileUsingXCCDF(from, using, id, logger, ovalDefinitions) {
134
148
  logger.debug(`Updating profile ${from.name} with control IDs: ${id}`);
135
149
  // Parse the XCCDF benchmark and convert it into a Profile
136
150
  logger.debug('Loading XCCDF File');
137
- const xccdfProfile = (0, xccdf_1.processXCCDF)(using, false, id);
151
+ const xccdfProfile = (0, xccdf_1.processXCCDF)(using, false, id, ovalDefinitions);
138
152
  logger.debug('Loaded XCCDF File');
139
- logger.debug('Loading XCCDF File with newline replacements');
140
- const xccdfProfileWithNLReplacement = (0, xccdf_1.processXCCDF)(using, true, id);
141
- logger.debug('Loaded XCCDF File with newline replacements');
142
153
  // Update the profile and return
143
154
  logger.debug('Creating updated profile');
144
155
  const updatedProfile = updateProfile(from, xccdfProfile, logger);
145
156
  logger.debug('Creating diff markdown');
146
157
  // Create the markdown
147
- const markdown = (0, diffMarkdown_1.createDiffMarkdown)(updatedProfile.diff, xccdfProfileWithNLReplacement);
158
+ const markdown = (0, diffMarkdown_1.createDiffMarkdown)(updatedProfile.diff);
148
159
  logger.debug('Profile update complete');
149
160
  return {
150
161
  profile: updatedProfile.profile,
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@mitre/inspec-objects",
9
- "version": "0.0.16",
9
+ "version": "0.0.17",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@types/flat": "^5.0.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.16",
3
+ "version": "0.0.19",
4
4
  "description": "Typescript objects for normalizing between InSpec profiles and XCCDF benchmarks",
5
5
  "main": "lib/index.js",
6
6
  "publishConfig": {