r/webdevelopment • u/mxrkkkkkkkkkk • 13d ago
Discussion Any developer here?
I build a website but before making that website live i want to hide some sensitive API keys like Aws, Fast2SMS etc from frontend so no one else can use them... I tried Gitignore but I don't think that will hide my secrets.. Any developer who can help?
3
u/RoyPartha04 13d ago
You put those in as env variables and not use on frontend. Frontend makes request to your backend, server communicates with AWS etc using API keys.
1
u/Winter-Science-4651 13d ago
U should never put any keys in frontend, all the data should come from the backend server where frontend only contact backend server to get the data, keys or any third party api should be handled in the backend as well.
1
u/iCantStopTheDark 13d ago
Create a file called .env.local and add it to gitignore if it’s not there already. That’s where you store local variables.
Your hosting service be able to provide a place for you to securely store variables for the public website.
Considering you new to this, I suggest you rotate all of your API keys, as you probably already compromised them.
1
u/Ronin-s_Spirit 12d ago
Kays must be on the server and never leave it (serverless providers usually have some buttons to upload keys). Anybody can read your clientside.
1
u/ApogeeWatcher 12d ago
The reason .gitignore is not the answer is that it only keeps a file out of the repository, and anything your frontend reads at build time still gets baked into the JavaScript the browser downloads.
1
u/Human_Experience0810 11d ago
Gitignore only prevents files from being committed to Git. It doesn't hide API keys from the frontend. Anything included in frontend JavaScript or network requests can potentially be inspected by users. My advice is to store your keys in environment variables on the server and make API calls through backend endpoints. Your frontend should communicate with your backend, and the backend should communicate with AWS, Fast2SMS, etc. Also, if you've already exposed any keys, rotate them immediately and set appropriate usage restrictions. Never rely on hiding or obfuscating frontend code to protect secrets.
1
u/JakeRaine 11d ago
Yeah remove any api keys from your actual .env files etc and definitely code, create a .env file if you dont have one, just the variables no values and then in your hosting setup the guarded environment variables there, rotate all api keys you have because if they were at any point in code, gitignore or an env file etc they can be found in your git commit history
4
u/JohnCasey3306 13d ago
Never store any API keys in your front end code . Your instinct is right -- gitignore just hides the file from the repo, not the deployment.
Ideally your front end would make a request to a back end, and the API keys would be an environment variable on the server (so hidden).
Alternatively there are front end web app servers like Netlify that allow you to define hidden environment variables that the front end can reference privately without exposing them