← All posts
·6 min read·GuardLayer·How we write

Next.js allowedDevOrigins: fix blocked dev requests

Next.jsDev serverCORSConfigurationSecurity

Blocked cross-origin request to Next.js dev resource means a page loaded from a hostname other than localhost (your phone on a LAN IP, a tunnel, a custom local domain) asked next dev for its scripts or its hot-reload connection. Add that exact hostname, without http:// or a port, to allowedDevOrigins in next.config and restart. There is no "allow all": a bare * or ** is rejected, because this check is what stops other websites from reading your dev build.

The dev server serves things production never does: unminified client code, source maps, and a WebSocket for hot module replacement. Since Next.js 16.2 it refuses those to any origin you haven't listed. Your pages still load from the other device. Their JavaScript doesn't, so the page renders but nothing is interactive and HMR never connects.

What does "Blocked cross-origin request" mean in Next.js?

It means the Origin (or, for a script tag, the Referer) of a request to /_next/* or /__nextjs* named a host that isn't localhost, a subdomain of localhost, the host the server was started with, or an entry in allowedDevOrigins. The wording depends on your version:

# Next.js 16.2 and later (blocks by default)
Blocked cross-origin request to Next.js dev resource /_next/webpack-hmr from "192.168.1.20".
Cross-origin access to Next.js dev resources is blocked by default for safety.

# 15.2.2 to 16.1.x, when allowedDevOrigins is set
Blocked cross-origin request from 192.168.1.20 to /_next/* resource. To allow this,
configure "allowedDevOrigins" in next.config

# 15.2.2 to 16.1.x, when it isn't set (a warning only, nothing blocked)
Cross origin request detected from 192.168.1.20 to /_next/* resource. In a future major
version of Next.js, you will need to explicitly configure "allowedDevOrigins" in next.config
to allow this.

The older two come from block-cross-site.ts and the 16.2+ one from block-cross-site-dev.ts in vercel/next.js. The blocked request gets a 403 with the body Unauthorized. In 16.2+ the message also prints the exact allowedDevOrigins line to add.

How do I fix it?

Copy the hostname from the message into next.config and restart next dev:

// next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  allowedDevOrigins: [
    "192.168.1.20",          // your phone or laptop on the LAN
    "myapp.local",           // a custom local hostname
    "ada-dev.example.com",   // your own reserved tunnel host
  ],
};

export default nextConfig;

The allowedDevOrigins docs say only the hostname is matched: "The scheme, the port, the path, and the query string are ignored." Wildcards work per label: * "stands in for exactly one label of the hostname, and ** for one or more". So *.example.com matches ada.example.com, and **.example.com also matches ada.eu.example.com. Neither matches example.com itself.

Why is allowedDevOrigins not working?

When the entry is there and requests still fail, it's almost always one of these:

  1. It has a scheme or port. "http://192.168.1.20:3000" never matches. Write "192.168.1.20".
  2. It's a partial wildcard. The docs: "Partial replacement is not supported. Write *.local-origin.dev, rather than team-*.local-origin.dev." And ** only works at the start.
  3. You didn't restart. The config is read when next dev starts.
  4. The hostname is different from what you typed in the browser. Some tunnels rewrite the host. Use the one in the log line, which is what the server saw.
  5. The request has Origin: null. A sandboxed iframe or a privacy-sensitive context sends no usable origin. The 16.2+ message says so ("from a privacy-sensitive or opaque origin"), and no entry can allow it. Load the page from a normal origin.

How do I allow all origins in allowedDevOrigins?

You can't. In current versions the matcher (matchWildcardDomain in csrf-protection.ts) refuses a pattern that is only * or **, and the option takes a list of hostnames, not true. The reason is a pair of real vulnerabilities.

CVE-2025-48068 (GHSA-3h52-269p-cp9r): Next.js 13.0.0 to 14.2.29 and 15.0.0 to 15.2.1 didn't check the origin of requests to the dev server. A website you visited while next dev was running could hijack its WebSocket and include its scripts, exposing the source of your client components. The fix in 14.2.30 and 15.2.2 was opt-in: you had to set allowedDevOrigins to turn it on.

CVE-2026-27977 (GHSA-jcc7-9wpm-mj36): in Next.js 16.0.1 through 16.1.6, a request with Origin: null could bypass allowedDevOrigins, letting attacker-controlled browser code "connect to internal development endpoints". Fixed in 16.1.7; the advisory notes it "affects development mode only."

So an allow-all entry would bring back exactly the hole the option was built to close. The same applies to wildcards over shared domains: *.ngrok-free.app, *.trycloudflare.com or **.app.github.dev list every tunnel and codespace anyone else opens. Any page on any of them can then load your dev assets and talk to your HMR socket while your dev server is running. List your one reserved tunnel hostname instead. The same shared-domain trap exists for Server Actions, covered in the safe fix for "Invalid Server Actions request".

Are you protected on 15.x or 16.0–16.1?

Only if you set the option. From the 15.2.2 fix through 16.1.x (and on the 14.2.30+ backport, which the advisory also describes as opt-in), the check runs in warn mode when allowedDevOrigins is undefined: you get the "Cross origin request detected" warning and the request goes through. Setting it, even to an empty list, switches it to blocking:

// next.config.ts, on 15.2.2 to 16.1.x: [] means "localhost only", and blocks the rest
const nextConfig = { allowedDevOrigins: [] };

Better still, upgrade. 16.2 and later block by default, and every current release line is past both fixes. The latest safe Next.js version lists today's floors, which also cover production advisories that matter far more than this one.

Two more things to check. Don't run next dev -H 0.0.0.0 on a network you don't trust, since that exposes the dev server to every device on it. And keep dev-only hosts out of production config: allowedDevOrigins only affects next dev, but a tunnel hostname next to it in serverActions.allowedOrigins applies in production too.

Quick self-check

# your Next.js version (15.2.2 to 16.1.x: is allowedDevOrigins set?)
npm ls next

# every entry, and any shared-domain or allow-all wildcard
grep -rn "allowedDevOrigins" next.config.*
grep -nE "ngrok|trycloudflare|github\.dev|loca\.lt|[\"']\*\*?[\"']" next.config.*

Every entry should be a hostname you control. A shared tunnel domain or a bare * should go.

Does GuardLayer catch this?

Not the config. GuardLayer doesn't read allowedDevOrigins entries today, so use the grep above. What it does check is your next version: the dependency rule flags any version below the current patched floors (16.4.5 and 15.5.29 as of November 2026), which sit well above both dev-server fixes. The Next.js app-layer security guide covers the rules it runs on your code.

FAQ

What is allowedDevOrigins in Next.js? A next.config option listing extra hostnames that may request the dev server's internal resources (/_next/*, HMR). It only affects next dev.

Why does my page load on my phone but nothing works? The HTML is served, but the scripts and the HMR connection are blocked as cross-origin. Add your computer's LAN IP, the one in the log line, to allowedDevOrigins.

Do I include the port in allowedDevOrigins? No. Only the hostname is matched. Write 192.168.1.20, not http://192.168.1.20:3000.

Does allowedDevOrigins affect production? No. Production builds don't serve these dev resources. For cross-origin rules in production, look at CORS headers and serverActions.allowedOrigins.

Is it safe to add *.ngrok-free.app? No. It trusts every ngrok tunnel anyone opens. Use your own reserved subdomain as an exact entry.

Scan your Next.js + Supabase app — free

GuardLayer runs 43 checks — exposed keys, missing RLS, over-permissive policies, unprotected Server Actions — with the exact fix inline. Connect GitHub and it checks every push too — free on public repos.

No signup, no card. Raw files aren’t kept; only the report is saved.

Keep reading