localhost:5173 / allowed-hosts

Blocked request. This host is not allowed.

The Vite dev server only answers to localhost, hostnames ending in .localhost, and IP addresses — every other hostname has to be listed in server.allowedHosts.

error
Blocked request. This host ("app.local") is not allowed.
To allow this host, add "app.local" to `server.allowedHosts` in vite.config.js.

Allow the hostname you actually use

Add the hostname to server.allowedHosts. A leading dot covers the domain and every subdomain under it: .example.com allows example.com, foo.example.com and foo.bar.example.com.

vite.config.js
export default defineConfig({
  server: {
    allowedHosts: ['app.local', '.example.com'],
  },
})

Why the check exists

Without it, any website you visit could point a domain it controls at 127.0.0.1 and then read your dev server through it — your source code, your .env values, whatever the server serves. That is a DNS rebinding attack. The host check is what stops it, which is why the fix is a list and not a switch.

Do not set it to true

allowedHosts: true disables the check completely and hands that attack back to anyone who can get you to open a page. It shows up in a lot of forum answers because it makes the error disappear. So does deleting your firewall.

vite.config.js
// what most answers tell you to do
server: { allowedHosts: true }   // ← any website can now read your dev server

// what to do instead
server: { allowedHosts: ['the-one-host-you-need'] }

Only add hosts whose DNS you control

A hostname is safe to add if you decide which IP it resolves to. Your own domain qualifies. A domain owned by someone else does not, because they can point it at your machine. Never add a top-level domain like .com — anyone can buy a name under it.

Tunnels, containers and reverse proxies

This is where the error usually appears: ngrok, Cloudflare Tunnel, a Docker service name, a Traefik or nginx host in front of Vite. The browser sends that hostname in the Host header, Vite compares it against the list, and rejects it. Add the exact hostname the browser uses — not the IP, not localhost.

vite.config.js
server: {
  host: true,                       // listen on the LAN, not just 127.0.0.1
  allowedHosts: ['.ngrok-free.app'] // the hostname the browser sees
}

CI and throwaway environments

When the hostname is only known at runtime, pass it in instead of editing the config.

bash
__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=preview-42.internal npm run dev

vite preview has its own list

preview.allowedHosts defaults to server.allowedHosts, so it usually inherits the right value. If you set it explicitly, set it in both places — a build that works in dev and gets blocked in preview is almost always this.

vite.config.js
export default defineConfig({
  server:  { allowedHosts: ['app.local'] },
  preview: { allowedHosts: ['app.local'] },
})

One case where it never fires

Over HTTPS the host check is skipped entirely. If the error disappeared after you put TLS in front of the dev server, it was not fixed — it was bypassed.

# faq

Questions

Which hosts are allowed without configuration?

localhost, any hostname ending in .localhost, and all IP addresses. Everything else is rejected until you list it.

Does .example.com include example.com itself?

Yes. A leading dot allows the bare domain and every subdomain under it.

Is allowedHosts: true safe on a machine behind a firewall?

No. The attack comes through your own browser, from a page you opened — a firewall does not see it as an incoming connection.

Why did this start after an upgrade?

The host check was added as a security fix. Projects that reached the dev server under a custom hostname worked before the upgrade and stop working after it.

# next

Related

# sources

Checked against the Vite documentation on 2026-09-11.