存储 Firestore 数据模型的最佳实践
Best practice for storing Firestore data model
使用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";
然而,在这两种情况下,我们都在客户端代码中公开了数据库的整个数据模型,从而使攻击者的工作更加容易,以防他们以某种方式获得应用程序的源代码。在使用 No-SQL 数据库(例如 Firestore)时,是否有任何好的做法或建议的方法来最大程度地减少客户端代码中数据库结构的暴露?
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.
由于无法避免暴露数据库结构,因此 collections/documents 的名称应该明确存在于您的代码中,以便您可以在引用中使用它们。但只要您正确保护数据库,这就不是问题。您可以将一些逻辑(如果可能)移到服务器端,将是一个不错的选择。
如果需要,您也可以尝试将这些名称存储在本地数据库中并对其进行加密,但我认为这样做没有任何好处。是否需要某种加密由您决定。
使用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";
然而,在这两种情况下,我们都在客户端代码中公开了数据库的整个数据模型,从而使攻击者的工作更加容易,以防他们以某种方式获得应用程序的源代码。在使用 No-SQL 数据库(例如 Firestore)时,是否有任何好的做法或建议的方法来最大程度地减少客户端代码中数据库结构的暴露?
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.
由于无法避免暴露数据库结构,因此 collections/documents 的名称应该明确存在于您的代码中,以便您可以在引用中使用它们。但只要您正确保护数据库,这就不是问题。您可以将一些逻辑(如果可能)移到服务器端,将是一个不错的选择。
如果需要,您也可以尝试将这些名称存储在本地数据库中并对其进行加密,但我认为这样做没有任何好处。是否需要某种加密由您决定。