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

Private environment variables #1455

Closed
Nick-Mazuk opened this issue May 14, 2021 · 1 comment
Closed

Private environment variables #1455

Nick-Mazuk opened this issue May 14, 2021 · 1 comment
Labels

Comments

@Nick-Mazuk
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently, all environment variables can be exposed in the browser. As per the Vite docs:

Since any variables exposed to your Vite source code will end up in your client bundle, VITE_* variables should not contain any sensitive information.

This exposes a potential security risk with API secrets.

Describe the solution you'd like

Next.js has an elegant solution where are not exposed to the browser by default. To make an environment variable public, it needs to begin with NEXT_PUBLIC.

A similar solution would work really well.

All vite environment variables can be private by default. But by using VITE_PUBLIC, they can be exposed to the browser as well.

Describe alternatives you've considered

In the meantime, I'm likely just going to use this system myself and be careful to not reveal private variables in the browser.

How important is this feature to you?

Fairly important. Keeping API secrets a secret is quite important, and if the framework were to do that automatically, it saves lots of time double-checking "is the code only running on the server?" as well as removes all potential for human error.

@benmccann
Copy link
Member

I'm going to close this in favor of vitejs/vite#3176. We'd like all environment variables to be exposed on the server and the VITE_ ones globally available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants