【发布时间】: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