optimizely / optimizely/swift-sdk
[ENHANCEMENT] Hash API keys used internally for caching
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 24
- Forks
- 39
- Avg merge
- 13h 3m
- Merged PRs (30d)
- 2
Description
Description
Right now, some SDK persistence mechanisms use the raw SDK/API key directly in local persistence metadata (for example cache filenames or UserDefaults keys).
Even though this may not expose the key publicly, it means sensitive identifiers are persisted on disk in plaintext. For teams with stricter security or compliance requirements, this creates unnecessary risk and makes auditing harder.
Benefits
This reduces plaintext SDK key exposure from local storage with minimal implementation footprint — a single String extension and callsite changes; and no new public API surface, making it straightforward for the SDK team to review and adopt.
Detail
Hash the SDK key internally before using it as a persistence identifier, using SHA-256 via CryptoKit. Persistence identifiers would then be derived from sdkKey.sha256Hash rather than the raw key. This would apply to:
- Datafile cache key / filename generation
UserDefaultskeys for last-modified metadata- Any other persistence identifiers derived from the SDK key
This is technically a breaking change for existing cache entries. The consequence is a one-time cache miss on first launch after upgrading — the datafile is re-fetched and last-modified metadata is reset. For most apps this is acceptable and avoids the complexity of a migration path.
Examples
import CryptoKit
extension String {
var sha256Hash: String {
let digest = SHA256.hash(data: Data(utf8))
return digest.map { String(format: "%02x", $0) }.joined()
}
}
Callsite usage would simply replace raw sdkKey references with sdkKey.sha256Hash wherever persistence identifiers are generated.
Risks/Downsides
- One-time cache miss for existing users on upgrade (datafile re-fetched,
last-modifiedreset) - Not user-configurable — a fixed SHA-256 derivation is applied internally
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the SDK persistence mechanisms that generate datafile cache filenames and UserDefaults keys for last-modified metadata. Trace every persistence identifier derived from sdkKey, then verify the identifiers use the proposed CryptoKit SHA-256 value and that existing entries are safely treated as a one-time cache miss after the change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- security
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100