Skip to content

Commit c509959

Browse files
committed
Parse gosec results
1 parent a36c29d commit c509959

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ The extension allows you to import the output from SAST tools into notes, making
7070

7171
Currently supported tools include:
7272

73-
- semgrep (https://semgrep.dev/)
7473
- bandit (https://bandit.readthedocs.io/en/latest/)
7574
- brakeman (https://brakemanscanner.org/)
7675
- checkov (https://www.checkov.io/)
76+
- gosec (https://github.com/securego/gosec)
77+
- semgrep (https://semgrep.dev/)
7778

7879
## Extension Settings
7980

src/parsers/gosec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { ToolFinding } from '../models/toolFinding';
5+
6+
class GosecParser {
7+
static parse(fileContent: string) {
8+
const toolFindings: ToolFinding[] = [];
9+
10+
try {
11+
const gosecFindings = JSON.parse(fileContent).Issues;
12+
gosecFindings.map((gosecFinding: any) => {
13+
// uri
14+
const uri = vscode.Uri.file(gosecFinding.file);
15+
16+
// range
17+
const line = gosecFinding.line;
18+
const range = new vscode.Range(line - 1, 0, line - 1, 0);
19+
20+
// instantiate tool finding and add to list
21+
const toolFinding = new ToolFinding(uri, range, gosecFinding.details);
22+
toolFindings.push(toolFinding);
23+
});
24+
} catch {
25+
/* empty */
26+
}
27+
28+
return toolFindings;
29+
}
30+
}
31+
32+
export { GosecParser };

src/webviews/importToolResultsWebview.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { commentController } from '../controllers/comments';
55
import { BanditParser } from '../parsers/bandit';
66
import { BrakemanParser } from '../parsers/brakeman';
77
import { CheckovParser } from '../parsers/checkov';
8+
import { GosecParser } from '../parsers/gosec';
89
import { SemgrepParser } from '../parsers/semgrep';
910
import { ToolFinding } from '../models/toolFinding';
1011
import { saveNoteComment } from '../helpers';
@@ -86,6 +87,7 @@ export class ImportToolResultsWebview implements vscode.WebviewViewProvider {
8687
<option value="bandit">bandit (JSON)</option>
8788
<option value="brakeman">brakeman (JSON)</option>
8889
<option value="checkov">checkov (JSON)</option>
90+
<option value="gosec">gosec (JSON)</option>
8991
<option value="semgrep">semgrep (JSON)</option>
9092
</select>
9193
</p>
@@ -124,6 +126,10 @@ function processToolFile(
124126
toolFindings = CheckovParser.parse(fileContent);
125127
break;
126128
}
129+
case 'gosec': {
130+
toolFindings = GosecParser.parse(fileContent);
131+
break;
132+
}
127133
case 'semgrep': {
128134
toolFindings = SemgrepParser.parse(fileContent);
129135
break;

0 commit comments

Comments
 (0)