@contrast/contrast 2.0.2-beta.1 → 2.0.2-beta.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 +2 -1
- package/dist/assess/assessConfig.js +9 -0
- package/dist/assess/assessConfig.js.map +1 -0
- package/dist/assess/help.js +37 -0
- package/dist/assess/help.js.map +1 -0
- package/dist/assess/http/index.js +39 -0
- package/dist/assess/http/index.js.map +1 -0
- package/dist/assess/index.js +69 -0
- package/dist/assess/index.js.map +1 -0
- package/dist/assess/metadata/findYamlFile.js +59 -0
- package/dist/assess/metadata/findYamlFile.js.map +1 -0
- package/dist/assess/metadata/index.js +37 -0
- package/dist/assess/metadata/index.js.map +1 -0
- package/dist/assess/metadata/utils.js +159 -0
- package/dist/assess/metadata/utils.js.map +1 -0
- package/dist/assess/printing/index.js +11 -0
- package/dist/assess/printing/index.js.map +1 -0
- package/dist/assess/printing/utils.js +119 -0
- package/dist/assess/printing/utils.js.map +1 -0
- package/dist/audit/auditConfig.js +9 -0
- package/dist/audit/auditConfig.js.map +1 -0
- package/dist/{commands/audit → audit}/auditController.js +9 -13
- package/dist/audit/auditController.js.map +1 -0
- package/dist/audit/auditRequests.js +193 -0
- package/dist/audit/auditRequests.js.map +1 -0
- package/dist/audit/auditRequestsLegacy.js +63 -0
- package/dist/audit/auditRequestsLegacy.js.map +1 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +16 -29
- package/dist/audit/catalogueApplication/catalogueApplication.js.map +1 -0
- package/dist/audit/help.js +68 -0
- package/dist/audit/help.js.map +1 -0
- package/dist/audit/languageAnalysisEngine/commonApi.js +12 -14
- package/dist/audit/languageAnalysisEngine/commonApi.js.map +1 -0
- package/dist/audit/languageAnalysisEngine/filterProjectPath.js +2 -1
- package/dist/audit/languageAnalysisEngine/filterProjectPath.js.map +1 -0
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +9 -12
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js.map +1 -0
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +18 -30
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js.map +1 -0
- package/dist/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +9 -9
- package/dist/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js.map +1 -0
- package/dist/audit/processAudit.js +21 -0
- package/dist/audit/processAudit.js.map +1 -0
- package/dist/audit/report/commonReportingFunctions.js +33 -61
- package/dist/audit/report/commonReportingFunctions.js.map +1 -0
- package/dist/audit/report/models/reportGuidanceModel.js +2 -5
- package/dist/audit/report/models/reportGuidanceModel.js.map +1 -0
- package/dist/audit/report/models/reportLibraryModel.js +3 -7
- package/dist/audit/report/models/reportLibraryModel.js.map +1 -0
- package/dist/audit/report/models/reportListModel.js +4 -9
- package/dist/audit/report/models/reportListModel.js.map +1 -0
- package/dist/audit/report/models/reportOutputModel.js +4 -9
- package/dist/audit/report/models/reportOutputModel.js.map +1 -0
- package/dist/audit/report/models/reportSeverityModel.js +2 -5
- package/dist/audit/report/models/reportSeverityModel.js.map +1 -0
- package/dist/audit/report/models/severityCountModel.js +3 -5
- package/dist/audit/report/models/severityCountModel.js.map +1 -0
- package/dist/audit/report/reportingFeature.js +27 -55
- package/dist/audit/report/reportingFeature.js.map +1 -0
- package/dist/audit/report/utils/reportUtils.js +28 -59
- package/dist/audit/report/utils/reportUtils.js.map +1 -0
- package/dist/audit/save.js +14 -16
- package/dist/audit/save.js.map +1 -0
- package/dist/{commands/audit → audit}/saveFile.js +3 -6
- package/dist/audit/saveFile.js.map +1 -0
- package/dist/auth/auth.js +103 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/authRequests.js +18 -0
- package/dist/auth/authRequests.js.map +1 -0
- package/dist/cliConstants.js +48 -18
- package/dist/cliConstants.js.map +1 -0
- package/dist/commands/config/config.js +12 -13
- package/dist/commands/config/config.js.map +1 -0
- package/dist/commands/learn/learn.js +3 -6
- package/dist/commands/learn/learn.js.map +1 -0
- package/dist/commands/learn/processLearn.js +3 -6
- package/dist/commands/learn/processLearn.js.map +1 -0
- package/dist/common/HTTPClient.js +193 -94
- package/dist/common/HTTPClient.js.map +1 -0
- package/dist/{scan → common}/autoDetection.js +53 -36
- package/dist/common/autoDetection.js.map +1 -0
- package/dist/common/baseRequest.js +59 -23
- package/dist/common/baseRequest.js.map +1 -0
- package/dist/common/commonHelp.js +13 -13
- package/dist/common/commonHelp.js.map +1 -0
- package/dist/common/errorHandling.js +49 -63
- package/dist/common/errorHandling.js.map +1 -0
- package/dist/common/fail.js +6 -12
- package/dist/common/fail.js.map +1 -0
- package/dist/common/stringManipulations.js +8 -0
- package/dist/common/stringManipulations.js.map +1 -0
- package/dist/common/versionChecker.js +16 -19
- package/dist/common/versionChecker.js.map +1 -0
- package/dist/constants/constants.js +46 -65
- package/dist/constants/constants.js.map +1 -0
- package/dist/constants/lambda.js +8 -5
- package/dist/constants/lambda.js.map +1 -0
- package/dist/constants/locales.js +14 -10
- package/dist/constants/locales.js.map +1 -0
- package/dist/github/fingerprintConfig.js +10 -0
- package/dist/github/fingerprintConfig.js.map +1 -0
- package/dist/github/processFingerprint.js +25 -0
- package/dist/github/processFingerprint.js.map +1 -0
- package/dist/github/projectGroup.js +225 -0
- package/dist/github/projectGroup.js.map +1 -0
- package/dist/github/repoServices.js +91 -0
- package/dist/github/repoServices.js.map +1 -0
- package/dist/index.js +42 -39
- package/dist/index.js.map +1 -0
- package/dist/lambda/analytics.js +6 -9
- package/dist/lambda/analytics.js.map +1 -0
- package/dist/lambda/arn.js +6 -9
- package/dist/lambda/arn.js.map +1 -0
- package/dist/lambda/aws.js +29 -34
- package/dist/lambda/aws.js.map +1 -0
- package/dist/lambda/cliError.js +13 -41
- package/dist/lambda/cliError.js.map +1 -0
- package/dist/lambda/constants.js +3 -4
- package/dist/lambda/constants.js.map +1 -0
- package/dist/lambda/help.js +39 -44
- package/dist/lambda/help.js.map +1 -0
- package/dist/lambda/lambda.js +61 -65
- package/dist/lambda/lambda.js.map +1 -0
- package/dist/lambda/lambdaUtils.js +38 -32
- package/dist/lambda/lambdaUtils.js.map +1 -0
- package/dist/lambda/logUtils.js +21 -17
- package/dist/lambda/logUtils.js.map +1 -0
- package/dist/lambda/scanDetailCompletion.js +19 -25
- package/dist/lambda/scanDetailCompletion.js.map +1 -0
- package/dist/lambda/scanRequest.js +34 -41
- package/dist/lambda/scanRequest.js.map +1 -0
- package/dist/lambda/scanResults.js +8 -10
- package/dist/lambda/scanResults.js.map +1 -0
- package/dist/lambda/types.js +5 -7
- package/dist/lambda/types.js.map +1 -0
- package/dist/lambda/utils.js +33 -35
- package/dist/lambda/utils.js.map +1 -0
- package/dist/sbom/generateSbom.js +6 -10
- package/dist/sbom/generateSbom.js.map +1 -0
- package/dist/scaAnalysis/common/auditReport.js +8 -12
- package/dist/scaAnalysis/common/auditReport.js.map +1 -0
- package/dist/scaAnalysis/common/commonReportingFunctionsSca.js +26 -32
- package/dist/scaAnalysis/common/commonReportingFunctionsSca.js.map +1 -0
- package/dist/scaAnalysis/common/formatMessage.js +8 -17
- package/dist/scaAnalysis/common/formatMessage.js.map +1 -0
- package/dist/scaAnalysis/common/models/ScaReportModel.js +4 -9
- package/dist/scaAnalysis/common/models/ScaReportModel.js.map +1 -0
- package/dist/scaAnalysis/common/scaParserForGoAndJava.js +10 -9
- package/dist/scaAnalysis/common/scaParserForGoAndJava.js.map +1 -0
- package/dist/scaAnalysis/common/scaServicesUpload.js +59 -90
- package/dist/scaAnalysis/common/scaServicesUpload.js.map +1 -0
- package/dist/scaAnalysis/common/treeUpload.js +15 -25
- package/dist/scaAnalysis/common/treeUpload.js.map +1 -0
- package/dist/scaAnalysis/common/utils/reportUtilsSca.js +21 -29
- package/dist/scaAnalysis/common/utils/reportUtilsSca.js.map +1 -0
- package/dist/scaAnalysis/dotnet/analysis.js +12 -18
- package/dist/scaAnalysis/dotnet/analysis.js.map +1 -0
- package/dist/scaAnalysis/dotnet/index.js +4 -7
- package/dist/scaAnalysis/dotnet/index.js.map +1 -0
- package/dist/scaAnalysis/go/goAnalysis.js +8 -11
- package/dist/scaAnalysis/go/goAnalysis.js.map +1 -0
- package/dist/scaAnalysis/go/goParseDeps.js +9 -7
- package/dist/scaAnalysis/go/goParseDeps.js.map +1 -0
- package/dist/scaAnalysis/go/goReadDepFile.js +10 -8
- package/dist/scaAnalysis/go/goReadDepFile.js.map +1 -0
- package/dist/scaAnalysis/java/analysis.js +23 -20
- package/dist/scaAnalysis/java/analysis.js.map +1 -0
- package/dist/scaAnalysis/java/index.js +7 -10
- package/dist/scaAnalysis/java/index.js.map +1 -0
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +43 -43
- package/dist/scaAnalysis/java/javaBuildDepsParser.js.map +1 -0
- package/dist/scaAnalysis/javascript/analysis.js +16 -20
- package/dist/scaAnalysis/javascript/analysis.js.map +1 -0
- package/dist/scaAnalysis/javascript/index.js +17 -19
- package/dist/scaAnalysis/javascript/index.js.map +1 -0
- package/dist/scaAnalysis/javascript/scaServiceParser.js +8 -15
- package/dist/scaAnalysis/javascript/scaServiceParser.js.map +1 -0
- package/dist/scaAnalysis/legacy/legacyFlow.js +13 -15
- package/dist/scaAnalysis/legacy/legacyFlow.js.map +1 -0
- package/dist/scaAnalysis/php/analysis.js +15 -16
- package/dist/scaAnalysis/php/analysis.js.map +1 -0
- package/dist/scaAnalysis/php/index.js +5 -8
- package/dist/scaAnalysis/php/index.js.map +1 -0
- package/dist/scaAnalysis/php/phpNewServicesMapper.js +9 -12
- package/dist/scaAnalysis/php/phpNewServicesMapper.js.map +1 -0
- package/dist/scaAnalysis/processServicesFlow.js +86 -32
- package/dist/scaAnalysis/processServicesFlow.js.map +1 -0
- package/dist/scaAnalysis/python/analysis.js +16 -23
- package/dist/scaAnalysis/python/analysis.js.map +1 -0
- package/dist/scaAnalysis/python/index.js +4 -7
- package/dist/scaAnalysis/python/index.js.map +1 -0
- package/dist/scaAnalysis/repoMode/gradleParser.js +7 -13
- package/dist/scaAnalysis/repoMode/gradleParser.js.map +1 -0
- package/dist/scaAnalysis/repoMode/index.js +9 -12
- package/dist/scaAnalysis/repoMode/index.js.map +1 -0
- package/dist/scaAnalysis/repoMode/mavenParser.js +26 -14
- package/dist/scaAnalysis/repoMode/mavenParser.js.map +1 -0
- package/dist/scaAnalysis/ruby/analysis.js +32 -46
- package/dist/scaAnalysis/ruby/analysis.js.map +1 -0
- package/dist/scaAnalysis/ruby/index.js +5 -8
- package/dist/scaAnalysis/ruby/index.js.map +1 -0
- package/dist/scaAnalysis/scaAnalysis.js +49 -51
- package/dist/scaAnalysis/scaAnalysis.js.map +1 -0
- package/dist/scan/fileUtils.js +36 -40
- package/dist/scan/fileUtils.js.map +1 -0
- package/dist/scan/formatScanOutput.js +47 -61
- package/dist/scan/formatScanOutput.js.map +1 -0
- package/dist/scan/help.js +8 -11
- package/dist/scan/help.js.map +1 -0
- package/dist/scan/models/groupedResultsModel.js +2 -5
- package/dist/scan/models/groupedResultsModel.js.map +1 -0
- package/dist/scan/models/resultContentModel.js +2 -2
- package/dist/scan/models/resultContentModel.js.map +1 -0
- package/dist/scan/models/scanResultsModel.js +2 -5
- package/dist/scan/models/scanResultsModel.js.map +1 -0
- package/dist/scan/populateProjectIdAndProjectName.js +22 -60
- package/dist/scan/populateProjectIdAndProjectName.js.map +1 -0
- package/dist/scan/processScan.js +28 -0
- package/dist/scan/processScan.js.map +1 -0
- package/dist/scan/saveResults.js +3 -6
- package/dist/scan/saveResults.js.map +1 -0
- package/dist/scan/scan.js +33 -53
- package/dist/scan/scan.js.map +1 -0
- package/dist/scan/scanConfig.js +14 -12
- package/dist/scan/scanConfig.js.map +1 -0
- package/dist/scan/scanController.js +19 -21
- package/dist/scan/scanController.js.map +1 -0
- package/dist/scan/scanRequests.js +86 -0
- package/dist/scan/scanRequests.js.map +1 -0
- package/dist/scan/scanResults.js +26 -72
- package/dist/scan/scanResults.js.map +1 -0
- package/dist/telemetry/telemetry.js +29 -59
- package/dist/telemetry/telemetry.js.map +1 -0
- package/dist/utils/capabilities.js +2 -1
- package/dist/utils/capabilities.js.map +1 -0
- package/dist/utils/commonApi.js +58 -50
- package/dist/utils/commonApi.js.map +1 -0
- package/dist/utils/filterProjectPath.js +2 -1
- package/dist/utils/filterProjectPath.js.map +1 -0
- package/dist/utils/generalAPI.js +11 -33
- package/dist/utils/generalAPI.js.map +1 -0
- package/dist/utils/getConfig.js +8 -13
- package/dist/utils/getConfig.js.map +1 -0
- package/dist/utils/oraWrapper.js +7 -14
- package/dist/utils/oraWrapper.js.map +1 -0
- package/dist/utils/paramsUtil/commandlineParams.js +2 -5
- package/dist/utils/paramsUtil/commandlineParams.js.map +1 -0
- package/dist/utils/paramsUtil/configStoreParams.js +9 -10
- package/dist/utils/paramsUtil/configStoreParams.js.map +1 -0
- package/dist/utils/paramsUtil/envVariableParams.js +2 -3
- package/dist/utils/paramsUtil/envVariableParams.js.map +1 -0
- package/dist/utils/paramsUtil/paramHandler.js +12 -13
- package/dist/utils/paramsUtil/paramHandler.js.map +1 -0
- package/dist/utils/parsedCLIOptions.js +4 -7
- package/dist/utils/parsedCLIOptions.js.map +1 -0
- package/dist/utils/requestUtils.js +7 -13
- package/dist/utils/requestUtils.js.map +1 -0
- package/dist/utils/saveFile.js +8 -11
- package/dist/utils/saveFile.js.map +1 -0
- package/dist/utils/validationCheck.js +5 -11
- package/dist/utils/validationCheck.js.map +1 -0
- package/package.json +39 -48
- package/.prettierignore +0 -1
- package/bin/contrast.js +0 -2
- package/dist/audit/languageAnalysisEngine/util/requestUtils.js +0 -14
- package/dist/commands/audit/auditConfig.js +0 -12
- package/dist/commands/audit/help.js +0 -70
- package/dist/commands/audit/processAudit.js +0 -24
- package/dist/commands/auth/auth.js +0 -120
- package/dist/commands/github/fingerprintConfig.js +0 -13
- package/dist/commands/github/processFingerprint.js +0 -28
- package/dist/commands/github/projectGroup.js +0 -254
- package/dist/commands/github/repoServices.js +0 -108
- package/dist/commands/scan/processScan.js +0 -31
- package/dist/lambda/__mocks__/aws.js +0 -21
- package/dist/lambda/__mocks__/lambdaConfig.json +0 -42
- package/src/audit/catalogueApplication/catalogueApplication.js +0 -51
- package/src/audit/languageAnalysisEngine/commonApi.js +0 -20
- package/src/audit/languageAnalysisEngine/filterProjectPath.js +0 -21
- package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +0 -36
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +0 -57
- package/src/audit/languageAnalysisEngine/util/requestUtils.js +0 -17
- package/src/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +0 -63
- package/src/audit/report/commonReportingFunctions.js +0 -412
- package/src/audit/report/models/reportGuidanceModel.ts +0 -5
- package/src/audit/report/models/reportLibraryModel.ts +0 -30
- package/src/audit/report/models/reportListModel.ts +0 -49
- package/src/audit/report/models/reportOutputModel.ts +0 -29
- package/src/audit/report/models/reportSeverityModel.ts +0 -18
- package/src/audit/report/models/severityCountModel.ts +0 -22
- package/src/audit/report/reportingFeature.ts +0 -110
- package/src/audit/report/utils/reportUtils.ts +0 -165
- package/src/audit/save.js +0 -67
- package/src/cliConstants.js +0 -522
- package/src/commands/audit/auditConfig.js +0 -18
- package/src/commands/audit/auditController.js +0 -50
- package/src/commands/audit/help.js +0 -72
- package/src/commands/audit/processAudit.js +0 -34
- package/src/commands/audit/saveFile.js +0 -15
- package/src/commands/auth/auth.js +0 -146
- package/src/commands/config/config.js +0 -41
- package/src/commands/github/fingerprintConfig.js +0 -19
- package/src/commands/github/processFingerprint.js +0 -37
- package/src/commands/github/projectGroup.js +0 -294
- package/src/commands/github/repoServices.js +0 -122
- package/src/commands/learn/learn.js +0 -10
- package/src/commands/learn/processLearn.js +0 -13
- package/src/commands/scan/processScan.js +0 -42
- package/src/common/HTTPClient.js +0 -775
- package/src/common/baseRequest.ts +0 -83
- package/src/common/commonHelp.js +0 -53
- package/src/common/errorHandling.js +0 -157
- package/src/common/fail.js +0 -79
- package/src/common/versionChecker.js +0 -75
- package/src/constants/constants.js +0 -71
- package/src/constants/lambda.js +0 -85
- package/src/constants/locales.js +0 -365
- package/src/index.ts +0 -142
- package/src/lambda/__mocks__/aws.ts +0 -32
- package/src/lambda/__mocks__/lambdaConfig.json +0 -42
- package/src/lambda/analytics.ts +0 -9
- package/src/lambda/arn.ts +0 -33
- package/src/lambda/aws.ts +0 -248
- package/src/lambda/cliError.ts +0 -72
- package/src/lambda/constants.ts +0 -11
- package/src/lambda/help.ts +0 -92
- package/src/lambda/lambda.ts +0 -230
- package/src/lambda/lambdaUtils.ts +0 -111
- package/src/lambda/logUtils.ts +0 -64
- package/src/lambda/scanDetailCompletion.ts +0 -78
- package/src/lambda/scanRequest.ts +0 -169
- package/src/lambda/scanResults.ts +0 -29
- package/src/lambda/types.ts +0 -36
- package/src/lambda/utils.ts +0 -188
- package/src/sbom/generateSbom.ts +0 -45
- package/src/scaAnalysis/common/auditReport.js +0 -59
- package/src/scaAnalysis/common/commonReportingFunctionsSca.js +0 -276
- package/src/scaAnalysis/common/formatMessage.js +0 -67
- package/src/scaAnalysis/common/models/ScaReportModel.ts +0 -81
- package/src/scaAnalysis/common/scaParserForGoAndJava.js +0 -41
- package/src/scaAnalysis/common/scaServicesUpload.js +0 -155
- package/src/scaAnalysis/common/treeUpload.js +0 -51
- package/src/scaAnalysis/common/utils/reportUtilsSca.ts +0 -123
- package/src/scaAnalysis/dotnet/analysis.js +0 -72
- package/src/scaAnalysis/dotnet/index.js +0 -11
- package/src/scaAnalysis/go/goAnalysis.js +0 -26
- package/src/scaAnalysis/go/goParseDeps.js +0 -203
- package/src/scaAnalysis/go/goReadDepFile.js +0 -34
- package/src/scaAnalysis/java/analysis.js +0 -148
- package/src/scaAnalysis/java/index.js +0 -29
- package/src/scaAnalysis/java/javaBuildDepsParser.js +0 -439
- package/src/scaAnalysis/javascript/analysis.js +0 -111
- package/src/scaAnalysis/javascript/index.js +0 -104
- package/src/scaAnalysis/javascript/scaServiceParser.js +0 -151
- package/src/scaAnalysis/legacy/legacyFlow.js +0 -43
- package/src/scaAnalysis/php/analysis.js +0 -78
- package/src/scaAnalysis/php/index.js +0 -28
- package/src/scaAnalysis/php/phpNewServicesMapper.js +0 -77
- package/src/scaAnalysis/processServicesFlow.js +0 -119
- package/src/scaAnalysis/python/analysis.js +0 -93
- package/src/scaAnalysis/python/index.js +0 -16
- package/src/scaAnalysis/repoMode/gradleParser.js +0 -88
- package/src/scaAnalysis/repoMode/index.js +0 -21
- package/src/scaAnalysis/repoMode/mavenParser.js +0 -139
- package/src/scaAnalysis/ruby/analysis.js +0 -413
- package/src/scaAnalysis/ruby/index.js +0 -16
- package/src/scaAnalysis/scaAnalysis.js +0 -171
- package/src/scan/autoDetection.js +0 -175
- package/src/scan/fileUtils.js +0 -206
- package/src/scan/formatScanOutput.ts +0 -225
- package/src/scan/help.js +0 -56
- package/src/scan/models/groupedResultsModel.ts +0 -20
- package/src/scan/models/resultContentModel.ts +0 -86
- package/src/scan/models/scanResultsModel.ts +0 -55
- package/src/scan/populateProjectIdAndProjectName.js +0 -73
- package/src/scan/saveResults.js +0 -14
- package/src/scan/scan.ts +0 -68
- package/src/scan/scanConfig.js +0 -58
- package/src/scan/scanController.js +0 -98
- package/src/scan/scanResults.js +0 -171
- package/src/telemetry/telemetry.ts +0 -154
- package/src/utils/capabilities.js +0 -12
- package/src/utils/commonApi.js +0 -103
- package/src/utils/filterProjectPath.js +0 -25
- package/src/utils/generalAPI.js +0 -52
- package/src/utils/getConfig.ts +0 -34
- package/src/utils/oraWrapper.js +0 -29
- package/src/utils/paramsUtil/commandlineParams.js +0 -12
- package/src/utils/paramsUtil/configStoreParams.js +0 -19
- package/src/utils/paramsUtil/envVariableParams.js +0 -10
- package/src/utils/paramsUtil/paramHandler.js +0 -38
- package/src/utils/parsedCLIOptions.js +0 -32
- package/src/utils/requestUtils.js +0 -29
- package/src/utils/saveFile.js +0 -20
- package/src/utils/validationCheck.js +0 -39
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import logSymbols from 'log-symbols'
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import i18n from 'i18n'
|
|
4
|
-
import {
|
|
5
|
-
FunctionConfiguration,
|
|
6
|
-
ListFunctionsCommand
|
|
7
|
-
} from '@aws-sdk/client-lambda'
|
|
8
|
-
import { groupBy, sortBy } from 'lodash'
|
|
9
|
-
import { getLambdaClient } from './aws'
|
|
10
|
-
import ora from '../utils/oraWrapper'
|
|
11
|
-
import { LambdaOptions } from './lambda'
|
|
12
|
-
import { log, getReadableFileSize } from './logUtils'
|
|
13
|
-
|
|
14
|
-
type RuntimeLanguage = 'java' | 'python' | 'node' | 'dotnet'
|
|
15
|
-
|
|
16
|
-
type FilterLambdas = {
|
|
17
|
-
runtimes: RuntimeLanguage[]
|
|
18
|
-
filterText?: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @param fucntions all user lambdas
|
|
24
|
-
* @param options filter values: runtime / free text
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
const printAvailableLambdas = (
|
|
28
|
-
fucntions: FunctionConfiguration[] = [],
|
|
29
|
-
options: FilterLambdas
|
|
30
|
-
) => {
|
|
31
|
-
const { runtimes, filterText = '' } = options
|
|
32
|
-
const searchValue = filterText?.trim().toLowerCase()
|
|
33
|
-
|
|
34
|
-
const filteredFunctions = fucntions
|
|
35
|
-
.filter(f => runtimes.some(r => f.Runtime?.includes(r)))
|
|
36
|
-
.filter(f => f.FunctionName?.toLowerCase().includes(searchValue))
|
|
37
|
-
log(
|
|
38
|
-
i18n.__('availableForScan', {
|
|
39
|
-
icon: logSymbols.success,
|
|
40
|
-
count: `${filteredFunctions.length}`
|
|
41
|
-
})
|
|
42
|
-
)
|
|
43
|
-
const groupByRuntime = groupBy(filteredFunctions, 'Runtime')
|
|
44
|
-
|
|
45
|
-
Object.entries(groupByRuntime).forEach(([runtime, arr]) => {
|
|
46
|
-
const sorted = sortBy(arr, 'FunctionName')
|
|
47
|
-
const count = `${arr.filter(a => a.Runtime === runtime).length}`
|
|
48
|
-
|
|
49
|
-
log(chalk.gray(i18n.__('runtimeCount', { runtime, count })))
|
|
50
|
-
sorted.forEach(f => {
|
|
51
|
-
const size = f.CodeSize ? getReadableFileSize(f.CodeSize) : ''
|
|
52
|
-
log(`${f.FunctionName} ${chalk.gray(`(${size})`)}`)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
* @param lambdaOptions to create lambdaClient
|
|
60
|
-
* @returns list of all user lambdas that availbale to scan
|
|
61
|
-
*/
|
|
62
|
-
const getAllLambdas = async (lambdaOptions: LambdaOptions) => {
|
|
63
|
-
const functions: FunctionConfiguration[] = []
|
|
64
|
-
const spinner = ora.returnOra(i18n.__('loadingFunctionList'))
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const client = getLambdaClient(lambdaOptions)
|
|
68
|
-
const command = new ListFunctionsCommand({})
|
|
69
|
-
|
|
70
|
-
ora.startSpinner(spinner)
|
|
71
|
-
|
|
72
|
-
const data = await client.send(command)
|
|
73
|
-
const { Functions } = data
|
|
74
|
-
let { NextMarker } = data
|
|
75
|
-
|
|
76
|
-
if (!Functions?.length) {
|
|
77
|
-
ora.failSpinner(spinner, i18n.__('noFunctionsFound'))
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
functions.push(...Functions)
|
|
82
|
-
spinner.text = i18n.__('functionsFound', { count: `${functions.length}` })
|
|
83
|
-
|
|
84
|
-
// pagination on functions
|
|
85
|
-
while (NextMarker) {
|
|
86
|
-
command.input.Marker = NextMarker
|
|
87
|
-
const chank = await client.send(command)
|
|
88
|
-
|
|
89
|
-
if (chank.Functions?.length) {
|
|
90
|
-
functions.push(...chank.Functions)
|
|
91
|
-
spinner.text = i18n.__('functionsFound', {
|
|
92
|
-
count: `${functions.length}`
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
NextMarker = chank.NextMarker
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
ora.succeedSpinner(
|
|
100
|
-
spinner,
|
|
101
|
-
i18n.__('functionsFound', { count: `${functions.length}` })
|
|
102
|
-
)
|
|
103
|
-
} catch (error) {
|
|
104
|
-
ora.failSpinner(spinner, i18n.__('failedToLoadFunctions'))
|
|
105
|
-
throw error
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return functions
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { getAllLambdas, printAvailableLambdas }
|
package/src/lambda/logUtils.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import util from 'util'
|
|
3
|
-
|
|
4
|
-
interface logStyles {
|
|
5
|
-
bold?: boolean
|
|
6
|
-
italic?: boolean
|
|
7
|
-
underline?: boolean
|
|
8
|
-
strikethrough?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const log = (message: string | number, styles?: logStyles) => {
|
|
12
|
-
let chalkFunction = chalk.reset
|
|
13
|
-
|
|
14
|
-
if (styles?.bold) {
|
|
15
|
-
chalkFunction = chalk.bold
|
|
16
|
-
} else if (styles?.italic) {
|
|
17
|
-
chalkFunction = chalk.italic
|
|
18
|
-
} else if (styles?.underline) {
|
|
19
|
-
chalkFunction = chalk.underline
|
|
20
|
-
} else if (styles?.strikethrough) {
|
|
21
|
-
chalkFunction = chalk.strikethrough
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
console.log(styles ? chalkFunction(message) : message)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param obj any json object or string
|
|
30
|
-
* @param depth determines how levels it will recurse to show the json
|
|
31
|
-
*/
|
|
32
|
-
const prettyPrintJson = (obj: string | any, depth: number | null = null) => {
|
|
33
|
-
if (!obj) {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let objToPrint = obj
|
|
38
|
-
|
|
39
|
-
if (typeof obj === 'string') {
|
|
40
|
-
objToPrint = JSON.parse(obj)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
console.log(util.inspect(objToPrint, { colors: true, depth }))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @param fileSizeInBytes
|
|
49
|
-
*
|
|
50
|
-
* @returns human readable format
|
|
51
|
-
*/
|
|
52
|
-
const getReadableFileSize = (fileSizeInBytes: number) => {
|
|
53
|
-
let i = -1
|
|
54
|
-
const byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']
|
|
55
|
-
|
|
56
|
-
do {
|
|
57
|
-
fileSizeInBytes = fileSizeInBytes / 1024
|
|
58
|
-
i++
|
|
59
|
-
} while (fileSizeInBytes > 1024)
|
|
60
|
-
|
|
61
|
-
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { log, prettyPrintJson, getReadableFileSize }
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import i18n from 'i18n'
|
|
2
|
-
import { sleep } from '../utils/requestUtils'
|
|
3
|
-
import { getHttpClient } from '../utils/commonApi'
|
|
4
|
-
import { ApiParams } from './lambda'
|
|
5
|
-
import HTTPClient from '../common/HTTPClient'
|
|
6
|
-
import ora from '../utils/oraWrapper'
|
|
7
|
-
import { CliError } from './cliError'
|
|
8
|
-
import { ERRORS } from './constants'
|
|
9
|
-
import { ContrastConf } from '../utils/getConfig'
|
|
10
|
-
|
|
11
|
-
const MS_IN_MINUTE = 1000 * 60
|
|
12
|
-
|
|
13
|
-
const getScanResources = async (
|
|
14
|
-
config: ContrastConf,
|
|
15
|
-
params: ApiParams,
|
|
16
|
-
scanId: string,
|
|
17
|
-
httpClient: HTTPClient
|
|
18
|
-
) => {
|
|
19
|
-
const res = await httpClient.getScanResources(config, params, scanId)
|
|
20
|
-
const { statusCode, body } = res
|
|
21
|
-
|
|
22
|
-
if (statusCode === 200) {
|
|
23
|
-
return res
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const { errorCode } = body || {}
|
|
27
|
-
throw new CliError(ERRORS.FAILED_TO_GET_SCAN, { statusCode, errorCode })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const pollScanUntilCompletion = async (
|
|
31
|
-
config: any,
|
|
32
|
-
timeoutInMinutes: number,
|
|
33
|
-
params: ApiParams,
|
|
34
|
-
scanId: string
|
|
35
|
-
) => {
|
|
36
|
-
const client = getHttpClient(config)
|
|
37
|
-
|
|
38
|
-
const activeStatuses = ['PENDING', 'SCANNING', 'QUEUED']
|
|
39
|
-
const maxEndTime = new Date().getTime() + timeoutInMinutes * MS_IN_MINUTE
|
|
40
|
-
const startScanSpinner = ora.returnOra(i18n.__('scanStarted'))
|
|
41
|
-
ora.startSpinner(startScanSpinner)
|
|
42
|
-
|
|
43
|
-
await sleep(5000) // wait 5 sec before first polling
|
|
44
|
-
|
|
45
|
-
let complete = false
|
|
46
|
-
while (!complete) {
|
|
47
|
-
try {
|
|
48
|
-
const result = await exports.getScanResources(
|
|
49
|
-
config,
|
|
50
|
-
params,
|
|
51
|
-
scanId,
|
|
52
|
-
client
|
|
53
|
-
)
|
|
54
|
-
const { resources: scans } = result.body.data
|
|
55
|
-
const staticScans = scans?.filter((s: any) => s.scanType === 2)
|
|
56
|
-
complete = staticScans.some((s: any) => !activeStatuses.includes(s.state))
|
|
57
|
-
|
|
58
|
-
if (complete) {
|
|
59
|
-
ora.succeedSpinner(startScanSpinner, 'Scan Finished')
|
|
60
|
-
return scans
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
await sleep(2 * 1000)
|
|
64
|
-
} catch (error) {
|
|
65
|
-
ora.failSpinner(startScanSpinner, i18n.__('scanFailed'))
|
|
66
|
-
throw error
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (Date.now() >= maxEndTime) {
|
|
70
|
-
ora.failSpinner(startScanSpinner, i18n.__('scanTimedOut'))
|
|
71
|
-
throw new CliError(ERRORS.FAILED_TO_GET_SCAN, {
|
|
72
|
-
errorCode: 'waitingTimedOut'
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export { pollScanUntilCompletion, getScanResources }
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import i18n from 'i18n'
|
|
2
|
-
import logSymbols from 'log-symbols'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import { parseARN } from './arn'
|
|
5
|
-
import {
|
|
6
|
-
getLambdaClient,
|
|
7
|
-
getLambdaFunctionConfiguration,
|
|
8
|
-
getLambdaPolicies,
|
|
9
|
-
getLayersLinks
|
|
10
|
-
} from './aws'
|
|
11
|
-
import { toLowerKeys } from './utils'
|
|
12
|
-
import { getHttpClient } from '../utils/commonApi'
|
|
13
|
-
import { ApiParams, LambdaOptions } from './lambda'
|
|
14
|
-
import { log, prettyPrintJson } from './logUtils'
|
|
15
|
-
import { CliError } from './cliError'
|
|
16
|
-
import { ERRORS } from './constants'
|
|
17
|
-
import { sleep } from '../utils/requestUtils'
|
|
18
|
-
|
|
19
|
-
const MAX_RETRIES = 2
|
|
20
|
-
|
|
21
|
-
const sendScanPostRequest: (
|
|
22
|
-
config: any,
|
|
23
|
-
params: ApiParams,
|
|
24
|
-
functionsEvent: unknown,
|
|
25
|
-
showProgress?: boolean,
|
|
26
|
-
retryNumber?: number
|
|
27
|
-
) => any = async (
|
|
28
|
-
config,
|
|
29
|
-
params,
|
|
30
|
-
functionsEvent,
|
|
31
|
-
showProgress = false,
|
|
32
|
-
retryNumber = 0
|
|
33
|
-
) => {
|
|
34
|
-
const client = getHttpClient(config)
|
|
35
|
-
|
|
36
|
-
if (showProgress) {
|
|
37
|
-
log(i18n.__('sendingScanRequest', { icon: logSymbols.success }))
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const res = await client.postFunctionScan(config, params, functionsEvent)
|
|
41
|
-
const { statusCode, body } = res
|
|
42
|
-
|
|
43
|
-
if (statusCode === 201) {
|
|
44
|
-
if (showProgress) {
|
|
45
|
-
log(i18n.__('scanRequestedSuccessfully', { icon: logSymbols.success }))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return body?.data?.scanId
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let { errorCode } = body?.data || {}
|
|
52
|
-
const { data } = body?.data || {}
|
|
53
|
-
|
|
54
|
-
let description = ''
|
|
55
|
-
switch (errorCode) {
|
|
56
|
-
case 'not_supported_runtime':
|
|
57
|
-
description = i18n.__(errorCode, {
|
|
58
|
-
runtime: data?.runtime,
|
|
59
|
-
supportedRuntimes: data?.supportedRuntimes.sort().join(' | ')
|
|
60
|
-
})
|
|
61
|
-
errorCode = false
|
|
62
|
-
break
|
|
63
|
-
case 'not_supported_lambda':
|
|
64
|
-
description = i18n.__(errorCode)
|
|
65
|
-
errorCode = false
|
|
66
|
-
break
|
|
67
|
-
default:
|
|
68
|
-
if (retryNumber < MAX_RETRIES) {
|
|
69
|
-
await sleep(3 * 1000)
|
|
70
|
-
return sendScanPostRequest(
|
|
71
|
-
config,
|
|
72
|
-
params,
|
|
73
|
-
functionsEvent,
|
|
74
|
-
showProgress,
|
|
75
|
-
retryNumber + 1
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
throw new CliError(ERRORS.FAILED_TO_START_SCAN, {
|
|
81
|
-
statusCode,
|
|
82
|
-
errorCode,
|
|
83
|
-
data,
|
|
84
|
-
description
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const createFunctionEvent = (
|
|
89
|
-
lambdaConfig: any,
|
|
90
|
-
layersLinks: any,
|
|
91
|
-
lambdaPolicies: any
|
|
92
|
-
) => {
|
|
93
|
-
delete lambdaConfig.$metadata
|
|
94
|
-
|
|
95
|
-
const functionEvent = toLowerKeys(lambdaConfig.Configuration)
|
|
96
|
-
functionEvent['code'] = lambdaConfig.Code
|
|
97
|
-
functionEvent['rolePolicies'] = lambdaPolicies
|
|
98
|
-
|
|
99
|
-
if (layersLinks) {
|
|
100
|
-
functionEvent['layers'] = layersLinks
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return { function: functionEvent }
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const requestScanFunctionPost = async (
|
|
107
|
-
config: any,
|
|
108
|
-
lambdaOptions: LambdaOptions
|
|
109
|
-
) => {
|
|
110
|
-
const { verbose, jsonOutput, functionName } = lambdaOptions
|
|
111
|
-
const lambdaClient = getLambdaClient(lambdaOptions)
|
|
112
|
-
|
|
113
|
-
if (!jsonOutput) {
|
|
114
|
-
log(
|
|
115
|
-
i18n.__('fetchingConfiguration', {
|
|
116
|
-
icon: logSymbols.success,
|
|
117
|
-
functionName: chalk.bold(functionName)
|
|
118
|
-
})
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const lambdaConfig = await getLambdaFunctionConfiguration(
|
|
123
|
-
lambdaClient,
|
|
124
|
-
lambdaOptions
|
|
125
|
-
)
|
|
126
|
-
if (!lambdaConfig?.Configuration) {
|
|
127
|
-
throw new CliError(ERRORS.FAILED_TO_START_SCAN, {
|
|
128
|
-
errorCode: 'missingLambdaConfig'
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
const { Configuration } = lambdaConfig
|
|
132
|
-
const layersLinks = await getLayersLinks(lambdaClient, Configuration)
|
|
133
|
-
const lambdaPolicies = await getLambdaPolicies(Configuration, lambdaOptions)
|
|
134
|
-
|
|
135
|
-
const functionEvent = createFunctionEvent(
|
|
136
|
-
lambdaConfig,
|
|
137
|
-
layersLinks,
|
|
138
|
-
lambdaPolicies
|
|
139
|
-
)
|
|
140
|
-
const { FunctionArn: functionArn } = Configuration
|
|
141
|
-
if (!functionArn) {
|
|
142
|
-
throw new CliError(ERRORS.FAILED_TO_START_SCAN, {
|
|
143
|
-
errorCode: 'missingLambdaArn'
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const parsedARN = parseARN(functionArn)
|
|
148
|
-
const params: ApiParams = {
|
|
149
|
-
organizationId: config.organizationId,
|
|
150
|
-
provider: 'aws',
|
|
151
|
-
accountId: parsedARN.accountId
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (verbose) {
|
|
155
|
-
log(i18n.__('fetchedConfiguration', { icon: logSymbols.success }))
|
|
156
|
-
prettyPrintJson(functionEvent)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const scanId = await sendScanPostRequest(
|
|
160
|
-
config,
|
|
161
|
-
params,
|
|
162
|
-
functionEvent,
|
|
163
|
-
!jsonOutput
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
return { scanId, params, functionArn }
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export { sendScanPostRequest, requestScanFunctionPost, createFunctionEvent }
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getHttpClient } from '../utils/commonApi'
|
|
2
|
-
import { CliError } from './cliError'
|
|
3
|
-
import { ERRORS } from './constants'
|
|
4
|
-
import { ApiParams } from './lambda'
|
|
5
|
-
|
|
6
|
-
const getScanResults = async (
|
|
7
|
-
config: any,
|
|
8
|
-
params: ApiParams,
|
|
9
|
-
scanId: string,
|
|
10
|
-
functionArn: string
|
|
11
|
-
) => {
|
|
12
|
-
const client = getHttpClient(config)
|
|
13
|
-
|
|
14
|
-
const { statusCode, body } = await client.getFunctionScanResults(
|
|
15
|
-
config,
|
|
16
|
-
params,
|
|
17
|
-
scanId,
|
|
18
|
-
functionArn
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
if (statusCode === 200) {
|
|
22
|
-
return body
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const { errorCode } = body || {}
|
|
26
|
-
throw new CliError(ERRORS.FAILED_TO_GET_RESULTS, { statusCode, errorCode })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { getScanResults }
|
package/src/lambda/types.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export enum StatusType {
|
|
2
|
-
FAILED = 'failed',
|
|
3
|
-
SUCCESS = 'success'
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export enum EventType {
|
|
7
|
-
START = 'start_command_session',
|
|
8
|
-
END = 'end_command_session'
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type LambdaOptions = {
|
|
12
|
-
functionName?: string
|
|
13
|
-
listFunctions?: boolean
|
|
14
|
-
region?: string
|
|
15
|
-
endpointUrl?: string
|
|
16
|
-
profile?: string
|
|
17
|
-
help?: boolean
|
|
18
|
-
verbose?: boolean
|
|
19
|
-
jsonOutput?: boolean
|
|
20
|
-
_unknown?: string[]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type ScanFunctionData = {
|
|
24
|
-
functionArn: string
|
|
25
|
-
scanId: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type AnalyticsOption = {
|
|
29
|
-
sessionId: string
|
|
30
|
-
eventType: EventType
|
|
31
|
-
packageVersion: string
|
|
32
|
-
arguments?: LambdaOptions
|
|
33
|
-
scanFunctionData?: ScanFunctionData
|
|
34
|
-
status?: StatusType
|
|
35
|
-
errorMsg?: string
|
|
36
|
-
}
|
package/src/lambda/utils.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import { groupBy, sortBy, capitalize, minBy } from 'lodash'
|
|
3
|
-
import i18n from 'i18n'
|
|
4
|
-
import { log } from './logUtils'
|
|
5
|
-
|
|
6
|
-
// fix for using `plural`
|
|
7
|
-
// https://github.com/mashpie/i18n-node/issues/429
|
|
8
|
-
i18n.setLocale('en')
|
|
9
|
-
|
|
10
|
-
class PrintVulnerability {
|
|
11
|
-
index: number
|
|
12
|
-
vulnerability: any
|
|
13
|
-
group?: any[]
|
|
14
|
-
title: string
|
|
15
|
-
severity: string
|
|
16
|
-
remediation: string
|
|
17
|
-
description: string
|
|
18
|
-
recommendation: string
|
|
19
|
-
whatHappened: string
|
|
20
|
-
|
|
21
|
-
constructor(index: number, vulnerability: any, group?: any[]) {
|
|
22
|
-
const { severityText, title, description, remediation, categoryText } =
|
|
23
|
-
vulnerability
|
|
24
|
-
|
|
25
|
-
this.group = group
|
|
26
|
-
this.vulnerability = vulnerability
|
|
27
|
-
this.index = index
|
|
28
|
-
this.title = title
|
|
29
|
-
this.severity = capitalize(severityText)
|
|
30
|
-
this.description = underlineLinks(description)
|
|
31
|
-
this.remediation = remediation?.description
|
|
32
|
-
this.recommendation = ''
|
|
33
|
-
this.whatHappened = ''
|
|
34
|
-
|
|
35
|
-
if (categoryText === 'PERMISSIONS') {
|
|
36
|
-
this.formatPermissions()
|
|
37
|
-
} else if (categoryText === 'DEPENDENCIES') {
|
|
38
|
-
this.formatDependencies()
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
formatPermissions() {
|
|
43
|
-
const { leastPrivilege, comment } = this.vulnerability.evidence
|
|
44
|
-
const violatingPolicies = leastPrivilege?.violatingPolicies || []
|
|
45
|
-
|
|
46
|
-
const filteredPolicies = violatingPolicies
|
|
47
|
-
.filter((vp: any) => vp?.suggestedPolicy?.suggestedPolicyCode?.length)
|
|
48
|
-
.map((vp: any) => vp?.suggestedPolicy)
|
|
49
|
-
|
|
50
|
-
const shouldNumerate = filteredPolicies.length > 1
|
|
51
|
-
filteredPolicies.forEach((policies: any, i: number) => {
|
|
52
|
-
const { suggestedPolicyCode, description } = policies
|
|
53
|
-
|
|
54
|
-
suggestedPolicyCode.forEach((policy: any) => {
|
|
55
|
-
const { snippet, title } = policy
|
|
56
|
-
this.recommendation += shouldNumerate
|
|
57
|
-
? ` ${i + 1}. ${description}\n`
|
|
58
|
-
: `${description}\n`
|
|
59
|
-
|
|
60
|
-
if (title !== 'DELETE POLICY') {
|
|
61
|
-
this.recommendation += `${snippet}\n`
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
if (comment?.length) {
|
|
67
|
-
const splitComment = (comment: string) => {
|
|
68
|
-
const [policy, description] = comment.split(':').map(c => c.trim())
|
|
69
|
-
return { policy, description }
|
|
70
|
-
}
|
|
71
|
-
const groupByPolicy = groupBy(comment, c => splitComment(c).policy)
|
|
72
|
-
|
|
73
|
-
Object.entries(groupByPolicy).forEach(([policy, commentArr]) => {
|
|
74
|
-
const comments = commentArr
|
|
75
|
-
.map(splitComment)
|
|
76
|
-
.map(({ description }) => ` - ${description}`)
|
|
77
|
-
.join('\n')
|
|
78
|
-
this.whatHappened += i18n.__('whatHappenedItem', { policy, comments })
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
formatDependencies() {
|
|
84
|
-
if (!this.group?.length) {
|
|
85
|
-
this.recommendation = this.vulnerability?.remediation?.description
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const maxSeverity = minBy(this.group, 'severity')
|
|
90
|
-
this.title = i18n.__('vulnerableDependency')
|
|
91
|
-
this.severity = capitalize(maxSeverity.severityText)
|
|
92
|
-
this.recommendation = maxSeverity.remediation?.description
|
|
93
|
-
|
|
94
|
-
const library = groupByDependency({ title: this.vulnerability.title })
|
|
95
|
-
const [packageName, version] = library.split(':')
|
|
96
|
-
const allCves = this.group.map(groupByCVE)
|
|
97
|
-
|
|
98
|
-
this.description = i18n.__mf('vulnerableDependencyDescriptions', {
|
|
99
|
-
NUM: this.group.length,
|
|
100
|
-
packageName,
|
|
101
|
-
version,
|
|
102
|
-
cves: allCves.join(' | ')
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
print() {
|
|
107
|
-
log(`${this.index}.`)
|
|
108
|
-
// prettier-ignore
|
|
109
|
-
log(`${chalk.bold(this.severity)} | ${chalk.bold(this.title)} ${this.description}`)
|
|
110
|
-
|
|
111
|
-
if (this.whatHappened) {
|
|
112
|
-
log(`\n${chalk.bold(i18n.__('whatHappenedTitle'))}\n${this.whatHappened}`)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (this.recommendation) {
|
|
116
|
-
log(`${chalk.bold(i18n.__('recommendation'))}\n${this.recommendation}`)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
log('')
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const groupByCVE = ({ title }: any) =>
|
|
124
|
-
title.substring(0, title.indexOf('[') - 1)
|
|
125
|
-
|
|
126
|
-
const groupByDependency = ({ title }: any) =>
|
|
127
|
-
title.substring(title.indexOf('[') + 1, title.indexOf(']'))
|
|
128
|
-
|
|
129
|
-
const printResults = (results: any[]) => {
|
|
130
|
-
//filter out any vulnerabs which is not least privilege or dependencies- cli does not handle other vulnerabs yet
|
|
131
|
-
const vulnerabs = results.filter(r => r.category === 1 || r.category === 4)
|
|
132
|
-
const sortBySeverity = sortBy(vulnerabs, ['severity', 'title'])
|
|
133
|
-
const notDependencies = sortBySeverity.filter(r => r.category !== 1)
|
|
134
|
-
const dependencies = sortBySeverity.filter(r => r.category === 1)
|
|
135
|
-
const dependenciesByLibrary = groupBy(dependencies, groupByDependency)
|
|
136
|
-
|
|
137
|
-
log('')
|
|
138
|
-
|
|
139
|
-
notDependencies.forEach((vulnerability: any, index: number) => {
|
|
140
|
-
const printVulnerab = new PrintVulnerability(index + 1, vulnerability)
|
|
141
|
-
printVulnerab.print()
|
|
142
|
-
})
|
|
143
|
-
const prevIndex = notDependencies.length + 1
|
|
144
|
-
Object.entries(dependenciesByLibrary).forEach(([, group], i) => {
|
|
145
|
-
const printVulnerab = new PrintVulnerability(prevIndex + i, group[0], group)
|
|
146
|
-
printVulnerab.print()
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
const dependenciesCount = Object.keys(dependenciesByLibrary).length
|
|
150
|
-
const resultCount = notDependencies.length + dependenciesCount
|
|
151
|
-
log(i18n.__n('foundVulnerabilities', resultCount), { bold: true })
|
|
152
|
-
|
|
153
|
-
const counters = getNotDependenciesCounters(notDependencies)
|
|
154
|
-
if (dependenciesCount) {
|
|
155
|
-
counters.push(i18n.__n('dependenciesCount', dependenciesCount))
|
|
156
|
-
}
|
|
157
|
-
log(counters.join(' | '), { bold: true })
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const getNotDependenciesCounters = (notDependencies: any[]) => {
|
|
161
|
-
const groupByType = groupBy(notDependencies, ['categoryText'])
|
|
162
|
-
return Object.values(groupByType).map(
|
|
163
|
-
group => `${group.length} ${capitalize(group[0].categoryText)}`
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const underlineLinks = (text: string) => {
|
|
168
|
-
if (!text) {
|
|
169
|
-
return text
|
|
170
|
-
}
|
|
171
|
-
const urlRegex = /(https?:\/\/[^\s]+)/g
|
|
172
|
-
return text.replace(urlRegex, chalk.underline('$1'))
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function toLowerKeys(obj: Record<string, unknown>) {
|
|
176
|
-
return Object.keys(obj).reduce((accumulator, key) => {
|
|
177
|
-
const new_key = `${key[0].toLowerCase()}${key.slice(1)}`
|
|
178
|
-
accumulator[new_key] = obj[key]
|
|
179
|
-
return accumulator
|
|
180
|
-
}, {} as Record<string, unknown>)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export { toLowerKeys, printResults }
|
|
184
|
-
export const exportedForTesting = {
|
|
185
|
-
underlineLinks,
|
|
186
|
-
printResults,
|
|
187
|
-
PrintVulnerability
|
|
188
|
-
}
|