【问题标题】:How is it possible that listening to Firestore collection allows to access data that I shouldn't have access to?收听 Firestore 集合怎么可能允许访问我不应该访问的数据?
【发布时间】:2020-09-09 14:26:57
【问题描述】:

鉴于以下规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Nobody except superuser and member can see member data
    match /Member/{id} {
      allow get: if ((request.auth != null) && (id == request.auth.uid));
      allow list: if ((request.auth != null) && (id == request.auth.uid));
            //allow read: if ((request.auth != null) && (id == request.auth.uid));
      allow update: if ((request.auth != null) && (id == request.auth.uid));
      allow delete: if ((request.auth != null) && (id == request.auth.uid));
      allow create: if ((request.auth != null) && (id == request.auth.uid));
        }
  }
}

还有我的数据:会员收藏。

文档 ID:PIijFvYPXQPSlheQxotvFvXW4VI2 包含一些字段 文档 ID:QM6tGSkA2SRSPjHGIurDiARd6zv1,其中包含一些字段

我认为有意义的观察:

1) 使用规则游乐场

Simulation type: get
Location: /Member/PIijFvYPXQPSlheQxotvFvXW4VI2
Authenticate: false

结果:

模拟读取被拒绝,原因是:“allow get: if ((request.auth != null) && (id == request.auth.uid));”这完全有道理。

2) 使用规则游乐场

Simulation type: get
Location: /Member/PIijFvYPXQPSlheQxotvFvXW4VI2
Authenticate: true
Provider: Google
Firebase UID: QM6tGSkA2SRSPjHGIurDiARd6zv1

结果:

模拟读取被拒绝,原因是:“allow get: if ((request.auth != null) && (id == request.auth.uid));”这完全有道理。

3) 使用规则游乐场

Simulation type: get
Location: /Member/PIijFvYPXQPSlheQxotvFvXW4VI2
Authenticate: true
Provider: Google
Firebase UID: PIijFvYPXQPSlheQxotvFvXW4VI2

结果:

允许模拟读取。这完全有道理。

4) 在颤动中,

Codesn-p 1:

await AbstractRepositoryS
ingleton.singleton
    .userRepository()
    .signInWithGoogle()
    .then((value) async {
      await AbstractRepositorySingleton.singleton
          .memberRepository().valuesList().then((event) {
        print("Success");
      });

Codesn-p 2(AbstractRepositorySingleton.singleton.memberRepository().valuesList()的实现)

  Future<List<MemberModel>> valuesList() async {
    return await MemberCollection.getDocuments().then((value) {
      var list = value.documents;
      return list.map((doc) => _populateDoc(doc)).toList();
    });
  }

Codesn-p 3:

final CollectionReference MemberCollection = Firestore.instance.collection('Member');

行动:

我运行代码 sn-p 1,它要求我登录到我的手机。我使用 firebase UID = PIijFvYPXQPSlheQxotvFvXW4VI2 登录,然后运行对所有成员的查询。

结果:

这失败了,哪些又是有意义的。

我的观察毫无意义:

Codesn-p 1:

await AbstractRepositorySingleton.singleton
    .userRepository()
    .signInWithGoogle()
    .then((value) async {
      await AbstractRepositorySingleton.singleton
          .memberRepository().values().listen((event) {
        print("Success");
      });

Codesn-p 2(AbstractRepositorySingleton.singleton.memberRepository().values()的实现)

  Stream<List<MemberModel>> values() {
    return MemberCollection.snapshots().map((snapshot) {
      return snapshot.documents
            .map((doc) => _populateDoc(doc)).toList();
    });
  }

行动:

我运行代码 sn-p 1,它要求我登录手机,我使用 firebase ID = PIijFvYPXQPSlheQxotvFvXW4VI2 的用户登录, 然后执行所有成员的 LISTEN。

结果

这成功了,_populateDoc 允许我读取所有成员的所有数据字段。
基本上,这种机制似乎允许我阅读整个集合,即使是我应该无权访问的数据。 但是,我确定我做错了什么……但是什么。 请指教。非常感谢。

【问题讨论】:

    标签: flutter google-cloud-firestore firebase-security


    【解决方案1】:

    我注意到的一件事是在 listen() 方法期间发生了错误:

    com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
    

    仍然由于某种原因,我在 _populateDoc 的断点中有 4 次命中,我可以愉快地从文档中读取成员数据。

    在考虑了一些额外的想法后,我得出结论,这可能与我手机上的 Firestore 数据的本地缓存有关。

    所以我尝试了另一部手机,该特定应用程序以前从未运行过,但我遇到了同样的错误,并且我在 _populateDoc 的断点中遇到了 1 次命中。

    我开始觉得有点意思了。但是,如果有人可以证实这一点。这是在某个地方记录的吗?

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 2018-10-01
      相关资源
      最近更新 更多