Potential fix for code scanning alert no. 4: Clear text storage of sensitive information #223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/InvolutionHell/involutionhell/security/code-scanning/4
General fix:
Sensitive information like API keys should never be persisted in localStorage in cleartext. You should either avoid storing these secrets at all, or encrypt them before saving them, storing only encrypted values in localStorage. Decryption should only occur in-memory when needed and with a key/password only the user knows.
Best approach for the provided code:
The best way, without removing any existing functionality, is to encrypt the
openaiApiKeyandgeminiApiKeyfields before persisting and decrypt them after reading. One standard approach for browser environments is to use the Web Crypto API (window.crypto.subtle), as third-party modules likecrypto-jsare large and discouraged for new projects.The general steps:
openaiApiKeyandgeminiApiKey(if present) before storage using a secret only the user knows (for example, a passphrase supplied by the user—not stored in localStorage).Code changes needed:
parseStoredSettingsand related) to decrypt the keys when they are loaded.Given that only this file is accessible for modifications, the encryption/decryption helpers and modifications must be in
app/hooks/useAssistantSettings.tsx.Suggested fixes powered by Copilot Autofix. Review carefully before merging.