mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 16:14:40 +00:00
Embedded web content — browser tabs, napplets, nSites — runs in WebViews in the `:napplet` process, and their cookies, localStorage, IndexedDB and service workers were SHARED across every Nostr account on the device. Nothing in the repo ever cleared them: no `CookieManager`, no `WebStorage` call anywhere. So a web app stayed logged in as the previous account after a switch, and a Nostr web client's localStorage — which routinely holds decrypted DMs, drafts and follow caches — was readable by whichever account came next. For a user keeping a pseudonymous npub apart from a real one, the app could correlate the two itself. Uses the androidx.webkit multi-profile API (already a dependency) to give each account its own profile: cookies, storage, geolocation grants and service workers are all partitioned per `Profile`. Switching accounts moves to that account's jar and switching back restores the session intact — isolation rather than deletion, so nothing is lost. The sandbox never learns which account it is serving. The main process derives an opaque, domain-separated SHA-256 of the account pubkey, truncated to 32 hex chars, and passes only that; `:napplet` validates the shape before use, so a compromised sandbox cannot mint a name for another account's jar. Both re-arm paths read the current profile at send time, so a re-created session can never resurrect the previous account's jar. Where MULTI_PROFILE is unsupported (older WebView), isolation degrades to lossy-but-safe: cookies and web storage are wiped when the account behind the WebViews changes, rather than silently shared. Known gap, documented at the logout hook: a removed account's profile is not deleted. It cannot be done from the main process — WebView profiles live in the `:napplet` data directory, and booting WebView here would collide on it — so it needs a broker message that has the sandbox call `ProfileStore.deleteProfile`, and that must refuse a profile still bound to a live WebView. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>