angular / angular/angularfire

Firebase storage 403 on delete

Open
#3,279 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
7.8k
Forks
2.2k
Avg merge
22h 28m
Merged PRs (30d)
6

Description

### Version info

**Angular:** 14.1.0

**Firebase:** 9.6.10

**AngularFire:** 7.4.0

**Other (e.g. Ionic/Cordova, Node, browser, operating system):**
Mac
node 16.16.0
Chrome latest

### How to reproduce these conditions

**Failing test unit, Stackblitz demonstrating the problem**

**Steps to set up and reproduce**

**Sample data and security rules**

private _getImagePath(): Observable {
return of('debug/users/%USERID%/images/exportimage'); //For demo purpose
}

// Succeeds
setImage(data: Blob): Observable {
return this._getImagePath().pipe(
switchMap(path => new Observable(obs => {
this.storage.ref(path).put(data).then(x => {
obs.next(x);
obs.complete();
});
}))
);
}

// Succeeds
getMetadata(): Observable{
return this._getImagePath().pipe(
switchMap(path => this.storage.ref(path).getMetadata())
);
}

// Succeeds
getUrl(): Observable{
return this._getImagePath().pipe(
switchMap(path => this.storage.ref(path).getDownloadURL())
);
}

// fails
deleteImage(){
return this._getImagePath().pipe(
switchMap(path => this.storage.ref(path).delete())
);
}

I get the same result from `this._storage.storage.refFromURL(url).delete()`

rules:

service firebase.storage {
match /b/admob-app-id-5092275243.appspot.com/o {
match /debug/users/{userId}/images/exportimage {
allow read: if request.auth.uid == userId;
allow write: if request.auth.uid == userId &&
request.resource.size < 1 * 1024 * 1024 &&
request.resource.contentType.matches('image/.*');
}

match /release/users/{userId}/images/exportimage {
allow read: if request.auth.uid == userId;
allow write: if request.auth.uid == userId &&
request.resource.size < 1 * 1024 * 1024 &&
request.resource.contentType.matches('image/.*');
}
}
}

### Debug output

** Errors in the JavaScript console **
FirebaseError: Firebase Storage: User does not have permission to access 'debug/users/L7vT58BkdXQTHa6nF3hNgHVeHcq1/images/exportimage'. (storage/unauthorized)

** Output from `firebase.database().enableLogging(true);` **

** Screenshots **

### Expected behavior

The image should be deleted

### Actual behavior

403 unauthorised

Contributor guide

Open the contributing guide

Research direction

Start with the deleteImage() and refFromURL(url).delete() examples, then inspect the Firebase Storage security rules shown in the report. Reproduce the 403 with the listed Angular, Firebase, and AngularFire versions and determine what behavior should allow deletion; done means deletion succeeds under the documented rules or the issue is shown to be a configuration problem.

Written by the indexing model from the issue text.

Assessment

Tech stack
firebase, typescript
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.