@contrast/contrast 1.0.4 → 1.0.7
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/.prettierignore +0 -3
- package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
- package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +4 -2
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +2 -1
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +2 -1
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +2 -1
- package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +6 -2
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +39 -1
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +69 -30
- package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +24 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +3 -1
- package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +13 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +2 -2
- package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +56 -45
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +65 -17
- package/dist/commands/audit/auditConfig.js +8 -2
- package/dist/commands/audit/auditController.js +9 -3
- package/dist/commands/audit/processAudit.js +1 -1
- package/dist/commands/scan/processScan.js +7 -4
- package/dist/commands/scan/sca/scaAnalysis.js +60 -0
- package/dist/common/HTTPClient.js +50 -16
- package/dist/common/errorHandling.js +11 -16
- package/dist/common/versionChecker.js +1 -1
- package/dist/constants/constants.js +24 -2
- package/dist/constants/locales.js +31 -36
- package/dist/constants.js +20 -0
- package/dist/lambda/analytics.js +11 -0
- package/dist/lambda/lambda.js +35 -4
- package/dist/lambda/types.js +13 -0
- package/dist/scaAnalysis/common/formatMessage.js +35 -0
- package/dist/scaAnalysis/common/treeUpload.js +29 -0
- package/dist/scaAnalysis/go/goAnalysis.js +17 -0
- package/dist/scaAnalysis/go/goParseDeps.js +158 -0
- package/dist/scaAnalysis/go/goReadDepFile.js +23 -0
- package/dist/scaAnalysis/java/analysis.js +105 -0
- package/dist/scaAnalysis/java/index.js +18 -0
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +339 -0
- package/dist/scaAnalysis/python/analysis.js +41 -0
- package/dist/scaAnalysis/python/index.js +10 -0
- package/dist/scaAnalysis/ruby/analysis.js +226 -0
- package/dist/scaAnalysis/ruby/index.js +10 -0
- package/dist/scan/autoDetection.js +50 -1
- package/dist/scan/fileUtils.js +80 -1
- package/dist/scan/formatScanOutput.js +213 -0
- package/dist/scan/help.js +3 -1
- package/dist/scan/models/groupedResultsModel.js +2 -1
- package/dist/scan/models/scanResultsModel.js +3 -1
- package/dist/scan/populateProjectIdAndProjectName.js +2 -1
- package/dist/scan/scan.js +6 -99
- package/dist/scan/scanConfig.js +6 -1
- package/dist/scan/scanController.js +26 -7
- package/dist/scan/scanResults.js +20 -20
- package/dist/utils/commonApi.js +4 -1
- package/dist/utils/oraWrapper.js +5 -1
- package/package.json +12 -7
- package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
- package/src/audit/catalogueApplication/catalogueApplication.js +3 -16
- package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +11 -8
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +2 -1
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +2 -1
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +2 -1
- package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +17 -5
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +76 -3
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +122 -40
- package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +3 -3
- package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +15 -11
- package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +29 -0
- package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +12 -3
- package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +16 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +3 -3
- package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +87 -65
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +78 -25
- package/src/commands/audit/auditConfig.ts +12 -3
- package/src/commands/audit/auditController.ts +9 -3
- package/src/commands/audit/processAudit.ts +4 -1
- package/src/commands/scan/processScan.js +10 -4
- package/src/commands/scan/sca/scaAnalysis.js +83 -0
- package/src/common/HTTPClient.js +65 -25
- package/src/common/errorHandling.ts +14 -22
- package/src/common/versionChecker.ts +1 -1
- package/src/constants/constants.js +24 -2
- package/src/constants/locales.js +33 -50
- package/src/constants.js +22 -0
- package/src/lambda/analytics.ts +9 -0
- package/src/lambda/arn.ts +2 -1
- package/src/lambda/lambda.ts +37 -17
- package/src/lambda/types.ts +35 -0
- package/src/lambda/utils.ts +2 -7
- package/src/scaAnalysis/common/formatMessage.js +38 -0
- package/src/scaAnalysis/common/treeUpload.js +30 -0
- package/src/scaAnalysis/go/goAnalysis.js +19 -0
- package/src/scaAnalysis/go/goParseDeps.js +203 -0
- package/src/scaAnalysis/go/goReadDepFile.js +32 -0
- package/src/scaAnalysis/java/analysis.js +142 -0
- package/src/scaAnalysis/java/index.js +21 -0
- package/src/scaAnalysis/java/javaBuildDepsParser.js +404 -0
- package/src/scaAnalysis/python/analysis.js +48 -0
- package/src/scaAnalysis/python/index.js +11 -0
- package/src/scaAnalysis/ruby/analysis.js +282 -0
- package/src/scaAnalysis/ruby/index.js +11 -0
- package/src/scan/autoDetection.js +58 -1
- package/src/scan/fileUtils.js +99 -1
- package/src/scan/formatScanOutput.ts +249 -0
- package/src/scan/help.js +3 -1
- package/src/scan/models/groupedResultsModel.ts +7 -5
- package/src/scan/models/resultContentModel.ts +2 -2
- package/src/scan/models/scanResultsModel.ts +5 -2
- package/src/scan/populateProjectIdAndProjectName.js +3 -1
- package/src/scan/scan.ts +8 -136
- package/src/scan/scanConfig.js +5 -1
- package/src/scan/scanController.js +30 -10
- package/src/scan/scanResults.js +31 -18
- package/src/utils/commonApi.js +4 -1
- package/src/utils/oraWrapper.js +6 -1
|
@@ -2,7 +2,7 @@ export class ReportLibraryModel {
|
|
|
2
2
|
name: string
|
|
3
3
|
cveArray: ReportCVEModel[]
|
|
4
4
|
|
|
5
|
-
constructor
|
|
5
|
+
constructor(name: string, cveArray: ReportCVEModel[]) {
|
|
6
6
|
this.name = name
|
|
7
7
|
this.cveArray = cveArray
|
|
8
8
|
}
|
|
@@ -16,12 +16,12 @@ export class ReportCVEModel {
|
|
|
16
16
|
severityCode?: string
|
|
17
17
|
cvss3SeverityCode?: string
|
|
18
18
|
|
|
19
|
-
constructor
|
|
19
|
+
constructor(
|
|
20
20
|
name: string,
|
|
21
21
|
description: string,
|
|
22
22
|
severityCode: string,
|
|
23
23
|
cvss3SeverityCode: string
|
|
24
|
-
){
|
|
24
|
+
) {
|
|
25
25
|
this.name = name
|
|
26
26
|
this.description = description
|
|
27
27
|
this.severityCode = severityCode
|
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
import {ReportSeverityModel} from
|
|
2
|
-
import {ReportCVEModel} from
|
|
1
|
+
import { ReportSeverityModel } from './reportSeverityModel'
|
|
2
|
+
import { ReportCVEModel } from './reportLibraryModel'
|
|
3
3
|
|
|
4
4
|
export class ReportList {
|
|
5
5
|
reportOutputList: ReportModelStructure[]
|
|
6
6
|
|
|
7
|
-
constructor
|
|
7
|
+
constructor() {
|
|
8
8
|
this.reportOutputList = []
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class ReportModelStructure {
|
|
13
|
-
compositeKey: ReportCompositeKey
|
|
14
|
-
cveArray: ReportCVEModel[]
|
|
13
|
+
compositeKey: ReportCompositeKey
|
|
14
|
+
cveArray: ReportCVEModel[]
|
|
15
15
|
|
|
16
|
-
constructor
|
|
16
|
+
constructor(compositeKey: ReportCompositeKey, cveArray: ReportCVEModel[]) {
|
|
17
17
|
this.compositeKey = compositeKey
|
|
18
18
|
this.cveArray = cveArray
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class ReportCompositeKey {
|
|
23
|
-
libraryName!: string
|
|
24
|
-
libraryVersion!: string
|
|
25
|
-
highestSeverity!: ReportSeverityModel
|
|
23
|
+
libraryName!: string
|
|
24
|
+
libraryVersion!: string
|
|
25
|
+
highestSeverity!: ReportSeverityModel
|
|
26
26
|
|
|
27
|
-
constructor
|
|
27
|
+
constructor(
|
|
28
|
+
libraryName: string,
|
|
29
|
+
libraryVersion: string,
|
|
30
|
+
highestSeverity: ReportSeverityModel
|
|
31
|
+
) {
|
|
28
32
|
this.libraryName = libraryName
|
|
29
33
|
this.libraryVersion = libraryVersion
|
|
30
34
|
this.highestSeverity = highestSeverity
|
|
31
35
|
}
|
|
32
|
-
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class ReportOutputModel {
|
|
2
|
+
header: ReportOutputHeaderModel
|
|
3
|
+
body: ReportOutputBodyModel
|
|
4
|
+
|
|
5
|
+
constructor(header: ReportOutputHeaderModel, body: ReportOutputBodyModel) {
|
|
6
|
+
this.header = header
|
|
7
|
+
this.body = body
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ReportOutputHeaderModel {
|
|
12
|
+
vulnMessage: string
|
|
13
|
+
introducesMessage: string
|
|
14
|
+
|
|
15
|
+
constructor(vulnMessage: string, introducesMessage: string) {
|
|
16
|
+
this.vulnMessage = vulnMessage
|
|
17
|
+
this.introducesMessage = introducesMessage
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ReportOutputBodyModel {
|
|
22
|
+
issueMessage: string
|
|
23
|
+
adviceMessage: string
|
|
24
|
+
|
|
25
|
+
constructor(bodyIssueMessage: string, bodyAdviceMessage: string) {
|
|
26
|
+
this.issueMessage = bodyIssueMessage
|
|
27
|
+
this.adviceMessage = bodyAdviceMessage
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export class ReportSeverityModel {
|
|
2
|
-
severity
|
|
3
|
-
priority
|
|
2
|
+
severity: string
|
|
3
|
+
priority: number
|
|
4
|
+
outputColour: string
|
|
5
|
+
cveName: string
|
|
4
6
|
|
|
5
|
-
constructor(
|
|
7
|
+
constructor(
|
|
8
|
+
severity: string,
|
|
9
|
+
priority: number,
|
|
10
|
+
outputColour: string,
|
|
11
|
+
cveName: string
|
|
12
|
+
) {
|
|
6
13
|
this.severity = severity
|
|
7
14
|
this.priority = priority
|
|
15
|
+
this.outputColour = outputColour
|
|
16
|
+
this.cveName = cveName
|
|
8
17
|
}
|
|
9
18
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class SeverityCountModel {
|
|
2
|
+
critical!: number
|
|
3
|
+
high!: number
|
|
4
|
+
medium!: number
|
|
5
|
+
low!: number
|
|
6
|
+
note!: number
|
|
7
|
+
|
|
8
|
+
//needed as default to stop NaN when new object constructed
|
|
9
|
+
constructor() {
|
|
10
|
+
this.critical = 0
|
|
11
|
+
this.high = 0
|
|
12
|
+
this.medium = 0
|
|
13
|
+
this.low = 0
|
|
14
|
+
this.note = 0
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from './commonReportingFunctions'
|
|
6
6
|
import {
|
|
7
7
|
convertGenericToTypedLibraries,
|
|
8
|
-
|
|
8
|
+
severityCountAllLibraries
|
|
9
9
|
} from './utils/reportUtils'
|
|
10
10
|
|
|
11
11
|
export async function vulnerabilityReport(
|
|
@@ -41,7 +41,7 @@ export function formatVulnerabilityOutput(
|
|
|
41
41
|
let numberOfCves = 0
|
|
42
42
|
vulnerableLibraries.forEach(lib => (numberOfCves += lib.cveArray.length))
|
|
43
43
|
|
|
44
|
-
createLibraryHeader(id, numberOfVulnerableLibraries, numberOfCves
|
|
44
|
+
createLibraryHeader(id, numberOfVulnerableLibraries, numberOfCves)
|
|
45
45
|
|
|
46
46
|
const hasSomeVulnerabilitiesReported = printVulnerabilityResponse(
|
|
47
47
|
vulnerableLibraries,
|
|
@@ -51,6 +51,6 @@ export function formatVulnerabilityOutput(
|
|
|
51
51
|
return [
|
|
52
52
|
hasSomeVulnerabilitiesReported,
|
|
53
53
|
numberOfCves,
|
|
54
|
-
|
|
54
|
+
severityCountAllLibraries(vulnerableLibraries)
|
|
55
55
|
]
|
|
56
56
|
}
|
|
@@ -4,42 +4,66 @@ import {
|
|
|
4
4
|
} from '../models/reportLibraryModel'
|
|
5
5
|
import { ReportSeverityModel } from '../models/reportSeverityModel'
|
|
6
6
|
import languageAnalysisEngine from '../../../languageAnalysisEngine/constants'
|
|
7
|
+
import {
|
|
8
|
+
CRITICAL_COLOUR,
|
|
9
|
+
CRITICAL_PRIORITY,
|
|
10
|
+
HIGH_COLOUR,
|
|
11
|
+
HIGH_PRIORITY,
|
|
12
|
+
LOW_COLOUR,
|
|
13
|
+
LOW_PRIORITY,
|
|
14
|
+
MEDIUM_COLOUR,
|
|
15
|
+
MEDIUM_PRIORITY,
|
|
16
|
+
NOTE_COLOUR,
|
|
17
|
+
NOTE_PRIORITY
|
|
18
|
+
} from '../../../../constants/constants'
|
|
19
|
+
import { orderBy } from 'lodash'
|
|
20
|
+
import { SeverityCountModel } from '../models/severityCountModel'
|
|
7
21
|
const {
|
|
8
22
|
supportedLanguages: { GO }
|
|
9
23
|
} = languageAnalysisEngine
|
|
10
24
|
|
|
11
25
|
export function findHighestSeverityCVE(cveArray: ReportCVEModel[]) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const mappedToReportSeverityModels = cveArray.map(cve => findCVESeverity(cve))
|
|
27
|
+
|
|
28
|
+
//order and get first
|
|
29
|
+
return orderBy(mappedToReportSeverityModels, cve => cve?.priority)[0]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function findCVESeveritiesAndOrderByHighestPriority(
|
|
33
|
+
cves: ReportCVEModel[]
|
|
34
|
+
) {
|
|
35
|
+
return orderBy(
|
|
36
|
+
cves.map(cve => findCVESeverity(cve)),
|
|
37
|
+
['priority'],
|
|
38
|
+
['asc']
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function findCVESeverity(cve: ReportCVEModel) {
|
|
43
|
+
const cveName = cve.name as string
|
|
44
|
+
if (cve.cvss3SeverityCode === 'CRITICAL' || cve.severityCode === 'CRITICAL') {
|
|
45
|
+
return new ReportSeverityModel(
|
|
46
|
+
'CRITICAL',
|
|
47
|
+
CRITICAL_PRIORITY,
|
|
48
|
+
CRITICAL_COLOUR,
|
|
49
|
+
cveName
|
|
22
50
|
)
|
|
23
|
-
) {
|
|
24
|
-
return new ReportSeverityModel('HIGH',
|
|
51
|
+
} else if (cve.cvss3SeverityCode === 'HIGH' || cve.severityCode === 'HIGH') {
|
|
52
|
+
return new ReportSeverityModel('HIGH', HIGH_PRIORITY, HIGH_COLOUR, cveName)
|
|
25
53
|
} else if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
54
|
+
cve.cvss3SeverityCode === 'MEDIUM' ||
|
|
55
|
+
cve.severityCode === 'MEDIUM'
|
|
29
56
|
) {
|
|
30
|
-
return new ReportSeverityModel(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
return new ReportSeverityModel(
|
|
58
|
+
'MEDIUM',
|
|
59
|
+
MEDIUM_PRIORITY,
|
|
60
|
+
MEDIUM_COLOUR,
|
|
61
|
+
cveName
|
|
34
62
|
)
|
|
35
|
-
) {
|
|
36
|
-
return new ReportSeverityModel('LOW',
|
|
37
|
-
} else if (
|
|
38
|
-
|
|
39
|
-
cve => cve.cvss3SeverityCode === 'NOTE' || cve.severityCode === 'NOTE'
|
|
40
|
-
)
|
|
41
|
-
) {
|
|
42
|
-
return new ReportSeverityModel('NOTE', 5)
|
|
63
|
+
} else if (cve.cvss3SeverityCode === 'LOW' || cve.severityCode === 'LOW') {
|
|
64
|
+
return new ReportSeverityModel('LOW', LOW_PRIORITY, LOW_COLOUR, cveName)
|
|
65
|
+
} else if (cve.cvss3SeverityCode === 'NOTE' || cve.severityCode === 'NOTE') {
|
|
66
|
+
return new ReportSeverityModel('NOTE', NOTE_PRIORITY, NOTE_COLOUR, cveName)
|
|
43
67
|
}
|
|
44
68
|
}
|
|
45
69
|
|
|
@@ -49,45 +73,43 @@ export function convertGenericToTypedLibraries(libraries: any) {
|
|
|
49
73
|
})
|
|
50
74
|
}
|
|
51
75
|
|
|
52
|
-
export function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
export function severityCountAllLibraries(
|
|
77
|
+
vulnerableLibraries: ReportLibraryModel[]
|
|
78
|
+
) {
|
|
79
|
+
const severityCount = new SeverityCountModel()
|
|
80
|
+
vulnerableLibraries.forEach(lib =>
|
|
81
|
+
severityCountAllCVEs(lib.cveArray, severityCount)
|
|
82
|
+
)
|
|
83
|
+
return severityCount
|
|
84
|
+
}
|
|
60
85
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
})
|
|
86
|
+
export function severityCountAllCVEs(
|
|
87
|
+
cveArray: ReportCVEModel[],
|
|
88
|
+
severityCount: SeverityCountModel
|
|
89
|
+
) {
|
|
90
|
+
const severityCountInner = severityCount
|
|
91
|
+
cveArray.forEach(cve => severityCountSingleCVE(cve, severityCountInner))
|
|
92
|
+
return severityCountInner
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function severityCountSingleCVE(
|
|
96
|
+
cve: ReportCVEModel,
|
|
97
|
+
severityCount: SeverityCountModel
|
|
98
|
+
) {
|
|
99
|
+
if (cve.cvss3SeverityCode === 'CRITICAL' || cve.severityCode === 'CRITICAL') {
|
|
100
|
+
severityCount.critical += 1
|
|
101
|
+
} else if (cve.cvss3SeverityCode === 'HIGH' || cve.severityCode === 'HIGH') {
|
|
102
|
+
severityCount.high += 1
|
|
103
|
+
} else if (
|
|
104
|
+
cve.cvss3SeverityCode === 'MEDIUM' ||
|
|
105
|
+
cve.severityCode === 'MEDIUM'
|
|
106
|
+
) {
|
|
107
|
+
severityCount.medium += 1
|
|
108
|
+
} else if (cve.cvss3SeverityCode === 'LOW' || cve.severityCode === 'LOW') {
|
|
109
|
+
severityCount.low += 1
|
|
110
|
+
} else if (cve.cvss3SeverityCode === 'NOTE' || cve.severityCode === 'NOTE') {
|
|
111
|
+
severityCount.note += 1
|
|
112
|
+
}
|
|
91
113
|
|
|
92
114
|
return severityCount
|
|
93
115
|
}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
const prettyjson = require('prettyjson')
|
|
2
|
-
const i18n = require('i18n')
|
|
3
|
-
const { getHttpClient } = require('../../utils/commonApi')
|
|
4
1
|
const { handleResponseErrors } = require('../../common/errorHandling')
|
|
5
2
|
const { APP_VERSION } = require('../../constants/constants')
|
|
3
|
+
const commonApi = require('../../utils/commonApi')
|
|
4
|
+
const _ = require('lodash')
|
|
5
|
+
const oraFunctions = require('../../utils/oraWrapper')
|
|
6
|
+
const i18n = require('i18n')
|
|
7
|
+
const oraWrapper = require('../../utils/oraWrapper')
|
|
8
|
+
const requestUtils = require('../../utils/requestUtils')
|
|
9
|
+
const { performance } = require('perf_hooks')
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
console.log(
|
|
9
|
-
'\n **************************' +
|
|
10
|
-
i18n.__('successHeader') +
|
|
11
|
-
'************************** '
|
|
12
|
-
)
|
|
13
|
-
console.log('\n' + i18n.__('snapshotSuccessMessage') + '\n')
|
|
14
|
-
console.log(
|
|
15
|
-
` ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`
|
|
16
|
-
)
|
|
17
|
-
console.log('\n ***********************************************************')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const newSendSnapShot = async (analysis, applicationId) => {
|
|
11
|
+
const newSendSnapShot = async analysis => {
|
|
21
12
|
const analysisLanguage = analysis.config.language.toLowerCase()
|
|
22
13
|
const requestBody = {
|
|
23
14
|
appID: analysis.config.applicationId,
|
|
@@ -25,18 +16,12 @@ const newSendSnapShot = async (analysis, applicationId) => {
|
|
|
25
16
|
snapshot: { [analysisLanguage]: analysis[analysisLanguage] }
|
|
26
17
|
}
|
|
27
18
|
|
|
28
|
-
const client = getHttpClient(analysis.config)
|
|
19
|
+
const client = commonApi.getHttpClient(analysis.config)
|
|
29
20
|
|
|
30
21
|
return client
|
|
31
22
|
.sendSnapshot(requestBody, analysis.config)
|
|
32
23
|
.then(res => {
|
|
33
|
-
// if (!analysis.config.silent) {
|
|
34
|
-
// console.log(prettyjson.render(requestBody))
|
|
35
|
-
// }
|
|
36
24
|
if (res.statusCode === 201) {
|
|
37
|
-
if (analysis.config.host !== 'https://ce.contrastsecurity.com/') {
|
|
38
|
-
displaySnapshotSuccessMessage(analysis.config)
|
|
39
|
-
}
|
|
40
25
|
return res.body
|
|
41
26
|
} else {
|
|
42
27
|
handleResponseErrors(res, 'snapshot')
|
|
@@ -47,7 +32,75 @@ const newSendSnapShot = async (analysis, applicationId) => {
|
|
|
47
32
|
})
|
|
48
33
|
}
|
|
49
34
|
|
|
35
|
+
const pollSnapshotResults = async (config, snapshotId, client) => {
|
|
36
|
+
await requestUtils.sleep(5000)
|
|
37
|
+
return client
|
|
38
|
+
.getReportStatusById(config, snapshotId)
|
|
39
|
+
.then(res => {
|
|
40
|
+
return res
|
|
41
|
+
})
|
|
42
|
+
.catch(err => {
|
|
43
|
+
console.log(err)
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getTimeout = config => {
|
|
48
|
+
if (config.timeout) {
|
|
49
|
+
return config.timeout
|
|
50
|
+
} else {
|
|
51
|
+
if (config.verbose) {
|
|
52
|
+
console.log('Timeout set to 2 minutes')
|
|
53
|
+
}
|
|
54
|
+
return 120
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const pollForSnapshotCompletition = async (
|
|
59
|
+
config,
|
|
60
|
+
snapshotId,
|
|
61
|
+
reportSpinner
|
|
62
|
+
) => {
|
|
63
|
+
const client = commonApi.getHttpClient(config)
|
|
64
|
+
const startTime = performance.now()
|
|
65
|
+
const timeout = getTimeout(config)
|
|
66
|
+
|
|
67
|
+
let complete = false
|
|
68
|
+
if (!_.isNil(snapshotId)) {
|
|
69
|
+
while (!complete) {
|
|
70
|
+
let result = await pollSnapshotResults(config, snapshotId, client)
|
|
71
|
+
if (result.statusCode === 200) {
|
|
72
|
+
if (result.body.status === 'PROCESSED') {
|
|
73
|
+
complete = true
|
|
74
|
+
return result.body
|
|
75
|
+
}
|
|
76
|
+
if (result.body.status === 'FAILED') {
|
|
77
|
+
complete = true
|
|
78
|
+
if (config.debug) {
|
|
79
|
+
oraFunctions.failSpinner(
|
|
80
|
+
reportSpinner,
|
|
81
|
+
i18n.__('auditNotCompleted')
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
console.log(result.body.errorMessage)
|
|
85
|
+
oraWrapper.stopSpinner(reportSpinner)
|
|
86
|
+
console.log('Contrast audit finished')
|
|
87
|
+
process.exit(1)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const endTime = performance.now() - startTime
|
|
91
|
+
if (requestUtils.millisToSeconds(endTime) > timeout) {
|
|
92
|
+
oraFunctions.failSpinner(
|
|
93
|
+
reportSpinner,
|
|
94
|
+
'Contrast audit timed out at the specified ' + timeout + ' seconds.'
|
|
95
|
+
)
|
|
96
|
+
console.log('Please try again, allowing more time.')
|
|
97
|
+
process.exit(1)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
50
103
|
module.exports = {
|
|
51
104
|
newSendSnapShot: newSendSnapShot,
|
|
52
|
-
|
|
105
|
+
pollForSnapshotCompletition: pollForSnapshotCompletition
|
|
53
106
|
}
|
|
@@ -2,6 +2,10 @@ import paramHandler from '../../utils/paramsUtil/paramHandler'
|
|
|
2
2
|
import constants from '../../constants'
|
|
3
3
|
import cliOptions from '../../utils/parsedCLIOptions'
|
|
4
4
|
import languageAnalysisEngine from '../../audit/languageAnalysisEngine/constants'
|
|
5
|
+
import {
|
|
6
|
+
determineProjectLanguage,
|
|
7
|
+
identifyLanguages
|
|
8
|
+
} from '../../audit/autodetection/autoDetectLanguage'
|
|
5
9
|
|
|
6
10
|
const {
|
|
7
11
|
supportedLanguages: { NODE, JAVASCRIPT }
|
|
@@ -18,9 +22,14 @@ export const getAuditConfig = (argv: string[]): { [key: string]: string } => {
|
|
|
18
22
|
auditParameters.language === undefined ||
|
|
19
23
|
auditParameters.language === null
|
|
20
24
|
) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
try {
|
|
26
|
+
auditParameters.language = determineProjectLanguage(
|
|
27
|
+
identifyLanguages(auditParameters)
|
|
28
|
+
)
|
|
29
|
+
} catch (err: any) {
|
|
30
|
+
console.log(err.message)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
24
33
|
} else if (auditParameters.language.toUpperCase() === JAVASCRIPT) {
|
|
25
34
|
auditParameters.language = NODE.toLowerCase()
|
|
26
35
|
}
|
|
@@ -3,20 +3,26 @@ import commonApi from '../../audit/languageAnalysisEngine/commonApi'
|
|
|
3
3
|
|
|
4
4
|
const identifyLanguageAE = require('./../../audit/languageAnalysisEngine')
|
|
5
5
|
const languageFactory = require('../../audit/languageAnalysisEngine/languageAnalysisFactory')
|
|
6
|
+
const { v4: uuidv4 } = require('uuid')
|
|
6
7
|
|
|
7
|
-
const dealWithNoAppId = async (config: { [x: string]: string }) => {
|
|
8
|
-
let appID
|
|
8
|
+
export const dealWithNoAppId = async (config: { [x: string]: string }) => {
|
|
9
|
+
let appID: string
|
|
9
10
|
try {
|
|
11
|
+
// @ts-ignore
|
|
10
12
|
appID = await commonApi.returnAppId(config)
|
|
11
13
|
if (!appID && config.applicationName) {
|
|
12
14
|
return await catalogueApplication(config)
|
|
13
15
|
}
|
|
16
|
+
if (!appID && !config.applicationName) {
|
|
17
|
+
config.applicationName = uuidv4()
|
|
18
|
+
return await catalogueApplication(config)
|
|
19
|
+
}
|
|
14
20
|
// @ts-ignore
|
|
15
21
|
} catch (e) {
|
|
16
22
|
// @ts-ignore
|
|
17
23
|
if (e.toString().includes('tunneling socket could not be established')) {
|
|
18
24
|
// @ts-ignore
|
|
19
|
-
console.log(e.message)
|
|
25
|
+
console.log(e.message.toString())
|
|
20
26
|
console.log(
|
|
21
27
|
'There seems to be an issue with your proxy, please check and try again'
|
|
22
28
|
)
|
|
@@ -7,9 +7,12 @@ export type parameterInput = string[]
|
|
|
7
7
|
export const processAudit = async (argv: parameterInput) => {
|
|
8
8
|
if (argv.indexOf('--help') != -1) {
|
|
9
9
|
printHelpMessage()
|
|
10
|
-
process.exit(
|
|
10
|
+
process.exit(0)
|
|
11
11
|
}
|
|
12
12
|
const config = getAuditConfig(argv)
|
|
13
|
+
|
|
14
|
+
// console.log(config)
|
|
15
|
+
|
|
13
16
|
const auditResults = await startAudit(config)
|
|
14
17
|
}
|
|
15
18
|
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
const { startScan } = require('../../scan/scanController')
|
|
2
|
-
const { scanUsageGuide } = require('../../scan/help')
|
|
3
1
|
const scanConfig = require('../../scan/scanConfig')
|
|
2
|
+
const { startScan } = require('../../scan/scanController')
|
|
4
3
|
const { saveScanFile } = require('../../utils/saveFile')
|
|
5
4
|
const { ScanResultsModel } = require('../../scan/models/scanResultsModel')
|
|
6
|
-
const { formatScanOutput } = require('../../scan/
|
|
5
|
+
const { formatScanOutput } = require('../../scan/formatScanOutput')
|
|
6
|
+
const { processSca } = require('./sca/scaAnalysis')
|
|
7
7
|
|
|
8
8
|
const processScan = async argvMain => {
|
|
9
9
|
let config = scanConfig.getScanConfig(argvMain)
|
|
10
|
+
// console.log(config)
|
|
11
|
+
//try SCA analysis first
|
|
12
|
+
if (config.experimental) {
|
|
13
|
+
await processSca(config)
|
|
14
|
+
}
|
|
10
15
|
|
|
11
16
|
let scanResults = new ScanResultsModel(await startScan(config))
|
|
12
|
-
|
|
17
|
+
|
|
18
|
+
if (scanResults.scanResultsInstances !== undefined) {
|
|
13
19
|
formatScanOutput(scanResults)
|
|
14
20
|
}
|
|
15
21
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const autoDetection = require('../../../scan/autoDetection')
|
|
2
|
+
const javaAnalysis = require('../../../scaAnalysis/java')
|
|
3
|
+
const treeUpload = require('../../../scaAnalysis/common/treeUpload')
|
|
4
|
+
const {
|
|
5
|
+
manualDetectAuditFilesAndLanguages
|
|
6
|
+
} = require('../../../scan/autoDetection')
|
|
7
|
+
const auditController = require('../../audit/auditController')
|
|
8
|
+
const {
|
|
9
|
+
supportedLanguages: { JAVA, GO, RUBY, PYTHON }
|
|
10
|
+
} = require('../../../audit/languageAnalysisEngine/constants')
|
|
11
|
+
const goAnalysis = require('../../../scaAnalysis/go/goAnalysis')
|
|
12
|
+
const { rubyAnalysis } = require('../../../scaAnalysis/ruby')
|
|
13
|
+
const { pythonAnalysis } = require('../../../scaAnalysis/python')
|
|
14
|
+
|
|
15
|
+
const processSca = async config => {
|
|
16
|
+
let filesFound
|
|
17
|
+
if (config.projectPath) {
|
|
18
|
+
filesFound = manualDetectAuditFilesAndLanguages(config.projectPath)
|
|
19
|
+
} else {
|
|
20
|
+
filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config)
|
|
21
|
+
config.projectPath = process.cwd()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// files found looks like [ { javascript: [ Array ] } ]
|
|
25
|
+
//check we have the language and call the right analyser
|
|
26
|
+
//refactor new analyser and see if we can clean it up
|
|
27
|
+
let messageToSend = undefined
|
|
28
|
+
if (filesFound.length === 1) {
|
|
29
|
+
switch (Object.keys(filesFound[0])[0]) {
|
|
30
|
+
case JAVA:
|
|
31
|
+
messageToSend = javaAnalysis.javaAnalysis(config, filesFound[0])
|
|
32
|
+
config.language = JAVA
|
|
33
|
+
break
|
|
34
|
+
// case 'javascript':
|
|
35
|
+
// // code block
|
|
36
|
+
// break;
|
|
37
|
+
// case 'dotnet':
|
|
38
|
+
// // code block
|
|
39
|
+
// break;
|
|
40
|
+
case RUBY:
|
|
41
|
+
messageToSend = rubyAnalysis(config, filesFound[0])
|
|
42
|
+
config.language = RUBY
|
|
43
|
+
break
|
|
44
|
+
case PYTHON:
|
|
45
|
+
messageToSend = pythonAnalysis(config, filesFound[0])
|
|
46
|
+
config.language = PYTHON
|
|
47
|
+
break
|
|
48
|
+
// case 'ruby':
|
|
49
|
+
// // code block
|
|
50
|
+
// break;
|
|
51
|
+
// case 'php':
|
|
52
|
+
// // code block
|
|
53
|
+
// break;
|
|
54
|
+
case GO:
|
|
55
|
+
messageToSend = goAnalysis.goAnalysis(config, filesFound[0])
|
|
56
|
+
config.language = GO
|
|
57
|
+
break
|
|
58
|
+
default:
|
|
59
|
+
//something is wrong
|
|
60
|
+
console.log('language detected not supported')
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!config.applicationId) {
|
|
65
|
+
config.applicationId = await auditController.dealWithNoAppId(config)
|
|
66
|
+
}
|
|
67
|
+
//send message to TS
|
|
68
|
+
console.log('processing dependencies')
|
|
69
|
+
const response = await treeUpload.commonSendSnapShot(messageToSend, config)
|
|
70
|
+
} else {
|
|
71
|
+
if (filesFound.length === 0) {
|
|
72
|
+
console.log('no compatible dependency files detected. Continuing...')
|
|
73
|
+
} else {
|
|
74
|
+
console.log(
|
|
75
|
+
'multiple language files detected, please use --project-path to specify a directory or the file where dependencies are declared'
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
processSca
|
|
83
|
+
}
|