[SECURITY] [DOC] - Vite environment variables in defineConfig()#19510
[SECURITY] [DOC] - Vite environment variables in defineConfig()#19510qu35t-code wants to merge 1 commit intovitejs:mainfrom
Conversation
|
I'm open to adding a info block warning against doing something like |
|
I never said that what is in the current documentation is a security issue, only that it could become one if developers copy the code snippet and return the variable that is defined ! |
|
I also add that it's never a good practice to retrieve all environment variables into a single variable. |
I don't think the current code is problematic. The problem is that people are passing sensitive values to The reason why this section exists is to tell users how to use arbitrary env vars (including values from .env files). If they only need env vars limited to a specific prefix, they won't need to use any of this code. It'll be available automatically. If we remove |
Description
Hello,
As a security auditor (pentester), I have repeatedly encountered cases where client applications expose all environment variables directly in the application's JavaScript code. This often leads to a complete compromise of the application and even its underlying infrastructure.
A common thread in these incidents is that all of these applications use
Viteto build their code. After conducting some research in the official documentation, I realized that the code example provided in thedefineConfig()code snippet could be misleading and potentially lead to this critical security issue.Here's an example of vulnerable code:
By default, the documentation suggests using an empty string (
'') as thethird argumentof theloadEnv()function, which results in loading all environment variables.To improve the documentation and security, I suggest a small but impactful change to the documentation snippet: by default, only variables with a specific prefix (
VITE_andAPP_) should be included (rather than all environment variables). Additionally, awarningshould be added about the risks of passing the env variable directly in the return statement of the function when using''as thethirdargument.