@contrast/contrast 1.0.2 → 1.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.
- package/.prettierignore +4 -0
- package/README.md +24 -16
- package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
- package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +30 -13
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +25 -0
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +51 -237
- 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 +2 -14
- package/dist/commands/audit/auditConfig.js +8 -2
- package/dist/commands/audit/auditController.js +14 -5
- 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 +13 -27
- package/dist/commands/scan/sca/scaAnalysis.js +44 -0
- package/dist/common/HTTPClient.js +29 -26
- package/dist/common/errorHandling.js +15 -39
- package/dist/common/versionChecker.js +32 -0
- package/dist/constants/constants.js +16 -2
- package/dist/constants/lambda.js +3 -1
- package/dist/constants/locales.js +58 -48
- package/dist/constants.js +59 -3
- package/dist/index.js +48 -30
- package/dist/lambda/help.js +22 -14
- package/dist/lambda/lambda.js +6 -0
- package/dist/sbom/generateSbom.js +20 -0
- package/dist/scaAnalysis/common/formatMessage.js +11 -0
- package/dist/scaAnalysis/common/treeUpload.js +30 -0
- package/dist/scaAnalysis/java/analysis.js +116 -0
- package/dist/scaAnalysis/java/index.js +18 -0
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +326 -0
- package/dist/scan/autoDetection.js +46 -1
- package/dist/scan/fileUtils.js +73 -1
- package/dist/scan/formatScanOutput.js +212 -0
- package/dist/scan/help.js +6 -2
- package/dist/scan/models/groupedResultsModel.js +11 -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 +26 -101
- package/dist/scan/scanConfig.js +20 -1
- package/dist/scan/scanController.js +8 -4
- package/dist/scan/scanResults.js +8 -17
- package/dist/utils/getConfig.js +3 -0
- package/dist/utils/requestUtils.js +1 -1
- package/dist/utils/saveFile.js +19 -0
- package/package.json +3 -2
- package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
- package/src/audit/catalogueApplication/catalogueApplication.js +4 -16
- package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +41 -19
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +71 -0
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +105 -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 +2 -22
- package/src/commands/audit/auditConfig.ts +12 -3
- package/src/commands/audit/auditController.ts +21 -5
- package/src/commands/audit/processAudit.ts +3 -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 +15 -31
- package/src/commands/scan/sca/scaAnalysis.js +73 -0
- package/src/common/HTTPClient.js +42 -36
- package/src/common/errorHandling.ts +17 -48
- package/src/common/versionChecker.ts +41 -0
- package/src/constants/constants.js +17 -4
- package/src/constants/lambda.js +3 -1
- package/src/constants/locales.js +69 -63
- package/src/constants.js +66 -3
- package/src/index.ts +62 -36
- package/src/lambda/help.ts +22 -14
- package/src/lambda/lambda.ts +8 -0
- package/src/sbom/generateSbom.ts +17 -0
- package/src/scaAnalysis/common/formatMessage.js +10 -0
- package/src/scaAnalysis/common/treeUpload.js +34 -0
- package/src/scaAnalysis/java/analysis.js +159 -0
- package/src/scaAnalysis/java/index.js +21 -0
- package/src/scaAnalysis/java/javaBuildDepsParser.js +391 -0
- package/src/scan/autoDetection.js +54 -1
- package/src/scan/fileUtils.js +91 -1
- package/src/scan/formatScanOutput.ts +241 -0
- package/src/scan/help.js +6 -2
- package/src/scan/models/groupedResultsModel.ts +20 -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 +62 -0
- package/src/scan/scanConfig.js +26 -1
- package/src/scan/scanController.js +12 -4
- package/src/scan/scanResults.js +19 -17
- package/src/utils/getConfig.ts +12 -0
- 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/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 -167
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
const i18n = require('i18n')
|
|
2
|
-
const commonApi = require('../commonApi')
|
|
3
|
-
const commonReport = require('./commonReportingFunctions')
|
|
4
|
-
|
|
5
|
-
function displaySuccessMessageVulnerabilities() {
|
|
6
|
-
console.log(i18n.__('vulnerabilitiesSuccessMessage'))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const vulnerabilityReport = async (analysis, applicationId, config) => {
|
|
10
|
-
let depRiskReportCount = {}
|
|
11
|
-
if (analysis.language === 'NODE') {
|
|
12
|
-
depRiskReportCount = await commonReport.dependencyRiskReport(
|
|
13
|
-
analysis.node.packageJSON,
|
|
14
|
-
config
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
if (config['report']) {
|
|
18
|
-
const reportResponse = await commonReport.getReport(applicationId)
|
|
19
|
-
if (reportResponse !== undefined) {
|
|
20
|
-
const libraryVulnerabilityInput = createLibraryVulnerabilityInput(
|
|
21
|
-
reportResponse.reports
|
|
22
|
-
)
|
|
23
|
-
const libraryVulnerabilityResponse = await getLibraryVulnerabilities(
|
|
24
|
-
libraryVulnerabilityInput,
|
|
25
|
-
applicationId
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
const severity = config['cve_severity']
|
|
29
|
-
const id = applicationId
|
|
30
|
-
const name = config.applicationName
|
|
31
|
-
const hasSomeVulnerabilitiesReported = formatVulnerabilityOutput(
|
|
32
|
-
libraryVulnerabilityResponse,
|
|
33
|
-
severity,
|
|
34
|
-
id,
|
|
35
|
-
name,
|
|
36
|
-
depRiskReportCount,
|
|
37
|
-
config
|
|
38
|
-
)
|
|
39
|
-
commonReport.analyseReportOptions(hasSomeVulnerabilitiesReported)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const createLibraryVulnerabilityInput = report => {
|
|
45
|
-
const language = Object.keys(report[0].report)[0]
|
|
46
|
-
const reportTree = report[0].report[language].dependencyTree
|
|
47
|
-
const libraries = reportTree[Object.keys(reportTree)[0]]
|
|
48
|
-
|
|
49
|
-
let gav = []
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
for (const key of Object.keys(libraries)) {
|
|
52
|
-
gav.push({
|
|
53
|
-
name: libraries[key].name,
|
|
54
|
-
group: libraries[key].group,
|
|
55
|
-
version: libraries[key].resolved
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
name_group_versions: gav,
|
|
61
|
-
language: language.toUpperCase()
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const oldCountSeverity = vulnerableLibraries => {
|
|
66
|
-
const severityCount = {
|
|
67
|
-
critical: 0,
|
|
68
|
-
high: 0,
|
|
69
|
-
medium: 0,
|
|
70
|
-
low: 0
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
vulnerableLibraries.forEach(lib => {
|
|
74
|
-
lib.vulns.forEach(vuln => {
|
|
75
|
-
if (vuln.severity_code === 'HIGH') {
|
|
76
|
-
severityCount['high'] += 1
|
|
77
|
-
} else if (vuln.severity_code === 'MEDIUM') {
|
|
78
|
-
severityCount['medium'] += 1
|
|
79
|
-
} else if (vuln.severity_code === 'LOW') {
|
|
80
|
-
severityCount['low'] += 1
|
|
81
|
-
} else if (vuln.severity_code === 'CRITICAL') {
|
|
82
|
-
severityCount['critical'] += 1
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
return severityCount
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const parseVulnerabilites = libraryVulnerabilityResponse => {
|
|
90
|
-
let parsedVulnerabilites = {}
|
|
91
|
-
let vulnName = libraryVulnerabilityResponse.libraries
|
|
92
|
-
for (let x in vulnName) {
|
|
93
|
-
let vuln = vulnName[x].vulns
|
|
94
|
-
if (vuln.length > 0) {
|
|
95
|
-
let libname =
|
|
96
|
-
vulnName[x].group +
|
|
97
|
-
'/' +
|
|
98
|
-
vulnName[x].file_name +
|
|
99
|
-
'@' +
|
|
100
|
-
vulnName[x].file_version
|
|
101
|
-
parsedVulnerabilites[libname] = vulnName[x].vulns
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return parsedVulnerabilites
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const formatVulnerabilityOutput = (
|
|
108
|
-
libraryVulnerabilityResponse,
|
|
109
|
-
severity,
|
|
110
|
-
id,
|
|
111
|
-
name,
|
|
112
|
-
depRiskReportCount,
|
|
113
|
-
config
|
|
114
|
-
) => {
|
|
115
|
-
let vulnerableLibraries = libraryVulnerabilityResponse.libraries.filter(
|
|
116
|
-
data => {
|
|
117
|
-
return data.vulns.length > 0
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
const numberOfVulnerableLibraries = vulnerableLibraries.length
|
|
122
|
-
let numberOfCves = 0
|
|
123
|
-
vulnerableLibraries.forEach(lib => (numberOfCves += lib.vulns.length))
|
|
124
|
-
commonReport.createLibraryHeader(
|
|
125
|
-
id,
|
|
126
|
-
numberOfVulnerableLibraries,
|
|
127
|
-
numberOfCves,
|
|
128
|
-
name
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
const severityCount = oldCountSeverity(vulnerableLibraries)
|
|
132
|
-
|
|
133
|
-
// parse so filter code will work for both new (ignore dev dep) and current report
|
|
134
|
-
let vulnerabilities = parseVulnerabilites(libraryVulnerabilityResponse)
|
|
135
|
-
let filteredVulns = commonReport.filterVulnerabilitiesBySeverity(
|
|
136
|
-
severity,
|
|
137
|
-
vulnerabilities
|
|
138
|
-
)
|
|
139
|
-
let hasSomeVulnerabilitiesReported
|
|
140
|
-
hasSomeVulnerabilitiesReported = commonReport.printVulnerabilityResponse(
|
|
141
|
-
severity,
|
|
142
|
-
filteredVulns,
|
|
143
|
-
vulnerabilities
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
console.log(
|
|
147
|
-
'\n **************************' +
|
|
148
|
-
` Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVE's ` +
|
|
149
|
-
'************************** '
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
if (depRiskReportCount && depRiskReportCount.scopedCount === 0) {
|
|
153
|
-
console.log(' No private libraries that are not scoped detected')
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
console.log(
|
|
157
|
-
' \n Please go to the Contrast UI to view your dependency tree: \n' +
|
|
158
|
-
` \n ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`
|
|
159
|
-
)
|
|
160
|
-
return [hasSomeVulnerabilitiesReported, numberOfCves, severityCount]
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const getLibraryVulnerabilities = async (input, applicationId) => {
|
|
164
|
-
const requestBody = input
|
|
165
|
-
const addParams = agent.getAdditionalParams()
|
|
166
|
-
const userParams = await util.getParams(applicationId)
|
|
167
|
-
const protocol = getValidHost(userParams.host)
|
|
168
|
-
const client = commonApi.getHttpClient(userParams, protocol, addParams)
|
|
169
|
-
|
|
170
|
-
return client
|
|
171
|
-
.getLibraryVulnerabilities(requestBody, userParams)
|
|
172
|
-
.then(res => {
|
|
173
|
-
if (res.statusCode === 200) {
|
|
174
|
-
displaySuccessMessageVulnerabilities()
|
|
175
|
-
return res.body
|
|
176
|
-
} else {
|
|
177
|
-
handleResponseErrors(res, 'vulnerabilities')
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
.catch(err => {
|
|
181
|
-
console.log(err)
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
module.exports = {
|
|
186
|
-
vulnerabilityReport: vulnerabilityReport,
|
|
187
|
-
getLibraryVulnerabilities: getLibraryVulnerabilities,
|
|
188
|
-
formatVulnerabilityOutput: formatVulnerabilityOutput,
|
|
189
|
-
createLibraryVulnerabilityInput: createLibraryVulnerabilityInput
|
|
190
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import latestVersion from 'latest-version'
|
|
2
|
-
import { APP_VERSION } from '../constants/constants'
|
|
3
|
-
import boxen from 'boxen'
|
|
4
|
-
import chalk from 'chalk'
|
|
5
|
-
import semver from 'semver'
|
|
6
|
-
|
|
7
|
-
export default async function findLatestCLIVersion() {
|
|
8
|
-
const latestCLIVersion = await latestVersion('@contrast/contrast')
|
|
9
|
-
|
|
10
|
-
if (semver.lt(APP_VERSION, latestCLIVersion)) {
|
|
11
|
-
const updateAvailableMessage = `Update available ${chalk.yellow(
|
|
12
|
-
APP_VERSION
|
|
13
|
-
)} → ${chalk.green(latestCLIVersion)}`
|
|
14
|
-
|
|
15
|
-
const updateAvailableCommand = `Run ${chalk.cyan(
|
|
16
|
-
'npm i @contrast/contrast'
|
|
17
|
-
)} to update`
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
20
|
-
boxen(`${updateAvailableMessage}\n${updateAvailableCommand}`, {
|
|
21
|
-
margin: 1,
|
|
22
|
-
padding: 1,
|
|
23
|
-
align: 'center'
|
|
24
|
-
})
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/scan/scan.js
DELETED
|
@@ -1,167 +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
|
-
}
|
|
62
|
-
console.log(i18n.__('genericServiceError', res.statusCode))
|
|
63
|
-
process.exit(1)
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
.catch(err => {
|
|
67
|
-
console.log(err)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const formatScanOutput = (overview, results) => {
|
|
73
|
-
console.log()
|
|
74
|
-
|
|
75
|
-
if (results.content.length === 0) {
|
|
76
|
-
console.log(i18n.__('scanNoVulnerabilitiesFound'))
|
|
77
|
-
} else {
|
|
78
|
-
let message =
|
|
79
|
-
overview.critical || overview.high
|
|
80
|
-
? 'Here are your top priorities to fix'
|
|
81
|
-
: "No major issues, here's what we found"
|
|
82
|
-
console.log(chalk.bold(message))
|
|
83
|
-
console.log()
|
|
84
|
-
|
|
85
|
-
const groups = getGroups(results.content)
|
|
86
|
-
groups.forEach(entry => {
|
|
87
|
-
console.log(
|
|
88
|
-
chalk.bold(
|
|
89
|
-
`${entry.severity} | ${entry.ruleId} (${entry.lineInfoSet.size})`
|
|
90
|
-
)
|
|
91
|
-
)
|
|
92
|
-
let count = 1
|
|
93
|
-
entry.lineInfoSet.forEach(lineInfo => {
|
|
94
|
-
console.log(`\t ${count}. ${lineInfo}`)
|
|
95
|
-
count++
|
|
96
|
-
})
|
|
97
|
-
console.log(chalk.bold('How to fix:'))
|
|
98
|
-
console.log(entry.recommendation)
|
|
99
|
-
console.log()
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const totalVulnerabilities =
|
|
103
|
-
overview.critical +
|
|
104
|
-
overview.high +
|
|
105
|
-
overview.medium +
|
|
106
|
-
overview.low +
|
|
107
|
-
overview.note
|
|
108
|
-
|
|
109
|
-
console.log(chalk.bold(`Found ${totalVulnerabilities} vulnerabilities`))
|
|
110
|
-
console.log(
|
|
111
|
-
i18n.__(
|
|
112
|
-
'foundDetailedVulnerabilities',
|
|
113
|
-
overview.critical,
|
|
114
|
-
overview.high,
|
|
115
|
-
overview.medium,
|
|
116
|
-
overview.low,
|
|
117
|
-
overview.note
|
|
118
|
-
)
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const getGroups = content => {
|
|
124
|
-
const groupTypeSet = new Set(content.map(({ ruleId }) => ruleId))
|
|
125
|
-
let groupTypeResults = []
|
|
126
|
-
groupTypeSet.forEach(groupName => {
|
|
127
|
-
let groupResultsObj = {
|
|
128
|
-
ruleId: groupName,
|
|
129
|
-
lineInfoSet: new Set(),
|
|
130
|
-
recommendation: '',
|
|
131
|
-
severity: ''
|
|
132
|
-
}
|
|
133
|
-
content.forEach(resultEntry => {
|
|
134
|
-
if (resultEntry.ruleId === groupName) {
|
|
135
|
-
groupResultsObj.severity = resultEntry.severity
|
|
136
|
-
groupResultsObj.recommendation = resultEntry.recommendation
|
|
137
|
-
? stripMustacheTags(resultEntry.recommendation)
|
|
138
|
-
: 'No Recommendations Data Found'
|
|
139
|
-
groupResultsObj.lineInfoSet.add(formattedCodeLine(resultEntry))
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
groupTypeResults.push(groupResultsObj)
|
|
143
|
-
})
|
|
144
|
-
return groupTypeResults
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const formattedCodeLine = resultEntry => {
|
|
148
|
-
let lineUri = resultEntry.locations[0]?.physicalLocation.artifactLocation.uri
|
|
149
|
-
return lineUri + ' @ ' + setLineNumber(resultEntry)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const setLineNumber = resultEntry => {
|
|
153
|
-
return resultEntry.codeFlows?.[0]?.threadFlows[0]?.locations[0]?.location
|
|
154
|
-
?.physicalLocation?.region?.startLine
|
|
155
|
-
? resultEntry.codeFlows[0]?.threadFlows[0]?.locations[0]?.location
|
|
156
|
-
?.physicalLocation?.region?.startLine
|
|
157
|
-
: resultEntry.locations[0]?.physicalLocation?.region?.startLine
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
module.exports = {
|
|
161
|
-
sendScan: sendScan,
|
|
162
|
-
getGroups: getGroups,
|
|
163
|
-
allowedFileTypes: allowedFileTypes,
|
|
164
|
-
isFileAllowed: isFileAllowed,
|
|
165
|
-
stripMustacheTags: stripMustacheTags,
|
|
166
|
-
formatScanOutput: formatScanOutput
|
|
167
|
-
}
|