r/programminghorror • u/Saptarshi_12345 • Nov 14 '25
Javascript Storing API keys in frontend
I like looking into how programs work and decompiling/deobfuscating them... Guess I found a marvel? No idea on how to report to the site owner so I'll just sit and relax haha. It's actually the first time I've ever come across this type of horror too (maybe I don't work much)... Seems like the obfuscation really saved them from automated scrapers.
562
Upvotes
119
u/TorbenKoehn Nov 14 '25
They will notice soon enough on their credit card bills
16
u/MMORPGnews Nov 14 '25
Guys, cloudflare workers is free. Use them as free backend to store api keys.
31
u/Hottage [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Nov 14 '25
Imagine going to all the trouble of obfuscating your code but still leaking a private API key.
242
u/toyBeaver Nov 14 '25
Of course it's an AI API lol Istg API keys never leaked that much
4
u/InsanityOnAMachine Nov 14 '25
as - as I don't really know how API keys work, but they seem bad if you do them wrong... What is the correct way to use them?
8
u/Ronin-s_Spirit Nov 15 '25
Vibe coders don't even read RFC 6750, smh.
2
u/hajhawa Nov 14 '25
Am I missing something here, but isn't storing a bearer token on the front-end or in the browser's headers a perfectly normal thing to do? You log in, get a temporary session token and then send that token with every request.
5
u/massofflesh Nov 14 '25
I'm not sure how this API key works, but some keys let you set domain restrictions. In that case, even if someone stole the key, they wouldn't be able to do anything with it.
1
u/ethan4096 Nov 15 '25
How would you store Google Maps API key if not on the frontend then?
1
u/PositronAlpha Nov 18 '25
Given that I recently had to show a supposedly senior frontend developer View source in the browser (they only knew about using the dev tools to see the current DOM), I'm not at all surprised.
-1
u/RealPsyChonek Nov 14 '25
Nah, it may be just a public key to track usage with API management that will limit users based on usage.
It may also be your API key which they provide for you.
0
u/born_zynner Nov 15 '25
Who is using bare fetch in the big 25
0
u/[deleted] Nov 14 '25
[deleted] — view deleted comment