Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add reference folder to branch chooser (#652)
* feat: add reference folder to branch chooser This code change introduces the ability to specify a reference folder for Snyk scans, in addition to the existing base branch option. This is particularly useful for projects that are not under Git version control. Here's a breakdown of the changes: * **`FolderConfig`**: A new field `referenceFolderPath` has been added to store the path of the reference folder. Additionally, `scanCommandConfig` has been added to support running commands before and after a scan, optionally only on the reference folder. * **`SnykToolWindowPanel.kt`**: * `getRootNodeText()` now displays the reference folder information if it's set, otherwise it falls back to the base branch. * The UI now updates to reflect the chosen reference folder. Error handling has been slightly improved. * **`BranchChooserComboboxDialog.kt`**: * This dialog now includes a file chooser for selecting the reference folder. * The dialog validates that either a base branch or a reference folder is selected. The member `comboBoxes` has been renamed to `baseBranches` and changed to a `MutableMap<FolderConfig, ComboBox<String>>`. Also a new `MutableMap<FolderConfig, TextFieldWithBrowseButton>` has been introduced for the reference folders. * **`BranchChooserComboBoxDialogTest.kt`**: The tests have been updated to reflect the changes in `BranchChooserComboboxDialog.kt`, specifically the change from `comboBoxes` to `baseBranches`. * **`Utils.kt`**: A new function `isExecutable()` has been added, likely used for validating pre/post scan commands. * **`SnykLanguageClient.kt`**: A debug log message has been added to show the hash codes of the old and new tokens during authentication, likely for debugging token refresh issues. Key improvements: * **Support for non-Git projects**: The reference folder option allows Snyk to scan projects not managed by Git. * **More flexible configuration**: Users can now specify both a base branch and a reference folder, or just one of them. * **Improved UI**: The tool window displays the chosen reference folder. * **Better error handling**: The code includes more robust error handling for configuration updates. This change makes the Snyk plugin more versatile and user-friendly, especially for users working with projects outside of Git. The addition of pre/post scan commands provides further customization options for the scanning process. The debugging enhancements in `SnykLanguageClient.kt` should help diagnose token-related issues more easily. * fix: set folderConfig properties as nullable * fix: always set reference folder * fix: use sha256 for logging a hashed token The changes introduce a SHA-256 hashing function for strings and use it to log the hash of the Snyk authentication token instead of the Java `hashCode()` method. This improves security by avoiding logging potentially sensitive information in plain text, even in debug logs. The `hashCode()` method is not suitable for security purposes as it's not cryptographically secure and can lead to collisions. Here's a breakdown: * **`src/main/kotlin/io/snyk/plugin/Utils.kt`**: This file adds the `sha256()` extension function to the `String` class. This function computes the SHA-256 hash of the string and returns it as a hexadecimal string. * **`src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt`**: In the `hasAuthenticated` function: - The old token is now fetched with a null-safe operator (`?: ""`) to handle cases where no token is present. - The logging lines using `oldToken.hashCode()` and `param.token.hashCode()` are replaced with `oldToken.sha256()` and `param.token?.sha256()` respectively. This change ensures that the actual token value is never logged, even in debug mode. The null-safe operator (`?.`) on `param.token` handles the case where the new token might be null. In summary, these changes improve the security of the plugin by preventing the accidental logging of sensitive authentication tokens. They replace the insecure `hashCode()` method with a proper cryptographic hash function (SHA-256) for logging purposes, offering better protection against information leakage. * docs: update CHANGELOG.md This changelog entry describes the following changes for version 2.11.1: **Changed:** * Added support for 2025.1. * Added the ability to select a reference folder instead of a branch for delta scanning, displaying only net-new issues. **Fixed:** * Fixed a bug related to workspace folder configuration on language server (re-)start. * fix: add test to check for validation, renamed dialog --------- Co-authored-by: Abdelrahman Shawki Hassan <[email protected]>
- Loading branch information