Skip to content
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

docs: update security warnings around server.cors and server.allowedHosts #19378

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red added the documentation Improvements or additions to documentation label Feb 7, 2025
Comment on lines 185 to 189
::: danger

We recommend setting a specific value rather than `true` to avoid exposing the source code to untrusted origins.
Setting this to `true` grants any websites to send requests to your dev server, allowing them to download your source code and content. We recommend always using an explicit list of allowed origins.

:::
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dominikg I updated the warning here based on your suggestion 👍

Comment on lines 66 to 70
::: danger

Setting this to `true` virtually grants any websites to send requests to your dev server by DNS rebinding attacks, allowing them to download your source code and content. We recommend always using an explicit list of allowed hosts. See [GHSA-vg6x-rcgg-rjx6](https://github.com/vitejs/vite/security/advisories/GHSA-vg6x-rcgg-rjx6) for more details.

:::
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a similar warning to server.cors for server.allowedHosts as well. Technically, it is safe to set server.allowedHosts: true if the dev server runs behind a reverse proxy (the reverse proxy needs to check the host in that case though). But I didn't mention it here as I guess that usage isn't common and setting allowedHosts doesn't hurt.

Comment on lines +56 to +64
::: details What hosts are safe to be added?

Hosts that you have control over which IP addresses they resolve to are safe to add to the list of allowed hosts.

For example, if you own a domain `vite.dev`, you can add `vite.dev` and `.vite.dev` to the list. If you don't own that domain and you cannot trust the owner of that domain, you should not add it.

Especially, you should never add Top-Level Domains like `.com` to the list. This is because anyone can purchase a domain like `example.com` and control the IP address it resolves to.

:::
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While CORS is a general thing, this allowedHosts is not that general and the users weren't sure what value are safe to be set. I added a explanation here.

Co-authored-by: patak <583075+patak-dev@users.noreply.github.com>
@patak-dev patak-dev merged commit 1aacf8b into vitejs:main Feb 7, 2025
10 of 11 checks passed
@sapphi-red sapphi-red deleted the docs/update-security-warnings branch February 7, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants