1

我正在尝试使用 firebase 存储,查看授权用户可以从 Web 客户端上传文件,我想知道是什么阻止了用户通过调整 javascript 来更改路径。

考虑以下

我想按如下方式组织用户文件。

root : {
     users :
            uid1 : images {}
                 : audio {}
    -users:
            uid2 : images {}
                 : audio {} 
    -users:
          : uid3 : images {}
                 : audio {} 
     }

然后上传一张图片到 /userid/images/

        var storage     = firebase.storage();
        var storageRef  = storage.ref();
        var imagesRef   = storageRef.child(uid_g).child('images').child(path);

问题 :

是什么阻止用户将child('images')更改为child('audio')

我只是想确保我设置的路径不会在存储上更改。

服务器上的规则我只允许用户读取和写入他们的数据。

// Grants a user access to a node matching their user ID
service firebase.storage {
  match /b/<your-firbase-storage-bucket>/o {
    // Files look like: "user/<UID>/path/to/file.txt"
    match /user/{userId}/{allPaths=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}
4

1 回答 1

0

您可以继续使用安全规则来创建更多路径限制:

service firebase.storage {
  match /b/<your-firbase-storage-bucket>/o {
    match /user/{userId} {
      match /images {
        // This will match only /user/{userId}/images
        allow read, write: if imageCondition();
      }
      match /audio {
        // If you don't want the user to change to audio, you can either say if false or just don't include this path
        allow read, write: if audioCondition();
      }
    }
  }
}
于 2016-06-20T16:21:12.340 回答