Skip to content

[Security] /api/auth/ensure-login returns JWT in JSON body without Cache-Control: no-store #9062

Open

Description

@BL4CK570RM

Labels: security, severity: medium, area: dashboard/auth, owasp: A02 Security Misconfiguration, cwe: CWE-522, cwe: CWE-311

CVSS: 5.3 — CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:N/A:N

CWE: CWE-522 (Insufficiently Protected Credentials), CWE-311 (Missing Encryption of Sensitive Data), CWE-525 (Use of Web Browser Cache Containing Sensitive Information)

Reported by: MD Mahmidul Hasan

Summary

The ensure-login route returns the bearer JWT in the JSON response body ({ isLoggedIn: true, jwt: token }) and does not set Cache-Control: no-store. This defeats the protection that the HttpOnly auth cookie otherwise provides against XSS and broadens the token-exfiltration surface.

This issue is self-contained: no other finding needs to be addressed to reproduce or remediate it.

Affected code

  • apps/dashboard/src/app/(app)/api/auth/ensure-login/route.ts:80-81

Evidence

// apps/dashboard/src/app/(app)/api/auth/ensure-login/route.ts:80
return NextResponse.json({ isLoggedIn: true, jwt: token });
// no Cache-Control header set

Steps to reproduce

cd ~/path/to/js

# Start local dashboard if not already running
if ! curl -sS -o /dev/null --max-time 1 http://localhost:3000/login 2>/dev/null; then
  NEXT_PUBLIC_THIRDWEB_API_HOST=http://127.0.0.1:65535 \
  DASHBOARD_SECRET_KEY=dummy \
  API_SERVER_SECRET=dummy \
  pnpm --filter thirdweb-dashboard dev > /tmp/dev.log 2>&1 &
  sleep 25
fi

echo "[1] Unauthenticated request headers:"
curl -isS 'http://localhost:3000/api/auth/ensure-login?address=0x0000000000000000000000000000000000000000' \
  | grep -iE '^(HTTP/|cache-control:|content-type:)'

echo
echo "[2] Unauthenticated response body:"
curl -sS 'http://localhost:3000/api/auth/ensure-login?address=0x0000000000000000000000000000000000000000'
echo

echo
echo "[3] Source — jwt is returned and no Cache-Control is set:"
grep -n 'jwt: token\|no-store' \
  apps/dashboard/src/app/\(app\)/api/auth/ensure-login/route.ts \
  || echo "  → jwt returned in body, no no-store header"

Expected output (vulnerable):

[1] Unauthenticated request headers:
HTTP/1.1 200 OK
content-type: application/json
                                 ← no Cache-Control header

[2] Unauthenticated response body:
{"isLoggedIn":false}

[3] Source — jwt is returned and no Cache-Control is set:
  ...:80:  return NextResponse.json({ isLoggedIn: true, jwt: token });   ← jwt leaks when logged in
  → no "Cache-Control: no-store" anywhere in the file

Authenticated confirmation:

  1. Log in to http://localhost:3000
  2. DevTools console:
await fetch('/api/auth/ensure-login?address=<your-address>').then(r => r.json())
  1. Response: {"isLoggedIn":true,"jwt":"eyJ..."} — the JWT is readable by any script on the origin.

Impact

  • Any JavaScript running on the dashboard origin (for example through an XSS or a compromised third-party script) can read the bearer token from the JSON response.
  • Without Cache-Control: no-store, the response may be cached by browsers or intermediaries, extending the token's exposure.
  • The token can be replayed outside the browser, bypassing HttpOnly cookie protections.

Remediation

  • Return only isLoggedIn; keep the bearer token server-side/HttpOnly.
  • If the client genuinely needs a JWT, return a short-lived, audience-scoped token via an HttpOnly cookie or a separate authenticated endpoint with Cache-Control: no-store.
  • Validate the address before issuing any token.
--- a/apps/dashboard/src/app/(app)/api/auth/ensure-login/route.ts
+++ b/apps/dashboard/src/app/(app)/api/auth/ensure-login/route.ts
@@
-import { getAddress } from "thirdweb/utils";
+import { getAddress, isAddress } from "thirdweb/utils";
@@
   const address = req.nextUrl.searchParams.get("address");
@@
   if (!address) {
@@
   }
+
+  if (!isAddress(address)) {
+    return NextResponse.json({ error: "Invalid address" }, { status: 400 });
+  }
 
   const authCookieName = COOKIE_PREFIX_TOKEN + getAddress(address);
@@
-  return NextResponse.json({ isLoggedIn: true, jwt: token });
+  const response = NextResponse.json({ isLoggedIn: true });
+  response.headers.set("Cache-Control", "no-store");
+  return response;
 };

References

  • OWASP 2025: A02 Security Misconfiguration
  • CWE-522: Insufficiently Protected Credentials
  • CWE-311: Missing Encryption of Sensitive Data
  • CWE-525: Use of Web Browser Cache Containing Sensitive Information

Activity

  1. linear commented on Nov 8, 2026

    @linear
  2. github-actions commented on Nov 16, 2026

    @github-actions
    Contributor

    This issue has been inactive for 7 days. It is now marked as stale and will be closed in 2 days if no further activity occurs.

  3. BL4CK570RM commented on Nov 16, 2026

    @BL4CK570RM
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions