Skip to content

Commit 4af7f32

Browse files
committed
Parse brakeman results
1 parent 017c2cc commit 4af7f32

3 files changed

Lines changed: 58 additions & 5 deletions

File tree

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
Security Notes allows the creation of notes within source files, which can be replied to, reacted to using emojis, and assigned statuses such as "TODO", "Vulnerable" and "Not Vulnerable".
1616

17-
Also, it allows importing the output from SAST tools into notes, making the processing of the findings much easier. Currently supported tools include:
18-
19-
- semgrep (https://semgrep.dev/)
20-
- bandit (https://bandit.readthedocs.io/en/latest/)
17+
Also, it allows importing the output from SAST tools (such as semgrep, bandit and brakeman), into notes, making the processing of the findings much easier.
2118

2219
Finally, collaborate with others by using a centralized database for notes that will be automatically synced in **real-time**! Create a note locally, and it will be automatically pushed to whoever is working with you on the project.
2320

@@ -67,10 +64,16 @@ Naturally, you will want to collaborate with remote peers. To do so in a secure
6764
6865
## Importing SAST results
6966

70-
The extension allows you to import the output from SAST tools (currently only [Semgrep](https://semgrep.dev/)) into notes, making the processing of the findings much easier:
67+
The extension allows you to import the output from SAST tools into notes, making the processing of the findings much easier:
7168

7269
![Demo for semgrep import](images/demo-semgrep-import.gif)
7370

71+
Currently supported tools include:
72+
73+
- semgrep (https://semgrep.dev/)
74+
- bandit (https://bandit.readthedocs.io/en/latest/)
75+
- brakeman (https://brakemanscanner.org/)
76+
7477
## Extension Settings
7578

7679
Various settings for the extension can be configured in VSCode's User Settings page (`CMD+Shift+P` / `Ctrl + Shift + P` -> _Preferences: Open Settings (UI)_):

src/parsers/brakeman.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { ToolFinding } from '../models/toolFinding';
5+
6+
class BrakemanParser {
7+
static parse(fileContent: string) {
8+
const toolFindings: ToolFinding[] = [];
9+
10+
try {
11+
const brakemanFindings = JSON.parse(fileContent).warnings;
12+
brakemanFindings.map((brakemanFinding: any) => {
13+
// uri
14+
let fullPath = '';
15+
if (vscode.workspace.workspaceFolders) {
16+
fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
17+
}
18+
const uri = vscode.Uri.file(`${fullPath}${brakemanFinding.file}`);
19+
20+
// range
21+
const range = new vscode.Range(
22+
brakemanFinding.line - 1,
23+
0,
24+
brakemanFinding.line - 1,
25+
0,
26+
);
27+
28+
// instantiate tool finding and add to list
29+
const toolFinding = new ToolFinding(
30+
uri,
31+
range,
32+
`${brakemanFinding.warning_type}: ${brakemanFinding.message}`,
33+
);
34+
toolFindings.push(toolFinding);
35+
});
36+
} catch {
37+
/* empty */
38+
}
39+
40+
return toolFindings;
41+
}
42+
}
43+
44+
export { BrakemanParser };

src/webviews/importToolResultsWebview.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from 'vscode';
44
import { commentController } from '../controllers/comments';
55
import { BanditParser } from '../parsers/bandit';
66
import { SemgrepParser } from '../parsers/semgrep';
7+
import { BrakemanParser } from '../parsers/brakeman';
78
import { ToolFinding } from '../models/toolFinding';
89
import { saveNoteComment } from '../helpers';
910
import { RemoteDb } from '../persistence/remote-db';
@@ -83,6 +84,7 @@ export class ImportToolResultsWebview implements vscode.WebviewViewProvider {
8384
<select id="toolSelect">
8485
<option value="semgrep">semgrep</option>
8586
<option value="bandit">bandit</option>
87+
<option value="brakeman">brakeman</option>
8688
</select>
8789
</p>
8890
<p>Select file:</p>
@@ -116,6 +118,10 @@ function processToolFile(
116118
toolFindings = BanditParser.parse(fileContent);
117119
break;
118120
}
121+
case 'brakeman': {
122+
toolFindings = BrakemanParser.parse(fileContent);
123+
break;
124+
}
119125
}
120126

121127
if (!toolFindings.length) {

0 commit comments

Comments
 (0)