@contrast/contrast 1.0.1 → 1.0.4
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 +2 -0
- package/README.md +103 -133
- package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +26 -11
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +62 -234
- package/dist/audit/languageAnalysisEngine/report/models/reportLibraryModel.js +19 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +24 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +10 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +24 -129
- package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +85 -0
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +3 -1
- package/dist/commands/audit/auditController.js +6 -3
- package/dist/commands/audit/saveFile.js +11 -0
- package/dist/commands/auth/auth.js +19 -1
- package/dist/commands/config/config.js +19 -8
- package/dist/commands/scan/processScan.js +8 -25
- package/dist/common/HTTPClient.js +30 -26
- package/dist/common/errorHandling.js +17 -1
- package/dist/common/versionChecker.js +32 -0
- package/dist/constants/constants.js +4 -2
- package/dist/constants/lambda.js +3 -1
- package/dist/constants/locales.js +41 -18
- package/dist/constants.js +39 -3
- package/dist/index.js +49 -28
- package/dist/lambda/help.js +22 -14
- package/dist/lambda/lambda.js +6 -0
- package/dist/sbom/generateSbom.js +20 -0
- package/dist/scan/help.js +4 -2
- package/dist/scan/models/groupedResultsModel.js +10 -0
- package/dist/scan/models/resultContentModel.js +2 -0
- package/dist/scan/models/scanResultsModel.js +11 -0
- package/dist/scan/populateProjectIdAndProjectName.js +1 -0
- package/dist/scan/saveResults.js +9 -10
- package/dist/scan/scan.js +99 -74
- package/dist/scan/scanConfig.js +20 -1
- package/dist/scan/scanController.js +7 -2
- package/dist/scan/scanResults.js +6 -0
- package/dist/utils/getConfig.js +3 -0
- package/dist/utils/paramsUtil/commandlineParams.js +1 -1
- package/dist/utils/requestUtils.js +1 -1
- package/dist/utils/saveFile.js +19 -0
- package/package.json +2 -2
- package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +33 -15
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +127 -0
- package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +30 -0
- package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +32 -0
- package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +9 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -0
- package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +110 -0
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +3 -1
- package/src/commands/audit/auditController.ts +12 -3
- package/src/commands/audit/processAudit.ts +0 -1
- package/src/commands/audit/saveFile.ts +6 -0
- package/src/commands/auth/auth.js +25 -1
- package/src/commands/config/config.js +22 -8
- package/src/commands/scan/processScan.js +8 -29
- package/src/common/HTTPClient.js +42 -36
- package/src/common/errorHandling.ts +29 -2
- package/src/common/versionChecker.ts +41 -0
- package/src/constants/constants.js +5 -4
- package/src/constants/lambda.js +3 -1
- package/src/constants/locales.js +51 -19
- package/src/constants.js +44 -3
- package/src/index.ts +63 -31
- package/src/lambda/help.ts +22 -14
- package/src/lambda/lambda.ts +8 -0
- package/src/sbom/generateSbom.ts +17 -0
- package/src/scan/help.js +4 -2
- package/src/scan/models/groupedResultsModel.ts +18 -0
- package/src/scan/models/resultContentModel.ts +86 -0
- package/src/scan/models/scanResultsModel.ts +52 -0
- package/src/scan/populateProjectIdAndProjectName.js +1 -0
- package/src/scan/saveResults.js +8 -9
- package/src/scan/scan.ts +192 -0
- package/src/scan/scanConfig.js +26 -1
- package/src/scan/scanController.js +11 -2
- package/src/scan/scanResults.js +11 -0
- package/src/utils/getConfig.ts +12 -0
- package/src/utils/paramsUtil/commandlineParams.js +1 -1
- package/src/utils/requestUtils.js +1 -1
- package/src/utils/saveFile.js +19 -0
- package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
- package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
- package/dist/common/findLatestCLIVersion.js +0 -23
- package/dist/lambda/scanDetail.js +0 -30
- package/dist/scan/fileFinder.js +0 -15
- package/dist/utils/fileUtils.js +0 -31
- package/dist/utils/paramsUtil/genericCommandLineParams.js +0 -12
- package/dist/utils/paramsUtil/yamlParams.js +0 -6
- package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -27
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +0 -303
- package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -124
- package/src/audit/languageAnalysisEngine/report/reportingFeature.js +0 -190
- package/src/common/findLatestCLIVersion.ts +0 -27
- package/src/scan/scan.js +0 -162
package/src/scan/scan.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
const commonApi = require('../utils/commonApi.js')
|
|
2
|
-
const fileUtils = require('../scan/fileUtils')
|
|
3
|
-
const allowedFileTypes = ['.jar', '.war', '.js', '.zip', '.exe']
|
|
4
|
-
const i18n = require('i18n')
|
|
5
|
-
const oraWrapper = require('../utils/oraWrapper')
|
|
6
|
-
const chalk = require('chalk')
|
|
7
|
-
|
|
8
|
-
const isFileAllowed = scanOption => {
|
|
9
|
-
let valid = false
|
|
10
|
-
allowedFileTypes.forEach(fileType => {
|
|
11
|
-
if (scanOption.endsWith(fileType)) {
|
|
12
|
-
valid = true
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
return valid
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const stripMustacheTags = oldString => {
|
|
19
|
-
return oldString
|
|
20
|
-
.replace(/\n/g, ' ')
|
|
21
|
-
.replace(/{{.*?}}/g, '\n')
|
|
22
|
-
.replace(/\s+/g, ' ')
|
|
23
|
-
.trim()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const sendScan = async config => {
|
|
27
|
-
if (!isFileAllowed(config.file)) {
|
|
28
|
-
console.log(i18n.__('scanErrorFileMessage'))
|
|
29
|
-
process.exit(9)
|
|
30
|
-
} else {
|
|
31
|
-
fileUtils.checkFilePermissions(config.file)
|
|
32
|
-
const client = commonApi.getHttpClient(config)
|
|
33
|
-
|
|
34
|
-
const startUploadSpinner = oraWrapper.returnOra(i18n.__('uploadingScan'))
|
|
35
|
-
oraWrapper.startSpinner(startUploadSpinner)
|
|
36
|
-
|
|
37
|
-
return await client
|
|
38
|
-
.sendArtifact(config)
|
|
39
|
-
.then(res => {
|
|
40
|
-
if (res.statusCode === 201) {
|
|
41
|
-
oraWrapper.succeedSpinner(
|
|
42
|
-
startUploadSpinner,
|
|
43
|
-
i18n.__('uploadingScanSuccessful')
|
|
44
|
-
)
|
|
45
|
-
if (config.verbose) {
|
|
46
|
-
console.log(i18n.__('responseMessage', res.body))
|
|
47
|
-
}
|
|
48
|
-
return res.body.id
|
|
49
|
-
} else {
|
|
50
|
-
if (config.debug) {
|
|
51
|
-
console.log(res.statusCode)
|
|
52
|
-
console.log(config)
|
|
53
|
-
}
|
|
54
|
-
oraWrapper.failSpinner(
|
|
55
|
-
startUploadSpinner,
|
|
56
|
-
i18n.__('uploadingScanFail')
|
|
57
|
-
)
|
|
58
|
-
if (res.statusCode === 403) {
|
|
59
|
-
console.log(i18n.__('permissionsError'))
|
|
60
|
-
}
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
.catch(err => {
|
|
65
|
-
console.log(err)
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const formatScanOutput = (overview, results) => {
|
|
71
|
-
console.log()
|
|
72
|
-
//check for no vulnerabilities and show a different message
|
|
73
|
-
|
|
74
|
-
if (results.content.length === 0) {
|
|
75
|
-
console.log(i18n.__('scanNoVulnerabilitiesFound'))
|
|
76
|
-
} else {
|
|
77
|
-
console.log(chalk.bold('Here are your top priorities to fix'))
|
|
78
|
-
console.log()
|
|
79
|
-
|
|
80
|
-
const groups = getGroups(results.content)
|
|
81
|
-
groups.forEach(entry => {
|
|
82
|
-
console.log(
|
|
83
|
-
chalk.bold(
|
|
84
|
-
`${entry.severity} | ${entry.ruleId} (${entry.lineInfoSet.size})`
|
|
85
|
-
)
|
|
86
|
-
)
|
|
87
|
-
let count = 1
|
|
88
|
-
entry.lineInfoSet.forEach(lineInfo => {
|
|
89
|
-
console.log(`\t ${count}. ${lineInfo}`)
|
|
90
|
-
count++
|
|
91
|
-
})
|
|
92
|
-
console.log(chalk.bold('How to fix:'))
|
|
93
|
-
console.log(entry.recommendation)
|
|
94
|
-
console.log()
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const totalVulnerabilities =
|
|
98
|
-
overview.critical +
|
|
99
|
-
overview.high +
|
|
100
|
-
overview.medium +
|
|
101
|
-
overview.low +
|
|
102
|
-
overview.note
|
|
103
|
-
|
|
104
|
-
console.log(chalk.bold(`Found ${totalVulnerabilities} vulnerabilities`))
|
|
105
|
-
console.log(
|
|
106
|
-
i18n.__(
|
|
107
|
-
'foundDetailedVulnerabilities',
|
|
108
|
-
overview.critical,
|
|
109
|
-
overview.high,
|
|
110
|
-
overview.medium,
|
|
111
|
-
overview.low,
|
|
112
|
-
overview.note
|
|
113
|
-
)
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const getGroups = content => {
|
|
119
|
-
const groupTypeSet = new Set(content.map(({ ruleId }) => ruleId))
|
|
120
|
-
let groupTypeResults = []
|
|
121
|
-
groupTypeSet.forEach(groupName => {
|
|
122
|
-
let groupResultsObj = {
|
|
123
|
-
ruleId: groupName,
|
|
124
|
-
lineInfoSet: new Set(),
|
|
125
|
-
recommendation: '',
|
|
126
|
-
severity: ''
|
|
127
|
-
}
|
|
128
|
-
content.forEach(resultEntry => {
|
|
129
|
-
if (resultEntry.ruleId === groupName) {
|
|
130
|
-
groupResultsObj.severity = resultEntry.severity
|
|
131
|
-
groupResultsObj.recommendation = resultEntry.recommendation
|
|
132
|
-
? stripMustacheTags(resultEntry.recommendation)
|
|
133
|
-
: ''
|
|
134
|
-
groupResultsObj.lineInfoSet.add(formattedCodeLine(resultEntry))
|
|
135
|
-
}
|
|
136
|
-
})
|
|
137
|
-
groupTypeResults.push(groupResultsObj)
|
|
138
|
-
})
|
|
139
|
-
return groupTypeResults
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const formattedCodeLine = resultEntry => {
|
|
143
|
-
let lineUri = resultEntry.locations[0]?.physicalLocation.artifactLocation.uri
|
|
144
|
-
return lineUri + ' @ ' + setLineNumber(resultEntry)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const setLineNumber = resultEntry => {
|
|
148
|
-
return resultEntry.codeFlows?.[0]?.threadFlows[0]?.locations[0]?.location
|
|
149
|
-
?.physicalLocation?.region?.startLine
|
|
150
|
-
? resultEntry.codeFlows[0]?.threadFlows[0]?.locations[0]?.location
|
|
151
|
-
?.physicalLocation?.region?.startLine
|
|
152
|
-
: resultEntry.locations[0]?.physicalLocation?.region?.startLine
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
module.exports = {
|
|
156
|
-
sendScan: sendScan,
|
|
157
|
-
getGroups: getGroups,
|
|
158
|
-
allowedFileTypes: allowedFileTypes,
|
|
159
|
-
isFileAllowed: isFileAllowed,
|
|
160
|
-
stripMustacheTags: stripMustacheTags,
|
|
161
|
-
formatScanOutput: formatScanOutput
|
|
162
|
-
}
|