firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.97k stars 915 forks source link

Content-Disposition Header Error with Non-Standard Whitespace in Filenames in Storage Emulator #6834

Open peteshilling opened 3 months ago

peteshilling commented 3 months ago

[REQUIRED] Environment info

firebase-tools: 13.4.0

Platform: macOS 14.2.1, M2

[REQUIRED] Test case

This can be reproduced in the emulator UI tool itself without any additional code.

[REQUIRED] Steps to reproduce

  1. Run firebase emulators:start
  2. Capture a screenshot in macOS (cmd + shift + 3)
  3. Open emulator UI, go to Storage, click 'Upload file', select screenshot that was captured in step 2
  4. After upload, click on the file.

[REQUIRED] Expected behavior

You should be able to view a preview of the uploaded image.

[REQUIRED] Actual behavior

After I select the image file the preview image in the right side panel shows a broken image and the emulators crash.

Error log shows this

[debug] [2024-03-05T03:27:42.889Z] TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Content-Disposition"]
    at ServerResponse.setHeader (node:_http_outgoing:655:3)
    at sendFileBytes (/Users/x/Documents/GitHub/x/node_modules/firebase-tools/lib/emulator/storage/apis/shared.js:20:9)
    at /Users/x/Documents/GitHub/x/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:101:47
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[error] 
[error] Error: An unexpected error has occurred.

Upon investigating, it looks like adding the filename to the Content-Disposition header in this commit caused the bug to start occurring.

It took me a while to realize there is something about the automated screenshot filenames that is causing the issue, but as best as I can tell, that's what it is.

aalej commented 3 months ago

Hey @peteshilling, thanks for the detailed report and for sharing your observations. I was able to reproduce this issue. I’ll notify our engineering team about this so they can take a look.

peteshilling commented 3 months ago

Thank you, @aalej. It's one of those bugs that isn't a big deal once you know what is happening (just avoid using screenshot files when testing), but at first it looked like a much bigger issue and took some time to narrow down.

garrett-wombat commented 1 month ago

Im having the same issue, except its happening when i await bucket.file(filePath).download({ destination: tempFilePath }); within a cloud function. The function is onFinalize of storage object.

[debug] [2024-05-03T04:27:42.785Z] TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Content-Disposition"]
    at ServerResponse.setHeader (node:_http_outgoing:651:3)
    at sendFileBytes (/X/services/firebase/node_modules/.pnpm/firebase-tools@13.0.3/node_modules/firebase-tools/lib/emulator/storage/apis/shared.js:19:9)
    at /X/services/firebase/node_modules/.pnpm/firebase-tools@13.0.3/node_modules/firebase-tools/lib/emulator/storage/apis/gcloud.js:88:47
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[error] 
[error] Error: An unexpected error has occurred.
kylefoley commented 1 month ago

Seeing the exact same thing. Any update on this bug @aalej ? Firebase-tools version 13.7.2

jarodl commented 1 month ago

I'm seeing this issue when the client app attempts to download images stored using Firebase Storage while using the emulator.

lautenschlager-dev commented 2 weeks ago

I'm seeing this issue when the client app attempts to download images stored using Firebase Storage while using the emulator.

I can confirm that. Any news if that gets resolved?

kylefoley commented 6 days ago

@aalej @joehan this still reproduces in 13.11.4. Filename is "Screenshot 2024-06-23 at 8.35.19 AM.png".

Screenshot 2024-06-24 at 10 56 31 AM Screenshot 2024-06-24 at 10 56 52 AM
aalej commented 5 days ago

Hey @kylefoley, sorry to hear you’re still encountering this issue and thanks for following up on this. I tried uploading and viewing a file named "Screenshot 2024-06-23 at 8.35.19 AM.png" on the storage emulator, but no errors were raised. Currently using v13.11.4 as well.

image

I think I may have missed something here, could you provide us with details on how you encountered the issue? Was the error raised when viewing the file via the UI Emulator?

kylefoley commented 5 days ago

Absolutely, sorry I should have added this to start.

I'm locally running an angular app pointed to emulator cloud functions. When I call admin.storage().bucket(FIREBASE_STORAGE_BUCKET).file(path).getSignedUrl({ action: 'read', expires: Date.now() + 15 * 60 * 1000 })) on the cloud function side, I get that error and it kills the emulator. Uploading seems to work ok, but getting the signed URL is where it dies.

This cloud function performs just fine when deployed. Let me know if you need any more debug information.