@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.
@@ -1,11 +1,10 @@
1
- import {data as CCINistMappings} from '@mitre/hdf-converters/lib/src/mappings/CciNistMappingData'
2
1
  import Profile from '../objects/profile';
3
- import { convertEncodedHTMLIntoJson, convertEncodedXmlIntoJson, impactNumberToSeverityString, severityStringToImpact } from '../utilities/xccdf';
2
+ import { convertEncodedHTMLIntoJson, convertEncodedXmlIntoJson, impactNumberToSeverityString, removeXMLSpecialCharacters, severityStringToImpact } from '../utilities/xccdf';
4
3
  import { BenchmarkGroup, BenchmarkRule, DecodedDescription, FrontMatter, Notice, ParsedXCCDF, RationaleElement } from '../types/xccdf';
5
4
  import Control from '../objects/control';
6
5
  import _ from 'lodash';
7
6
  import { OvalDefinitionValue } from '../types/oval';
8
- import { CciNistMappingData } from '@mitre/hdf-converters';
7
+ import {data as CciNistMappingData} from '../mappings/CciNistMappingData'
9
8
 
10
9
  export type GroupContextualizedRule = BenchmarkRule & {group: Omit<BenchmarkGroup, 'Rule' | 'Group'>}
11
10
 
@@ -27,7 +26,7 @@ export function extractAllRules(groups: BenchmarkGroup[]): GroupContextualizedRu
27
26
  return rules
28
27
  }
29
28
 
30
- export function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalDefinitionValue>): Profile {
29
+ export function processXCCDF(xml: string, removeNewlines = false, ovalDefinitions?: Record<string, OvalDefinitionValue>): Profile {
31
30
  const parsedXML: ParsedXCCDF = convertEncodedXmlIntoJson(xml)
32
31
  const rules = extractAllRules(parsedXML.Benchmark[0].Group)
33
32
 
@@ -47,8 +46,16 @@ export function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalD
47
46
  const control = new Control();
48
47
 
49
48
  control.id = rule.group['@_id']
50
- control.title = rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`
51
- control.desc = typeof extractedDescription === 'string' ? extractedDescription : extractedDescription.VulnDiscussion?.split('Satisfies: ')[0]
49
+
50
+ if (removeNewlines) {
51
+ const title = removeXMLSpecialCharacters(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`)
52
+ control.title = title.replace(/\n/g, '{{{{newlineHERE}}}}')
53
+ const desc = removeXMLSpecialCharacters(typeof extractedDescription === 'string' ? extractedDescription : extractedDescription.VulnDiscussion?.split('Satisfies: ')[0] || 'Missing Description')
54
+ control.desc = desc?.replace(/\n/g, '{{{{newlineHERE}}}}')
55
+ } else {
56
+ control.title = removeXMLSpecialCharacters(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`)
57
+ control.desc = removeXMLSpecialCharacters(typeof extractedDescription === 'string' ? extractedDescription : extractedDescription.VulnDiscussion?.split('Satisfies: ')[0] || 'Missing Description')
58
+ }
52
59
  control.impact = severityStringToImpact(rule['@_severity'] || 'critical', rule.group['@_id'])
53
60
 
54
61
  if (!control.descs || Array.isArray(control.descs)) {
@@ -57,7 +64,13 @@ export function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalD
57
64
 
58
65
  if (rule.check) {
59
66
  if (rule.check.some((ruleValue) => 'check-content' in ruleValue)) {
60
- control.descs.check = rule.check ? rule.check[0]['check-content'] : 'Missing description'
67
+ if (removeNewlines) {
68
+ const check = removeXMLSpecialCharacters(rule.check ? rule.check[0]['check-content'] : 'Missing description')
69
+ control.descs.check = check.replace(/\n/g, '{{{{newlineHERE}}}}')
70
+ } else {
71
+ control.descs.check = removeXMLSpecialCharacters(rule.check ? rule.check[0]['check-content'] : 'Missing description')
72
+ }
73
+
61
74
  } else if (rule.check.some((ruleValue) => 'check-content-ref' in ruleValue) && ovalDefinitions) {
62
75
  let referenceID: string | null = null;
63
76
  for (const checkContent of rule.check) {
@@ -70,23 +83,34 @@ export function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalD
70
83
  }
71
84
  }
72
85
  if (referenceID && referenceID in ovalDefinitions) {
73
- control.descs.check = ovalDefinitions[referenceID].metadata[0].title
74
- } else if (referenceID ) {
86
+ if (removeNewlines) {
87
+ const check = removeXMLSpecialCharacters(ovalDefinitions[referenceID].metadata[0].title)
88
+ control.descs.check = check.replace(/\n/g, '{{{{newlineHERE}}}}')
89
+ } else {
90
+ control.descs.check = removeXMLSpecialCharacters(ovalDefinitions[referenceID].metadata[0].title)
91
+ }
92
+ } else if (referenceID) {
75
93
  console.warn(`Could not find OVAL definition for ${referenceID}`)
76
94
  }
77
95
  }
78
96
  }
97
+
98
+ if (removeNewlines) {
99
+ const fix = removeXMLSpecialCharacters(rule.fixtext ? rule.fixtext[0]['#text'] : (rule.fix ? (rule.fix[0] as Notice)['#text'] || 'Missing fix text' : 'Missing fix text'))
100
+ control.descs.fix = fix.replace(/\n/g, '{{{{newlineHERE}}}}')
101
+ } else {
102
+ control.descs.fix = removeXMLSpecialCharacters(rule.fixtext ? rule.fixtext[0]['#text'] : (rule.fix ? (rule.fix[0] as Notice)['#text'] || 'Missing fix text' : 'Missing fix text'))
103
+ }
79
104
 
80
- control.descs.fix = rule.fixtext ? rule.fixtext[0]['#text'] : (rule.fix ? (rule.fix[0] as Notice)['#text'] || 'Missing fix text' : 'Missing fix text')
81
105
  control.tags.severity = impactNumberToSeverityString(severityStringToImpact(rule['@_severity'] || 'critical', control.id))
82
106
  control.tags.gid = rule.group['@_id'],
83
107
  control.tags.rid = rule['@_id']
84
108
  control.tags.stig_id = rule['version']
85
109
 
86
110
  if (typeof rule.group.title === "string") {
87
- control.tags.gtitle = rule.group.title
111
+ control.tags.gtitle = removeXMLSpecialCharacters(rule.group.title)
88
112
  } else {
89
- control.tags.gtitle = _.get(rule.group, 'title[0].#text')
113
+ control.tags.gtitle = removeXMLSpecialCharacters(_.get(rule.group, 'title[0].#text'))
90
114
  }
91
115
 
92
116
  if (rule['fix'] && rule['fix'].length > 0) {
@@ -116,7 +140,13 @@ export function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalD
116
140
  control.tags.ia_controls = extractedDescription.IAControls || undefined
117
141
  }
118
142
 
119
- control.tags = _.omitBy(control.tags, (value) => value === undefined)
143
+ control.tags = _.mapValues(_.omitBy(control.tags, (value) => value === undefined), (value) => {
144
+ if (typeof value === 'string') {
145
+ return removeXMLSpecialCharacters(value)
146
+ } else {
147
+ return value
148
+ }
149
+ })
120
150
 
121
151
  // Get all identifiers from the rule
122
152
  if (rule.ident) {
@@ -207,8 +237,8 @@ export function processXCCDF(xml: string, ovalDefinitions?: Record<string, OvalD
207
237
  if (!('nist' in control.tags)) {
208
238
  control.tags.nist = []
209
239
  }
210
- if (cci in CciNistMappingData.data) {
211
- control.tags.nist?.push(_.get(CciNistMappingData.data, cci))
240
+ if (cci in CciNistMappingData) {
241
+ control.tags.nist?.push(_.get(CciNistMappingData, cci))
212
242
  }
213
243
  })
214
244
  }
@@ -2,10 +2,19 @@ import { diff } from 'json-diff';
2
2
  import Profile from '../objects/profile';
3
3
  import { ProfileDiff } from '../types/diff';
4
4
  import _ from 'lodash'
5
- import Control from '../objects/control';
6
5
 
7
- export function updateControl(originalControlString: string, originalControl: Control, updatedControl: Control) {
8
- console.log('Here is the original control:');
6
+ export function removeNewlines(control?: Record<string, unknown>): Record<string, unknown> {
7
+ if (!control) {
8
+ return {};
9
+ }
10
+ return _.mapValues(control, (value) => {
11
+ if (typeof value === 'string') {
12
+ return value.replace(/\n/g, '{{{{newlineHERE}}}}').trim();
13
+ } else if (typeof value === 'object' && value !== null) {
14
+ return removeNewlines(value as Record<string, unknown>);
15
+ }
16
+ return value;
17
+ });
9
18
  }
10
19
 
11
20
  export function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDiff {
@@ -42,8 +51,10 @@ export function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDi
42
51
  const toControl = toProfile.controls.find((control) => control.id === fromControl.id)
43
52
  if (toControl) {
44
53
  const controlDiff: Record<string, any> | undefined = diff(fromControl, toControl);
54
+ console.log(controlDiff)
45
55
  if (controlDiff) {
46
56
  Object.entries(controlDiff).forEach(([key, value]) => {
57
+ console.log(value)
47
58
  if (_.has(value, '__new')) {
48
59
  _.set(profileDiff, 'changedControls.'+fromControl.id +'.'+key.replace('.', '\\.'), _.get(controlDiff, key+'.__new'))
49
60
  } else if (typeof value === 'object') {
@@ -16,6 +16,10 @@ export function convertEncodedXmlIntoJson(
16
16
  })
17
17
  }
18
18
 
19
+ export function removeXMLSpecialCharacters(input: string): string {
20
+ return input.replace(/&amp;/gm, '&').replace(/&lt;/gm, '<').replace(/&gt;/gm, '>')
21
+ }
22
+
19
23
  export function severityStringToImpact(string: string, id: string): number {
20
24
  if (string.match(/none|na|n\/a|not[\s()*_|]?applicable/i)?.length) {
21
25
  return 0.0
package/tsconfig.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "include": [
17
17
  "index.ts",
18
18
  "src/**/*",
19
- "types/**/*.d.ts"
19
+ "types/*"
20
20
  ],
21
21
  }
22
22
 
package/error.log DELETED
@@ -1,12 +0,0 @@
1
- yarn run v1.22.19
2
- $ jest 2
3
- No tests found, exiting with code 1
4
- Run with `--passWithNoTests` to exit with code 0
5
- In /home/c/Documents/SAF/ts-inspec-objects
6
- 219 files checked.
7
- testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 4 matches
8
- testPathIgnorePatterns: /node_modules/ - 219 matches
9
- testRegex: - 0 matches
10
- Pattern: 2 - 0 matches
11
- error Command failed with exit code 1.
12
- info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@@ -1,238 +0,0 @@
1
- export type ContextualizedDependency = Dependency & {
2
- parentDependencies: string[];
3
- };
4
-
5
- export type IonChannelAnalysisResponse = {
6
- analysis: IonChannelAnalysis;
7
- };
8
-
9
- export type IonChannelAnalysis = {
10
- id: string;
11
- analysis_id: string;
12
- team_id: string;
13
- project_id: string;
14
- name: string;
15
- text: string;
16
- type: string;
17
- source: string;
18
- branch: string;
19
- description: string;
20
- risk: string;
21
- summary: string;
22
- passed: boolean;
23
- ruleset_id: string;
24
- ruleset_name: string;
25
- status: string;
26
- created_at: Date;
27
- updated_at: Date;
28
- duration: number;
29
- trigger_hash: string;
30
- trigger_text: string;
31
- trigger_author: string;
32
- trigger: string;
33
- scan_summaries: ScanSummary[];
34
- public: boolean;
35
- };
36
-
37
- export type ScanSummary = {
38
- id: string;
39
- team_id: string;
40
- project_id: string;
41
- analysis_id: string;
42
- summary: string;
43
- results: Results;
44
- created_at: Date;
45
- updated_at: Date;
46
- duration: number;
47
- name: string;
48
- description: string;
49
- };
50
-
51
- export type Results = {
52
- type: string;
53
- data: Data;
54
- };
55
-
56
- export type Data = {
57
- vulnerabilities?: DataVulnerability[];
58
- meta?: Meta;
59
- dependencies?: Dependency[];
60
- CSS?: number;
61
- HTML?: number;
62
- JavaScript?: number;
63
- Vue?: number;
64
- committers?: number;
65
- name?: string;
66
- url?: string;
67
- committed_at?: Date;
68
- old_names?: string[];
69
- stars?: number;
70
- name_changed?: boolean;
71
- compilers?: null;
72
- docker_file?: DockerFile;
73
- known_viruses?: number;
74
- engine_version?: string;
75
- scanned_directories?: number;
76
- scanned_files?: number;
77
- infected_files?: number;
78
- data_scanned?: string;
79
- data_read?: string;
80
- time?: string;
81
- file_notes?: Record<string, unknown>;
82
- clam_av_details?: ClamAVDetails;
83
- license?: License;
84
- checksum?: string;
85
- difference?: boolean;
86
- message?: string;
87
- valid?: boolean;
88
- content?: string;
89
- };
90
-
91
- export type ClamAVDetails = {
92
- clamav_version: string;
93
- clamav_db_version: string;
94
- };
95
-
96
- export type Dependency = {
97
- latest_version: string;
98
- org: string;
99
- name: string;
100
- type: string;
101
- package: string;
102
- version: string;
103
- scope: Scope;
104
- requirement: string;
105
- file: File;
106
- outdated_version: OutdatedVersion;
107
- dependencies: Dependency[];
108
- };
109
-
110
- export enum File {
111
- Empty = '',
112
- PackageJSON = 'package.json'
113
- }
114
-
115
- export type OutdatedVersion = {
116
- major_behind: number;
117
- minor_behind: number;
118
- patch_behind: number;
119
- };
120
-
121
- export enum Scope {
122
- Runtime = 'runtime'
123
- }
124
-
125
- export type DockerFile = {
126
- images: null;
127
- dependencies: null;
128
- };
129
-
130
- export type License = {
131
- name: string;
132
- type: TypeElement[];
133
- };
134
-
135
- export type TypeElement = {
136
- name: string;
137
- confidence: number;
138
- };
139
-
140
- export type Meta = {
141
- vulnerability_count?: number;
142
- resolved_to?: string;
143
- first_degree_count?: number;
144
- no_version_count?: number;
145
- total_unique_count?: number;
146
- update_available_count?: number;
147
- vulnerable_count?: number;
148
- };
149
-
150
- export type DataVulnerability = {
151
- id: number;
152
- external_id: string;
153
- source_id: number;
154
- title: string;
155
- name: string;
156
- org: string;
157
- version: string;
158
- up: string;
159
- edition: string;
160
- aliases: null;
161
- created_at: Date;
162
- updated_at: Date;
163
- references: null;
164
- part: string;
165
- language: string;
166
- vulnerabilities: VulnerabilityVulnerability[];
167
- query: Dependency;
168
- };
169
-
170
- export type VulnerabilityVulnerability = {
171
- id: number;
172
- external_id: string;
173
- source: Source[];
174
- title: string;
175
- summary: string;
176
- score: string;
177
- score_version?: string;
178
- score_system: string;
179
- score_details: ScoreDetails;
180
- vector: string;
181
- access_complexity: string;
182
- vulnerability_authentication: string;
183
- confidentiality_impact: string;
184
- integrity_impact: string;
185
- availability_impact: string;
186
- vulnerabilty_source: string;
187
- assessment_check: null;
188
- scanner: null;
189
- recommendation: string;
190
- references: null;
191
- modified_at: Date;
192
- published_at: Date;
193
- created_at: Date;
194
- updated_at: Date;
195
- mttr_seconds: null;
196
- dependencies: null;
197
- };
198
-
199
- export type ScoreDetails = {
200
- cvssv2?: Cvssv2;
201
- cvssv3?: Cvssv3;
202
- };
203
-
204
- export type Cvssv2 = {
205
- vectorString: string;
206
- accessVector: string;
207
- accessComplexity: string;
208
- authentication: string;
209
- confidentialityImpact: string;
210
- integrityImpact: string;
211
- availabilityImpact: string;
212
- baseScore: number;
213
- };
214
-
215
- export type Cvssv3 = {
216
- vectorString: string;
217
- attackVector: string;
218
- attackComplexity: string;
219
- privilegesRequired: string;
220
- userInteraction: string;
221
- scope: string;
222
- confidentialityImpact: string;
223
- integrityImpact: string;
224
- availabilityImpact: string;
225
- baseScore: number;
226
- baseSeverity: string;
227
- };
228
-
229
- export type Source = {
230
- id: number;
231
- name: string;
232
- description: string;
233
- created_at: Date;
234
- updated_at: Date;
235
- attribution: string;
236
- license: string;
237
- copyright_url: string;
238
- };
@@ -1,72 +0,0 @@
1
- export type Projects = {
2
- data: Project[];
3
- meta: Meta;
4
- };
5
-
6
- export type Project = {
7
- id: string;
8
- team_id: string;
9
- name: string;
10
- active: boolean;
11
- draft: boolean;
12
- chat_channel: string;
13
- created_at: Date;
14
- updated_at: Date;
15
- deploy_key: string;
16
- should_monitor: boolean;
17
- monitor_frequency: string;
18
- poc_name: string;
19
- poc_email: string;
20
- username: string;
21
- password: string;
22
- key_fingerprint: string;
23
- private: boolean;
24
- aliases: null;
25
- tags: null;
26
- ruleset_history: null;
27
- sbom_id: string;
28
- sbom_entry_id: string;
29
- cpe: string;
30
- purl: string;
31
- ruleset_name: string;
32
- analysis_summary: AnalysisSummary;
33
- status: Status;
34
- };
35
-
36
- export type AnalysisSummary = {
37
- id: string;
38
- analysis_id: string;
39
- team_id: string;
40
- project_id: string;
41
- name: string;
42
- text: null;
43
- type: string;
44
- source: string;
45
- branch: string;
46
- description: string;
47
- risk: string;
48
- summary: string;
49
- passed: boolean;
50
- ruleset_id: string;
51
- ruleset_name: string;
52
- status: string;
53
- created_at: Date;
54
- updated_at: Date;
55
- duration: number;
56
- trigger_hash: string;
57
- trigger_text: string;
58
- trigger_author: string;
59
- trigger: string;
60
- };
61
-
62
- export enum Status {
63
- Errored = 'errored',
64
- Failing = 'failing',
65
- Passing = 'passing'
66
- }
67
-
68
- export type Meta = {
69
- total_count: number;
70
- limit: number;
71
- offset: number;
72
- };
@@ -1,26 +0,0 @@
1
- export type IonChannelTeams = {
2
- data: Team[];
3
- meta: Meta;
4
- };
5
-
6
- export type Team = {
7
- id: string;
8
- created_at: Date;
9
- updated_at: Date;
10
- deleted_at: Date;
11
- name: string;
12
- delivering: boolean;
13
- sys_admin: boolean;
14
- poc_name: string;
15
- poc_email: string;
16
- default_deploy_key: string;
17
- organization_id: string;
18
- user_id: string;
19
- role: string;
20
- status: string;
21
- };
22
-
23
- export type Meta = {
24
- total_count: number;
25
- offset: number;
26
- };
@@ -1,67 +0,0 @@
1
- export type MappedXCCDFtoHDF = {
2
- Benchmark: Benchmark;
3
- };
4
-
5
- export type Benchmark = {
6
- id: string;
7
- date: string;
8
- title: string;
9
- Profile: Profile[];
10
- Rule: Rule[];
11
- metadata: MetaData;
12
- passthrough: string;
13
- version: string;
14
- TestResult: {
15
- endTime: string;
16
- hasAttributes: boolean;
17
- // Any as defined by InSpec Inputs, matching InSpecJS
18
- attributes: {[key: string]: any}[];
19
- results: TestResult[];
20
- };
21
- };
22
-
23
- export type Profile = {
24
- id: string;
25
- title: string;
26
- description: string;
27
- select: string[];
28
- };
29
-
30
- export type Rule = {
31
- groupId?: string;
32
- id: string;
33
- title?: string;
34
- description?: string;
35
- code?: string;
36
- warning?: string;
37
- rationale?: string;
38
- checkContent?: string;
39
- fix?: string;
40
- ccis: string[];
41
- };
42
-
43
- export type MetaData = {
44
- maintainer?: string;
45
- copyright?: string;
46
- };
47
-
48
- export type XCCDFSeverity = 'info' | 'low' | 'medium' | 'high';
49
-
50
- export type TestResultStatus =
51
- | 'pass'
52
- | 'fail'
53
- | 'error'
54
- | 'unknown'
55
- | 'notapplicable'
56
- | 'notchecked'
57
- | 'notselected'
58
- | 'informational'
59
- | 'fixed';
60
-
61
- export type TestResult = {
62
- idref: string;
63
- result: TestResultStatus;
64
- messageType: string;
65
- message: string;
66
- code: string;
67
- };
@@ -1,88 +0,0 @@
1
- declare module '@mitre/splunk-sdk-no-env' {
2
- export type SplunkConfig = {
3
- scheme: string;
4
- host: string;
5
- port?: number;
6
- username?: string;
7
- password?: string;
8
- index: string;
9
- owner?: string;
10
- app?: string;
11
- sessionKey?: string;
12
- autologin?: boolean;
13
- version?: string;
14
- insecure?: boolean;
15
- };
16
-
17
- export type jobTrackCallbacks = {
18
- done?: (job: Job) => void;
19
- ready?: (job: Job) => void;
20
- progress?: (job: Job) => void;
21
- failed?: (job: Job) => void;
22
- error?: (err: any) => void;
23
- };
24
-
25
- class Http {
26
- constructor();
27
- }
28
-
29
- class Logger {
30
- error(message: any): void;
31
- }
32
-
33
- class Indexs {
34
- fetch(callback: (error: any, success: any, indexes: Index[]) => void): void;
35
- }
36
-
37
- class Index {
38
- name: string;
39
-
40
- submitEvent(
41
- event: string,
42
- config: {sourcetype: string; index: string},
43
- callback: (error: any) => void
44
- ): void;
45
- }
46
-
47
- class Jobs {
48
- fetch(callback: (error: any, success: any, jobs: Job[]) => void): void;
49
-
50
- create(
51
- query: string,
52
- params: unknown,
53
- callback: (error: any, createdJob: Job) => void
54
- ): void;
55
- }
56
-
57
- class Job {
58
- track(
59
- options: {period?: number},
60
- callbacks: jobTrackCallbacks | ((readyStatus: any) => void)
61
- ): void;
62
-
63
- results(
64
- params: {count: number},
65
- callback: (
66
- err: any,
67
- results: {fields: string[]; rows: string[]},
68
- job: Job
69
- ) => void
70
- ): void;
71
- }
72
-
73
- class Service {
74
- constructor(config: SplunkConfig);
75
- constructor(httpInstance: any, config: SplunkConfig);
76
-
77
- login(callback: (error: any, success: any) => void): boolean;
78
- indexes(): Indexs;
79
- jobs(): Jobs;
80
-
81
- requestOptions: {
82
- strictSSL: boolean;
83
- };
84
- }
85
- }
86
-
87
- declare module '@mitre/splunk-sdk-no-env/lib/platform/client/jquery_http';
88
-