Set firebase storage to write only - firebase

I need to set firebase storage rules so unauthenticated users can upload a file but can't read a file.
So far I have:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow write: if true
allow read: if false
}
}
}
Is this the correct way to do this?

This rule will help you to read only if user is authenticated else it won't allow. For more details you can read docs
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if request.auth != null;
allow write: if true;
}
}
}

Related

Firestore permission error in test database mode

I know that questions about Firestore permission errors have been asked a lot, but my situation may be unique. This is because of three things:
my database is in test mode which should allow access to anyone (right?)
I am getting the error while simulating my app with an authenticated firebase user
I am able to write data--the error only happened while reading it.
Here are my security rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2021, 12, 31);
}
}
}
Here is a screenshot of a description of Firestore's test database mode:
The actual error I got was this:
Error: Error Domain=FIRStorageErrorDomain Code=-13021 "User does not have permission
to access gs://zimmerfour.appspot.com/senderID." UserInfo={object=senderID,
ResponseBody={
"error": {
"code": 403,
"message": "Permission denied. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources."
EDIT:
I haven't changed the overall Cloud Storage rules. They are still set to the default of:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
The error message is coming from Cloud Storage for Firebase (as indicated by FIRStorageErrorDomain and the error message), which is protected by its own set of security rules in your project.
Try this method, it worked for me :)
// if you want to allow for all to read, write
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
// if you want to allow for all to read, and authenticated users to write
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read;
allow write: if request.auth != null;
}
}
}
// if you want to allow for only authenticated users to write or read
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}

Firebase Change Permissions Public Access SwiftUI

I am using Firebase for Auth and image storage--images that are publically available thoughout my app, like profile pictures. How do I set up the permissions appropriately so that any user (or even non-authenticated entities) can read these public images?
My security rules:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
In your question, you say that you want non-authenticated entities to see the images, but your rules are set up to only allow authenticated entities to see them. You can change your rules to:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read;
allow write: if request.auth != null;
}
}
}

Firebase rules change

I want to stop reading data from firebase by using rules change. Here is the rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
I want to disallow all. How to do that ?
Change this:
allow read, write;
to this:
allow read, write: if false;

how to set strong firebase rules

Recently I got a mail from firebase in which they told me that all requests from clients are declined after 4 days and to update my security rule.
In my app, there is no need for logging, anyone can download and play quizzes but I did not allow anyone to write to the database. I manually update the database.
So please suggest to me what rule am I use to avoid that request decline problem.
My realtime database rules are-
"rules": {
".read": true,
".write": false
}
and storage rules are-
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
you can try if
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}

making a folder public in Firebase Storage

i need to set a folder public with only read permisions in firebase storage, my security rules are
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write:if request.auth.uid != null;
}
match /{platos=**} {
allow read;
}
}
}
the folder is called platos and im not sure if those rules are secured the others folders must have protection only for logued users
The first rule should concern your folder, because otherwise the first rule is applied which rejects reads:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /platos/{allPaths=**} {
allow read;
allow write: if request.auth != null;
}
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
You can just delete the authentication code request.auth.uid != null and give only the read permission.
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read;
}
}
}

Resources