Menu
next-query

Security

What the dev panel exposes, and why it does nothing outside development.

What runs in production

query(), revalidate() and tags(). They are the library. Everything else in the package is for development.

The demo component NextQueryDemo lives at @angelitolm/next-query/demo, not in the package root. It renders in production with only the entries you pass it and never calls the server, so it needs no dev guard. It is meant for docs and demos.

The panel is dev-only by default

  • The query registry that feeds the panel only fills in next dev (or on a staging server that opted in).
  • The panel reads the .next cache files (Next's fetch cache) and shows response previews.
  • In a production build <NextQuery /> renders null and makes no request. The panel itself is a separate chunk that pages never load for visitors; the playground's production smoke test checks this on every run.
  • The panel talks to the server through server actions. A server action is a public endpoint, like any other. Outside development each one throws next-query devtools are dev-only unless the request carries the staging secret, and the tags the browser sends are validated before they are used.

Staging (self-hosted)

next-query is a development tool. Its panel does not belong in a production environment, and nothing in the package turns it on there by itself.

A staging server used for specific QA testing is the one exception, and it is a decision your development team makes on purpose: the panel stays off until someone sets the secret below on that server. Do it only on staging, only for the time QA needs it, and never on the environment your users reach.

Never in production

Do not set NEXT_QUERY_SECRET in production, not even temporarily to debug. The panel exposes cached responses and lets whoever holds the secret revalidate your cache.

To enable it on a self-hosted staging server (next build + next start), set a secret of at least 16 characters on the server:

bash
NEXT_QUERY_SECRET=a-long-random-string

Then, in the browser that should see the panel, set it as the next-query cookie (once, from the DevTools console):

js
document.cookie = 'next-query=a-long-random-string; path=/; max-age=2592000; samesite=strict'

Reload the page: the panel appears for that browser only. It shows the same thing as in development (every tagged fetch and query(), with HTTP status, response headers, freshness and revalidate buttons).

How the access check works

  • Without the variable, or with one shorter than 16 characters, production behaves exactly as described above.
  • On every page load, <NextQuery /> looks for a next-query cookie. Without it, it does nothing: no request, no panel code downloaded. Your visitors never pay for the panel.
  • With the cookie, it calls the hasAccess() server action once. The server compares the cookie with the secret in constant time. Only on success does the browser download the panel's chunk.
  • The other server actions (getEntries, revalidateTags) check the secret on every call, so they can't be called without it either. A wrong cookie is refused like none.

Turn it off

  • For one browser: delete the cookie, document.cookie = 'next-query=; path=/; max-age=0', and reload.
  • For everyone: remove NEXT_QUERY_SECRET from the server and restart it.

Limits

  • The panel reads .next/cache/fetch-cache from disk, so it needs a single next start process with Next's default cache. On Vercel, serverless platforms or with a custom cacheHandler (Redis…) the fetch list is empty or partial.
  • On staging the registry keeps one entry per query() key read, in memory. Fine for QA traffic, one more reason it doesn't belong in production.
  • Anyone with the secret can read cached previews and revalidate tags. Treat it like a password: never use a NEXT_PUBLIC_ variable for it, and rotate it when someone leaves the team.

next dev listens on your network

While next dev runs, anyone who can reach it (usually everyone on your LAN) can read previews of your cached fetch responses and query data, up to about 16 KB each, and revalidate tags. This is the same exposure as next dev itself. Do not run it on an untrusted network, and never expose a dev server to the internet.

What to keep in mind

  • Fetch URLs, including query strings (which may carry keys), are sent to the panel in development too.
  • A preview is the response body of a tagged fetch, or the data of a query, as JSON or text. If it is something private, it shows up in the panel in development.
  • Revalidating is harmless by design: it expires cached data, and the next read refetches it.