|
1 | | -# README |
2 | | - |
3 | | -## SAH - Static Analysis Hero |
4 | | - |
5 | | -Finds vulnerabilities in source code using pattern matching, allows easy organization and export of findings. |
6 | | -SAH is used while having the project to review open in VSCode. |
7 | | -Open the command palette (`Ctrl + Shift + P`) and type "SAH" for all available commands. |
8 | | -Additionally some commands are available from the context menu (right click), and from keyboard shortcut. |
9 | | -Results in this plugin are organized as *Matches*. |
10 | | -A match is a possible finding, based on a list of regular expressions or semgrep rules, that should hint at common vulnerabilities. |
11 | | - |
12 | | -### Usage |
13 | | - |
14 | | -- [README](#readme) |
15 | | - - [SAH - Static Analysis Hero](#sah---static-analysis-hero) |
16 | | - - [Usage](#usage) |
17 | | - - [Install](#install) |
18 | | - - [Review Projects](#review-projects) |
19 | | - - [New Project](#new-project) |
20 | | - - [Load Project](#load-project) |
21 | | - - [Scan For Potential Findings](#scan-for-potential-findings) |
22 | | - - [Semgrep Scan](#semgrep-scan) |
23 | | - - [Import semgrep Scan](#import-semgrep-scan) |
24 | | - - [Review Matches](#review-matches) |
| 1 | +# Static Analysis Hero (SAH) |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +SAH is a Visual Studio Code extension for efficient and effective security code reviews. It integrates external code scanning tools (e.g. semgrep / opengrep) and provides a toolbox for reviewing source code for security vulnerabilities. |
| 6 | + |
| 7 | +SAH is used while having the project to review open in VSCode. Open the command palette (`Ctrl + Shift + P`) and type "SAH" for all available commands. Additionally, some commands are available from the context menu (right click), and from keyboard shortcut. |
| 8 | + |
| 9 | +Results in this plugin are organized as *Matches*. A match is a possible security vulnerability, based on a list of regular expressions or semgrep / opengrep rule. Upon manual inspection, matches can be categorized as findings or false positives. |
| 10 | + |
| 11 | +### Table of Contents |
| 12 | +- [Installation](#installation) |
| 13 | +- [Usage](#usage) |
| 14 | + - [Working with Projects](#working-with-projects) |
| 15 | + - [New Project](#new-project) |
| 16 | + - [Load Project](#load-project) |
| 17 | + - [Scan For Potential Findings](#scan-for-potential-findings) |
| 18 | + - [Scan Code](#scan-code) |
| 19 | + - [Import Semgrep / Opengrep Scan](#import-semgrep--opengrep-scan) |
| 20 | + - [Scanning Sandbox](#scanning-sandbox) |
| 21 | + - [Review Matches](#review-matches) |
25 | 22 | - [Blacklist Files And Directories](#blacklist-files-and-directories) |
26 | | - - [Command Palette](#command-palette) |
| 23 | +- [Command Palette](#command-palette) |
| 24 | +- [Contribution & Dev Setup](#contribution--dev-setup) |
| 25 | + - [Development Setup](#development-setup) |
| 26 | + - [Debugging in VSCode](#debugging-in-vscode) |
27 | 27 |
|
28 | | -#### Install |
29 | 28 |
|
30 | | -To build this plugin, you need a recent version of nodejs and npm on your machine. |
| 29 | +## Installation |
31 | 30 |
|
| 31 | +1. Download the `.vsix`-file from the Releases section in GitHub. |
| 32 | +2. In VSCode, navigate to the Extensions menu and select `Install from VSIX...`. |
| 33 | +3. After installation, launch SAH from the command palette (`Ctrl + Shift + P`). |
32 | 34 |
|
33 | | -``` |
34 | | -sudo apt install npm nodejs |
35 | | -git clone git@github.com:usdAG/sah.git |
36 | | -cd visual-source-code-plugin |
37 | | -npm install |
38 | | -npm install vsce |
39 | | -node_modules/vsce/vsce package |
40 | | -``` |
| 35 | +If you want to build SAH from source, see instructions in the section [Contribution & Dev Setup](#contribution--dev-setup) below. |
41 | 36 |
|
42 | | -You can the install the resulting .vsix file in VSCode via the `Extensions: Install from VSIX...` command. |
43 | 37 |
|
44 | | -#### Review Projects |
| 38 | +## Usage |
45 | 39 |
|
46 | | -##### New Project |
| 40 | +### Working with Projects |
47 | 41 |
|
48 | | -To start a review project open command palette and run `SAH New Project`. |
49 | | -Create a file that should be used as a project file. |
| 42 | +#### New Project |
| 43 | + |
| 44 | +To start a review project, open the command palette and choose `SAH: New Project`. |
| 45 | +Select a file that will be used to preserve the project state (in JSON format). |
50 | 46 | All actions will automatically be saved to this file. |
51 | 47 |
|
52 | | -##### Load Project |
| 48 | +#### Load Project |
53 | 49 |
|
54 | | -To resume a previous project, or import a project file, run `SAH Load Project` from the command palette and select the respective project file. |
| 50 | +To resume a project, or import a project file, run `SAH: Load Project` from the command palette and select the respective project file. |
55 | 51 | If there is no review project loaded, all actions are temporary only! |
56 | 52 |
|
57 | | -#### Scan For Potential Findings |
58 | 53 |
|
59 | | -To add a scan, you can either run a new *semgrep* scan or import an existing one into the TOL. |
| 54 | +### Scan For Potential Findings |
| 55 | + |
| 56 | +To add a scan, you can either run a new *semgrep*/ *opengrep* scan or import scan results into the tool. |
| 57 | + |
| 58 | +#### Scan Code |
| 59 | + |
| 60 | +Call the `SAH: Scan Code` command from the command palette. SAH allows you to start semgrep scans from within the plugin. |
60 | 61 |
|
61 | | -##### Semgrep Scan |
| 62 | +This requires an install of semgrep/ opengrep on the local system. |
| 63 | +Installation is recommended by using `pipx` (e.g. for semgrep `pipx install semgrep`). |
62 | 64 |
|
63 | | -Call the `SAH Semgrep` dialog from the command palette. |
64 | | -The SAH allows you to start scans from within the plugin. |
| 65 | +The interface lets you define the following parameters: |
| 66 | +- The *config* to use for the scan: Either point to custom rules on disk or provide the name(s) of a standard ruleset, such as `p/owasp-top-ten` available in the [semgrep registry](https://semgrep.dev/r) |
| 67 | +- The *output destination* specifies a path to write the scan results on disk (in addition to storing the results in the project file) |
| 68 | +- Optional: *Include Patterns* / *Exclude Patterns* tune the scanning engine of semgrep to include or exclude resources for scanning |
65 | 69 |
|
66 | | -This requires an install of semgrep on the local system. |
67 | | -Installation is recommended by using `pipx` -> `pipx install semgrep` |
| 70 | +After configuration, start the scan. Progress will be transparent during the scan and the results are automatically imported into the matches view. |
68 | 71 |
|
69 | | -The dialog lets you define the following parameters: |
70 | | -- The path to scan (by default the working directory opened in the VSCode Workspace) |
71 | | -- The config to use for the scan: This can either be an OS path to rules or a standard ruleset such as `p/owasp-top-ten` available in the [semgrep registry](https://semgrep.dev/r) |
72 | | -- The outpath writes the scan to a chosen location on disk for archival |
73 | | -- Include Patterns/ Exclude Patterns tune the scanning engine of semgrep to include/ exclude resources for scanning |
| 72 | +*Note that semgrep requires an active Internet connection to download / update rules from the registry.* |
74 | 73 |
|
75 | | -When finished configuring you can start the scan by clicking the "Start Scan" button. |
76 | | -After the scan is finished results are automatically imported into the matches view. |
77 | 74 |
|
| 75 | +#### Import Semgrep / Opengrep Scan |
78 | 76 |
|
79 | | -#### Import semgrep Scan |
| 77 | +It is possible to import existing semgrep/opengrep scan results into SAH. To do so, use the upper section in the `SAH: Scan Code` command. For example, run the following command in a terminal and select the resulting outputfile for import: `semgrep scan -c "<ruleset>" --json -o <outputfile>`. |
80 | 78 |
|
81 | | -If you already have a semgrep scan you can import them also in `SAH semgrep`. An exemplary command to run a semgrep scan, importable by the SAH, is as follows: `semgrep scan -c "<ruleset>" --json -o <outputfile>`. |
82 | | -Some important notices: |
| 79 | +Important notes: |
83 | 80 | - `--json` is required as the plugin can only parse the JSON output of semgrep |
84 | | -- The SAH creates links from the findings to the affected files. In order for this to work it currently requires your semgrep scans to *NOT* include the full paths, but scan from the project/worksapce root. This can be achieved by scanning a path like `.` or removing the path entirely. Tip: If you already performed a scan and the paths don't match just edit the json file. |
| 81 | +- SAH creates links from the findings to the affected files. In order for this to work, it currently requires your semgrep scans to *NOT* include the full paths, but scan from the project/workspace root. This can be achieved by scanning a path like `.` or removing the path entirely. Tip: If you already performed a scan and the paths don't match, manually edit the json file. |
| 82 | + |
| 83 | + |
| 84 | +#### Scanning Sandbox |
| 85 | + |
| 86 | +With the `SAH: Scanning Sandbox` command you can open the scanning sandbox. It allows you to quickly develop new rules in a running project and test their detection capabilities in the codebase - without importing the results into the project state. You can either specify a ruleset or a single rule - that will conveniently be opened in a separate tab inside VSCode for quick edits - to run against the current workspace. It directly integrates a view of all matches found with this rule. |
85 | 87 |
|
86 | | -#### Review Matches |
| 88 | +Using the scanning sandbox is useful for developing new or enhancing existing rules. Once your satisfied with the results of your scan, you can directly import the results into the project - and thus the *Matches View* - for further review. |
87 | 89 |
|
88 | | -You can get an overview of all matches by using the `SAH Show Matches List` commmand. |
89 | 90 |
|
90 | | -It enables you to review and work through the list of issues. |
91 | | -You can also categorize them with the buttons on every match. This enables priorization of certain matches. |
| 91 | +### Review Matches |
92 | 92 |
|
93 | | -To only get matches from a certain file right click the file in the workspace explorer. |
| 93 | +In order to list all matches, use the `SAH: Show Matches List` commmand. This provides an overview with various filter options. |
94 | 94 |
|
95 | | -You can filter the matches to only show matches from certain paths in the workspace or exclude other paths. This can be done by going to the "File Explorer" on the bottom left of the workspace panel. |
96 | | -By right clicking on a folder you can either exclude it or show matches only from this path. Reset is possible in the top bar of this File Explorer. |
| 95 | +For each match, multiple utility functions are available: |
97 | 96 |
|
98 | | -### Blacklist Files And Directories |
| 97 | +- *Jump to code*: Opens the corresponding file and selects the exact match in the correct line of the file |
| 98 | +- *Finding*: After review, set the status of this match to finding when it represents an actual vulnerability (true positive) |
| 99 | +- *False Positive*: After review, set the status of this match to false positive when there is no vulnerability |
| 100 | +- *Save for Later*: Use this status to mark this finding for follow-up review (e.g. when passing on the project to another person) |
99 | 101 |
|
100 | | -You may not want to search every single file or directory in the project. In this case, create a file in your project folder called '`.sahignore`'. This file should contain names of all the files and directories that you want to be excluded from the code scan. |
101 | | -In lieu of a `.sahignore` file, a default blacklist is used containing some commonly blacklisted files and directories (`node_modules`, `package-lock.json` etc.) |
| 102 | +*Tip:* While performing the manual code review, filter for the status "Unprocessed" to hide matches which have already been classified. |
102 | 103 |
|
103 | | -### Command Palette |
| 104 | +To narrow down the manual analysis, use the context menu with a *right click* on a file in the workspace. This allows to |
| 105 | + |
| 106 | +- *SAH: Only show Matches for this file*: Filter matches for a single file |
| 107 | +- *SAH: Exclude File/Folder*: Filter matches *not* in a single file or folder |
| 108 | +- *SAH: Reset the exclusion of all files/folders* |
| 109 | + |
| 110 | +Finally, SAH provides an additional *File Explorer* in the bottom left panel that shows excluded files (toggle with button) as well as the number of findings per file. |
| 111 | + |
| 112 | +#### Blacklist Files And Directories |
| 113 | + |
| 114 | +You may not want to search every single file or directory in the project. In this case, create a file in your project folder called '`.semgrepignore`'. This file should contain names of all the files and directories that you want to be excluded from the code scan. |
| 115 | +In lieu of a `.semgrepignore` file, a default blacklist is used containing some commonly blacklisted files and directories (`node_modules`, `package-lock.json`, etc.) |
| 116 | + |
| 117 | +## Command Palette |
| 118 | + |
| 119 | +- `SAH: New Project`: Create a new project on disk to work with SAH and save your progress |
| 120 | +- `SAH: Load Project`: Open FS window to select and load a review project file. |
| 121 | +- `SAH: Save Project`: Manually save the current state to the project state |
| 122 | +- `SAH: Scan Code`: Scan the currently opened workspace directory for potential findings. |
| 123 | +- `SAH: Show Matches List`: Switch to *Matches* view in the SAH panel. |
| 124 | +- `SAH: Scanning Sandbox`: Allows you to easily test/ adjust rules on your current workspace and import resulting matches afterwards |
| 125 | +- `SAH: Show Help`: Renders this README inside VSCode for quick help |
| 126 | +- `SAH: Set Log Level to <LEVEL>`: Allows you to update the Loglevel for troubleshooting. Levels are: Off, Debug, Info, Warn, Error. |
| 127 | + |
| 128 | + |
| 129 | +## Contribution & Dev Setup |
| 130 | + |
| 131 | +### Development Setup |
| 132 | + |
| 133 | +To build this plugin, you need a recent version of nodejs and npm, as well as vsce to create the `vsix` package. |
| 134 | + |
| 135 | +``` |
| 136 | +sudo apt install npm nodejs |
| 137 | +git clone ssh://git@github.com:usdAG/sah |
| 138 | +cd sah |
| 139 | +npm install --legacy-peer-deps |
| 140 | +npm install '@vscode/vsce' --legacy-peer-deps |
| 141 | +node_modules/@vscode/vsce/vsce package |
| 142 | +``` |
104 | 143 |
|
105 | | -- `SAH Add To Finding`: Open dialog to add a code snippet to a finding. |
106 | | -- `SAH Load Project`: Open FS window to select and load a review project file. |
107 | | -- `SAH Create New Finding`: Open dialog to create a new finding. |
108 | | -- `SAH Scan Code`: Scan the currently opened workspace directory for potential findings. |
109 | | -- `SAH New Project`: Open FS window to name a review project file and create a new review project. |
110 | | -- `SAH Show Findingslist`: Switch to *Findings* view in the SAH panel. |
111 | | -- `SAH Show Matcheslist`: Switch to *Matches* view in the SAH panel. |
112 | | -- `SAH Semgrep`: Import a semgrep scan or perform a semgrep scan from within the SAH |
| 144 | +### Debugging in VSCode |
| 145 | +In VS Code, open the code of SAH. Then use `F5` to launch a debugging session. |
0 commit comments