Hide API Keys Without dotenv environment variables | Hiding API Keys in Javascript Netlify

  Рет қаралды 44,186

Dave Gray

Dave Gray

Күн бұрын

Пікірлер: 68
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
This tutorial helps you keep your API key out of your code repository. That said, if you want to learn how to keep your API key completely out of your frontend code, you will want to watch my tutorial about setting up a NodeJS API Key Relay: kzbin.info/www/bejne/q5ycoamfrtulqsk
@sextronnics
@sextronnics 3 жыл бұрын
You can also use a sql server in another data center install sql php and apache and something cool to encript/decript stuff. encrypt the keys in a very secure way so it can be decrypted by your machine only, store the encripted keys in SQL database write some php allow your domains that use any of the keys only to access your servers others should not get an answer from the server. From here there are multiple methodes on how you can or might want to use the keys including decoding and sending it to some secret place on your websites server over end to end encrypted connection and use it on your webserver. your websites webserver should delete the file when it's no longer needed . Yes it's not as fast as what you do but it is very secure and not easy to find the data and even if someone is able to get access to the database they are not able to crack the keys and more important if they crack the keys most people do not know how to use them and what the keys should be used for... maybe you want to try something like this, it's what I did 15 years ago and it is still very secure however if the hackers want to there is no system secure enough but this is hard to hack... Good luck and happy coding ! Best Regards,
@harlemjulian29
@harlemjulian29 3 жыл бұрын
I guess it is pretty off topic but does anybody know a good site to stream new series online?
@korbinkylo1921
@korbinkylo1921 3 жыл бұрын
@Harlem Julian Flixportal xD
@harlemjulian29
@harlemjulian29 3 жыл бұрын
@Korbin Kylo Thank you, I went there and it seems like a nice service =) I really appreciate it!
@korbinkylo1921
@korbinkylo1921 3 жыл бұрын
@Harlem Julian No problem :)
@HideBuz
@HideBuz Жыл бұрын
You rock! Your long tutorials are awesome!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@danielvega646
@danielvega646 Жыл бұрын
I will never forget you, Dave Gray. Thank you so much for being so cool! Greetings from Colombia.
@zenguitarankh
@zenguitarankh Жыл бұрын
"Oh man....what's this github guardian email?...oh of course...I exposed the apikey so it's flagging me....time to search around for how I deal with this.....I bet it's gonna be hard to find someone with my exact situation....with github with netlify.....with a weather app....." (Dave has entered the chat) Thanks once again man.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome! 🚀
@eliz964
@eliz964 4 жыл бұрын
You have such good content. You deserve way more subscribers.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
Thank you!
@eliodrallag4806
@eliodrallag4806 3 жыл бұрын
This is what I've been looking for. Thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
You're welcome. This solution will keep the key out of GitHub. If you want to keep it out of your code completely, consider a bit more in-depth solution like this one: kzbin.info/www/bejne/q5ycoamfrtulqsk
@ritakriti
@ritakriti Жыл бұрын
If we pass an api key this way in the headers then that key value is showing in network call ...can you help how to hide that?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Right - this is just a quick way to not send it to GitHub and still deploy. You want this video: kzbin.info/www/bejne/q5ycoamfrtulqsk
@reverbmusic8444
@reverbmusic8444 Жыл бұрын
did you find a solution ?
@sportsstimulant4228
@sportsstimulant4228 2 жыл бұрын
Can youse .env file ? And .gitignore file can put . nodemoduls and .env files recent time ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You can use a dot env file but you should never send it to Github. Always put the .env file in your .gitignore file. This tutorial shows how you can hide an API key from Github and still deploy to Netlify without using a .env file.
@ponce7600
@ponce7600 4 жыл бұрын
thanks for the video, but at the end you say it's a good way to hide the api key, but, you're showing it! sorry, I don't understand, it's not hidden, anyone who sniffs the code will be able to find it.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
I said it is a good way to avoid putting a key in a GitHub repository and acknowledged there are other ways to hide the keys from your code entirely such as serverless or a backend relay. I plan to make videos on those methods as well. If you have a student project though, this method allows you to keep your key out of a GitHub repository and still use it for your project. Thanks for watching.
@thabangndlovu
@thabangndlovu 2 жыл бұрын
Thank you for the tutorial👍
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome!
@daniyalarif9487
@daniyalarif9487 3 жыл бұрын
Hi, the test.js file you created, wont that be on github anyways showing the keys?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
No, it will not go to Github. The apikey.js file is in the .gitignore file. That keeps it from going to Github. If you are referring to the file created on Netlify, it won't go to Github either. Netlify pulls files from the Github repo, but it does not send files to Github. I hope that helps to clarify 💯
@abigiyatadesse2672
@abigiyatadesse2672 Жыл бұрын
Thank you so much for the video.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome!
@RaniaAmina
@RaniaAmina Жыл бұрын
Is there also possible to hide also from sources tab for plain html and vanilla js?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You would need to create an API key relay as I show here: kzbin.info/www/bejne/q5ycoamfrtulqsk
@RaniaAmina
@RaniaAmina Жыл бұрын
@@DaveGrayTeachesCode thanks for answer. Will try on next project
@namucho266
@namucho266 Жыл бұрын
interesting video! thank you
@mozammel-being-mozammel
@mozammel-being-mozammel Жыл бұрын
Now, what's the point of doing this? Anyone inspecting my source code from browser can now easily read and copy my api key and db configs....
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
If you use an API key in your frontend code at all, it can be seen through dev tools. As explained in the video, the point is not sending the key to GitHub. Especially for student projects. Want to keep it out of the frontend completely? Watch my video on setting up a relay: kzbin.info/www/bejne/q5ycoamfrtulqsk
@avshinkampf
@avshinkampf 3 жыл бұрын
Nice work again, I tried the .dotenv way on my project, but this was easier!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Glad it helped! 💯
@naolfekadu6101
@naolfekadu6101 2 жыл бұрын
this is not even hiding the api, the title is so misleading
@chinmaysonawane57
@chinmaysonawane57 2 жыл бұрын
Thanks man this solved my problem
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad it helped!
@robertomaclean1140
@robertomaclean1140 9 ай бұрын
I hadn't idea Burton C. Bell is a programmer
@ecdu-eu
@ecdu-eu 2 жыл бұрын
Dear Dave, I hope you are well. Thank you very much for your effort and the video. It's really a big help. Maybe you have time-if it's not too much trouble-to answer two questions for me: I can get your project to run locally on my Ubuntu system without any problems. However, I have problems hosting the project on netlify. My questions about this would be: 1) How can I start the project with a file index.html so that .env remains hidden and (2) do you know a way how to activate the repository on netlify? netlify deploy works, but additional modules that were integrated via package.json do not work. The background to my question is that I would like to hide a larger number of required Amazon AWS SDK API's. Does it perhaps make sense to use react at this point? I would be grateful to you for an answer, since I've been desperate here for days. Many thanks and best regards, Stefan
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Javascript runs in the browser and anything used in the browser can be viewed. You can make it difficult to read with minification - that is minifying the JS files - but it will still be available to anyone that knows how to use devtools. You might consider putting the logic you want to hide in Node.js code that runs on the server. You can then set up a relay. I show how to do this here: kzbin.info/www/bejne/q5ycoamfrtulqsk
@Abberath
@Abberath 2 жыл бұрын
​@@DaveGrayTeachesCode I ran the build command but my netlify app still wont make the api call.
@ronaldodurandluna8617
@ronaldodurandluna8617 6 ай бұрын
Thanks you !!
@Crunkmastaflexx
@Crunkmastaflexx 3 жыл бұрын
thats a great trick! love it
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Glad I could help 💯
@TheVedantshah
@TheVedantshah 3 жыл бұрын
Hey i'm getting a Uncaught SyntaxError: Cannot use import statement outside a module error, what am I doing wrong?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Sounds like your script tag needs type="module". At least that is the most common cause of that error.
@muhammadk23
@muhammadk23 2 жыл бұрын
so after researching for hours and i got to a place to secure my api key but after all this damn api is still visible? Ridiculous😂 thanks for the tutorial btw
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome - this works as a quick fix for student projects, but better solutions are here: kzbin.info/www/bejne/q5ycoamfrtulqsk and here: kzbin.info/www/bejne/gGi1fKtum5l5qNU
@minhduc9821
@minhduc9821 3 жыл бұрын
Hi, thank you for the video. How about smudging and cleaning data so whenever I checkout a branch the api key is updated?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
A different approach involving a little more upfront work, but this may be a good solution for development. I have not attempted it, so I am not sure how it would work with a Netlify deploy. I may have to try it out! Good question! Anyone wondering what we are discussing can look at this link for an overview: www.juandebravo.com/2017/12/02/git-filter-smudge-and-clean/
@fraternidadeaustriaca2625
@fraternidadeaustriaca2625 2 жыл бұрын
Thanks a lot!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome!
@my_vk_vlogs
@my_vk_vlogs 4 жыл бұрын
From git-hub we can hide api key this approach. but hackers can able to view our api key after deployment via source code. How we can hide our api key some one can't view our all kind of secret key.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
You are correct, and I mention this in the video. This also applied to the dot env approach. I will make other videos showing the approaches I mentioned: 1) a node js relay and 2) a serverless function. Thanks for asking.
@my_vk_vlogs
@my_vk_vlogs 4 жыл бұрын
@@DaveGrayTeachesCode thanks for your quick response
@webflyer035
@webflyer035 Жыл бұрын
Someone trying to steal your api-key already knows where to look for it😂
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
If they want to specifically steal yours, but if want just want to keep it out of Github for a student project, personal project, etc. - this works. GitHub has bots crawling it for those keys.
@danielvega646
@danielvega646 Жыл бұрын
does this still work?
@darshaanaghicha8023
@darshaanaghicha8023 4 жыл бұрын
I want this weather app tutorial... Where can I find it?
@darshaanaghicha8023
@darshaanaghicha8023 4 жыл бұрын
Where can I find a tutorial on this app??
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
I need to make the tutorial. It is more complex than the average weather app, I am looking forward to making it when I can. Thanks for asking!
@darshaanaghicha8023
@darshaanaghicha8023 4 жыл бұрын
@@DaveGrayTeachesCode Sure I will be waiting for that. I am sure I will learn alot from it. I have learnt a lot from your videos. thanks sir
@DaveGrayTeachesCode
@DaveGrayTeachesCode 4 жыл бұрын
@@darshaanaghicha8023 I am glad to hear it and happy to help. Thanks!
@lukasfritz6222
@lukasfritz6222 Жыл бұрын
Bad video because api key still gets shown in browser
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
I explained what this was for in the video. Search my channel for the API key relay. That is what you want.
@sabeerbikba8585
@sabeerbikba8585 10 ай бұрын
really
How To Hide API Keys Using Netlify
56:55
Dan Fletcher
Рет қаралды 18 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
$1 vs $500,000 Plane Ticket!
12:20
MrBeast
Рет қаралды 122 МЛН
БАБУШКА ШАРИТ #shorts
0:16
Паша Осадчий
Рет қаралды 4,1 МЛН
5 JavaScript API Key Mistakes (and how to fix them)
12:49
James Q Quick
Рет қаралды 80 М.
Your API Keys are NOT SAFE in a native app 🤬
9:26
Simon Grimm
Рет қаралды 14 М.
How to hide your API keys SAFELY when using React
24:45
Code with Ania Kubów
Рет қаралды 175 М.
Callbacks, Promises, Async Await | JavaScript Fetch API Explained
1:05:05
How to ACTUALLY Secure Your API (5 Steps)
7:42
Josh tried coding
Рет қаралды 69 М.
JavaScript Media Queries | Responsive Web Design
10:25
Dave Gray
Рет қаралды 10 М.
This Website has No Code, or Does it?
10:08
PwnFunction
Рет қаралды 1,1 МЛН
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН