The app responds with "Invalid Host header" or "Blocked request"
Symptomsโ
The app opens locally, but at the tunnel address you get an error from the app itself:
| App | What you see |
|---|---|
| Vite | Blocked request. This host ("brave-otter-4821.a.tuna.free") is not allowed. |
| webpack-dev-server | Invalid Host header |
| Django | 400 Bad Request, with Invalid HTTP_HOST header in the log |
| Rails | a Blocked hosts: brave-otter-4821.a.tuna.free page |
| Next.js | the page opens, but hot reload doesn't work, and the server console warns about a request to /_next/* from another origin |
In the inspector, the request reached the app, and the response came from the app, not from tuna.
Causeโ
tuna passes the Host header to the app exactly as the visitor sent it, with the tunnel address. Dev servers accept only localhost by default to protect against DNS rebinding attacks, so they reject any other name.
Fixโ
There are two ways. The first is simpler; the second is the right one if the app builds absolute links.
Replace the Host headerโ
The --request-header flag replaces Host before the request reaches the app, so the app sees the familiar localhost:
tuna http 5173 --request-header="host:localhost:5173"
The app will think it was opened at localhost. If it builds absolute links or redirects from Host, they will point to localhost. In that case, use the second way.
Allow the tunnel address in the appโ
Allow the tuna zones: a.2na.am for dynamic and reserved addresses and a.tuna.free for the free permanent subdomain. If the tunnel runs on your own domain, add it too. You only need this in development mode.
Vite, vite.config.js:
export default defineConfig({
server: {
allowedHosts: ['.a.2na.am', '.a.tuna.free'],
},
});
webpack-dev-server, webpack.config.js:
module.exports = {
devServer: {
allowedHosts: ['.a.2na.am', '.a.tuna.free'],
},
};
Django, settings.py. POST forms over HTTPS also need CSRF_TRUSTED_ORIGINS, otherwise Django responds with CSRF verification failed:
ALLOWED_HOSTS = ['localhost', '.a.2na.am', '.a.tuna.free']
CSRF_TRUSTED_ORIGINS = ['https://*.a.2na.am', 'https://*.a.tuna.free']
Rails, config/environments/development.rb:
config.hosts << ".a.2na.am"
config.hosts << ".a.tuna.free"
Next.js, next.config.js:
module.exports = {
allowedDevOrigins: ['*.a.2na.am', '*.a.tuna.free'],
};
Restart the dev server after the change.