@mitre/inspec-objects 0.0.1 → 0.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.
@@ -2,6 +2,11 @@ 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
+
7
+ export function updateControl(originalControlString: string, originalControl: Control, updatedControl: Control) {
8
+ console.log('Here is the original control:');
9
+ }
5
10
 
6
11
  export function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDiff {
7
12
  const profileDiff: ProfileDiff = {
@@ -14,8 +19,9 @@ export function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDi
14
19
  const toControlIDs = toProfile.controls.map((control) => control.id).sort();
15
20
 
16
21
  // Find new controls
17
- const controlIDDiff: string[][] = diff(fromControlIDs, toControlIDs)
18
- controlIDDiff.forEach((diffValue) => {
22
+ const controlIDDiff: string[][] | undefined = diff(fromControlIDs, toControlIDs)
23
+
24
+ controlIDDiff?.forEach((diffValue) => {
19
25
  if (diffValue[0] === '-') {
20
26
  profileDiff.removedControlIDs.push(diffValue[1])
21
27
  } else if (diffValue[0] === '+') {
@@ -41,7 +47,7 @@ export function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDi
41
47
  if (_.has(value, '__new')) {
42
48
  _.set(profileDiff, 'changedControls.'+fromControl.id +'.'+key.replace('.', '\\.'), _.get(controlDiff, key+'.__new'))
43
49
  } else if (typeof value === 'object') {
44
- Object.entries(value).forEach(([subKey, subValue]) => {
50
+ Object.entries(value).forEach(([subKey]) => {
45
51
  _.set(profileDiff, 'changedControls.'+fromControl.id +'.'+key.replace('.', '\\.')+'.'+subKey.replace('.', '\\.'), _.get(controlDiff, key+'.'+subKey+'.__new'))
46
52
  })
47
53
  }
@@ -21,3 +21,32 @@ const wrapAndEscapeQuotes = (s: string, lineLength?: number) =>
21
21
  escapeDoubleQuotes(wrap(s, lineLength)); // Escape backslashes and quotes, and wrap long lines
22
22
 
23
23
  export { escapeQuotes, escapeDoubleQuotes, wrapAndEscapeQuotes };
24
+
25
+ export function getFirstPath(
26
+ object: Record<string, unknown>,
27
+ paths: string[]
28
+ ): string {
29
+ const index = _.findIndex(paths, (p) => hasPath(object, p));
30
+
31
+ if (index === -1) {
32
+ throw new Error(
33
+ `Attestation is missing one of these paths: ${paths.join(', ')}`
34
+ );
35
+ } else {
36
+ return _.get(object, paths[index]) as string;
37
+ }
38
+ }
39
+
40
+ export function hasPath(
41
+ file: Record<string, unknown>,
42
+ path: string | string[]
43
+ ): boolean {
44
+ let pathArray;
45
+ if (typeof path === 'string') {
46
+ pathArray = [path];
47
+ } else {
48
+ pathArray = path;
49
+ }
50
+
51
+ return _.some(pathArray, (p) => _.has(file, p));
52
+ }
@@ -2,17 +2,21 @@ import parser from 'fast-xml-parser'
2
2
  import * as htmlparser from 'htmlparser2'
3
3
  import _ from 'lodash'
4
4
  import { DecodedDescription } from '../types/xccdf'
5
+ import fs from 'fs'
6
+ import { randomUUID } from 'crypto'
5
7
 
6
8
  export function convertEncodedXmlIntoJson(
7
- encodedXml: string,
9
+ encodedXml: string
8
10
  ): any {
9
11
  return parser.parse(encodedXml, {
10
12
  ignoreAttributes: false,
13
+ ignoreNameSpace: true,
11
14
  attributeNamePrefix: '@_',
15
+ arrayMode: true
12
16
  })
13
17
  }
14
18
 
15
- export function severityStringToImpact(string: string): number {
19
+ export function severityStringToImpact(string: string, id: string): number {
16
20
  if (string.match(/none|na|n\/a|not[\s()*_|]?applicable/i)?.length) {
17
21
  return 0.0
18
22
  }
@@ -33,7 +37,8 @@ export function severityStringToImpact(string: string): number {
33
37
  return 1.0
34
38
  }
35
39
 
36
- throw new Error(`${string}' is not a valid severity value. It should be one of the approved keywords`)
40
+ console.log(`${string} is not a valid severity value. It should be one of the approved keywords. ${id} will be treated as medium severity`)
41
+ return 0.5;
37
42
  }
38
43
 
39
44
  export function impactNumberToSeverityString(impact: number): string {
package/tsconfig.json CHANGED
@@ -15,7 +15,8 @@
15
15
  },
16
16
  "include": [
17
17
  "index.ts",
18
- "src/**/*"
18
+ "src/**/*",
19
+ "types/**/*.d.ts"
19
20
  ],
20
21
  }
21
22
 
@@ -0,0 +1,238 @@
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
+ };
@@ -0,0 +1,72 @@
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
+ };
@@ -0,0 +1,26 @@
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
+ };
@@ -0,0 +1,67 @@
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
+ };
@@ -0,0 +1,88 @@
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
+