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

environment variable values are appeared directly in production code #3574

Open
Thesiva7 opened this issue Jan 3, 2024 · 4 comments
Open
Labels

Comments

@Thesiva7
Copy link

Thesiva7 commented Jan 3, 2024

Hi,
I am using below code to load the environmental variables in production

new Dotenv({
path: path.join(webpackPaths.rootPath, '.env'),
safe: false,
silent: false,
defaults: false,
})

but in production files that environmental values are appearing directly. like below image :

production

but in development it is like below image :

development

how to hide environmental values in production code.

@amilajack @jooohhn

@Thesiva7 Thesiva7 added the bug label Jan 3, 2024
@Thesiva7 Thesiva7 changed the title environment variable values are appeared in production code environment variable values are appeared directly in production code Jan 3, 2024
@sanneh2
Copy link

sanneh2 commented Jan 8, 2024

This is part of the clientside bundle and therefore cannot be hidden from the client. React is responsible for this behavior. The client ID is ok to be seen in the public. You have to keep the SECRET_KEY secret. This is usually used on the server side. In this case inside the "main.js" process it will be hidden.

// main.js
const GOOGLE_SECRET = process.env.GOOGLE_SECRET

@Thesiva7
Copy link
Author

This is part of the clientside bundle and therefore cannot be hidden from the client. React is responsible for this behavior. The client ID is ok to be seen in the public. You have to keep the SECRET_KEY secret. This is usually used on the server side. In this case inside the "main.js" process it will be hidden.

// main.js
const GOOGLE_SECRET = process.env.GOOGLE_SECRET

Hi @sanneh2 ,
But in main.js also env variables visibling directly. I don't know how to hide the env variables from .env file in production application.

Please look below images of production main.js, i have marked encryptedkey field which have value from .env file

mainJS

store

@sanneh2
Copy link

sanneh2 commented Jan 12, 2024

This is a security question.

The best and most reliable thing is authentication and servers. So for example, if your users are logging in to your app, you could share secrets over a secure connection,

Unpackaging will always expose the entire code to the hacker. You can obfuscate it, encrypt it, or compile it with v8 bytecode which I heard works great.

But security with an external server will always be the safest bet, because you can move the secrets and confidential information to a remote location outside of your app.

@jooohhn
Copy link
Member

jooohhn commented Jan 22, 2024

Hey @Thesiva7

What @sanneh2 said on security is correct, you shouldn't keep secrets on the client. electron-store also advises that encryptionKey is not intended for security purposes, only obfuscation.

I'm not sure what your what your app's codebase looks like, but maybe Google's OAuth javascript
or server docs might help

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

3 participants