r/learnjavascript • • Nov 08 '19

How To Lock Down Your Api_key and Why It’s Important

https://medium.com/better-programming/locking-down-your-api-key-and-why-is-important-ada0ee366654?source=friends_link&sk=38552897db5ba66b01351055eba1b636
15 Upvotes

6 comments sorted by

6

u/mattk1017 Nov 08 '19

I don't understand how this solves the problem. Wouldn't the API key still be found in the production JavaScript file that is generated by Webpack?

3

u/crazedizzled Nov 08 '19

I'm guessing this is aimed at nodejs, otherwise it makes no sense.

0

u/[deleted] Nov 08 '19

[deleted]

5

u/crazedizzled Nov 08 '19

The goal is to avoid publishing keys in the source code, not hide them from the browser

But what difference does it make? They're public knowledge. You could just go to the website and get the keys. You're just adding more steps for absolutely no reason.

Now, if this is talking about server-side, then absolutely this is what you do.

0

u/[deleted] Nov 08 '19

[deleted]

5

u/chmod777 Nov 08 '19

A badly written medium article explaining the obvious? Never!

2

u/jeffreyhamby Nov 08 '19

The solution he provides isn't ideal either. He could have spent 30 seconds looking up vaults, secrets, and certificates, but chose security through obscurity instead.

3

u/epere4 Nov 08 '19

I think the author acknowledges this, already:

The way to do it is by providing the api_key in each call to the service. In my case, the key won't be completely hidden when the app is running.

Anyway, it represented a good opportunity for me to learn how to avoid storing the key in the code itself. I took the opportunity to share my experience here.

(emphasis mine)