vite: [vite 6.0.9] option server.allowedHosts doesn't take into account "true"
Describe the bug
hi, i’ve recently updated vite to 6.0.9, the main change being the allowedHosts server conf field,
it’s said in the documentation that if set to true, it will accept any hosts, but even when setting it to true i get the error:
Blocked request. This host (“hidden”) is not allowed.
To allow this host, add “hidden” to server.allowedHosts in vite.config.js.
(maybe i could be dumb but it really doesn’t seem to work)
Reproduction
google.com
Steps to reproduce
No response
System Info
System:
OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 4.68 GB / 15.34 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 18.19.1 - /usr/bin/node
npm: 9.2.0 - /usr/bin/npm
Browsers:
Chrome: 132.0.6834.83
npmPackages:
@vitejs/plugin-react: ^4.2.0 => 4.2.1
vite: 6.0.9 => 6.0.9
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 21
- Comments: 55 (8 by maintainers)
Commits related to this issue
- fix!: check host header to prevent DNS rebinding attacks and introduce `server.allowedHosts` — committed to vitejs/vite by sapphi-red 2 years ago
- fix: vite 6.0.11 is broken for cloud run https://github.com/vitejs/vite/issues/19242 — committed to brandon-nam/travel-wise by tohhengxing 2 years ago
Yes, same issue coming to me as well when I am trying below config in my vite config file (vite.config.ts). Please fix it.
I resolved this by updating vite.config - what’s odd here is that I had not upgraded to 6+ and the error just presented overnight. Also the type definitions are not happy with this addition, but it works:
The problem still exists in 6.0.11.
Downgrading to 6.0.8 makes it work.
I had the same issue while developing a Shopify-Remix app and using Ngrok as a tunnel. At first everything was working fine and suddenly it stopped working and vite was blocking all Ngrok requests even though it was added in
server.allowedHosts.After some debugging and trying to run vite separately using
npm run viteit gave an error:Port 3000 is in use, trying another oneAnd indeed there was something already running on port 3000. The issue went away after that.
I suggest running vite on the project to check for any errors
npm run viteHope this helps someone ✌
No, those are not the only choices. You have a third choice to create a PR that fixes your problem, and a fourth choice to create a reproduction so that others can investigate the cause.
Also happening for latest 4.x.x version. Downgrading to
v4.4.5fixed it.i’m not sure i have the time rn to make a replication for something this simple, if someone want to provide one
in the mean time i’ve rollbacked to 6.0.8
it’s really a breaking issue for a lot of people,
changing the default allowedHost from 0.0.0.0 to localhost and having a bug on the same field to set back to 0.0.0.0 will break a lot of vite installations, i’ll stick on 6.0.8 until it’s fixed, thanks for your hard work nonetheless, vite is great
https://vite.dev/config/server-options#server-allowedhosts
Tried to follow the same procedure but not working…
Blocked request. This host (“hostname”) is not allowed. To allow this host, add “hostname” to
server.allowedHostsin vite.config.js.I resolved the issue by NOT using
vite previewanymore, but installing http-server and runninghttp-server dist. Worked right out of the box! 🚀Downgrade to 4.4.5.
FIXED (at least for me)
so i was making a git for reproduction, a basic vite + react project, + custom domain in the hosts file but i didn’t manage to reproduce. then i tried everything that was different from my main project, and then when i used a dockerfile to host the reproduction project, i reproduced! so the hunt begin to understand the fuck happened in this dockerfile here is the one i used, if you can see the issue
yes, in the final stage i miss the vite.config.ts file, should have the line:
COPY --from=build ./home/node/app/vite.config.ts ./but i didn’t thought it would be needed because the others options where taken into account so from the start of the projet i never added it in the final stage (here is mine for reference)because even if all of the other values are used during the build stage, the “server” is used when invoking the vite server, so he don’t have it, right?
so the issue was: IM A DUMBASS THAT FORGOT THE VITE.CONFIG.TS FILE (if you come accross this issue in the future, check again if you have the config file at the moment you invoke vite)
@patak-dev @sapphi-red you can tell me “told you, can’t reproduce” 😂
Yeah, we are using vite: 5.1.3 with React 18 (works for local dev…but when we do deployment on docker image in K8s with nginx proxy we encouter this issue too!!) Ay Karamba! Trying to leave no stone unturned to fix it!
same here, two of my applications are affected…
Thank you, @mdesantis ! Setting the
--hostparameter did the trick for me.Same issue when running:
on a
react appthat runs withpnpm run dev(note that accessing localhost works perfectly fine – it’s the cloudflared service that does not).I’m on a macbook air m1 chip from 2020.
No resolution and blocked if using 6.0.9, 6.1.0 and 6.1.1. Downgraded to 6.0.8 and it is now resolved.
Jezus what a complete mess sorry but how was this release to prod when its just breaking for everyone?
My project is just React + Vite, a simple SPA. And it is affected.
Thanks @OxCom . Of course, this could play a part, but my feeling based on this thread was that it affected more than sveltekit users
Thanks @sapphi-red , a couple of things stand out -
default for
allowedHostsbeing set to[]but not being overridden bytrue- so, an issue with where the user config is merged with the default config.and / or, https://github.com/vitejs/vite/commit/bd896fb5f312fc0ff1730166d1d142fc0d34ba6d#diff-abb3345b6e3b2ec6d297c2ebc54cca85ae4487a31bac3cc9e78457f5114adb26R864 removing
allowedHosts !== truehere so as not to trigger the middleware when not required?Will hopefully have more time later this week to look more
Blocked request. This host (“myhost.com”) is not allowed. To allow this host, add “myhost.com” to
preview.allowedHostsin vite.config.js.That is why I hate vite, one day it works and other just dont.
Hm… please take a look into tools that use vite to run. For example I have same issue with vite + storybook, because of storybook. I defined in storybook config the server options:
and the problem is that mergeConfig will replace
serveroptions from viteAlso encountering this after pushing an update today, no changes to vite config Running on GCP / Cloud Run