我目前正在使用heroku存储我的环境变量以进行Firebase身份验证初始化。我正在使用服务器获取环境变量,然后使用socket.io将其发送到客户端。以下是我的意思。
1)从服务器向客户端发送环境变量的示例:
socket.emit('value', process.env.apiKey);
2)将其作为data [0]存储在客户端中:
socket.on('value', function(data) {
firebase.initializeApp({
apiKey: data[0],
});
})
这样安全吗?如果我在客户端上保存了apiKey的值,有人可以从客户端取回apiKey的值吗?
谢谢
如果数据是从客户端使用的,则恶意用户可以从那里获取数据。像在这里一样动态地查找数据,仅增加了一个额外的步骤。
But the data that you pass to
initializeApp
is basic configuration data that allows the code to find your Firebase project on the servers. It is not a secret, it's not a security mechanism ,and it can be safely shared with your users. See my answer here, for why you don't have to try and secure this data: Is it safe to expose Firebase apiKey to the public?