Blog · · The Expose team

Invalid Host header when sharing a dev server: why it happens and the fix for each framework

Fix Invalid Host header in webpack, React, Vue CLI, Angular, Vite, Next.js, Django and Rails. Allow your tunnel's hostname, not every host, in one line.

"Invalid Host header" means your dev server refused the request because the hostname in it isn't on the server's list of allowed hosts. On localhost everything works. Open the same app through a tunnel URL, a custom local domain or a proxy, and the browser sends a hostname the dev server has never heard of, so it answers with an error instead of your app.

The fix is one line of config: add that hostname, or the domain it ends in, to the dev server's allowlist. Don't switch the check off. It exists to stop other websites from reading your dev server.

For an Expose tunnel, the domain to allow is .sharedwithexpose.com:

// vite.config.js
export default {
  server: {
    allowedHosts: ['.sharedwithexpose.com'],
  },
}

Every framework names this setting differently. The table below has the one you need.

The fix for each framework
#

Framework What you see Setting Entry for an Expose tunnel
webpack-dev-server 4+ Invalid Host header devServer.allowedHosts '.sharedwithexpose.com'
Create React App Invalid Host header (only with proxy set) None, only an off switch See below
Vue CLI Invalid Host header devServer.allowedHosts in vue.config.js '.sharedwithexpose.com'
Angular Blocked request. This host (…) is not allowed. allowedHosts in angular.json ".sharedwithexpose.com"
Vite Blocked request. This host (…) is not allowed. server.allowedHosts '.sharedwithexpose.com'
Next.js Blocked cross-origin request … to /_next/* resource allowedDevOrigins '**.sharedwithexpose.com'
Django DisallowedHost: Invalid HTTP_HOST header ALLOWED_HOSTS '.sharedwithexpose.com'
Rails Blocked hosts: … config.hosts ".sharedwithexpose.com"
Laravel Nothing, by default trustHosts only if you enabled it See below

A leading dot means "this domain and every subdomain of it" in all of these except Next.js, which uses * and ** wildcards instead. Restart the dev server after changing its config.

Why dev servers check the Host header
#

Every HTTP request carries a Host header with the hostname the browser asked for. Your dev server compares it with a list. Requests for localhost and, in most tools, for IP addresses pass. Anything else gets blocked.

The check stops an attack called DNS rebinding. It works like this:

  1. You visit a malicious page on evil.example while your dev server runs.
  2. The attacker's DNS server switches evil.example to 127.0.0.1, your own machine.
  3. The page's scripts now request evil.example:5173. The browser sends them to your dev server and treats the responses as same-origin, so the page can read your source code and anything your app returns.

The one thing the attacker can't change is the Host header. It still says evil.example, so a dev server that checks it refuses the request. Vite's security advisory from January 2025 puts it plainly: "Non-HTTPS servers are vulnerable to DNS rebinding attacks without validation on the Host header."

A tunnel trips the same check for an innocent reason. Its hostname, such as abc123.sharedwithexpose.com, is new to your dev server too.

Why allowing a tunnel domain keeps you safe
#

The attack only works with a hostname whose DNS the attacker controls. Nobody but the tunnel provider controls DNS for the tunnel's domain, and nobody but you controls yours. So allowing .sharedwithexpose.com or .share.example.com lets your tunnel in and still keeps the attacker out.

Switching the check off removes that protection for every site you visit while the dev server runs. Vite's docs say not to add a top-level domain like .com to the list for the same reason.

Find the hostname to allow
#

The error usually tells you. Vite, Angular, Django and Rails print the exact hostname they blocked, and Vite, Django and Rails even print the line to add.

Expose URLs come in three shapes:

You share with URL looks like Entry to allow
The free plan https://abc123.sharedwithexpose.com (random, new on every connection) .sharedwithexpose.com
A reserved subdomain on a Pro server https://my-app.eu-1.sharedwithexpose.com my-app.eu-1.sharedwithexpose.com
A custom domain https://my-app.share.example.com .share.example.com

The free URL changes every time you share, so only the domain suffix keeps working. With a reserved subdomain or your own domain, you can allow the exact hostname once and leave it. More on that below.

webpack-dev-server
#

webpack-dev-server answers a blocked request with a 403 and the body Invalid Host header. The hot-reload connection reports the same check as Invalid Host/Origin header. The setting is devServer.allowedHosts:

// webpack.config.js
module.exports = {
  // ...
  devServer: {
    allowedHosts: ['.sharedwithexpose.com'],
  },
};

It takes 'auto' (the default), 'all', or a list of hostnames. In the list, .host.com matches host.com and all its subdomains. 'auto' allows localhost, the value of the host option and the hostname in client.webSocketURL.

Older answers on Stack Overflow say disableHostCheck: true. That was webpack-dev-server 3. Version 4 removed it in favour of allowedHosts: 'all', which the version 5 docs say "bypasses host checking". A list with your tunnel domain does the job without that.

Create React App
#

Create React App (react-scripts 5) runs webpack-dev-server 4, but it doesn't let you set allowedHosts. Its dev server config decides on its own:

const disableFirewall =
  !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
// ...
allowedHosts: disableFirewall ? 'all' : [allowedHost],

That explains when you see the error. Without a proxy field in package.json, CRA allows every host already. Once you add proxy, it turns the check on with just your machine's private network address on the list, so a tunnel URL fails.

CRA offers two ways out, and neither is a narrow allowlist:

  • DANGEROUSLY_DISABLE_HOST_CHECK=true in .env.development.local turns the check off. CRA's own docs warn that "this is dangerous and exposes your machine to remote code execution from malicious websites" and say they don't recommend it. If you use it, keep it in that .local file, out of version control, and remove it when you stop sharing.
  • HOST=your-dev-host.com in .env.development is what CRA's docs recommend. CRA also uses HOST as the address the dev server listens on, though. That suits a dev hostname that points at your own machine, not a tunnel hostname that points at the tunnel's servers.

The React team deprecated Create React App for new apps on February 14, 2025, and it has no active maintainers. If you hit this regularly, moving the app to Vite gets you a real allowlist: one line, shown in the Vite section.

Vue CLI
#

Vue CLI passes devServer in vue.config.js straight to webpack-dev-server. @vue/cli-service 5 uses webpack-dev-server 4, so the webpack fix applies:

// vue.config.js
module.exports = {
  devServer: {
    allowedHosts: ['.sharedwithexpose.com'],
  },
};

Vue CLI is in maintenance mode, and the Vue team recommends create-vue, which uses Vite, for new projects. For a Vue app on Vite, see Vite.

Angular
#

Since the dev server moved to Vite, Angular blocks unknown hosts with a page titled "Blocked request" that says: "To allow this host, add it to allowedHosts under the serve target in angular.json." That's the fix:

{
  "projects": {
    "my-app": {
      "architect": {
        "serve": {
          "options": {
            "allowedHosts": [".sharedwithexpose.com"]
          }
        }
      }
    }
  }
}

The option is also available as ng serve --allowed-hosts. Angular passes it to Vite's option of the same name, so Vite's rules apply, including the leading dot. Setting it to true allows every host, which Angular's schema calls "not recommended and a security risk."

--disable-host-check belongs to the older webpack-based builder, @angular-devkit/build-angular:dev-server. The current @angular/build:dev-server builder doesn't have it. Check the builder of your serve target in angular.json to see which one you run. On the older builder, allowedHosts takes a list as well.

This is current as of Angular 22.

Vite
#

Vite shows:

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

Adding the exact hostname works until your next free URL. Add the domain instead:

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  server: {
    allowedHosts: ['.sharedwithexpose.com'],
  },
});

Some details from Vite's server options:

  • localhost, any name under .localhost and all IP addresses are allowed by default. That's why a LAN address like http://192.168.1.23:5173 works while a tunnel URL doesn't.
  • .example.com allows example.com, foo.example.com and foo.bar.example.com.
  • allowedHosts: true allows any host. Vite's docs warn that it lets "any website" reach your dev server through DNS rebinding.
  • The __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS environment variable adds hosts without touching the config, comma-separated. That's handy for a one-off share.
  • vite preview has its own preview.allowedHosts, which defaults to server.allowedHosts.

The check arrived with the security fix Vite published on January 20, 2025, in versions 6.0.9, 5.4.12 and 4.5.6. That's why projects that shared fine before an upgrade started showing the error. The Vite guide covers sharing a Vite app with Expose from start to finish.

Next.js
#

The Next.js dev server's check looks at a different header. It compares the Origin of requests to its dev-only resources under /_next/, such as hot reloading, with a list. So the symptom is different too: the page loads through the tunnel, but it doesn't update when you save, and the terminal shows one of these:

Blocked cross-origin request … to /_next/* resource.
To allow this, configure "allowedDevOrigins" in next.config

Cross origin request detected … to /_next/* resource.

Add the tunnel's domain to allowedDevOrigins:

// next.config.js
module.exports = {
  allowedDevOrigins: ['**.sharedwithexpose.com'],
};

Mind the wildcard. Next.js matches labels: * stands for exactly one label and ** for one or more. A free Expose URL like abc123.sharedwithexpose.com has one label before the domain. A Pro URL like my-app.eu-1.sharedwithexpose.com has two, so *.sharedwithexpose.com doesn't match it and **.sharedwithexpose.com does. With a custom domain, *.share.example.com is enough.

The current docs say Next.js blocks these requests by default. In Next.js 16.0 the dev server only logged the "detected" warning while allowedDevOrigins was unset, and blocked every unlisted origin once you set it. Either way, list your tunnel. The Next.js guide covers the other settings that need the public URL, such as NEXTAUTH_URL.

Django
#

Django raises DisallowedHost, and the message tells you what to add:

Invalid HTTP_HOST header: 'abc123.sharedwithexpose.com'. You may need to add 'abc123.sharedwithexpose.com' to ALLOWED_HOSTS.

In settings.py:

ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]', '.sharedwithexpose.com']

Keep the local entries. With DEBUG = True and an empty ALLOWED_HOSTS, Django allows .localhost, 127.0.0.1 and [::1] on its own. Once you set the list, only what's in it counts. A leading dot matches the domain and any subdomain. '*' matches anything and leaves the validation to you.

Forms fail with "Origin checking failed"
#

The page loads now, but submitting a form gives a 403:

Origin checking failed - https://abc123.sharedwithexpose.com does not match any trusted origins.

Django's CSRF protection compares the browser's Origin with the scheme and host Django sees itself. The browser is on https://, while runserver gets plain HTTP from the tunnel, so they don't match. Trust the tunnel's origin in CSRF_TRUSTED_ORIGINS, with the scheme:

CSRF_TRUSTED_ORIGINS = ['https://*.sharedwithexpose.com']

This is current as of Django 6.1.

Rails
#

Rails' development server shows a "Blocked hosts" page:

Blocked hosts: abc123.sharedwithexpose.com

Under it, Rails prints the line to add. To allow every Expose URL, add the domain to config/environments/development.rb:

Rails.application.configure do
  config.hosts << ".sharedwithexpose.com"
end

A leading dot allows the domain and all its subdomains. Entries can also be regular expressions or IPAddr ranges. To allow a host for one run without editing a file, set RAILS_DEVELOPMENT_HOSTS, comma-separated:

RAILS_DEVELOPMENT_HOSTS=".sharedwithexpose.com" bin/rails server

In development, Rails already allows localhost names and all IP addresses. config.hosts.clear empties the list, and an empty list means no host checks at all, so prefer adding your domain. This is current as of the Rails 8.1 guides.

Laravel
#

Laravel doesn't check the Host header unless you ask it to. Its docs say: "By default, Laravel will respond to all requests it receives regardless of the content of the HTTP request's Host header." If you turned on trustHosts in bootstrap/app.php, add a pattern for the tunnel. The entries are regular expressions:

->withMiddleware(function (Middleware $middleware) {
    $middleware->trustHosts(at: ['^laravel\.test$', '\.sharedwithexpose\.com$']);
})

The usual Laravel problems behind a tunnel are different: http:// links and Vite assets. The Laravel guide covers both. If npm run dev is running when you share a Herd or Valet site, Expose detects the Vite process, shares it too and rewrites the page, so you don't need the Vite fix above.

Rewrite the Host header in the tunnel instead?
#

Some tunnels can replace the Host header with localhost before the request reaches your app, so the dev server never sees the public hostname:

  • ngrok. The widely quoted ngrok http 3000 --host-header=rewrite is marked "deprecated" in ngrok's CLI reference, which says to "use traffic policy instead". ngrok's HTTP docs show a Traffic Policy with an add-headers action that sets host: localhost, started with --traffic-policy-file.
  • localtunnel. --local-host proxies to another hostname, and the README says this rewrites the Host header to that value.
  • Cloudflare Tunnel. The httpHostHeader origin parameter "sets the HTTP Host header on requests sent to the local service."

A rewrite gets you past a Host check, and that's all it does:

  • It doesn't fix Origin checks. The browser still sends Origin: https://your-tunnel-hostname. Next.js's allowedDevOrigins and Django's CSRF check look at that, so you still need those settings.
  • Your app thinks it's on localhost. Absolute URLs, redirects and OAuth callback URLs it builds from the request point at localhost. ngrok says it rewrites the Location header of responses to fix redirects. Links inside your HTML stay as they are.

The allowlist is one line, and it keeps your app aware of its public URL. Expose's own guides take that route: the Vite guide allows .sharedwithexpose.com, and the Next.js guide lists the Expose domain in allowedDevOrigins. For Laravel, the Laravel guide has the app trust the proxy, so it reads the forwarded scheme and host.

A hostname that stays the same
#

The domain suffix is the practical fix for free tunnels, because the URL is random and new on every connection. If you'd rather allow one exact hostname, or other settings need the URL too, a URL that stays the same helps more than any config trick.

With Expose Pro, at $79 per user per year, you reserve a subdomain and share with it:

expose share http://localhost:5173 --subdomain=my-app --server=eu-1

Your app is then always at https://my-app.eu-1.sharedwithexpose.com, and the allowlist entry is that exact hostname:

allowedHosts: ['my-app.eu-1.sharedwithexpose.com'],

Keep the --server the same, since the region is part of the hostname. A custom domain works the same way with one CNAME record, and then you allow .share.example.com, a domain only you control.

The same stable URL goes into the other places that need it: Django's CSRF_TRUSTED_ORIGINS, your NEXTAUTH_URL or APP_URL, OAuth callback URLs and webhook endpoints. You set them once instead of after every restart. To make the whole team share the same way, put the subdomain and server in an expose.yaml next to the allowlist in your repository.

If you're new to tunnels, hosting from localhost explains how they work and when port forwarding or a deploy fits better.

Questions
#

Why does it work on localhost and my LAN IP, but not through a tunnel?
#

Dev servers allow localhost by default, and Vite, webpack-dev-server and Rails also allow IP addresses. A tunnel URL is a hostname the server doesn't know. Add the tunnel's domain to the allowlist.

Is it safe to set allowedHosts to 'all' or true?
#

It turns off the protection against DNS rebinding for as long as the dev server runs. Any website you visit in that time could read responses from your dev server. Allowing your tunnel's domain costs one line and keeps the protection.

How do I disable the host check?
#

Each tool has a switch: allowedHosts: 'all' in webpack-dev-server 4 and 5, disableHostCheck: true in webpack-dev-server 3, DANGEROUSLY_DISABLE_HOST_CHECK=true in Create React App, --disable-host-check in Angular's older webpack builder, allowedHosts: true in Vite and Angular's current builder, ALLOWED_HOSTS = ['*'] in Django and config.hosts.clear in Rails. In almost every case, adding your tunnel domain is the better fix.

Why do I get "Invalid Host header" on my deployed server?
#

You're running the dev server in production. npm start in a Create React App project, for example, starts webpack-dev-server. Build the app and serve the output with a web server or a static host instead.

Does ngrok's --host-header=rewrite still work?
#

ngrok's CLI reference lists --host-header as deprecated and points to Traffic Policy, where an add-headers action can set the Host header. Rewriting the header doesn't help with Next.js or Django CSRF, which check the Origin header instead.


Framework behaviour is described as documented on November 17, 2026: webpack-dev-server 5 docs and migration guide, Create React App and its source, Vue CLI 5, Angular CLI 22, Vite 8, Next.js 16, Django 6.1 and Rails 8.1.