5 JavaScript API Key Mistakes (and how to fix them)

5 JavaScript API Key Mistakes (and how to fix them)

James Q Quick

2 года назад

71,659 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Mahdi Abdurrahman
Mahdi Abdurrahman - 24.09.2023 14:04

Cannot not use npm dotenv package in vanilla JavaScript.

Ответить
Meto
Meto - 03.08.2023 15:34

I have an api-key error case, my api-key is case sensitive, in javascript my execution does not progress, due to the error it shows in api-key, please does anyone know how to solve it?


"x-api-key": "swGwRN7X65XLuBqFFsthpwxMjhXjxL9CrUmvtW70"

error displayed: message: 'The request message is not properly formatted.'

Ответить
waffletube
waffletube - 11.06.2023 01:49

I guess what I don’t get is, yes I want to minimize exposing my api key or auth token via github or dev console, but I also want people to use the app I’ve made without having to make an account and login. Don’t some of these approaches go a little too far in “protecting” the keys? What’s the trade off if people can’t even use the thing. And what’s to stop multiple accounts from signing up and spamming your key anyway?

Ответить
Luiz Barni
Luiz Barni - 22.05.2023 21:40

Sure I need more help and explanations about how to solve the problem number four 😂. Nice video!

Ответить
Systemscai
Systemscai - 25.03.2023 17:43

whats the point of this video?

Ответить
Prashanth Shivanna
Prashanth Shivanna - 25.02.2023 07:07

Thanks James. Properly put up in an order to understand

Ответить
Khalil Bessaad
Khalil Bessaad - 06.02.2023 18:37

Actually you can use env variables in Astro if you're not using your API keys in client side code. Since Astro runs in build time, the requests that need the API keys will be sent during build time and no js code with the API keys would be shipped to the user.

Ответить
Angel Soto
Angel Soto - 02.02.2023 21:49

Thank you so much this helped a ton James!!

Ответить
SPORTS STIMULANT
SPORTS STIMULANT - 26.01.2023 20:27

Suppose in react before push it github or hosting craete .ENV file and write REACT_SECRET_API_KEY=abcd...........etc etc
And my index.js file code {process.env.REACT_SECRET_API_KEY} then add .ENV file to . gitignore after that if i push it github then okay or probelm ? I mean can hide my api key that's way ??

Ответить
ankurmay10
ankurmay10 - 16.01.2023 21:45

shouldn't we use a vault service to securing your API key and get api key dynamically to request backend.

Ответить
Jin youcheng
Jin youcheng - 10.01.2023 09:27

Hi, James. Thank you so much for this valuable video. Actually I have stored all my env variables in vercel, but when I see in browser/inspect/source tab, I could see all of them even though my github username, developer key etc which is very sensitive info. How to hide them? 🙏🙏🙏🙏

Ответить
DANser
DANser - 07.01.2023 09:10

So I with 0 dollars in my pocket basically can't use any API because I don't have a server to make it secret... veb dev is a giant headache.

Ответить
Goldfish brain John
Goldfish brain John - 29.12.2022 16:17

Should use other API as an example because there are two different types of API keys, Public and private API keys.

Public API keys, like Google Map API key, for example, will be always exposed to the internet because you need the key to access the map. This kind of keys should be restricted by limiting IP addresses, referer or domains to secure the usage.

Private API keys are for internal use, for example: APPs to APPs or servers to servers communication, so they shouldn't be exposed to public. Instead, they should be secured by ways mentioned in this video.

Ответить
S oxon
S oxon - 10.12.2022 14:19

And how does reading from env variable make it any secure ?

Any one who can look at your network tab have access to the curl and hence the key.

Please stop making these videos which gives people a false sense of security which is more dangerous in practice .

client secret in a react/single page application !!!

There is only one way to secure your JavaScript client and using oAuth.

Security is such a sensitive topic and videos like this only makes it worse.

Ответить
Desiree Bryant
Desiree Bryant - 06.12.2022 06:31

Do I have to give the web developer the secret key to implement the payment method?

Ответить
graa999
graa999 - 19.11.2022 15:17

People just do not understand security at all. All that .env bullshit about api keys ruins here: anyone can open devtools, network tab and see all exact headers browser sends to 3rd party api including your 'secret' key

Ответить
Stefan
Stefan - 01.11.2022 07:15

Hey James, I recently being diving in deeper in this topic and I been learning a new tool API managmenebt and Key Vault. Was wondering if you have knowledge on or could do a video about key vaults?

Ответить
The King
The King - 28.10.2022 01:38

Cors is good if backend consuming from website but if you have mobile app?

Ответить
Markus Eicher
Markus Eicher - 17.09.2022 12:13

Hi James. Thanks a lot for this post! I'm still learning about securely using my API keys. It seems that this will be a long, long way to go. I almost can't believe that there are no more robust and secure methods implemented in modern browsers. Seems like one has to go to university to be able to securely use widespread API's. But hey, let's figure it out. I like your content, and thanks again.

Ответить
Gavin S
Gavin S - 31.08.2022 11:48

Thanks for this video James, it was actually Ania's video that led me here and it's an issue I've been wrestling with for longer than I'd like to admit!

Ответить
Panic Box
Panic Box - 23.08.2022 08:39

Please make follow up video

Ответить
Jake
Jake - 29.07.2022 01:58

Is it okay to expose an API Key that is limited and retrieves information for demonstration purposes (i.e. demo projects hosted on GitHub Pages)?

Ответить
Christopher Huffman
Christopher Huffman - 20.07.2022 02:53

Absolutely need a demo with some visuals

Ответить
N H
N H - 17.07.2022 20:00

So you didn't explain how to solve it. Nice. What a waste of time.

Ответить
Daniel Rocha
Daniel Rocha - 24.06.2022 06:54

what if don't want to make localhost:3000/weather data available to all users, just to the ones that are authenticated?

Ответить
MikeOnTheBox
MikeOnTheBox - 28.05.2022 18:15

Using environment variables gives you a "false" sense of safeness, you are still exposing the API key to the world. Which not always is a problem as many API will give you an option to limit what URL requests can be made from, so exposing API keys isn't always a problem. Google Maps API key is one example that comes to my mind.

Ответить
DasDune Technologies
DasDune Technologies - 13.05.2022 11:22

Backend protection, use Firebase auth with custom claim with JWT

Ответить
AHMED
AHMED - 01.04.2022 18:46

Thats where i am stuck i created proxy node backend but i think its useless now because you can call it directly and get the data😂😂😓

Ответить
Radoslav Ivanov
Radoslav Ivanov - 30.03.2022 15:58

Great video James - Objective, honest, and on point, without unnecessary things!

Ответить
Rathapong P
Rathapong P - 30.03.2022 09:17

Do you not sing a song anymore?

Ответить
elAmigo805
elAmigo805 - 30.03.2022 04:01

Please make a demo. Even if it's a multipart video to avoid all mistakes.

Ответить
Vonnie Kinsey
Vonnie Kinsey - 29.03.2022 21:44

Vercel environment vars work great for prod. Thought you maybe are highlighting this as not the best solution.
NextJs newer version of 12 has resolved the ability to get env vars into the front-end. If the var is prefixed with NEXT_PUBLIC_..., then the value is return and not return of a blank. Although, it only works for NextJs. And, I do believe Vercel's NextJs would offer this only if it were secure approach.

Ответить
C Abellano
C Abellano - 29.03.2022 03:02

Thanks for this video, james. Yes, a demo would be nice.

Ответить
Sushin Pv
Sushin Pv - 28.03.2022 20:30

Hi James,

I work on full stack development for more than 5 years now, and created multiple apps which has more than 2million downloads on the playstore,

The methods which you have mentioned is having couple of issues,

Method 1: use cors : here I can simply create a backend server which internally calls your backend server which you have mentioned as proxy, and I'll be able to use it on any website I need

Method 2: Rate limit, if you rate limit an application just using the token without checking IP this could back fire, as this will lead to a DOSS attack and I can block your actual request

Method 3: JWT token, this has the same problem as initial one, where if a person is smart enough to get the secret key from the code base, he can easily get the JWT token from the network logs / network inspector, and we will be able to easily crack your refresh token mechanism too,

So here what I have done is, create a hash key mechanism with custom token, where the custom token is generated using browser finger print and few other information which I don't want to disclose and server will also use these same information to create a hash for every request, if it's found an hash mismatch, it will immediately blacklist the token, all the browser and every request will generate a unique hash, any of the parameters changes hash will change, this is one way to secure your service

Here what you have mentioned is the minimum requirements, but it will not fully secure your application

Ответить
Kiyoshi Tanaka
Kiyoshi Tanaka - 28.03.2022 13:10

Can you please make an Tutorial on SSR Streaming with Next.js

Ответить
notojujior
notojujior - 27.03.2022 16:17

As long as it’s being used on the client, the key can still be seen on the browser if you dig deep into it, no? Unless you mask it with a serverless function then yes it’ll be completely hidden.

Ответить
Duy Tran
Duy Tran - 27.03.2022 14:54

Great

Ответить
Dabayare
Dabayare - 27.03.2022 14:13

Why not have it on a database on the web, then construct a class with private values if ur shipping an app with API keys.

Ответить
Angshuman Roy
Angshuman Roy - 27.03.2022 10:29

Please make the follow up video

Ответить
Nicholas Singh
Nicholas Singh - 27.03.2022 08:05

Hey bro. How much longer before the everything svelte course is dropped?

Ответить
Hugo DUPREZ
Hugo DUPREZ - 27.03.2022 00:13

So there no solution to prevent a stranger to trigger our backend from a server ? (Apart login auth)

A simple like counter which is available for guests (no login) that be stored in a db can’t be secured to a stranger call?

Ответить
pastuh
pastuh - 26.03.2022 15:10

Not so much info about Chrome extensions and JWT. Would be nice to see some tips/tricks :)

Ответить
Hesam Alavi
Hesam Alavi - 26.03.2022 01:38

Yes, demo please :D

Ответить
badunius
badunius - 25.03.2022 11:10

DevTools > Network > see api key in plain text in the request
=/

Ответить
Richard Day
Richard Day - 25.03.2022 07:09

Please suggest in detail how to manage multiple dev/test/production .env files shared among multiple developers and testers.

Also, how would ex-developers (potential saboteurs) be denied access? Generate new keys and rebuild/redistribute a new generation of .env files?

Also, please address Pavel Pirogov's comment that many api keys are host-limited, apparently mitigating key secrecy as a serious issue.

Ответить
Allformyequine
Allformyequine - 25.03.2022 02:24

So would this also be true for using an API to say gather just simple blog posts from a CMS; I mean do you need to get special tokens for that type of application?

Ответить
Amy Stout
Amy Stout - 25.03.2022 02:01

I'm already making popcorn for the follow up :)

Ответить
Hans Wurst
Hans Wurst - 24.03.2022 22:15

I have to use Google Maps in a project. I was wondering if anything that you said would apply for the Google API key, but I guess it doesn't. Google forbids using Maps with a proxy as far as I know. Restricting the key to a host (via Cors in the Google account settings) is the only possible protection I guess.

Ответить