π§ Memory Protection
SuperSafe Wallet implements comprehensive memory protection strategies to minimize the lifetime of sensitive data in memory and protect against memory-based attacks.
Overviewβ
Principle: Minimize lifetime of sensitive data in memory.
JavaScript's memory model has inherent limitations, but SuperSafe implements multiple strategies to protect sensitive data:
- Immediate cleanup after use
- Scope limitation
- Automatic cleanup on lock
- Short-lived sessions
- Background-only crypto operations
Sensitive Data Handlingβ
Memory Protection Strategiesβ
// 1. Immediate cleanup after use
async signTransaction(tx, privateKey) {
try {
const signature = await ethers.Wallet.signTransaction(tx, privateKey);
return signature;
} finally {
// β Cannot zero out string in JavaScript
// β
But can remove references for GC
privateKey = null;
}
}
// 2. Scope limitation
async getPrivateKey(address) {
// Return key in minimal scope
return this.decryptedWallets.get(address);
}
// 3. Automatic cleanup on lock
async lock() {
// Clear all sensitive data
this.password = null;
this.vaultData = null;
this.decryptedWallets.clear(); // Clear Map
// Force garbage collection hint
if (global.gc) global.gc();
}
Memory Security Limitationsβ
JavaScript Memory Modelβ
Limitations:
- Cannot zero memory directly
- Cannot prevent memory dumps
- Cannot prevent swap to disk
- Garbage collection timing uncertain
Mitigations:
- Minimize sensitive data lifetime
- Clear references immediately
- Use short-lived sessions
- Auto-lock on inactivity
- Background-only crypto operations
Session State Managementβ
Session State (Memory Only)β
BackgroundSessionController {
// Security-critical state (never persisted unencrypted)
isUnlocked: boolean,
password: string, // Memory only
vaultData: Object, // Decrypted vault
decryptedWallets: Map<address, key>, // Private keys
// Session metadata
lastActivityTime: timestamp,
autoLockTimer: TimerId,
autoLockTimeoutMs: 900000, // 15 minutes default
// Connected sites
connectedSites: Map<origin, siteData>
}
Auto-Lock Systemβ
Purpose: Automatically lock wallet after inactivity to protect against unauthorized access.
// Auto-lock implementation
startAutoLockTimer() {
this.stopAutoLockTimer(); // Clear existing timer
this.autoLockTimer = setTimeout(() => {
console.log('[Security] β° Auto-lock triggered');
this.lock();
}, this.autoLockTimeoutMs);
console.log(`[Security] π Auto-lock timer started (${this.autoLockTimeoutMs}ms)`);
}
updateActivity() {
this.lastActivityTime = Date.now();
if (this.isUnlocked && !this.autoLockPaused) {
this.startAutoLockTimer(); // Reset timer
}
}
pauseAutoLock() {
this.autoLockPaused = true;
this.stopAutoLockTimer();
console.log('[Security] βΈοΈ Auto-lock paused');
}
resumeAutoLock() {
this.autoLockPaused = false;
if (this.isUnlocked) {
this.startAutoLockTimer();
}
console.log('[Security] βΆοΈ Auto-lock resumed');
}
Auto-Lock Triggers:
- Inactivity timeout (default 15 minutes)
- Browser close/reload
- Extension update
- Manual lock
- Session expiration
Lock Operationβ
Complete Memory Cleanupβ
async lock() {
console.log('[Security] π Locking vault...');
// 1. Clear sensitive data from memory
this.password = null;
this.vaultData = null;
this.decryptedWallets.clear();
// 2. Clear session state
this.isUnlocked = false;
// 3. Stop auto-lock timer
this.stopAutoLockTimer();
// 4. Clear session storage
await this.clearSessionState();
// 5. Notify all contexts
this.broadcastSessionLocked();
console.log('[Security] β
Vault locked successfully');
}
Best Practicesβ
Minimize Data Lifetimeβ
- Use minimal scope: Keep sensitive data in smallest possible scope
- Clear immediately: Remove references as soon as data is no longer needed
- Avoid caching: Don't cache sensitive data longer than necessary
- Short sessions: Use auto-lock to limit session duration
- Background only: All crypto operations in background service worker
Session Managementβ
- Auto-lock enabled: Default 15-minute timeout
- Activity tracking: Reset timer on user activity
- Manual lock: User can lock immediately
- Clean shutdown: Proper cleanup on extension close
Document Status: β
Current as of November 15, 2025
Code Version: v3.0.0+
Maintenance: Review after memory security improvements