javascript - Firebase firestore 应用程序 - 使用网络调用是一种好习惯吗?暴露 apiKey 可以让别人让你有额外的账单吗?
问题描述
我正在开发一个网络应用程序,它依赖于通过 Cordova 的 Firebase firestore 进行实时同步。
我尝试使用一个特定的插件但没有成功。
我最终只使用了这样的网络电话:
索引.html
我加载了
https://www.gstatic.com/firebasejs/5.8.0/firebase-app.js
https://www.gstatic.com/firebasejs/5.8.0/firebase-firestore.js
我加到头上
<meta http-equiv="Content-Security-Policy" content="
default-src 'self' *.googleapis.com data: gap:
https://ssl.gstatic.com;
script-src 'self' 'unsafe-inline' 'unsafe-eval'
https://*.gstatic.com https://*.googleapis.com;
style-src 'self' 'unsafe-inline';
media-src *;
connect-src *
">
index.js
firebase.initializeApp({
apiKey: 'my_api_key',
authDomain: 'localhost',
projectId: 'my_projectid'
});
var db = firebase.firestore();
function loadMessages() {
var query = firebase.firestore()
.collection('my_collection');
// Start listening to the query.
query.onSnapshot(function(snapshot) {
snapshot.docChanges().forEach(function(change) {
if (change.type === 'removed') {
console.log("deleted"+change.doc.id);
} else {
var message = change.doc.data();
//change color and text
console.log(change.doc.id+": "+message.status);
}
}
});
});
}
// We load currently existing chat messages and listen to new ones.
loadMessages();
它有效,但我想知道这种方法是否存在任何安全风险?
特别是因为 api_key 仍然暴露...
编辑
正如在底部评论中提到的:
如何防止我的 apikey 被其他人使用,然后被 Google 收取我未生成的呼叫的费用?有没有办法只允许来自我的应用程序“com.example.app”的呼叫?
谢谢
解决方案
推荐阅读
- javascript - 在开玩笑的单元测试中使用 javascript 模拟静态类
- ruby-on-rails - 带有拉丁字符的 Rails 查询
- python - FileNotFoundError Selenium Stealth Python
- reactjs - 在 UseEffect 中获取数据的无限循环
- ios - SwiftUI 如何在不使用导航视图的情况下显示大导航标题?
- python - aiohttp - 在获取大量 HTML 页面时拆分任务 - RuntimeError:无法重用已经等待的协程
- python - RuntimeError: all 只支持 torch.uint8 和 torch.bool dtypes
- flutter - 提供者不更新 Flutter 中的数据
- python - 如何在 bash 脚本中传递 JSON 字符串中的变量
- amazon-web-services - 试图了解 AWS 中基于 Web 的终端窗口和 ssh