Skip to content

Viewer stores bearer token in sessionStorage — users must re-enter on every new tab #1117

Description

@Shana-AE

Summary

The viewer stores the AGENTMEMORY_SECRET bearer token in sessionStorage instead of localStorage. Since sessionStorage is per-tab and cleared when the tab closes, users must re-enter the token every time they open a new tab or restart their browser.

Affected code

src/viewer/index.html (around line 1207–1212 on v0.9.27):

var VIEWER_TOKEN_STORAGE_KEY = 'agentmemory-viewer-token';

// Read
try { return sessionStorage.getItem(VIEWER_TOKEN_STORAGE_KEY) || ''; } catch (_) { return ''; }

// Write
if (token) sessionStorage.setItem(VIEWER_TOKEN_STORAGE_KEY, token);
else sessionStorage.removeItem(VIEWER_TOKEN_STORAGE_KEY);

Notably, the theme preference already uses localStorage (line 1070):

localStorage.setItem('agentmemory-theme', dark ? 'dark' : 'light');

So the less-sensitive setting persists, but the auth token does not.

Impact

Suggested fix

Use localStorage instead of sessionStorage for the token. If there are XSS concerns with localStorage, consider:

  1. A "Remember token" checkbox (default off = sessionStorage, on = localStorage)
  2. Token expiry (clear after N hours)
  3. The existing nonce-based CSP (script-src 'nonce-XXX') already provides strong XSS protection, making localStorage reasonably safe

Workaround

Local patch (entrypoint sed):

sed -i 's|sessionStorage.getItem(VIEWER_TOKEN|localStorage.getItem(VIEWER_TOKEN|g' viewer/index.html
sed -i 's|sessionStorage.setItem(VIEWER_TOKEN|localStorage.setItem(VIEWER_TOKEN|g' viewer/index.html
sed -i 's|sessionStorage.removeItem(VIEWER_TOKEN|localStorage.removeItem(VIEWER_TOKEN|g' viewer/index.html

Tested on v0.9.27.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions