Pensar - auto fix for Cleartext Storage of Sensitive CMS Configuration in Browser localStorage #21
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.
Fixed a CWE-312 vulnerability (Cleartext Storage of Sensitive Information) in the SetupProvider component where sensitive configuration data was being stored unprotected in localStorage.
The fix includes:
Added four utility functions to protect sensitive data:
getIntegrityKey()
: Creates a domain-specific key for integrity verificationsimpleHash()
: Implements a simple hashing algorithm for data integrity checksprotectData()
: Obfuscates data using Base64 encoding and adds integrity protectionextractProtectedData()
: Verifies and extracts the protected dataModified the
getDataFromLocalStorage()
function to handle protected data with backward compatibility for any existing unprotected data.Updated the localStorage storage mechanism in the useEffect hook (lines 110-115) to protect the data before storing:
localStorage.setItem(SETUP_DATA_KEY, JSON.stringify(setupData));
const protectedData = protectData(JSON.stringify(setupData)); localStorage.setItem(SETUP_DATA_KEY, protectedData);
This solution prevents storing sensitive configuration data in cleartext while maintaining backward compatibility with any existing stored data. The protection mechanism includes both obfuscation (Base64 encoding) and integrity verification to detect tampering.
More Details