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

Security .env issue when set VITE_SINGLETON_API_KEY & apiKey saved to local storage #161

Closed
reinaldomendes opened this issue Oct 28, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@reinaldomendes
Copy link

VITE_xxxx variables are exposed on the frontend

Configure import.meta.env.VITE_SINGLETON_API_KEY will expose meilisearch master key to the world.

From Vite Docs

https://vite.dev/guide/env-and-mode.html#env-files

Important

SECURITY NOTES

.env.*.local files are local-only and can contain sensitive variables. You should add *.local to your .gitignore to avoid them being checked into git.

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

More about the security issue.

vitejs/vite#14412

To Reproduce

  1. Configure Meilisearch-ui in Singleton mode
  2. Open meilisearch-ui on google chrome
  3. Open developer console in tab Source
  4. Search for Assets containing apiKey
  5. Add breakpoints when you find apiKey

Screenshots
Search API Key in source
Found Master Key in running code
Master Key found at localStorage

Environments (please complete the following information):

  • Not Applicable. All environments are exposed the same way.
@reinaldomendes reinaldomendes added the bug Something isn't working label Oct 28, 2024
@riccox
Copy link
Owner

riccox commented Oct 31, 2024

@reinaldomendes

The application itself is a SPA, so whether the API KEY is passed this way or not will expose the API KEY on the front end.

And the API KEY can be found in local storage of your browser as well if you are not in SINGLETON mode.

Maybe this should be write into docs to make it clear?

@reinaldomendes
Copy link
Author

@riccox

"The application itself is a SPA, so whether the API KEY is passed this way or not will expose the API KEY on the front end."

  • There is a difference between SINGLETON mode. If I download the source code and recompile with those env vars, they will be world exposed to anyone in the file "assets/zustand-xxxx.js".
  • Without pass VITE_SINGLETON_API_KEY in the environment variables the API Key will only exposed to the client browser (localstorage or debugging source code).

I just have download from github and then added the VITE_SINGLETON_API_KEY to .env file.

The I ran pnpm build.

The API KEY became exposed in dist/assets/zustand-B4CGb1Vr.js

Screenshot from 2024-10-31 06-40-59

@reinaldomendes
Copy link
Author

reinaldomendes commented Oct 31, 2024

@riccox

@reinaldomendes

The application itself is a SPA, so whether the API KEY is passed this way or not will expose the API KEY on the front end.

And the API KEY can be found in local storage of your browser as well if you are not in SINGLETON mode.

Maybe this should be write into docs to make it clear?

I think the docs should inform about exposing master key, it can cause leaks of master key.

The docker image is not exposing the API KEY, but if download the source and build, passing VITE_ env variables, the key will be found into assets js files(This is a major security issue).

Sensitive information must not defined in VITE_ variables.

The API KEY found in local storage may leak by XSS attack (I understand it is a SPA, but this risk should be noted)

  • I don't know if there's such type of vulnerability into your meilisearch-ui, but poisoned data from meiliseach index may read localStorage and send the master key to external website.

@riccox
Copy link
Owner

riccox commented Nov 1, 2024

@reinaldomendes

SINGLETON mode is designed to be used in local or internal network actually.

The risk of leaks of master key should be mentioned in documents.

Could you post a PR for this, or I will add this into README file later.

@riccox
Copy link
Owner

riccox commented Nov 4, 2024

Singleton mode usage docs have been updated.

@riccox riccox closed this as completed Nov 4, 2024
@github-project-automation github-project-automation bot moved this from 👁 In Progress to 🍻 Done in Meilisearch-UI Roadmap Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🍻 Done
Development

No branches or pull requests

2 participants