Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information