DEV Community

Daniel Pertu
Daniel Pertu

Posted on

Our whole browser storage is two cookies, and a signed-in page view uploads 53 KB of them

"We do not store anything on your device" is easy to write in a privacy notice and awkward to verify, including for the person who wrote it. Browser storage has at least six hiding places, and a framework, an analytics library or a bot check can each quietly use one. So I went looking on Nakodo for everything this app leaves in a browser.

A visitor who never signs in

First the responses. Every one of the 76 public pages, requested with no cookies at all:

while read u; do curl -sI "$u" | grep -i '^set-cookie'; done < urls.txt
# (nothing)
Enter fullscreen mode Exit fullscreen mode

Then the browser side, after browsing around the public pages:

document.cookie                     ""
localStorage                        0 keys
sessionStorage                      0 keys
indexedDB.databases()               []
caches.keys()                       []
navigator.serviceWorker             0 registrations
navigator.storage.estimate().usage  0 bytes (quota: 10,737,418,240)
Enter fullscreen mode Exit fullscreen mode

Zero of six. The interesting part is not that the number is zero but which decisions had to hold for it to be zero, because three separate features all wanted storage and all were pointed somewhere else.

Analytics was the loudest. PostHog defaults to a cookie plus a localStorage entry for its distinct ID, and the configuration this app ships says no:

posthog.init(POSTHOG_TOKEN, {
  // No cookies and nothing in local or session storage. The visitor's ID and
  // session live in the page's memory, so they last while the tab moves
  // between pages and start again on a reload or in a new tab. PostHog's own
  // cookieless_mode would also do without storage, but it turns session
  // recording off.
  persistence: "memory",
  person_profiles: "identified_only",
  respect_dnt: true,
Enter fullscreen mode Exit fullscreen mode

Prices were the subtle one. The pricing page shows a visitor's own currency, and the obvious implementation is to work the country out once and keep it in a cookie. This app reads a request header on every render instead, which is why that page and the home page are the only two on the site that cannot be served from the CDN cache, and the comment in the file says why:

// There's deliberately no cookie fallback: the site sets no cookies beyond the sign-in one.
Enter fullscreen mode Exit fullscreen mode

The third is the bot check, which is Cloudflare Turnstile and only renders on the sign-up form. I could not audit that one from this browser, because the profile holds a session and the sign-up page redirects into the app, so here is the honest version: Turnstile loads Cloudflare's script and runs its challenge in a cross-origin frame, so anything it keeps is in Cloudflare's own storage for its own domain rather than in any of the six places I measured on this origin. What it leaves on our side is a hidden cf-turnstile-response field, which is a form value and not storage.

A visitor who signs in

Exactly two cookies, and they are one logical cookie cut in half:

Name Bytes Flags Lifetime
sb-<project>-auth-token.0 3,180 Path /, SameSite Lax, not HttpOnly, not Secure 400 days
sb-<project>-auth-token.1 69 same same

Both numbers come from the library rather than from us. The split is here:

// @supabase/ssr/dist/main/utils/chunker.js
exports.MAX_CHUNK_SIZE = 3180;
Enter fullscreen mode Exit fullscreen mode

The session is a base64 bundle holding an access token, a refresh token and the user record, which comes to a little over 3 KB, so the writer cuts it at 3,180 bytes and numbers the pieces. A reader joins .0 and .1 back together by name. That is why the second cookie is 69 bytes: it is the remainder, and it will change size every time the encoded session does.

The lifetime is the other borrowed number:

// @supabase/ssr/dist/main/utils/constants.js
exports.DEFAULT_COOKIE_OPTIONS = {
  path: "/",
  sameSite: "lax",
  httpOnly: false,
  // https://developer.chrome.com/blog/cookie-max-age-expires
  maxAge: 400 * 24 * 60 * 60,
};
Enter fullscreen mode Exit fullscreen mode

400 days exactly, because that is the ceiling Chrome puts on cookie lifetime, so the library asks for precisely the most it can get. Reading the live cookie back gives an expiry 400 days out to the minute, which is a nice way to see a library's default and a browser's limit agree.

httpOnly: false is not an oversight either, in this app at least. The public header has to decide whether to offer "Open the app" or "Sign in" on a statically served page, and the way it does that is to read the cookie in the browser:

// Public pages are static, so the server can't say who is signed in. The
// browser can: Supabase keeps the session in a readable cookie.
const SESSION_COOKIE = /(?:^|;\s*)sb-[^=;]+-auth-token(?:\.\d+)?=/;
Enter fullscreen mode Exit fullscreen mode

Which is a real trade: a readable session cookie in exchange for a static home page with a correct header. The access token it holds is also what the client library needs to talk to Supabase directly, so HttpOnly was never available here without changing the whole auth shape.

The number I did not expect

One page view, signed in, counted through the DevTools protocol:

requests with request headers observed   17
requests carrying a Cookie header        16
total bytes of Cookie headers            53,200
Enter fullscreen mode Exit fullscreen mode

53 KB uploaded to read one page. The cookie's path is /, so it is attached to the document, to the React Server Components payload, to each font, and to every /_next/static chunk that was not already in the browser cache. Nothing is broken, but a 3.2 KB cookie at the root of an origin is a per-request upload tax on everything served from that origin, and on a slow uplink the upload is the expensive direction.

The usual answer is to serve static assets from a cookieless host. On this platform the assets are on the same origin by design, and the request count is small because almost everything is immutable and cached, so I am recording the cost rather than paying to avoid it. It does change how I read the earlier measurement that 31 of 44 requests on a page came from the browser cache: those 31 are also the ones that did not upload 3.2 KB each.

What is not marked Secure

The one item I will change. The session cookie has no Secure flag, because the library's defaults do not set one. In practice every request to this origin is HTTPS: the site sends strict-transport-security: max-age=63072000, so a browser that has been here once will refuse plaintext for two years. But the header has no preload directive, so the very first request a browser ever makes to the domain is not covered, and a cookie without Secure is a cookie that something on the wire is allowed to see or to overwrite on that one request.

createServerClient takes cookieOptions, so this is one line plus a deploy, and it is now on the list in front of the nicer-looking work.

Does the privacy notice match?

This is the part worth doing after an audit like this, and it is why I ran it. The cookies section says the only cookies are the ones that keep you signed in, that they are strictly necessary, and that there is therefore no consent banner. The analytics section says nothing is stored on your device, no cookies and no local storage, and that each visit gets a random ID that is forgotten when you close or reload the tab.

Measured: two sign-in cookies, nothing else, no storage of any kind for a visitor who never signs in, and a visitor ID that lives in a JavaScript variable. The notice and the browser agree, which is the only acceptable outcome and still worth checking rather than assuming, because any of those three decisions could be undone by a default in a library upgrade and nothing in the test suite would notice.

That last sentence is the actual finding. The zero is held in place by one library configuration, one comment in a pricing helper and one absent dependency, none of which has a test. A storage audit is cheap enough to run in a browser console, and now that I know what the answer should be, it is the kind of thing that belongs in CI rather than in a blog post.

Top comments (1)

Collapse
 
omyvnss profile image
Om Yaduvanshi •

the posthog detail is the one that stayed with me. a default that drops a cookie and a localStorage entry is exactly how a zero-storage claim quietly breaks, and it takes a deliberate config to hold the line. the 53 KB number is the sharper point though, since 16 of 17 requests carry the session cookie to fonts and static chunks. the secure flag fix being one line plus a deploy is a good place to start, as the first request is the one HSTS without preload does not cover.