Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

YuMp's avatar
Level 2

How can I hide stripe api key in javascript?

Hello good day. How can I hide stripe api key in javascript? It is showing up on the console. any idea how to solve this problem? Thanks. Good morning everyone.

Code --> https://pastebin.com/F6gc9y3K

API Showing in console screenshot https://i.ibb.co/WkrW9gH/screen.png

0 likes
9 replies
Sinnbeck's avatar

You can't. Don't put private keys in Javascript

1 like
YuMp's avatar
Level 2

@Sinnbeck Yes, I wanted to know how to load it through the .env file without it being displayed in the javascript code. Any idea? thanks for your reply

Sinnbeck's avatar

@YuMp if you need to use it inside Javascript, then people can find it. All Javascript is run inside the users browser, so best you can do is obfuscation (which isnt secure).

Only server side languages can load keys without leaking

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

I would imagine that the stripe key is your public key, and therefor is meant to be used in Javascript and can be shown without problems

1 like
YuMp's avatar
Level 2

@Sinnbeck Hi, even though I know he is not displaying the secret key which makes me relieved but thank you very much, you opened my mind. I did the following, stored the key in the database and called it on the blade. I don't know if it's right, but I believe it can solve part of the problems. var stripe = Stripe('{{ $form->key}}'); Thanks

Sinnbeck's avatar

@YuMp it is still shown to your users. Check the code on the page. You cannot use it in frontend without showing it in some way

1 like
YuMp's avatar
Level 2

@Sinnbeck It's right you're. actually still displaying the public key. But I believe that not displaying the secret key will have no problem, right?

lolsokje's avatar

@YuMp The public key is meant to be used in the front end, it's the secret key you have to worry about. As long as you don't show the secret key anywhere a user can see, you're good.

1 like
Sinnbeck's avatar

@YuMp as long as it's a public key, it's meant to be shown publicly

Please or to participate in this conversation.