2016-09-24 34 views
0

如果將此配置集成到JS中,那麼這不會是一個安全問題,因爲任何人都可以打開JS文件,訪問此詳細信息並訪問我的Firebase DB?需要幫助瞭解Firebase配置安全性

var config = { 
    apiKey: "xxxx", 
    authDomain: "xxx.firebaseapp.com", 
    databaseURL: "https://xxx.firebaseio.com", 
    storageBucket: "xxx.appspot.com", 
    messagingSenderId: "0000" 
}; 

如何確保它是安全的?

+2

任何可通過互聯網訪問的數據庫都可以通過sone找到。您可以通過設置誰可以訪問它以及他們可以做什麼的規則來確保數據庫的安全。對於Firebase,這些規則在[此處](https://firebase.google.com/docs/database/security/)中進行了說明。另請參閱我的答案在這裏:http://stackoverflow.com/questions/35418143/how-to-restrict-firebase-data-modification/35419194#35419194 –

回答

2

這只是讓客戶端可以識別您的應用程序。即使是apiKey更像是一個參考,並不像一個祕密密碼,所以不用擔心。您可以使用它在單個文件中實例化許多應用程序。 (見https://firebase.google.com/docs/web/setup)現在

// Intialize the "[DEFAULT]" App 
var mainApp = firebase.intializeApp({ ... }); 

// Intialize a "Secondary" App 
var secondaryApp = firebase.initializeApp({ ... }, "Secondary"); 
... 
mainApp.database().ref("path/to/data").set(value); 
secondaryApp.database().ref("path/to/data").set(anotherValue); 

,火力地堡安全的心臟是火力地堡實時的數據庫規則。在此處瞭解它們: https://firebase.google.com/docs/database/security/

Firebase實時數據庫規則以類似JSON的格式表示,所以您應該立即爲自己創建一些!