Skip to content

Commit 21838b6

Browse files
committed
feature: Add trivy as a runner
1 parent 9604a07 commit 21838b6

File tree

6 files changed

+1931
-18
lines changed

6 files changed

+1931
-18
lines changed

cmd/analyze.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,25 @@ func getToolName(toolName string, version string) string {
184184
return toolName
185185
}
186186

187+
func runEslintAnalysis(workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) {
188+
eslint := config.Config.Tools()["eslint"]
189+
eslintInstallationDirectory := eslint.InstallDir
190+
nodeRuntime := config.Config.Runtimes()["node"]
191+
nodeBinary := nodeRuntime.Binaries["node"]
192+
193+
tools.RunEslint(workDirectory, eslintInstallationDirectory, nodeBinary, pathsToCheck, autoFix, outputFile, outputFormat)
194+
}
195+
196+
func runTrivyAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) {
197+
trivy := config.Config.Tools()["trivy"]
198+
trivyBinary := trivy.Binaries["trivy"]
199+
200+
err := tools.RunTrivy(workDirectory, trivyBinary, pathsToCheck, outputFile, outputFormat)
201+
if err != nil {
202+
log.Fatalf("Error running Trivy: %v", err)
203+
}
204+
}
205+
187206
var analyzeCmd = &cobra.Command{
188207
Use: "analyze",
189208
Short: "Runs all linters.",
@@ -194,30 +213,23 @@ var analyzeCmd = &cobra.Command{
194213
log.Fatal(err)
195214
}
196215

197-
// TODO add more tools here
198-
switch toolToAnalyze {
199-
case "eslint":
200-
// nothing
201-
case "":
202-
log.Fatal("You need to specify a tool to run analysis with, e.g., '--tool eslint'", toolToAnalyze)
203-
default:
204-
log.Fatal("Trying to run unsupported tool: ", toolToAnalyze)
205-
}
206-
207-
eslint := config.Config.Tools()["eslint"]
208-
eslintInstallationDirectory := eslint.InstallDir
209-
nodeRuntime := config.Config.Runtimes()["node"]
210-
nodeBinary := nodeRuntime.Binaries["node"]
211-
212216
log.Printf("Running %s...\n", toolToAnalyze)
213217
if outputFormat == "sarif" {
214218
log.Println("Output will be in SARIF format")
215219
}
216-
217220
if outputFile != "" {
218221
log.Println("Output will be available at", outputFile)
219222
}
220223

221-
tools.RunEslint(workDirectory, eslintInstallationDirectory, nodeBinary, args, autoFix, outputFile, outputFormat)
224+
switch toolToAnalyze {
225+
case "eslint":
226+
runEslintAnalysis(workDirectory, args, autoFix, outputFile, outputFormat)
227+
case "trivy":
228+
runTrivyAnalysis(workDirectory, args, outputFile, outputFormat)
229+
case "":
230+
log.Fatal("You need to specify a tool to run analysis with, e.g., '--tool eslint'")
231+
default:
232+
log.Fatal("Trying to run unsupported tool: ", toolToAnalyze)
233+
}
222234
},
223-
}
235+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"fullName": "Trivy Vulnerability Scanner",
9+
"informationUri": "https://github.com/aquasecurity/trivy",
10+
"name": "Trivy",
11+
"rules": [
12+
{
13+
"id": "CVE-2024-21538",
14+
"name": "LanguageSpecificPackageVulnerability",
15+
"shortDescription": {
16+
"text": "cross-spawn: regular expression denial of service"
17+
},
18+
"fullDescription": {
19+
"text": "Versions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string."
20+
},
21+
"defaultConfiguration": {
22+
"level": "error"
23+
},
24+
"helpUri": "https://avd.aquasec.com/nvd/cve-2024-21538",
25+
"help": {
26+
"text": "Vulnerability CVE-2024-21538\nSeverity: HIGH\nPackage: cross-spawn\nFixed Version: 7.0.5, 6.0.6\nLink: [CVE-2024-21538](https://avd.aquasec.com/nvd/cve-2024-21538)\nVersions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string.",
27+
"markdown": "**Vulnerability CVE-2024-21538**\n| Severity | Package | Fixed Version | Link |\n| --- | --- | --- | --- |\n|HIGH|cross-spawn|7.0.5, 6.0.6|[CVE-2024-21538](https://avd.aquasec.com/nvd/cve-2024-21538)|\n\nVersions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string."
28+
},
29+
"properties": {
30+
"precision": "very-high",
31+
"security-severity": "7.5",
32+
"tags": [
33+
"vulnerability",
34+
"security",
35+
"HIGH"
36+
]
37+
}
38+
}
39+
],
40+
"version": "0.50.0"
41+
}
42+
},
43+
"results": [
44+
{
45+
"ruleId": "CVE-2024-21538",
46+
"ruleIndex": 0,
47+
"level": "error",
48+
"message": {
49+
"text": "Package: cross-spawn\nInstalled Version: 7.0.3\nVulnerability CVE-2024-21538\nSeverity: HIGH\nFixed Version: 7.0.5, 6.0.6\nLink: [CVE-2024-21538](https://avd.aquasec.com/nvd/cve-2024-21538)"
50+
},
51+
"locations": [
52+
{
53+
"physicalLocation": {
54+
"artifactLocation": {
55+
"uri": "package-lock.json",
56+
"uriBaseId": "ROOTPATH"
57+
},
58+
"region": {
59+
"startLine": 515,
60+
"startColumn": 1,
61+
"endLine": 527,
62+
"endColumn": 1
63+
}
64+
},
65+
"message": {
66+
"text": "package-lock.json: [email protected]"
67+
}
68+
}
69+
]
70+
}
71+
],
72+
"columnKind": "utf16CodeUnits",
73+
"originalUriBaseIds": {
74+
"ROOTPATH": {
75+
"uri": "testdata/repositories/trivy/src/"
76+
}
77+
}
78+
}
79+
]
80+
}

0 commit comments

Comments
 (0)