Skip to content

Vite config loadEnv exposing all envs to frontend. #16686

Closed as not planned
Closed as not planned
@pumanitro

Description

@pumanitro

Describe the bug

This line of code:
const clientEnv = loadEnv(mode, process.cwd(), '');

for vite.config.ts file (entire vite configuration) was the place that caused our CI/CD envs to be exposed to the world.

Of course, some bots that scrape the internet read compiled bundle, got our keys, and used them to cause a massacre.

Yes, we *** up using chatgpt generated config and doing code review.

Still, it should not be so easy to do it and I feel more people could be affected by that.

It is also hard to find it during the code review because these are 2 sings that can cost you and your company a lot of money.

IMO it should show some error at least somewhere, or take a value like 'YES_I_WANT_TO_EXPOSE_ALL_OF_MY_ENVS_TO_THE_WORLD_AND_BOTS'.

Reproduction

https://stackblitz.com/edit/vitejs-vite-e6fzdp?file=vite.config.ts&terminal=dev

Steps to reproduce

No response

System Info

Windows 10,
Chrome 124.0.6367.202
Packages:
    "vite": "~5.0.0",
    "vite-plugin-env-compatible": "^2.0.1",
    "vitest": "^1.3.1",

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions