@contrast/contrast 1.0.7 → 1.0.10
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/README.md +1 -1
- package/dist/audit/catalogueApplication/catalogueApplication.js +23 -5
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +17 -26
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +98 -37
- package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +2 -1
- package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +4 -3
- package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +3 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +87 -19
- package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +40 -7
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +6 -30
- package/dist/audit/save.js +37 -0
- package/dist/commands/audit/auditConfig.js +0 -16
- package/dist/commands/audit/auditController.js +18 -11
- package/dist/commands/audit/help.js +31 -25
- package/dist/commands/audit/processAudit.js +2 -2
- package/dist/commands/audit/saveFile.js +8 -4
- package/dist/commands/scan/sca/scaAnalysis.js +54 -16
- package/dist/common/HTTPClient.js +14 -8
- package/dist/common/errorHandling.js +2 -2
- package/dist/common/versionChecker.js +19 -4
- package/dist/constants/constants.js +7 -2
- package/dist/constants/locales.js +44 -44
- package/dist/constants.js +31 -14
- package/dist/index.js +55 -45
- package/dist/lambda/lambda.js +5 -2
- package/dist/sbom/generateSbom.js +5 -4
- package/dist/scaAnalysis/common/formatMessage.js +33 -6
- package/dist/scaAnalysis/common/treeUpload.js +4 -6
- package/dist/scaAnalysis/dotnet/analysis.js +43 -0
- package/dist/scaAnalysis/dotnet/index.js +10 -0
- package/dist/scaAnalysis/go/goReadDepFile.js +1 -3
- package/dist/scaAnalysis/java/analysis.js +5 -5
- package/dist/scaAnalysis/javascript/analysis.js +107 -0
- package/dist/scaAnalysis/javascript/index.js +53 -0
- package/dist/scaAnalysis/php/analysis.js +70 -0
- package/dist/scaAnalysis/php/index.js +17 -0
- package/dist/scaAnalysis/python/analysis.js +8 -7
- package/dist/scaAnalysis/ruby/analysis.js +8 -16
- package/dist/scaAnalysis/ruby/index.js +2 -2
- package/dist/scan/autoDetection.js +13 -24
- package/dist/scan/fileUtils.js +44 -14
- package/dist/scan/formatScanOutput.js +3 -3
- package/dist/scan/scanConfig.js +2 -2
- package/dist/utils/commonApi.js +1 -1
- package/dist/utils/filterProjectPath.js +7 -2
- package/dist/utils/getConfig.js +1 -6
- package/package.json +2 -3
- package/src/audit/catalogueApplication/catalogueApplication.js +28 -6
- package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +22 -58
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +157 -47
- package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +4 -1
- package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +11 -5
- package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +4 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +86 -32
- package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +44 -5
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +6 -32
- package/src/audit/save.js +48 -0
- package/src/commands/audit/auditConfig.ts +0 -25
- package/src/commands/audit/auditController.ts +18 -20
- package/src/commands/audit/help.ts +31 -25
- package/src/commands/audit/processAudit.ts +2 -5
- package/src/commands/audit/saveFile.ts +6 -2
- package/src/commands/scan/processScan.js +0 -1
- package/src/commands/scan/sca/scaAnalysis.js +87 -32
- package/src/common/HTTPClient.js +16 -9
- package/src/common/errorHandling.ts +2 -3
- package/src/common/versionChecker.ts +23 -4
- package/src/constants/constants.js +9 -3
- package/src/constants/locales.js +72 -50
- package/src/constants.js +32 -15
- package/src/index.ts +70 -58
- package/src/lambda/lambda.ts +5 -2
- package/src/lambda/types.ts +1 -0
- package/src/sbom/generateSbom.ts +2 -2
- package/src/scaAnalysis/common/formatMessage.js +35 -6
- package/src/scaAnalysis/common/treeUpload.js +4 -6
- package/src/scaAnalysis/dotnet/analysis.js +54 -0
- package/src/scaAnalysis/dotnet/index.js +11 -0
- package/src/scaAnalysis/go/goReadDepFile.js +1 -3
- package/src/scaAnalysis/java/analysis.js +5 -5
- package/src/scaAnalysis/javascript/analysis.js +126 -0
- package/src/scaAnalysis/javascript/index.js +75 -0
- package/src/scaAnalysis/php/analysis.js +78 -0
- package/src/scaAnalysis/php/index.js +22 -0
- package/src/scaAnalysis/python/analysis.js +8 -7
- package/src/scaAnalysis/ruby/analysis.js +8 -17
- package/src/scaAnalysis/ruby/index.js +2 -2
- package/src/scan/autoDetection.js +14 -27
- package/src/scan/fileUtils.js +46 -14
- package/src/scan/formatScanOutput.ts +3 -3
- package/src/scan/scanConfig.js +2 -4
- package/src/utils/commonApi.js +1 -1
- package/src/utils/filterProjectPath.js +6 -2
- package/src/utils/getConfig.ts +1 -12
- package/dist/audit/AnalysisEngine.js +0 -37
- package/dist/audit/autodetection/autoDetectLanguage.js +0 -32
- package/dist/audit/dotnetAnalysisEngine/index.js +0 -25
- package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -35
- package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -15
- package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -18
- package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -14
- package/dist/audit/dotnetAnalysisEngine/sanitizer.js +0 -9
- package/dist/audit/goAnalysisEngine/index.js +0 -17
- package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +0 -164
- package/dist/audit/goAnalysisEngine/readProjectFileContents.js +0 -21
- package/dist/audit/goAnalysisEngine/sanitizer.js +0 -5
- package/dist/audit/javaAnalysisEngine/index.js +0 -34
- package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -155
- package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -353
- package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +0 -98
- package/dist/audit/javaAnalysisEngine/sanitizer.js +0 -5
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -25
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -25
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -35
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -24
- package/dist/audit/languageAnalysisEngine/constants.js +0 -20
- package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -25
- package/dist/audit/languageAnalysisEngine/index.js +0 -39
- package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -89
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -159
- package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -40
- package/dist/audit/nodeAnalysisEngine/index.js +0 -31
- package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -18
- package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -18
- package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -17
- package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -14
- package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -24
- package/dist/audit/nodeAnalysisEngine/sanitizer.js +0 -9
- package/dist/audit/phpAnalysisEngine/index.js +0 -23
- package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +0 -52
- package/dist/audit/phpAnalysisEngine/readLockFileContents.js +0 -13
- package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +0 -16
- package/dist/audit/phpAnalysisEngine/sanitizer.js +0 -5
- package/dist/audit/pythonAnalysisEngine/index.js +0 -25
- package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -17
- package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -21
- package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -13
- package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -14
- package/dist/audit/pythonAnalysisEngine/sanitizer.js +0 -7
- package/dist/audit/rubyAnalysisEngine/index.js +0 -25
- package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -176
- package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +0 -22
- package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +0 -14
- package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -14
- package/dist/audit/rubyAnalysisEngine/sanitizer.js +0 -6
- package/src/audit/AnalysisEngine.js +0 -103
- package/src/audit/autodetection/autoDetectLanguage.ts +0 -40
- package/src/audit/dotnetAnalysisEngine/index.js +0 -26
- package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -47
- package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -29
- package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -30
- package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -26
- package/src/audit/dotnetAnalysisEngine/sanitizer.js +0 -11
- package/src/audit/goAnalysisEngine/index.js +0 -18
- package/src/audit/goAnalysisEngine/parseProjectFileContents.js +0 -209
- package/src/audit/goAnalysisEngine/readProjectFileContents.js +0 -31
- package/src/audit/goAnalysisEngine/sanitizer.js +0 -7
- package/src/audit/javaAnalysisEngine/index.js +0 -41
- package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -225
- package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -420
- package/src/audit/javaAnalysisEngine/readProjectFileContents.js +0 -141
- package/src/audit/javaAnalysisEngine/sanitizer.js +0 -6
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -36
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -42
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -54
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -33
- package/src/audit/languageAnalysisEngine/constants.js +0 -23
- package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -41
- package/src/audit/languageAnalysisEngine/index.js +0 -45
- package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -124
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -250
- package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -49
- package/src/audit/nodeAnalysisEngine/index.js +0 -35
- package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -20
- package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -26
- package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -23
- package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -27
- package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -36
- package/src/audit/nodeAnalysisEngine/sanitizer.js +0 -11
- package/src/audit/phpAnalysisEngine/index.js +0 -27
- package/src/audit/phpAnalysisEngine/parseLockFileContents.js +0 -60
- package/src/audit/phpAnalysisEngine/readLockFileContents.js +0 -14
- package/src/audit/phpAnalysisEngine/readProjectFileContents.js +0 -25
- package/src/audit/phpAnalysisEngine/sanitizer.js +0 -4
- package/src/audit/pythonAnalysisEngine/index.js +0 -55
- package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -23
- package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -33
- package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -16
- package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -22
- package/src/audit/pythonAnalysisEngine/sanitizer.js +0 -9
- package/src/audit/rubyAnalysisEngine/index.js +0 -30
- package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -215
- package/src/audit/rubyAnalysisEngine/parsedGemfile.js +0 -39
- package/src/audit/rubyAnalysisEngine/readGemfileContents.js +0 -18
- package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -17
- package/src/audit/rubyAnalysisEngine/sanitizer.js +0 -8
|
@@ -1,56 +1,110 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createLibraryHeader,
|
|
3
2
|
getReport,
|
|
4
3
|
printVulnerabilityResponse
|
|
5
4
|
} from './commonReportingFunctions'
|
|
6
5
|
import {
|
|
7
|
-
|
|
6
|
+
convertGenericToTypedLibraryVulns,
|
|
8
7
|
severityCountAllLibraries
|
|
9
8
|
} from './utils/reportUtils'
|
|
9
|
+
import i18n from 'i18n'
|
|
10
|
+
import chalk from 'chalk'
|
|
11
|
+
import * as constants from '../../../constants/constants'
|
|
10
12
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
applicationId: string,
|
|
14
|
-
reportId: string
|
|
15
|
-
) {
|
|
16
|
-
const reportResponse = await getReport(analysis.config, reportId)
|
|
13
|
+
export function convertKeysToStandardFormat(config: any, guidance: any) {
|
|
14
|
+
let convertedGuidance = guidance
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
switch (config.language) {
|
|
17
|
+
case constants.supportedLanguages.JAVA:
|
|
18
|
+
case constants.supportedLanguages.GO:
|
|
19
|
+
case constants.supportedLanguages.PHP:
|
|
20
|
+
break
|
|
21
|
+
case constants.supportedLanguages.NODE:
|
|
22
|
+
case constants.supportedLanguages.DOTNET:
|
|
23
|
+
case constants.supportedLanguages.PYTHON:
|
|
24
|
+
case constants.supportedLanguages.RUBY:
|
|
25
|
+
convertedGuidance = convertJSDotNetPython(guidance)
|
|
26
|
+
break
|
|
27
27
|
}
|
|
28
|
+
return convertedGuidance
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function convertJSDotNetPython(guidance: any) {
|
|
32
|
+
const returnObject = {}
|
|
33
|
+
|
|
34
|
+
Object.entries(guidance).forEach(([key, value]) => {
|
|
35
|
+
const splitKey = key.split('/')
|
|
36
|
+
if (splitKey.length === 2) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
returnObject[splitKey[1]] = value
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
return returnObject
|
|
28
42
|
}
|
|
29
43
|
|
|
30
44
|
export function formatVulnerabilityOutput(
|
|
31
45
|
libraryVulnerabilityResponse: any,
|
|
32
46
|
id: string,
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
config: any,
|
|
48
|
+
remediationGuidance: any
|
|
35
49
|
) {
|
|
36
|
-
const vulnerableLibraries =
|
|
50
|
+
const vulnerableLibraries = convertGenericToTypedLibraryVulns(
|
|
37
51
|
libraryVulnerabilityResponse
|
|
38
52
|
)
|
|
39
53
|
|
|
54
|
+
const guidance = convertKeysToStandardFormat(config, remediationGuidance)
|
|
55
|
+
|
|
40
56
|
const numberOfVulnerableLibraries = vulnerableLibraries.length
|
|
41
|
-
let numberOfCves = 0
|
|
42
|
-
vulnerableLibraries.forEach(lib => (numberOfCves += lib.cveArray.length))
|
|
43
57
|
|
|
44
|
-
|
|
58
|
+
if (numberOfVulnerableLibraries === 0) {
|
|
59
|
+
console.log(i18n.__('scanNoVulnerabilitiesFound'))
|
|
60
|
+
console.log(i18n.__('scanNoVulnerabilitiesFoundSecureCode'))
|
|
61
|
+
console.log(i18n.__('scanNoVulnerabilitiesFoundGoodWork'))
|
|
62
|
+
console.log(
|
|
63
|
+
chalk.bold(`Found ${numberOfVulnerableLibraries} vulnerabilities`)
|
|
64
|
+
)
|
|
65
|
+
console.log(
|
|
66
|
+
i18n.__(
|
|
67
|
+
'foundDetailedVulnerabilities',
|
|
68
|
+
String(0),
|
|
69
|
+
String(0),
|
|
70
|
+
String(0),
|
|
71
|
+
String(0),
|
|
72
|
+
String(0)
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
} else {
|
|
76
|
+
let numberOfCves = 0
|
|
77
|
+
vulnerableLibraries.forEach(lib => (numberOfCves += lib.cveArray.length))
|
|
78
|
+
|
|
79
|
+
const hasSomeVulnerabilitiesReported = printVulnerabilityResponse(
|
|
80
|
+
config,
|
|
81
|
+
vulnerableLibraries,
|
|
82
|
+
numberOfVulnerableLibraries,
|
|
83
|
+
numberOfCves,
|
|
84
|
+
guidance
|
|
85
|
+
)
|
|
45
86
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
87
|
+
return [
|
|
88
|
+
hasSomeVulnerabilitiesReported,
|
|
89
|
+
numberOfCves,
|
|
90
|
+
severityCountAllLibraries(vulnerableLibraries)
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function vulnerabilityReportV2(config: any, reportId: string) {
|
|
96
|
+
console.log()
|
|
97
|
+
const reportResponse = await getReport(config, reportId)
|
|
50
98
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
99
|
+
if (reportResponse !== undefined) {
|
|
100
|
+
const name = config.applicationName
|
|
101
|
+
formatVulnerabilityOutput(
|
|
102
|
+
reportResponse.vulnerabilities,
|
|
103
|
+
config.applicationId,
|
|
104
|
+
config,
|
|
105
|
+
reportResponse.remediationGuidance
|
|
106
|
+
? reportResponse.remediationGuidance
|
|
107
|
+
: {}
|
|
108
|
+
)
|
|
109
|
+
}
|
|
56
110
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ReportLibraryModel
|
|
4
4
|
} from '../models/reportLibraryModel'
|
|
5
5
|
import { ReportSeverityModel } from '../models/reportSeverityModel'
|
|
6
|
-
import languageAnalysisEngine from '
|
|
6
|
+
import languageAnalysisEngine from './../../../../constants/constants'
|
|
7
7
|
import {
|
|
8
8
|
CRITICAL_COLOUR,
|
|
9
9
|
CRITICAL_PRIORITY,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from '../../../../constants/constants'
|
|
19
19
|
import { orderBy } from 'lodash'
|
|
20
20
|
import { SeverityCountModel } from '../models/severityCountModel'
|
|
21
|
+
import { ReportModelStructure } from '../models/reportListModel'
|
|
21
22
|
const {
|
|
22
23
|
supportedLanguages: { GO }
|
|
23
24
|
} = languageAnalysisEngine
|
|
@@ -67,7 +68,7 @@ export function findCVESeverity(cve: ReportCVEModel) {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
export function
|
|
71
|
+
export function convertGenericToTypedLibraryVulns(libraries: any) {
|
|
71
72
|
return Object.entries(libraries).map(([name, cveArray]) => {
|
|
72
73
|
return new ReportLibraryModel(name, cveArray as ReportCVEModel[])
|
|
73
74
|
})
|
|
@@ -122,11 +123,49 @@ export function findNameAndVersion(library: ReportLibraryModel, config: any) {
|
|
|
122
123
|
|
|
123
124
|
return { name, version }
|
|
124
125
|
} else {
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
const
|
|
126
|
+
//spreads items from split into set so no duplicates appear
|
|
127
|
+
const uniqueSplitLibraryName = [...new Set(library.name.split('/'))]
|
|
128
|
+
const nameVersion = uniqueSplitLibraryName[1].split('@')
|
|
129
|
+
|
|
130
|
+
let parentLibrary
|
|
131
|
+
let name
|
|
132
|
+
if (
|
|
133
|
+
uniqueSplitLibraryName[0] !== 'null' &&
|
|
134
|
+
uniqueSplitLibraryName[0] !== '' &&
|
|
135
|
+
!uniqueSplitLibraryName[1].includes(uniqueSplitLibraryName[0])
|
|
136
|
+
) {
|
|
137
|
+
//if the parent lib (element 0) is not null, not blank and not already part of the library name
|
|
138
|
+
//e.g. shared-ini-file-loader-1.0.0-rc.3 is very generic - converts to @aws-sdk/shared-ini-file-loader-1.0.0-rc.3
|
|
139
|
+
parentLibrary = uniqueSplitLibraryName[0]
|
|
140
|
+
name = `${parentLibrary}/${nameVersion[0]}`
|
|
141
|
+
} else {
|
|
142
|
+
name = nameVersion[0]
|
|
143
|
+
}
|
|
144
|
+
|
|
128
145
|
const version = nameVersion[1]
|
|
129
146
|
|
|
130
147
|
return { name, version }
|
|
131
148
|
}
|
|
132
149
|
}
|
|
150
|
+
|
|
151
|
+
export function countVulnerableLibrariesBySeverity(
|
|
152
|
+
reportModelStructure: ReportModelStructure[]
|
|
153
|
+
) {
|
|
154
|
+
const severityCount = new SeverityCountModel()
|
|
155
|
+
reportModelStructure.forEach(vuln => {
|
|
156
|
+
const currentSeverity = vuln.compositeKey.highestSeverity.severity
|
|
157
|
+
if (currentSeverity === 'CRITICAL') {
|
|
158
|
+
severityCount.critical += 1
|
|
159
|
+
} else if (currentSeverity === 'HIGH') {
|
|
160
|
+
severityCount.high += 1
|
|
161
|
+
} else if (currentSeverity === 'MEDIUM') {
|
|
162
|
+
severityCount.medium += 1
|
|
163
|
+
} else if (currentSeverity === 'LOW') {
|
|
164
|
+
severityCount.low += 1
|
|
165
|
+
} else if (currentSeverity === 'NOTE') {
|
|
166
|
+
severityCount.note += 1
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
return severityCount
|
|
171
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const { handleResponseErrors } = require('../../common/errorHandling')
|
|
2
|
-
const { APP_VERSION } = require('../../constants/constants')
|
|
3
1
|
const commonApi = require('../../utils/commonApi')
|
|
4
2
|
const _ = require('lodash')
|
|
5
3
|
const oraFunctions = require('../../utils/oraWrapper')
|
|
@@ -8,30 +6,6 @@ const oraWrapper = require('../../utils/oraWrapper')
|
|
|
8
6
|
const requestUtils = require('../../utils/requestUtils')
|
|
9
7
|
const { performance } = require('perf_hooks')
|
|
10
8
|
|
|
11
|
-
const newSendSnapShot = async analysis => {
|
|
12
|
-
const analysisLanguage = analysis.config.language.toLowerCase()
|
|
13
|
-
const requestBody = {
|
|
14
|
-
appID: analysis.config.applicationId,
|
|
15
|
-
cliVersion: APP_VERSION,
|
|
16
|
-
snapshot: { [analysisLanguage]: analysis[analysisLanguage] }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const client = commonApi.getHttpClient(analysis.config)
|
|
20
|
-
|
|
21
|
-
return client
|
|
22
|
-
.sendSnapshot(requestBody, analysis.config)
|
|
23
|
-
.then(res => {
|
|
24
|
-
if (res.statusCode === 201) {
|
|
25
|
-
return res.body
|
|
26
|
-
} else {
|
|
27
|
-
handleResponseErrors(res, 'snapshot')
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
.catch(err => {
|
|
31
|
-
console.log(err)
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
9
|
const pollSnapshotResults = async (config, snapshotId, client) => {
|
|
36
10
|
await requestUtils.sleep(5000)
|
|
37
11
|
return client
|
|
@@ -49,9 +23,9 @@ const getTimeout = config => {
|
|
|
49
23
|
return config.timeout
|
|
50
24
|
} else {
|
|
51
25
|
if (config.verbose) {
|
|
52
|
-
console.log('Timeout set to
|
|
26
|
+
console.log('Timeout set to 5 minutes')
|
|
53
27
|
}
|
|
54
|
-
return
|
|
28
|
+
return 300
|
|
55
29
|
}
|
|
56
30
|
}
|
|
57
31
|
|
|
@@ -91,16 +65,16 @@ const pollForSnapshotCompletition = async (
|
|
|
91
65
|
if (requestUtils.millisToSeconds(endTime) > timeout) {
|
|
92
66
|
oraFunctions.failSpinner(
|
|
93
67
|
reportSpinner,
|
|
94
|
-
'Contrast audit timed out at the specified
|
|
68
|
+
'Contrast audit timed out at the specified timeout of ' +
|
|
69
|
+
timeout +
|
|
70
|
+
' seconds.'
|
|
95
71
|
)
|
|
96
|
-
|
|
97
|
-
process.exit(1)
|
|
72
|
+
throw new Error('You can update the timeout using --timeout')
|
|
98
73
|
}
|
|
99
74
|
}
|
|
100
75
|
}
|
|
101
76
|
}
|
|
102
77
|
|
|
103
78
|
module.exports = {
|
|
104
|
-
newSendSnapShot: newSendSnapShot,
|
|
105
79
|
pollForSnapshotCompletition: pollForSnapshotCompletition
|
|
106
80
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const i18n = require('i18n')
|
|
3
|
+
const chalk = require('chalk')
|
|
4
|
+
const save = require('../commands/audit/saveFile')
|
|
5
|
+
const sbom = require('../sbom/generateSbom')
|
|
6
|
+
const {
|
|
7
|
+
SBOM_CYCLONE_DX_FILE,
|
|
8
|
+
SBOM_SPDX_FILE
|
|
9
|
+
} = require('../constants/constants')
|
|
10
|
+
|
|
11
|
+
async function auditSave(config) {
|
|
12
|
+
let fileFormat
|
|
13
|
+
switch (config.save) {
|
|
14
|
+
case null:
|
|
15
|
+
case SBOM_CYCLONE_DX_FILE:
|
|
16
|
+
fileFormat = SBOM_CYCLONE_DX_FILE
|
|
17
|
+
break
|
|
18
|
+
case SBOM_SPDX_FILE:
|
|
19
|
+
fileFormat = SBOM_SPDX_FILE
|
|
20
|
+
break
|
|
21
|
+
default:
|
|
22
|
+
break
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (fileFormat) {
|
|
26
|
+
save.saveFile(
|
|
27
|
+
config,
|
|
28
|
+
fileFormat,
|
|
29
|
+
await sbom.generateSbom(config, fileFormat)
|
|
30
|
+
)
|
|
31
|
+
const filename = `${config.applicationId}-sbom-${fileFormat}.json`
|
|
32
|
+
if (fs.existsSync(filename)) {
|
|
33
|
+
console.log(i18n.__('auditSBOMSaveSuccess') + ` - ${filename}`)
|
|
34
|
+
} else {
|
|
35
|
+
console.log(
|
|
36
|
+
chalk.yellow.bold(
|
|
37
|
+
`\n Unable to save ${filename} Software Bill of Materials (SBOM)`
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
console.log(i18n.__('auditBadFiletypeSpecifiedForSave'))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
auditSave
|
|
48
|
+
}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import paramHandler from '../../utils/paramsUtil/paramHandler'
|
|
2
2
|
import constants from '../../constants'
|
|
3
3
|
import cliOptions from '../../utils/parsedCLIOptions'
|
|
4
|
-
import languageAnalysisEngine from '../../audit/languageAnalysisEngine/constants'
|
|
5
|
-
import {
|
|
6
|
-
determineProjectLanguage,
|
|
7
|
-
identifyLanguages
|
|
8
|
-
} from '../../audit/autodetection/autoDetectLanguage'
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
supportedLanguages: { NODE, JAVASCRIPT }
|
|
12
|
-
} = languageAnalysisEngine
|
|
13
4
|
|
|
14
5
|
export const getAuditConfig = (argv: string[]): { [key: string]: string } => {
|
|
15
6
|
const auditParameters = cliOptions.getCommandLineArgsCustom(
|
|
@@ -18,22 +9,6 @@ export const getAuditConfig = (argv: string[]): { [key: string]: string } => {
|
|
|
18
9
|
)
|
|
19
10
|
const paramsAuth = paramHandler.getAuth(auditParameters)
|
|
20
11
|
|
|
21
|
-
if (
|
|
22
|
-
auditParameters.language === undefined ||
|
|
23
|
-
auditParameters.language === null
|
|
24
|
-
) {
|
|
25
|
-
try {
|
|
26
|
-
auditParameters.language = determineProjectLanguage(
|
|
27
|
-
identifyLanguages(auditParameters)
|
|
28
|
-
)
|
|
29
|
-
} catch (err: any) {
|
|
30
|
-
console.log(err.message)
|
|
31
|
-
process.exit(1)
|
|
32
|
-
}
|
|
33
|
-
} else if (auditParameters.language.toUpperCase() === JAVASCRIPT) {
|
|
34
|
-
auditParameters.language = NODE.toLowerCase()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
12
|
// @ts-ignore
|
|
38
13
|
return { ...paramsAuth, ...auditParameters }
|
|
39
14
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { catalogueApplication } from '../../audit/catalogueApplication/catalogueApplication'
|
|
2
2
|
import commonApi from '../../audit/languageAnalysisEngine/commonApi'
|
|
3
3
|
|
|
4
|
-
const identifyLanguageAE = require('./../../audit/languageAnalysisEngine')
|
|
5
|
-
const languageFactory = require('../../audit/languageAnalysisEngine/languageAnalysisFactory')
|
|
6
|
-
const { v4: uuidv4 } = require('uuid')
|
|
7
|
-
|
|
8
4
|
export const dealWithNoAppId = async (config: { [x: string]: string }) => {
|
|
9
5
|
let appID: string
|
|
10
6
|
try {
|
|
@@ -14,14 +10,15 @@ export const dealWithNoAppId = async (config: { [x: string]: string }) => {
|
|
|
14
10
|
return await catalogueApplication(config)
|
|
15
11
|
}
|
|
16
12
|
if (!appID && !config.applicationName) {
|
|
17
|
-
config.applicationName =
|
|
18
|
-
|
|
13
|
+
config.applicationName = getAppName(config.file) as string
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
appID = await commonApi.returnAppId(config)
|
|
16
|
+
if (!appID) {
|
|
17
|
+
return await catalogueApplication(config)
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
} catch (e) {
|
|
22
|
-
// @ts-ignore
|
|
20
|
+
} catch (e: any) {
|
|
23
21
|
if (e.toString().includes('tunneling socket could not be established')) {
|
|
24
|
-
// @ts-ignore
|
|
25
22
|
console.log(e.message.toString())
|
|
26
23
|
console.log(
|
|
27
24
|
'There seems to be an issue with your proxy, please check and try again'
|
|
@@ -32,15 +29,16 @@ export const dealWithNoAppId = async (config: { [x: string]: string }) => {
|
|
|
32
29
|
return appID
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
export const getAppName = (file: string) => {
|
|
33
|
+
const last = file.charAt(file.length - 1)
|
|
34
|
+
if (last !== '/') {
|
|
35
|
+
return file.split('/').pop()
|
|
36
|
+
} else {
|
|
37
|
+
const str = removeLastChar(file)
|
|
38
|
+
return str.split('/').pop()
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
config
|
|
45
|
-
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const removeLastChar = (str: string) => {
|
|
43
|
+
return str.substring(0, str.length - 1)
|
|
46
44
|
}
|
|
@@ -13,35 +13,41 @@ const auditUsageGuide = commandLineUsage([
|
|
|
13
13
|
'{bold ' +
|
|
14
14
|
i18n.__('constantsAuditPrerequisitesContentSupportedLanguages') +
|
|
15
15
|
'}',
|
|
16
|
-
'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
'',
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'',
|
|
24
|
-
'{bold ' +
|
|
25
|
-
i18n.__('constantsAuditPrerequisitesContentDotNet') +
|
|
26
|
-
'}' +
|
|
27
|
-
i18n.__('constantsAuditPrerequisitesContentDotNetMessage'),
|
|
28
|
-
'{bold ' +
|
|
29
|
-
i18n.__('constantsAuditPrerequisitesContentLanguageNode') +
|
|
30
|
-
'}' +
|
|
31
|
-
i18n.__('constantsAuditPrerequisitesContentLanguageNodeMessage'),
|
|
32
|
-
'{bold ' +
|
|
33
|
-
i18n.__('constantsAuditPrerequisitesContentLanguageRuby') +
|
|
34
|
-
'}' +
|
|
35
|
-
i18n.__('constantsAuditPrerequisitesContentLanguageRubyMessage'),
|
|
36
|
-
'{bold ' +
|
|
37
|
-
i18n.__('constantsAuditPrerequisitesContentLanguagePython') +
|
|
38
|
-
'}' +
|
|
39
|
-
i18n.__('constantsAuditPrerequisitesContentLanguagePythonMessage')
|
|
16
|
+
i18n.__('constantsAuditPrerequisitesJavaContentMessage'),
|
|
17
|
+
i18n.__('constantsAuditPrerequisitesContentDotNetMessage'),
|
|
18
|
+
i18n.__('constantsAuditPrerequisitesContentNodeMessage'),
|
|
19
|
+
i18n.__('constantsAuditPrerequisitesContentRubyMessage'),
|
|
20
|
+
i18n.__('constantsAuditPrerequisitesContentPythonMessage'),
|
|
21
|
+
i18n.__('constantsAuditPrerequisitesContentGoMessage'),
|
|
22
|
+
i18n.__('constantsAuditPrerequisitesContentPHPMessage')
|
|
40
23
|
]
|
|
41
24
|
},
|
|
42
25
|
{
|
|
43
26
|
header: i18n.__('constantsAuditOptions'),
|
|
44
|
-
optionList: constants.commandLineDefinitions.auditOptionDefinitions
|
|
27
|
+
optionList: constants.commandLineDefinitions.auditOptionDefinitions,
|
|
28
|
+
hide: [
|
|
29
|
+
'application-id',
|
|
30
|
+
'application-name',
|
|
31
|
+
'organization-id',
|
|
32
|
+
'api-key',
|
|
33
|
+
'authorization',
|
|
34
|
+
'host',
|
|
35
|
+
'proxy',
|
|
36
|
+
'help',
|
|
37
|
+
'ff',
|
|
38
|
+
'ignore-cert-errors',
|
|
39
|
+
'verbose',
|
|
40
|
+
'debug',
|
|
41
|
+
'experimental',
|
|
42
|
+
'tags',
|
|
43
|
+
'sub-project',
|
|
44
|
+
'code',
|
|
45
|
+
'maven-settings-path',
|
|
46
|
+
'language',
|
|
47
|
+
'experimental',
|
|
48
|
+
'app-groups',
|
|
49
|
+
'metadata'
|
|
50
|
+
]
|
|
45
51
|
}
|
|
46
52
|
])
|
|
47
53
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { startAudit } from './auditController'
|
|
2
1
|
import { getAuditConfig } from './auditConfig'
|
|
3
2
|
import { auditUsageGuide } from './help'
|
|
3
|
+
import { processSca } from '../scan/sca/scaAnalysis'
|
|
4
4
|
|
|
5
5
|
export type parameterInput = string[]
|
|
6
6
|
|
|
@@ -10,10 +10,7 @@ export const processAudit = async (argv: parameterInput) => {
|
|
|
10
10
|
process.exit(0)
|
|
11
11
|
}
|
|
12
12
|
const config = getAuditConfig(argv)
|
|
13
|
-
|
|
14
|
-
// console.log(config)
|
|
15
|
-
|
|
16
|
-
const auditResults = await startAudit(config)
|
|
13
|
+
await processSca(config)
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
const printHelpMessage = () => {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
const fileName = `${config.applicationId}-sbom
|
|
3
|
+
export const saveFile = (config: any, type: string, rawResults: any) => {
|
|
4
|
+
const fileName = `${config.applicationId}-sbom-${type}.json`
|
|
5
5
|
fs.writeFileSync(fileName, JSON.stringify(rawResults))
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
saveFile
|
|
10
|
+
}
|