firebase-tools
firebase-tools copied to clipboard
Uploading a file to Storage with matching Rules crashes the emulator
[REQUIRED] Environment info
firebase-tools: 11.3.0
Platform: Windows 10 (64bit)
[REQUIRED] Test case
Android client (real device) uploads a file to Cloud Storage Emulator having a matching Rule causes an 'An unexpected error' in Firebase Console and the emulator terminated.
[REQUIRED] Steps to reproduce
- Set a simple matching storage rule as below
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false; // deny unmatched paths by default
}
match /users/{userId}/media/{fileName} {
allow read, write: if true; // rule of interest
}
}
}
- Android client (real device) uploads a file to path: /users/{autogeneratedUid}/media/{timestamp_autogeneratedUid}
[REQUIRED] Expected behavior
Android client can successfully uploads a file because the matching rule allows.
[REQUIRED] Actual behavior
Firebase console prints Error: An unexpected error has occurred.
and terminated immediately. No file was uploaded to Storage.
When inspecting firebase-debug.log, the only debug info given was:
[debug] [2022-07-25T06:23:11.504Z] Error: ENOENT: no such file or directory, open 'C:\Users\john\AppData\Local\Temp\firebase\storage\blobs\xxxxxxxx-32eb-4aeb-86d1-1432d20aa6ba_b_test-12345.appspot.com_o_users%252FbrNxbhVhAM5MRE39KQ9PWtwtNVkB%252Fmedia%252F1658730191_dabc107f-486c-4712-be23-9e6ea5d59664'
at openSync (node:fs:585:3)
at Persistence.readBytes (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\lib\emulator\storage\persistence.js:37:36)
at StorageLayer.uploadObject (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\lib\emulator\storage\files.js:157:52)
at handleUpload (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\lib\emulator\storage\apis\firebase.js:302:53)
at handleObjectPostRequest (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\lib\emulator\storage\apis\firebase.js:387:16)
at Layer.handle [as handle_request] (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\index.js:281:22
at param (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\index.js:354:14)
at param (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\index.js:365:14)
at param (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\index.js:365:14)
at Function.process_params (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\index.js:410:3)
at next (C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\node_modules\express\lib\router\index.js:275:10)
at C:\Users\john\AppData\Roaming\nvm\v16.15.1\node_modules\firebase-tools\lib\emulator\storage\apis\firebase.js:68:9
[error]
[error] Error: An unexpected error has occurred.
However, if I change the Storage rules to:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
And repeat the same upload, the expected behavior can be achieved (no crash, file uploaded).
Hi @tonyjhuang would you mind taking a look at this one too? Thank you!!
Ack, will take a look next week
Hi @phath9 do you have a sample project we can use to verify this bug on our end?
Filing internal bug to track, b/240635182
Hi @phath9, I'm trying to reproduce this bug but I'm having some trouble getting the same error. Could you send some sample code that leads to this error?
Also while trying to reproduce this bug I've stumbled upon another bug where the emulator crashes with the same error message you see when a file upload is blocked by the storage.rules. I'll be working on fixing that one in the meantime so hopefully that will help with your issue too.
I've fixed the issue I mentioned in https://github.com/firebase/firebase-tools/pull/4860 so I'm closing this for now. Please keep an eye out for the emulator release and give it another try then. If you're still having the issue please reopen this issue and I'd be happy to take a look