@mitre/inspec-objects 2.0.1 → 2.0.2

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.
@@ -4,17 +4,14 @@ on:
4
4
  types: [labeled]
5
5
  permissions:
6
6
  pull-requests: write
7
- contents: write
8
7
 
9
8
  jobs:
10
9
  approve:
11
10
  name: Auto-approve dependabot PRs
12
11
  if: github.event.pull_request.user.login == 'dependabot[bot]' && contains(github.event.pull_request.labels.*.name, 'dependencies')
13
- runs-on: ubuntu-latest
12
+ runs-on: ubuntu-24.04
14
13
  steps:
15
- - uses: hmarr/auto-approve-action@v3
16
- with:
17
- github-token: "${{ secrets.GITHUB_TOKEN }}"
14
+ - uses: hmarr/auto-approve-action@v4
18
15
  - name: Enable auto-merge for Dependabot PRs
19
16
  run: gh pr merge --auto --merge "$PR_URL"
20
17
  env:
@@ -8,9 +8,9 @@ on:
8
8
 
9
9
  jobs:
10
10
  update_draft_release:
11
- runs-on: ubuntu-latest
11
+ runs-on: ubuntu-24.04
12
12
  steps:
13
13
  # Drafts your next Release notes as Pull Requests are merged into "master"
14
- - uses: toolmantim/release-drafter@v5.2.0
14
+ - uses: release-drafter/release-drafter@v6
15
15
  env:
16
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -7,15 +7,15 @@ on:
7
7
  jobs:
8
8
  build:
9
9
  name: Run TS-InSpec-Objects E2E Tests
10
- runs-on: ubuntu-20.04
10
+ runs-on: ubuntu-24.04
11
11
 
12
12
  steps:
13
- - uses: actions/checkout@v3
13
+ - uses: actions/checkout@v4
14
14
 
15
15
  - name: Setup Node.js
16
- uses: actions/setup-node@v3
16
+ uses: actions/setup-node@v4
17
17
  with:
18
- node-version: 18
18
+ node-version: 22
19
19
  cache: 'npm'
20
20
 
21
21
  - name: Install dependencies
@@ -7,16 +7,16 @@ on:
7
7
  jobs:
8
8
  build:
9
9
  name: Lint TS-InSpec-Objects
10
- runs-on: ubuntu-20.04
10
+ runs-on: ubuntu-24.04
11
11
 
12
12
  steps:
13
13
  - name: Checkout code
14
- uses: actions/checkout@v3
14
+ uses: actions/checkout@v4
15
15
 
16
16
  - name: Setup Node.js
17
- uses: actions/setup-node@v3
17
+ uses: actions/setup-node@v4
18
18
  with:
19
- node-version: 18
19
+ node-version: 22
20
20
  cache: 'npm'
21
21
 
22
22
  - name: Install project dependencies
@@ -6,31 +6,28 @@ on:
6
6
 
7
7
  jobs:
8
8
  build-deploy:
9
- runs-on: ubuntu-20.04
9
+ runs-on: ubuntu-24.04
10
10
  steps:
11
- - uses: actions/checkout@v3
11
+ - uses: actions/checkout@v4
12
12
 
13
13
  - name: Setup node
14
- uses: actions/setup-node@v3
14
+ uses: actions/setup-node@v4
15
15
  with:
16
- node-version: 18
17
- registry-url: https://npm.pkg.github.com/
16
+ node-version: 22
17
+ registry-url: 'https://npm.pkg.github.com'
18
18
  scope: '@mitre'
19
19
 
20
20
  - name: Build the NPM Package
21
21
  run: |
22
22
  npm install
23
+ rm -rf test
23
24
  npm run build
25
+
24
26
  - name: Pack all items that are published
25
27
  run: npm pack
26
- # Setup .npmrc file to publish to GitHub Package Registry
27
- - uses: actions/setup-node@v1
28
- with:
29
- registry-url: 'https://npm.pkg.github.com'
30
- scope: '@mitre'
31
28
 
32
29
  # Publish inspec-objects to GitHub Package Registry
33
30
  - name: Publish inspec-objects to GPR
34
31
  run: npm publish mitre-inspec-objects-*.tgz
35
32
  env:
36
- NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33
+ NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -6,14 +6,14 @@ on:
6
6
 
7
7
  jobs:
8
8
  build-deploy:
9
- runs-on: ubuntu-20.04
9
+ runs-on: ubuntu-24.04
10
10
  steps:
11
- - uses: actions/checkout@v3
11
+ - uses: actions/checkout@v4
12
12
 
13
13
  - name: setup node
14
- uses: actions/setup-node@v3
14
+ uses: actions/setup-node@v4
15
15
  with:
16
- node-version: 18
16
+ node-version: 22
17
17
  registry-url: 'https://registry.npmjs.org'
18
18
 
19
19
  - name: Install project dependencies
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # ts-inspec-objects
2
- Typescript objects for InSpec profiles
2
+ Typescript objects for InSpec Profiles
3
3
 
4
- This repository contains the source code that facilitates the writing of InSpec profiles (for use in things like stub generation and delta comparisons) more consistent with `Chef Cookstyle` formatting for ease of use when comparing with new changes from delta and when generating InSpec stubs that match a standard format.
4
+ This repository contains the source code that facilitates the writing of InSpec Profiles (for use in things like stub generation and delta comparisons) more consistent with `Chef Cookstyle` formatting for ease of use when comparing with new changes from delta and when generating InSpec stubs that match a standard format.
5
5
 
6
6
  For more information about Chef Cookstyle see:
7
7
  - [chef/cookstyle on GitHub](https://github.com/chef/cookstyle)
8
8
  - [Chef Cookstyle on Chef documents page](https://docs.chef.io/workstation/cookstyle/)
9
9
 
10
+ The `ts-inspec-objects` provides the capability of updating InSpect Profiles and creating stub Profiles based on XCCDF Benchmarks. This is accomplished by providing `Profile` and `Control` classes and supporting methods (functions).
11
+
10
12
  ## How to Use
11
13
  The process code maintained in this repository generates a `npm` executable that is published to the `npm registry` as [mitre-inspec-objects](https://www.npmjs.com/package/@mitre/inspec-objects).
12
14
 
@@ -18,7 +20,7 @@ The package is a CommonJS-based npm written in TypeScript
18
20
 
19
21
  ## Parsing Process
20
22
 
21
- When using this library to parse `InSpec profiles` or `xccdf files` for the purposes of generating InSpec profiles, the general workflow is as follows:
23
+ When using this library to parse `InSpec Profiles` or `xccdf files` for the purposes of generating InSpec profiles, the general workflow is as follows:
22
24
  ```
23
25
  - The input is processed, read into a typescript object
24
26
  - Operated on with any required action / logic
@@ -39,16 +41,46 @@ Here are some formatting choices that are being made.
39
41
  2. Tag keywords are not quoted (ex: tag severity: 'medium')
40
42
  3. Each control file ends with a newline
41
43
 
42
- ### Workflow graphical representation
44
+ ---
45
+ ### XCCDF Workflow Process
46
+ Processes an XCCDF (Extensible Configuration Checklist Description Format) XML string based on the `Rule Identifier` provided and converts it into a Profile object.
47
+ If and OVAL definition is provided it retrives the oval objects and associated states and the Controls description check text is update with the content.
48
+ <div align="center">
49
+ <img src="images/ts-inspec-objects-xccdf-workflow-process.png" alt="Typescript Objects XCCDF Conversion Workflow Process" title="Typescript Objects XCCDF Conversion Workflow Process">
50
+ </div>
51
+
52
+ ### OVAL Workflow Process
53
+ Processes an OVAL (Open Vulnerability and Assessment Language) XML string and converts it into a JSON object.
54
+ The process extracts definitions and their associated criteria references and resolved values.
55
+ The process executes the following steps:
56
+ 1. Converts the OVAL XML string into a JSON object.
57
+ 2. Iterates through the OVAL definitions and extracts each definition.
58
+ 3. For each definition, extracts criteria references and resolves the associated objects and states.
59
+ 4. Logs warnings if any objects or states cannot be found.
60
+ <div align="center">
61
+ <img src="images/ts-inspec-objects-oval-workflow-process.png" alt="Typescript Objects Oval Conversion Workflow Process" title="Typescript Objects Oval Conversion Workflow Process">
62
+ </div>
63
+
64
+ ### InSpec Profile Workflow Process
65
+ Process a JSON string representing an InSpec profile, converts it, and processes it to return a `Profile` object.
66
+ It handles different versions of the InSpec JSON format and sorts the controls by their ID.
67
+ <div align="center">
68
+ <img src="images/ts-inspec-objects-inspec-profile-workflow-process.png" alt="Typescript Objects InSpec Profile Workflow Process" title="Typescript Objects InSpec Profile Workflow Process">
69
+ </div>
70
+
71
+ ### Update Profile Using XCCDF Workflow Process
72
+ Updates a Profile with new metadata from and XCCDF, based on the `Rule Indetefier` and logs the process.
43
73
  <div align="center">
44
- <img src="images/ts-inspec-objects.jpg" alt="Typescript Objects Generation Process" title="Typescript Objects Generation Process">
74
+ <img src="images/ts-inspec-objects-updateProfileUsingXccdf-workflow.png" alt="Typescript Objects Update Profile Using XCCDF Workflow Process" title="Typescript Objects Update Profile Using XCCDF Workflow Process">
45
75
  </div>
46
76
 
47
- ### Delta and Stub Process
77
+ ### Update Control Workflow Process
78
+ Updates a given control object with the provided partial control and logs the process.
48
79
  <div align="center">
49
- <img src="images/Delta_Process.jpg" alt="Delta and Stub Generation Process" title="Delta and Stub Generation Process">
80
+ <img src="images/ts-inspec-objects-process-updateControl-workflow.png" alt="Typescript Objects Update Control Workflow Process" title="Typescript Objects Update Control Workflow Process">
50
81
  </div>
51
82
 
83
+ ---
52
84
  ## Development Environment Configuration
53
85
  ### Installation
54
86
  To install the project, clone the repository and install the dependencies:
@@ -27,7 +27,8 @@ export type InputTextLang = {
27
27
  '@_lang': string;
28
28
  };
29
29
  /**
30
- * Processes an XCCDF XML string and converts it into a Profile object.
30
+ * Processes an XCCDF (Extensible Configuration Checklist Description Format) XML
31
+ * string and converts it into a Profile object.
31
32
  * NOTE: We are using the fast xml parser (FXP) V4 which requires to specify
32
33
  * which Whether a single tag should be parsed as an array or an object,
33
34
  * it can't be decided by FXP. We process every tag as an array, this is
@@ -75,7 +75,8 @@ function ensureDecodedXMLStringValue(input, defaultValue) {
75
75
  : lodash_1.default.get(input, '#text', defaultValue);
76
76
  }
77
77
  /**
78
- * Processes an XCCDF XML string and converts it into a Profile object.
78
+ * Processes an XCCDF (Extensible Configuration Checklist Description Format) XML
79
+ * string and converts it into a Profile object.
79
80
  * NOTE: We are using the fast xml parser (FXP) V4 which requires to specify
80
81
  * which Whether a single tag should be parsed as an array or an object,
81
82
  * it can't be decided by FXP. We process every tag as an array, this is
@@ -74,4 +74,14 @@ export declare function updateControlDescribeBlock(from: Control, update: Partia
74
74
  * @throws Will throw an error if a new control is added but the control data is not available.
75
75
  */
76
76
  export declare function updateProfile(from: Profile, using: Profile, logger: winston.Logger): Omit<UpdatedProfileReturn, 'markdown'>;
77
+ /**
78
+ * Update a Profile with with new metadata from a XCCDF benchmark
79
+ *
80
+ * @param from - A Profile object
81
+ * @param using - An XCCDF in string format (XML)
82
+ * @param id - Specifies the rule ID format to use ('group', 'rule', 'version', or 'cis').
83
+ * @param logger - A winston logger instance for logging debug information.
84
+ * @param ovalDefinitions - Optional OVAL definitions to use for resolving values.
85
+ * @returns The Updated Profile (profile, the diff between from and using, and the markdown)
86
+ */
77
87
  export declare function updateProfileUsingXCCDF(from: Profile, using: string, id: 'group' | 'rule' | 'version' | 'cis', logger: winston.Logger, ovalDefinitions?: Record<string, OvalDefinitionValue>): UpdatedProfileReturn;
@@ -377,9 +377,19 @@ function updateProfile(from, using, logger) {
377
377
  diff,
378
378
  };
379
379
  }
380
+ /**
381
+ * Update a Profile with with new metadata from a XCCDF benchmark
382
+ *
383
+ * @param from - A Profile object
384
+ * @param using - An XCCDF in string format (XML)
385
+ * @param id - Specifies the rule ID format to use ('group', 'rule', 'version', or 'cis').
386
+ * @param logger - A winston logger instance for logging debug information.
387
+ * @param ovalDefinitions - Optional OVAL definitions to use for resolving values.
388
+ * @returns The Updated Profile (profile, the diff between from and using, and the markdown)
389
+ */
380
390
  function updateProfileUsingXCCDF(from, using, id, logger, ovalDefinitions) {
381
391
  logger.info(`Updating profile ${from.name} with control IDs type: ${id}`);
382
- // Parse the XCCDF benchmark and convert it into a Profile
392
+ // Parse the XCCDF benchmark and convert it into a Profile object
383
393
  logger.debug('Loading XCCDF File');
384
394
  const xccdfProfile = (0, xccdf_1.processXCCDF)(using, false, id, ovalDefinitions);
385
395
  logger.debug('Loaded XCCDF File');
@@ -68,10 +68,17 @@ export declare function convertJsonIntoXML(data: any): string;
68
68
  */
69
69
  export declare function removeXMLSpecialCharacters(str: string): string;
70
70
  /**
71
- * Removes HTML tags from the given input string.
72
- *
71
+ * Removes all of the HTML tags and leaves only the text content.
72
+ *
73
73
  * @param input - The string from which HTML tags should be removed.
74
74
  * @returns A new string with all HTML tags removed.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const str = '<div>Hello <b>World</b>!</div>';
79
+ * const stripped = removeHtmlTags(str);
80
+ * console.log(stripped); // Output: "Hello World!"
81
+ * ```
75
82
  */
76
83
  export declare function removeHtmlTags(input: string): string;
77
84
  /**
@@ -118,12 +118,29 @@ function removeXMLSpecialCharacters(str) {
118
118
  return result;
119
119
  }
120
120
  /**
121
- * Removes HTML tags from the given input string.
122
- *
121
+ * Removes all of the HTML tags and leaves only the text content.
122
+ *
123
123
  * @param input - The string from which HTML tags should be removed.
124
124
  * @returns A new string with all HTML tags removed.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const str = '<div>Hello <b>World</b>!</div>';
129
+ * const stripped = removeHtmlTags(str);
130
+ * console.log(stripped); // Output: "Hello World!"
131
+ * ```
125
132
  */
126
133
  function removeHtmlTags(input) {
134
+ // Regex explained
135
+ // <: Matches the opening angle bracket of an HTML tag
136
+ // /?: Matches zero or one forward slash /, to include closing tags
137
+ // [^>]: Matches any character except the > symbol
138
+ // +: Ensures preceding pattern ([^>]) matches one or more characters
139
+ // (>|$):
140
+ // > matches the closing angle bracket of an HTML tag.
141
+ // $ matches the end of the string. This ensures the regex can handle
142
+ // cases where the tag is incomplete or unclosed (e.g., <div)
143
+ // g: Global flag to find all matches in the input string
127
144
  return input.replace(/<\/?[^>]+(>|$)/g, '');
128
145
  }
129
146
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Typescript objects for normalizing between InSpec profiles and XCCDF benchmarks",
5
5
  "main": "lib/index.js",
6
6
  "publishConfig": {
@@ -31,13 +31,13 @@
31
31
  "@types/lodash": "^4.14.178",
32
32
  "@types/mustache": "^4.2.0",
33
33
  "@types/pretty": "^2.0.1",
34
- "fast-xml-parser": "^4.5.1",
34
+ "fast-xml-parser": "^5.0.7",
35
35
  "flat": "5.0.2",
36
36
  "he": "^1.2.0",
37
37
  "htmlparser2": "^10.0.0",
38
38
  "inspecjs": "^2.6.6",
39
39
  "json-diff": "^1.0.6",
40
- "jstoxml": "^5.0.2",
40
+ "jstoxml": "^6.0.1",
41
41
  "lodash": "^4.17.21",
42
42
  "mustache": "^4.2.0",
43
43
  "pretty": "^2.0.0",
@@ -45,12 +45,12 @@
45
45
  "yaml": "^2.3.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/jest": "^29.5.12",
49
- "@types/node": "^22.5.2",
48
+ "@types/jest": "^30.0.0",
49
+ "@types/node": "^24.0.0",
50
50
  "@typescript-eslint/eslint-plugin": "^6.4.1",
51
51
  "@typescript-eslint/parser": "^6.0.0",
52
52
  "eslint": "^8.30.0",
53
- "jest": "^29.7.0",
53
+ "jest": "^30.0.0",
54
54
  "ts-jest": "^29.1.1",
55
55
  "tslib": "^2.4.0",
56
56
  "typescript": "^5.2.2"