Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protect Firebase Secret in javascript

I have created simple firebase chat system using pure javascript , Everything is working fine , But I have below code in javascript open to everyone.

  var config = {
    apiKey: "AIzaSyD0Bm91234567678srKwjUGrpu35dgIIE",
    authDomain: "example-26847.firebaseapp.com",
    databaseURL: "https://example-26847.firebaseio.com",
    projectId: "example-26847",
    storageBucket: "example-26847.appspot.com",
    messagingSenderId: "937123954572"
  };

But I feel like this is vulnerable to hacking , How do i protect it , I have only php web server.

like image 815
Ajay Websitica Avatar asked Aug 18 '26 13:08

Ajay Websitica


1 Answers

You don't have much choice.

Accessing it via JS

You actually need those keys in your javascript based app, so they will be in it one way or another. I don't think it expose much risk, you can still add some rules to only let read/write access to firestore based on apikeys/tokens you'll generate.
Another solution would be to get those ids from your server via an ajax/XHR request & store them locally in some private browser based storage.

VCS

Keeping those ids locally wihtout being commited to a VCS is easy (.gitignore for example with a .example)

Also, you don't need all of them, storageBucket only for storing file in GCP Storage, messagingSenderId for push notification.

like image 131
Hugo Gresse Avatar answered Aug 20 '26 04:08

Hugo Gresse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!