@mitre/inspec-objects 0.0.2 → 0.0.5

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,60 +0,0 @@
1
- import { diff } from 'json-diff';
2
- import Profile from '../objects/profile';
3
- import { ProfileDiff } from '../types/diff';
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
- }
10
-
11
- export function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDiff {
12
- const profileDiff: ProfileDiff = {
13
- addedControlIDs: [],
14
- removedControlIDs: [],
15
- changedControls: {}
16
- };
17
-
18
- const fromControlIDs = fromProfile.controls.map((control) => control.id).sort();
19
- const toControlIDs = toProfile.controls.map((control) => control.id).sort();
20
-
21
- // Find new controls
22
- const controlIDDiff: string[][] | undefined = diff(fromControlIDs, toControlIDs)
23
-
24
- controlIDDiff?.forEach((diffValue) => {
25
- if (diffValue[0] === '-') {
26
- profileDiff.removedControlIDs.push(diffValue[1])
27
- } else if (diffValue[0] === '+') {
28
- profileDiff.addedControlIDs.push(diffValue[1])
29
- }
30
- })
31
-
32
- // Add new controls to changedControls
33
- profileDiff.addedControlIDs.forEach((addedControl) => {
34
- const newControl = toProfile.controls.find((control) => addedControl === control.id)
35
- if (newControl) {
36
- profileDiff.changedControls[addedControl] = newControl
37
- }
38
- })
39
-
40
- // Find changed controls
41
- for (const fromControl of fromProfile.controls) {
42
- const toControl = toProfile.controls.find((control) => control.id === fromControl.id)
43
- if (toControl) {
44
- const controlDiff: Record<string, any> | undefined = diff(fromControl, toControl);
45
- if (controlDiff) {
46
- Object.entries(controlDiff).forEach(([key, value]) => {
47
- if (_.has(value, '__new')) {
48
- _.set(profileDiff, 'changedControls.'+fromControl.id +'.'+key.replace('.', '\\.'), _.get(controlDiff, key+'.__new'))
49
- } else if (typeof value === 'object') {
50
- Object.entries(value).forEach(([subKey]) => {
51
- _.set(profileDiff, 'changedControls.'+fromControl.id +'.'+key.replace('.', '\\.')+'.'+subKey.replace('.', '\\.'), _.get(controlDiff, key+'.'+subKey+'.__new'))
52
- })
53
- }
54
- })
55
- }
56
- }
57
- }
58
-
59
- return profileDiff
60
- }
@@ -1,52 +0,0 @@
1
- import _ from "lodash";
2
-
3
- // Breaks lines down to lineLength number of characters
4
- export function wrap(s: string, lineLength = 80): string {
5
- return s.replace(
6
- new RegExp(`(?![^\n]{1,${lineLength}}$)([^\n]{1,${lineLength}})`, "g"),
7
- "$1\n"
8
- );
9
- }
10
-
11
- export function unformatText(s: string): string {
12
- return s.replace(/\n/g, ' ').replace(/\\n/g, ' ').replace(/( +|\t)/g, ' ')
13
- }
14
-
15
- const escapeQuotes = (s: string) =>
16
- s.replace(/\\/g, "\\\\").replace(/'/g, "\\'"); // Escape backslashes and quotes
17
- const escapeDoubleQuotes = (s: string) =>
18
- s.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); // Escape backslashes and double quotes
19
-
20
- const wrapAndEscapeQuotes = (s: string, lineLength?: number) =>
21
- escapeDoubleQuotes(wrap(s, lineLength)); // Escape backslashes and quotes, and wrap long lines
22
-
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
- }
@@ -1,115 +0,0 @@
1
- import parser from 'fast-xml-parser'
2
- import * as htmlparser from 'htmlparser2'
3
- import _ from 'lodash'
4
- import { DecodedDescription } from '../types/xccdf'
5
- import fs from 'fs'
6
- import { randomUUID } from 'crypto'
7
-
8
- export function convertEncodedXmlIntoJson(
9
- encodedXml: string
10
- ): any {
11
- return parser.parse(encodedXml, {
12
- ignoreAttributes: false,
13
- ignoreNameSpace: true,
14
- attributeNamePrefix: '@_',
15
- arrayMode: true
16
- })
17
- }
18
-
19
- export function severityStringToImpact(string: string, id: string): number {
20
- if (string.match(/none|na|n\/a|not[\s()*_|]?applicable/i)?.length) {
21
- return 0.0
22
- }
23
-
24
- if (string.match(/low|cat(egory)?\s*(iii|3)/i)?.length) {
25
- return 0.3
26
- }
27
-
28
- if (string.match(/med(ium)?|cat(egory)?\s*(ii|2)/)?.length) {
29
- return 0.5
30
- }
31
-
32
- if (string.match(/high|cat(egory)?\s*(i|1)/)?.length) {
33
- return 0.7
34
- }
35
-
36
- if (string.match(/crit(ical)?|severe/)?.length) {
37
- return 1.0
38
- }
39
-
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;
42
- }
43
-
44
- export function impactNumberToSeverityString(impact: number): string {
45
- // Impact must be 0.0 - 1.0
46
- if (impact < 0.0 || impact > 1.0) {
47
- throw new Error('Impact cannot be less than 0.0 or greater than 1.0')
48
- } else {
49
- if (impact >= 0.9) {
50
- return 'critical'
51
- }
52
-
53
- if (impact >= 0.7) {
54
- return 'high'
55
- }
56
-
57
- if (impact >= 0.4) {
58
- return 'medium'
59
- }
60
-
61
- if (impact >= 0.1) {
62
- return 'low'
63
- }
64
-
65
- return 'none'
66
- }
67
- }
68
-
69
- export function convertEncodedHTMLIntoJson(encodedHTML?: string): DecodedDescription {
70
- if (encodedHTML) {
71
- // Some STIGs regarding XSS put the < character inside of the description which breaks parsing
72
- const patchedHTML = encodedHTML.replace(/"&lt;"/g, '[[[REPLACE_LESS_THAN]]]')
73
-
74
- const xmlChunks: string[] = []
75
- const htmlParser = new htmlparser.Parser({
76
- ontext(text: string) {
77
- xmlChunks.push(text)
78
- },
79
- })
80
- htmlParser.write(patchedHTML)
81
- htmlParser.end()
82
- const converted = convertEncodedXmlIntoJson(xmlChunks.join(''))
83
- let cleaned: Record<string, string | boolean | undefined> = {}
84
-
85
- if (typeof converted.VulnDiscussion === 'object') { // Some STIGs have xml tags inside of the actual text which breaks processing, e.g U_ASD_STIG_V5R1_Manual-xccdf.xml and all Oracle Database STIGs
86
- let extractedVulnDescription = ''
87
- const remainingFields = _.omit(converted.VulnDiscussion, ['FalsePositives', 'FalseNegatives', 'Documentable', 'Mitigations', 'SeverityOverrideGuidance', 'PotentialImpacts', 'ThirdPartyTools', 'MitigationControl', 'Responsibility', 'IAControls'])
88
- Object.entries(remainingFields).forEach(([field, value]) => {
89
- extractedVulnDescription += `<${field}> ${value}`
90
- })
91
- cleaned = {
92
- VulnDiscussion: extractedVulnDescription.replace(/\[\[\[REPLACE_LESS_THAN]]]/, '"<"'),
93
- }
94
- Object.entries(converted.VulnDiscussion).forEach(([key, value]) => {
95
- if (typeof value === 'string') {
96
- cleaned[key] = value.replace(/\[\[\[REPLACE_LESS_THAN]]]/, '"<"')
97
- } else {
98
- cleaned[key] = (value as boolean)
99
- }
100
- })
101
- } else {
102
- Object.entries(converted).forEach(([key, value]) => {
103
- if (typeof value === 'string') {
104
- cleaned[key] = value.replace(/\[\[\[REPLACE_LESS_THAN]]]/, '"<"')
105
- } else {
106
- cleaned[key] = (value as boolean)
107
- }
108
- })
109
- }
110
-
111
- return cleaned
112
- }
113
-
114
- return {}
115
- }
@@ -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
- };