Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
peteshilling opened this issue Mar 5, 2024 · 10 comments · Fixed by #7308

Comments

@peteshilling
Copy link

[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
Copy link
Contributor

aalej commented Mar 5, 2024

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
Copy link
Author

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
Copy link

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
Copy link

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

@jarodl
Copy link

jarodl commented May 19, 2024

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

@lautenschlager-dev
Copy link

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
Copy link

kylefoley commented Jun 24, 2024

@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 aalej reopened this Jun 25, 2024
@aalej
Copy link
Contributor

aalej commented Jun 25, 2024

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
Copy link

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.

@aalej
Copy link
Contributor

aalej commented Jul 3, 2024

Apologies for the delayed response here. I created this repo to try and replicate the setup you mentioned. It has a Cloud Function that has an onFinalize trigger which runs when a screenshot is uploaded. I’m uploading the image via the UI emulator.

At the moment, I’m still unable to reproduce the issue. Any chance you could give additional snippets of your functions code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants