Yoginth

IPFS Subdomain = Security Risk

If your main app runs on example.com, don't host your IPFS gateway at ipfs.example.com. It seems convenient, but it quietly expands your attack surface.

TL;DR

The Real Risk: Same‑Site, Not Same‑Origin

ipfs.example.com and example.com are different origins (they cannot directly read each other's localStorage). But they are the same site because they share the eTLD+1 (example.com). Same‑site leads to two big classes of problems:

  1. CSRF and ambient authority

If a user visits a malicious HTML page hosted on ipfs.example.com, any state‑changing requests it makes to https://example.com are considered same‑site. With SameSite=Lax/None cookies (or missing CSRF protections), the browser will attach the user's session cookies, and your app may process the request as if it came from your site.

  1. Cookie scope and leakage

If your app sets cookies with Domain=.example.com, those cookies are available to all subdomains, including ipfs.example.com. JavaScript on the IPFS page can read them unless they are HttpOnly.

These two together are enough to move money, change emails, or rotate keys if your CSRF defenses are weak. Keeping the gateway under a separate eTLD+1 removes the same‑site relationship entirely.

Note: Scripts loaded via <script src="https://ipfs.example.com/..."> execute in the context of the embedding page (e.g., example.com) and can read everything. Never embed untrusted scripts, regardless of domain.

What To Do Instead

Content-Disposition: attachment
X-Content-Type-Options: nosniff
Content-Security-Policy: default-src 'none'; base-uri 'none'; frame-ancestors 'none'
Set-Cookie: __Host-session=abc123; Path=/; Secure; HttpOnly; SameSite=Lax

Rules enforced by __Host-:

Quick Self‑Check

  1. Is your IPFS gateway on a subdomain of your app's domain?
  1. Do any auth cookies include Domain=.example.com?
  1. Can a page at ipfs.example.com perform a dangerous action on example.com without user interaction?

Bottom Line

Security starts at the domain boundary. At hey.xyz, we isolate untrusted content to keep user sessions and admin surfaces safe.

Security starts at the domain level. Don't let decentralized storage punch a hole in your centralized app. We follow the same on Hey.

Subscribe to my blog