2016-09-16 70 views
0

这些是我的Firebase存储规则。新用户可以访问其他用户上传的照片

match 
/{allPaths=**} { 
    allow read, write: if request.auth != null; 

这是用户如何将图片添加到存储

StorageReference filepathOne = mStorage.child(user_data.getString("uidkey", null)).child("Photos").child("id_one"); 

正如你可以看到我使用的UID作为文件路径名的一部分。我的假设是,每当用户上传他们想要的图片时,只有他们能够访问它,因为他们拥有唯一的UID。但是,我创建了一个新的用户帐户,出于某种原因,该用户即使拥有不同的UID,也能够访问其他用户上传的照片。

我还应该指出,我将URI存储在sharedpref中,然后将其转换为字符串以显示图片。

这是我怎样存储在SharedPref

Uri downloadUrl = taskSnapshot.getDownloadUrl();       

Picasso.with(getContext()) 
    .load(downloadUrl) 
    .fit().centerCrop() 
    .into(image); 

editor.putString(user_idone, (taskSnapshot.getDownloadUrl()).toString());        
editor.commit(); 

这是我从县和显示提取。

Picasso.with(getContext()) 
    .load(Uri.parse(user_data.getString("idonekey", null))) 
    .fit().centerCrop() 
    .into((ImageView) getView().findViewById(R.id.image)); 

回答

0

当前你的规则是“任何人都可以读/写任何东西,只要它们通过认证。”这听起来像你想改变规则,以反映您的文件结构,并提供更高的安全性:

service firebase.storage { 
    match /b/<your-bucket-name>/o { 
    match /{userId}/Photos/{fileName} { 
     allow read: if request.auth.uid == userId; 
    } 
    } 
} 

我们rules docs谈更深入的user and group based security

相关问题