@contrast/contrast 1.0.3 → 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 +1 -0
- package/README.md +20 -14
- package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +2 -12
- 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/scan/processScan.js +4 -3
- package/dist/common/HTTPClient.js +19 -26
- package/dist/common/versionChecker.js +14 -12
- package/dist/constants/constants.js +1 -1
- package/dist/constants/lambda.js +3 -1
- package/dist/constants/locales.js +17 -10
- package/dist/constants.js +5 -1
- package/dist/index.js +2 -2
- package/dist/lambda/help.js +22 -14
- package/dist/lambda/lambda.js +6 -0
- 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/scan.js +90 -95
- package/dist/scan/scanConfig.js +1 -1
- package/dist/utils/getConfig.js +3 -0
- package/package.json +2 -2
- package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +2 -16
- 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/scan/processScan.js +4 -6
- package/src/common/HTTPClient.js +31 -38
- package/src/common/errorHandling.ts +0 -1
- package/src/common/versionChecker.ts +24 -22
- package/src/constants/constants.js +1 -1
- package/src/constants/lambda.js +3 -1
- package/src/constants/locales.js +20 -10
- package/src/constants.js +7 -1
- package/src/index.ts +2 -3
- package/src/lambda/help.ts +22 -14
- package/src/lambda/lambda.ts +8 -0
- 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/scan.ts +192 -0
- package/src/scan/scanConfig.js +1 -1
- package/src/scan/scanController.js +2 -0
- package/src/utils/getConfig.ts +10 -0
- package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
- package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
- 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/scan/scan.js +0 -195
package/src/scan/scan.js
DELETED
|
@@ -1,195 +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(/\$\$LINK_DELIM\$\$/g, '\n')
|
|
23
|
-
.replace(/\s+/g, ' ')
|
|
24
|
-
.trim()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const sendScan = async config => {
|
|
28
|
-
if (!isFileAllowed(config.file)) {
|
|
29
|
-
console.log(i18n.__('scanErrorFileMessage'))
|
|
30
|
-
process.exit(9)
|
|
31
|
-
} else {
|
|
32
|
-
fileUtils.checkFilePermissions(config.file)
|
|
33
|
-
const client = commonApi.getHttpClient(config)
|
|
34
|
-
|
|
35
|
-
const startUploadSpinner = oraWrapper.returnOra(i18n.__('uploadingScan'))
|
|
36
|
-
oraWrapper.startSpinner(startUploadSpinner)
|
|
37
|
-
|
|
38
|
-
return await client
|
|
39
|
-
.sendArtifact(config)
|
|
40
|
-
.then(res => {
|
|
41
|
-
if (res.statusCode === 201) {
|
|
42
|
-
oraWrapper.succeedSpinner(
|
|
43
|
-
startUploadSpinner,
|
|
44
|
-
i18n.__('uploadingScanSuccessful')
|
|
45
|
-
)
|
|
46
|
-
if (config.verbose) {
|
|
47
|
-
console.log(i18n.__('responseMessage', res.body))
|
|
48
|
-
}
|
|
49
|
-
return res.body.id
|
|
50
|
-
} else {
|
|
51
|
-
if (config.debug) {
|
|
52
|
-
console.log(res.statusCode)
|
|
53
|
-
console.log(config)
|
|
54
|
-
}
|
|
55
|
-
oraWrapper.failSpinner(
|
|
56
|
-
startUploadSpinner,
|
|
57
|
-
i18n.__('uploadingScanFail')
|
|
58
|
-
)
|
|
59
|
-
if (res.statusCode === 403) {
|
|
60
|
-
console.log(i18n.__('permissionsError'))
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
console.log(i18n.__('genericServiceError', res.statusCode))
|
|
64
|
-
process.exit(1)
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
.catch(err => {
|
|
68
|
-
console.log(err)
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const formatScanOutput = (overview, results) => {
|
|
74
|
-
console.log()
|
|
75
|
-
|
|
76
|
-
if (results.content.length === 0) {
|
|
77
|
-
console.log(i18n.__('scanNoVulnerabilitiesFound'))
|
|
78
|
-
} else {
|
|
79
|
-
let message =
|
|
80
|
-
overview.critical || overview.high
|
|
81
|
-
? 'Here are your top priorities to fix'
|
|
82
|
-
: "No major issues, here's what we found"
|
|
83
|
-
console.log(chalk.bold(message))
|
|
84
|
-
console.log()
|
|
85
|
-
|
|
86
|
-
const groups = getGroups(results.content)
|
|
87
|
-
groups.forEach(entry => {
|
|
88
|
-
console.log(
|
|
89
|
-
chalk.bold(
|
|
90
|
-
`${entry.severity} | ${entry.ruleId} (${entry.lineInfoSet.size})`
|
|
91
|
-
)
|
|
92
|
-
)
|
|
93
|
-
let count = 1
|
|
94
|
-
entry.lineInfoSet.forEach(lineInfo => {
|
|
95
|
-
console.log(`\t ${count}. ${lineInfo}`)
|
|
96
|
-
count++
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
if (entry?.cwe && entry?.cwe.length > 0) {
|
|
100
|
-
formatLinks('cwe', entry.cwe)
|
|
101
|
-
}
|
|
102
|
-
if (entry?.reference && entry?.reference.length > 0) {
|
|
103
|
-
formatLinks('reference', entry.reference)
|
|
104
|
-
}
|
|
105
|
-
if (entry?.owasp && entry?.owasp.length > 0) {
|
|
106
|
-
formatLinks('owasp', entry.owasp)
|
|
107
|
-
}
|
|
108
|
-
console.log(chalk.bold('How to fix:'))
|
|
109
|
-
console.log(entry.recommendation)
|
|
110
|
-
console.log()
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
const totalVulnerabilities =
|
|
114
|
-
overview.critical +
|
|
115
|
-
overview.high +
|
|
116
|
-
overview.medium +
|
|
117
|
-
overview.low +
|
|
118
|
-
overview.note
|
|
119
|
-
|
|
120
|
-
let vulMessage =
|
|
121
|
-
totalVulnerabilities === 1 ? `vulnerability` : `vulnerabilities`
|
|
122
|
-
console.log(chalk.bold(`Found ${totalVulnerabilities} ${vulMessage}`))
|
|
123
|
-
console.log(
|
|
124
|
-
i18n.__(
|
|
125
|
-
'foundDetailedVulnerabilities',
|
|
126
|
-
overview.critical,
|
|
127
|
-
overview.high,
|
|
128
|
-
overview.medium,
|
|
129
|
-
overview.low,
|
|
130
|
-
overview.note
|
|
131
|
-
)
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const formatLinks = (objName, entry) => {
|
|
137
|
-
console.log(chalk.bold(objName + ':'))
|
|
138
|
-
entry.forEach(link => {
|
|
139
|
-
console.log(link)
|
|
140
|
-
})
|
|
141
|
-
console.log()
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const getGroups = content => {
|
|
145
|
-
const groupTypeSet = new Set(content.map(({ ruleId }) => ruleId))
|
|
146
|
-
let groupTypeResults = []
|
|
147
|
-
groupTypeSet.forEach(groupName => {
|
|
148
|
-
let groupResultsObj = {
|
|
149
|
-
ruleId: groupName,
|
|
150
|
-
lineInfoSet: new Set(),
|
|
151
|
-
cwe: '',
|
|
152
|
-
owasp: '',
|
|
153
|
-
reference: '',
|
|
154
|
-
recommendation: '',
|
|
155
|
-
severity: ''
|
|
156
|
-
}
|
|
157
|
-
content.forEach(resultEntry => {
|
|
158
|
-
if (resultEntry.ruleId === groupName) {
|
|
159
|
-
groupResultsObj.severity = resultEntry.severity
|
|
160
|
-
groupResultsObj.cwe = resultEntry.cwe
|
|
161
|
-
groupResultsObj.owasp = resultEntry.owasp
|
|
162
|
-
groupResultsObj.reference = resultEntry.reference
|
|
163
|
-
groupResultsObj.recommendation = resultEntry.recommendation
|
|
164
|
-
? stripMustacheTags(resultEntry.recommendation)
|
|
165
|
-
: 'No Recommendations Data Found'
|
|
166
|
-
groupResultsObj.lineInfoSet.add(formattedCodeLine(resultEntry))
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
groupTypeResults.push(groupResultsObj)
|
|
170
|
-
})
|
|
171
|
-
return groupTypeResults
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const formattedCodeLine = resultEntry => {
|
|
175
|
-
let lineUri = resultEntry.locations[0]?.physicalLocation.artifactLocation.uri
|
|
176
|
-
return lineUri + ' @ ' + setLineNumber(resultEntry)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const setLineNumber = resultEntry => {
|
|
180
|
-
return resultEntry.codeFlows?.[0]?.threadFlows[0]?.locations[0]?.location
|
|
181
|
-
?.physicalLocation?.region?.startLine
|
|
182
|
-
? resultEntry.codeFlows[0]?.threadFlows[0]?.locations[0]?.location
|
|
183
|
-
?.physicalLocation?.region?.startLine
|
|
184
|
-
: resultEntry.locations[0]?.physicalLocation?.region?.startLine
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
module.exports = {
|
|
188
|
-
sendScan: sendScan,
|
|
189
|
-
getGroups: getGroups,
|
|
190
|
-
allowedFileTypes: allowedFileTypes,
|
|
191
|
-
isFileAllowed: isFileAllowed,
|
|
192
|
-
stripMustacheTags: stripMustacheTags,
|
|
193
|
-
formatScanOutput: formatScanOutput,
|
|
194
|
-
formatLinks: formatLinks
|
|
195
|
-
}
|