android - 存储 Firestore 数据模型的最佳实践

标签 android database security google-cloud-firestore data-modeling

在使用Firestore和Android的时候,如果我们想把数据模型存放在一个地方,我们可以这样存放:

在 XML 中:

<string name="collection_users">users</string>
<string name="user_first_name">first</string>
<string name="user_last_name">last</string>
<string name="user_year_birth">born</string>

或直接在 Java 中:

public static final String COLLECTION_USERS = "users";
public static final String FIELD_FIRST_NAME = "first";
public static final String FIELD_LAST_NAME = "last";
public static final String FIELD_YEAR_BIRTH = "born";

然而,在这两种情况下,我们都在客户端代码中公开了数据库的整个数据模型,从而使攻击者的工作更加轻松,以防他们以某种方式获得应用程序的源代码。在使用 Firestore 等 No-SQL 数据库时,是否有任何好的做法或建议的方法来最大程度地减少客户端代码中数据库结构的暴露?

最佳答案

Is there any good practice or suggested approach to minimize the exposure of the structure of the DB when using a No-SQL DB such as Firestore?

当然可以,使用 Firestore 安全规则,这样您就可以根据需要保护您的数据库。为此,我建议您阅读有关 getting started with Cloud Firestore Security Rules 的官方文档。 .

Security rules provide access control and data validation in a simple yet expressive format. To build user-based and role-based access systems that keep your users' data safe, you need to use Firebase Authentication with Cloud Firestore Security Rules.

由于无法避免暴露数据库结构,因此集合/文档的名称应明确存在于您的代码中,以便您可以在引用中使用它们。但只要您正确保护数据库,这就不是问题。您可以将一些逻辑(如果可能)移到服务器端,这将是一个不错的选择。

如果需要,您也可以尝试将这些名称存储在本地数据库中并对其进行加密,但我认为这样做没有任何好处。您可以选择是否需要某种加密。

关于android - 存储 Firestore 数据模型的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56595990/

相关文章:

sql - QSqlTableModel 的问题——没有自动更新

c# - session 与事务

安卓反破解,到底值不值?

php - 使用 PHP 保护获取的数据

php - index.php 及其内容的保护

android - Chrome 自定义标签 : Why is CustomTabsClient. bindCustomTabsService() 无法正常工作?

android - 使用 Animation 使 ItemDecoration 移动

android - 如何使用 robolectric 测试应用程序类中的方法?

java - 找不到 native 方法 : com. example.pjtest.JniClass.get_time:()C

mysql - mysql 表中的数据非常大。即使是 select 语句也需要很多时间