[SECURITY] [DOC] - Vite environment variables in defineConfig() #19510
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Vite
to 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 argument
of 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, awarning
should be added about the risks of passing the env variable directly in the return statement of the function when using''
as thethird
argument.