2016-09-16 73 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

相關問題