使用 mongodb 时在电子应用程序中隐藏秘密 API 密钥

问题描述 投票:0回答:1

我目前正在考虑使用next js、mongodb 和realm 创建一个电子应用程序。

浏览完 mongodb 文档后,我发现了集成指南“使用 React 快速启动电子”。我发现本指南内容丰富,但我试图了解该公司在创建本指南时是否存在疏忽。

指南:https://www.mongodb.com/docs/realm/sdk/node/integrations/electron-cra/#std-label-node-electron-cra-client-quick-start

该指南有这个锅炉代码,使您能够写入领域。

const app = new Realm.App({ id: "<Your App ID>" }); // create a new instance of the Realm.App
async function run() {
  // login with an anonymous credential
  await app.logIn(Realm.Credentials.anonymous());
  const DogSchema = {
      name: "Dog",
      properties: {
        _id: 'int',
        name: "string",
        age: "int",
      },
      primaryKey: '_id'
  };
  const realm = await Realm.open({
    schema: [DogSchema],
    sync: {
      user: app.currentUser,
      partitionValue: "myPartition",
    },
  });
  // The myPartition realm is now synced to the device. You can
  // access it through the `realm` object returned by `Realm.open()`
  // write to the realm
}
run().catch(err => {
  console.error("Failed to open realm:", err)
});

要写入领域,您需要将应用程序 ID 放入代码中(如上所示),这是有意义的。没有意义的是,如果这是一个电子应用程序,那么有人就不能找到这个 id,然后能够在您的领域中写入和删除。这是一个疏忽还是 mongodb 希望用户自己弄清楚如何秘密存储该应用程序 ID。

由于它是专门讨论电子的指南,我认为他们会考虑安全性并将其放入指南中。

我对这个问题可能完全没有根据,但我只是想了解是否有可能在电子应用程序中秘密存储您的应用程序 id / api 密钥。如果不使用另一个 api 在启动时获取密钥就不可能,那么这真的是一个疏忽吗?或者可以保留该 ID 为纯文本并且仍然保证应用程序安全吗?

我知道 firebase 和 amplify 在使用 Electron 时也有这个问题。我想既然 mongodb 有一个直接引用 Electron 的指南,他们就会找到解决这个问题的简单方法。

reactjs mongodb security electron realm
1个回答
0
投票

您可以使用safeStorage API将您的应用程序ID存储在磁盘上并防止其他用户访问它。

© www.soinside.com 2019 - 2024. All rights reserved.