From 017c2cc06837b6e852bff41cd1a135342e73c454 Mon Sep 17 00:00:00 2001
From: Guillermo Gabarrin
Date: Sat, 1 Apr 2023 19:06:17 -0300
Subject: [PATCH 1/8] Parse bandit results
---
README.md | 7 ++--
src/parsers/bandit.ts | 41 ++++++++++++++++++++++++
src/webviews/importToolResultsWebview.ts | 14 ++++----
3 files changed, 54 insertions(+), 8 deletions(-)
create mode 100644 src/parsers/bandit.ts
diff --git a/README.md b/README.md
index a7d3cac..f3ce38e 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,10 @@
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".
-Also, it allows importing the output from SAST tools (currently only [Semgrep](https://semgrep.dev/)) into notes, making the processing of the findings much easier.
+Also, it allows importing the output from SAST tools into notes, making the processing of the findings much easier. Currently supported tools include:
+
+- semgrep (https://semgrep.dev/)
+- bandit (https://bandit.readthedocs.io/en/latest/)
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.
@@ -70,7 +73,7 @@ The extension allows you to import the output from SAST tools (currently only [S
## Extension Settings
-Various settings for the extension can be configured in VSCode's User Settings page (`CMD+Shift+P` / `Ctrl + Shift + P` -> *Preferences: Open Settings (UI)*):
+Various settings for the extension can be configured in VSCode's User Settings page (`CMD+Shift+P` / `Ctrl + Shift + P` -> _Preferences: Open Settings (UI)_):

diff --git a/src/parsers/bandit.ts b/src/parsers/bandit.ts
new file mode 100644
index 0000000..b451e4d
--- /dev/null
+++ b/src/parsers/bandit.ts
@@ -0,0 +1,41 @@
+'use strict';
+
+import * as vscode from 'vscode';
+import { ToolFinding } from '../models/toolFinding';
+
+class BanditParser {
+ static parse(fileContent: string) {
+ const toolFindings: ToolFinding[] = [];
+
+ try {
+ const banditFindings = JSON.parse(fileContent).results;
+ banditFindings.map((banditFinding: any) => {
+ // uri
+ let fullPath = '';
+ if (vscode.workspace.workspaceFolders) {
+ fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
+ }
+ const uri = vscode.Uri.file(`${fullPath}${banditFinding.filename}`);
+
+ // range
+ const lineRange = banditFinding.line_range;
+ const range = new vscode.Range(
+ lineRange[0] - 1,
+ 0,
+ (lineRange[1] ? lineRange[1] : lineRange[0]) - 1,
+ 0,
+ );
+
+ // instantiate tool finding and add to list
+ const toolFinding = new ToolFinding(uri, range, banditFinding.issue_text);
+ toolFindings.push(toolFinding);
+ });
+ } catch {
+ /* empty */
+ }
+
+ return toolFindings;
+ }
+}
+
+export { BanditParser };
diff --git a/src/webviews/importToolResultsWebview.ts b/src/webviews/importToolResultsWebview.ts
index 883c166..35191bd 100644
--- a/src/webviews/importToolResultsWebview.ts
+++ b/src/webviews/importToolResultsWebview.ts
@@ -2,6 +2,7 @@
import * as vscode from 'vscode';
import { commentController } from '../controllers/comments';
+import { BanditParser } from '../parsers/bandit';
import { SemgrepParser } from '../parsers/semgrep';
import { ToolFinding } from '../models/toolFinding';
import { saveNoteComment } from '../helpers';
@@ -42,12 +43,7 @@ export class ImportToolResultsWebview implements vscode.WebviewViewProvider {
webviewView.webview.onDidReceiveMessage((data) => {
switch (data.type) {
case 'processToolFile': {
- processToolFile(
- data.toolName,
- data.fileContent,
- this.noteMap,
- this.remoteDb,
- );
+ processToolFile(data.toolName, data.fileContent, this.noteMap, this.remoteDb);
}
}
});
@@ -86,6 +82,7 @@ export class ImportToolResultsWebview implements vscode.WebviewViewProvider {
Select file:
@@ -113,6 +110,11 @@ function processToolFile(
switch (toolName) {
case 'semgrep': {
toolFindings = SemgrepParser.parse(fileContent);
+ break;
+ }
+ case 'bandit': {
+ toolFindings = BanditParser.parse(fileContent);
+ break;
}
}
From 4af7f32fdb9dfd2983e572dfe2bb479f34686e2c Mon Sep 17 00:00:00 2001
From: Guillermo Gabarrin
Date: Sun, 2 Apr 2023 14:20:15 -0300
Subject: [PATCH 2/8] Parse brakeman results
---
README.md | 13 ++++---
src/parsers/brakeman.ts | 44 ++++++++++++++++++++++++
src/webviews/importToolResultsWebview.ts | 6 ++++
3 files changed, 58 insertions(+), 5 deletions(-)
create mode 100644 src/parsers/brakeman.ts
diff --git a/README.md b/README.md
index f3ce38e..53df0a7 100644
--- a/README.md
+++ b/README.md
@@ -14,10 +14,7 @@
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".
-Also, it allows importing the output from SAST tools into notes, making the processing of the findings much easier. Currently supported tools include:
-
-- semgrep (https://semgrep.dev/)
-- bandit (https://bandit.readthedocs.io/en/latest/)
+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.
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.
@@ -67,10 +64,16 @@ Naturally, you will want to collaborate with remote peers. To do so in a secure
## Importing SAST results
-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:
+The extension allows you to import the output from SAST tools into notes, making the processing of the findings much easier:

+Currently supported tools include:
+
+- semgrep (https://semgrep.dev/)
+- bandit (https://bandit.readthedocs.io/en/latest/)
+- brakeman (https://brakemanscanner.org/)
+
## Extension Settings
Various settings for the extension can be configured in VSCode's User Settings page (`CMD+Shift+P` / `Ctrl + Shift + P` -> _Preferences: Open Settings (UI)_):
diff --git a/src/parsers/brakeman.ts b/src/parsers/brakeman.ts
new file mode 100644
index 0000000..58f8b70
--- /dev/null
+++ b/src/parsers/brakeman.ts
@@ -0,0 +1,44 @@
+'use strict';
+
+import * as vscode from 'vscode';
+import { ToolFinding } from '../models/toolFinding';
+
+class BrakemanParser {
+ static parse(fileContent: string) {
+ const toolFindings: ToolFinding[] = [];
+
+ try {
+ const brakemanFindings = JSON.parse(fileContent).warnings;
+ brakemanFindings.map((brakemanFinding: any) => {
+ // uri
+ let fullPath = '';
+ if (vscode.workspace.workspaceFolders) {
+ fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
+ }
+ const uri = vscode.Uri.file(`${fullPath}${brakemanFinding.file}`);
+
+ // range
+ const range = new vscode.Range(
+ brakemanFinding.line - 1,
+ 0,
+ brakemanFinding.line - 1,
+ 0,
+ );
+
+ // instantiate tool finding and add to list
+ const toolFinding = new ToolFinding(
+ uri,
+ range,
+ `${brakemanFinding.warning_type}: ${brakemanFinding.message}`,
+ );
+ toolFindings.push(toolFinding);
+ });
+ } catch {
+ /* empty */
+ }
+
+ return toolFindings;
+ }
+}
+
+export { BrakemanParser };
diff --git a/src/webviews/importToolResultsWebview.ts b/src/webviews/importToolResultsWebview.ts
index 35191bd..a190767 100644
--- a/src/webviews/importToolResultsWebview.ts
+++ b/src/webviews/importToolResultsWebview.ts
@@ -4,6 +4,7 @@ import * as vscode from 'vscode';
import { commentController } from '../controllers/comments';
import { BanditParser } from '../parsers/bandit';
import { SemgrepParser } from '../parsers/semgrep';
+import { BrakemanParser } from '../parsers/brakeman';
import { ToolFinding } from '../models/toolFinding';
import { saveNoteComment } from '../helpers';
import { RemoteDb } from '../persistence/remote-db';
@@ -83,6 +84,7 @@ export class ImportToolResultsWebview implements vscode.WebviewViewProvider {