Skip to content

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

Merged
patak-cat merged 4 commits into
vitejs:mainfrom
sapphi-red:docs/update-security-warnings
Feb 7, 2025
Merged

docs: update security warnings around server.cors and server.allowedHosts#19378
patak-cat merged 4 commits into
vitejs:mainfrom
sapphi-red:docs/update-security-warnings

Conversation

@sapphi-red
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread docs/config/server-options.md Outdated
Comment thread docs/config/server-options.md Outdated
Co-authored-by: patak <583075+patak-dev@users.noreply.github.com>
@patak-cat patak-cat merged commit 1aacf8b into vitejs:main Feb 7, 2025
@sapphi-red sapphi-red deleted the docs/update-security-warnings branch February 7, 2025 08:01
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
…edHosts` (vitejs#19378)

Co-authored-by: "Dominik G." <dominik.goepel@gmx.de>
Co-authored-by: patak <583075+patak-dev@users.noreply.github.com>
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