-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for defining server.allowedHosts
through environment variables
#19273
Comments
Sorry for the breakage. I think adding the env var makes sense to me. Do you know if there's any similar env var names? I think it would be good to align with them.
Awesome 💚 |
if we go with an env variable, i think it would have to be accompanied by a check that it does not start with I wonder if there is a way for codesandbox to avoid the cross origin setup here or use existing means to configure the dev server eg hook the |
A long long time ago, create-react-app used to check the
There is a way... if we manually let the proxy forward header One thing I could try... is to only forward Overriding the binary is a bit more tricky, because when people fork a sandbox it is live cloned, so the running Vite process is cloned as well, it will continue running inside the child. But the hostname did change, so then we'd have to restart Vite with the new So we could also transparently fix it on our side by changing the proxy, but the environment variable feels a bit cleaner. It depends on what you're most comfortable with in terms of implementation. |
if there is a less hacky way for you to detect when to change the proxy and when not (what happens if someone were to use bun+vite?) i think i'd prefer that over adding a way to configure vite via environment variables. That could set a dangerous precedent and we have to answer a lot of questions like which value wins if both are set, what happens if the env value changes and the dev server is still running, will it pick up the new value when there is an automatic restart? Do we have to watch that value? |
if you are able to add a |
Yeah,
I think that's difficult to do for all the Vite-based frameworks that does not use |
I discussed with the team about the name and we think the env var named |
Thanks a lot for the quick response! The solution makes sense to me, I will open a PR with |
Description
Recently a security improvement was introduced to Vite, where Vite now checks if the domain in the
Host
header is configured inserver.allowedHosts
if it is notlocalhost
.This breaks some CodeSandbox examples, because while Vite is listening on
localhost:5173
, users access the server throughhttps://:id-5173.csb.app
on CodeSandbox. With newer versions of Vite, this returns a 403. Currently, we recommend people to add.csb.app
to theirserver.allowedHosts
, but it would be nice if we also have a way to make this work with no configuration.Suggested solution
I was thinking we could potentially solve this in two ways, and I'm curious what you're thinking of the possible solutions:
localhost
, that.csb.app
is allowed inserver.allowedHosts
, or:server.allowedHosts
by passing in environment variables. On the CodeSandbox side, we could introduce a default environment variable in all VMs (likeVITE_ALLOWED_HOST=.csb.app
), which would then also be used by Vite for its checks.I'm a big fan of Vite, I would love to contribute something like this if this makes sense to you!
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: