匿名身份验证够吗?

詹金

我正在开发不需要登录的应用程序,因为没有任何特定于用户的数据。我最初的计划是仅使我的整个数据库为只读。但是,经过研究后,我发现这些安全规则会使我的数据库非常脆弱。我的新计划是为每个打开我的应用程序的新用户实施匿名身份验证,然后在该用户退出我的应用程序后将其删除。该安全规则将仅允许在用户经过身份验证时进行读取。这足以防止某人使用滥用查询到我的数据库吗?

samthecodingman

通常没有

仅使用匿名身份验证会增加访问数据库的障碍,并且可以像进行数据库完全打开一样保护它免受简单的读取查询,但是您应该将其与限制可以执行的查询的安全规则结合使用。

假设我们从以下准系统规则开始:

// Allow read access on all documents to any user signed in to the application,
// and write access to only administrators
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if request.auth.uid != null;
      allow write: if request.auth.token.isAdmin === true;
    }
  }
}

要收紧规则,您应该首先删除通配符条目,然后将其替换为固定的文档路径。

// Allow read access on all documents at /posts/{postId} to any user signed in to the application,
// and write access to only administrators
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /posts/{postId} {
      allow read: if request.auth.uid != null;
      allow write: if request.auth.token.isAdmin === true;
    }
  }
}

甚至

// Allow read access on all documents at /posts/{postId} to any user signed in to the application,
// and write access to only administrators
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /posts/{postId} {
      allow read: if request.auth.uid != null;
      allow write: if request.auth.token.isAdmin === true;

      // allow same permissions on subcollections of /posts/{postId}
      match /{document=**} {
        allow read: if request.auth.uid != null;
        allow write: if request.auth.token.isAdmin === true;
      }
    }
  }
}

接下来,您应该考虑添加规则,以使用Firebase文档中所述粒度安全list规则来限制针对数据库执行的查询的大小Securely query data

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /posts/{postid} {

      // Deny any query not limited to 10 or fewer documents
      allow list: if request.auth != null
                  && request.query.limit <= 10;

      // Anyone can retrieve an individual post
      allow get: if request.auth != null;

      // Only an admin can write to posts
      allow write: if request.auth.token.isAdmin === true;
    }
  }
}

根据数据更新的频率,您还可以考虑将数据束存储在Firebase Storage上,或者甚至可以从Firebase Hosting提供数据,在CDN而不是您的应用程序可以提供这些数据束。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Firebase匿名身份验证

我可以在 firebase 身份验证中将身份验证提供程序从 google 帐户更改为匿名吗?

Firebase匿名身份验证(Android):终身?

Firebase匿名休息身份验证

WCF禁用匿名身份验证

匿名使用Firebase进行身份验证

通过Firebase匿名身份验证可以进行Google Cloud MySQL实例访问控制吗?

如果我在Firebase身份验证中有很多冗余匿名用户,可以吗?

在Ionic App中使用Firebase匿名身份验证安全吗?

SignalR似乎正在使用Windows身份验证,而不是使用匿名身份验证

流星RESTful身份验证。可能吗?

PAM是用户身份验证方法吗?

Firebase 匿名身份验证正在触发 JS if 语句的双方

Firebase:匿名身份验证-如何设置标识符?

Flutter Firebase身份验证:恢复为特定的匿名用户

在SonarQube 8.6上允许匿名身份验证

Firebase 数据库的匿名身份验证权限被拒绝

Owin自托管WebApi Windows身份验证和匿名

WCF服务的安全设置需要匿名身份验证

Firebase匿名身份验证和设备ID

以编程方式在IIS中启用或禁用匿名身份验证

Firebase 匿名身份验证在应用升级时丢失

Windows和.Net Core 2.0中的匿名身份验证

Spring-拒绝进行匿名身份验证

Firebase:在Cookie中存储匿名身份验证

从Cloud Functions匿名使用Firebase身份验证登录

使用mod_auth_openidc的可选或匿名身份验证

匿名身份验证不适用于android

Blazor 使用 Azure AD 身份验证允许匿名访问