MCPSafe.io
RegistryThreatsMethodologyDocsPricingScanSign in
MCPSafe.io

Security checks for MCP servers — public packages and private repos, fast or deep.

Legal

Privacy PolicyCookie PolicyTerms of ServiceSecurity disclosure

Resources

State of MCP SecuritySupportSystem statusMade in Germany 🇩🇪

© 2026 MCPSafe. All rights reserved.

GDPR — Privacy Policy
← Threat Catalog

Configuration & Environment

Session token stored in localStorage

MEDIUMCWE: CWE-522Rule: MCP-234

Frontend stores an MCP session or auth token in `localStorage` / `sessionStorage` — any XSS gives an attacker permanent token theft.

What it is

`localStorage` is readable by any JavaScript executing on the page. A single XSS — even a transient one — exfiltrates everything in storage to the attacker. The defense is to keep auth tokens in HttpOnly cookies (which JS cannot read) or in memory only (cleared on reload).

Why it matters for MCP

MCP servers often ship with their own admin UIs or web dashboards that use a JWT for auth. Putting that JWT in `localStorage` is the path of least resistance for SPA development, but it's the most common vector by which an MCP server's admin gets popped via an unrelated XSS in a dependency.

Vulnerable example

example.js
1
async function login(creds) {
2
  const res = await fetch("/api/login", { method: "POST", body: JSON.stringify(creds) });
3
  const { token } = await res.json();
4
  localStorage.setItem("auth_token", token);
5
}

Secure example

example.js
1
// Server sets HttpOnly cookie; JS never sees the token.
2
async function login(creds) {
3
  const res = await fetch("/api/login", {
4
    method: "POST",
5
    body: JSON.stringify(creds),
6
    credentials: "include",
7
  });
8
  if (!res.ok) throw new Error("login failed");
9
  // No client-side token storage.
10
}

How MCPSafe detects this

MCPSafe flags `localStorage.setItem(...)` / `sessionStorage.setItem(...)` calls where the key contains `token`, `jwt`, `auth`, `session`, or `bearer` (case-insensitive). Server-side cookie sets are not flagged.

See the full threat catalog for every documented detection.

Further reading

  • CWE-522: Insufficiently Protected Credentials
  • OWASP: HTML5 Security Cheat Sheet

Scan an MCP server for this issue

MCPSafe runs this check — and every other rule in the catalog — on any MCP server you paste in.

Scan now