-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Uncatchable attachment error. #1459
Comments
Co-authored-by: negrita_kalcheva <negrita.kalcheva@netbuilder.com>
This issue is stale because it has been open for 30 days with no activity. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
Any fix given for this issue? |
I was not able to verify the initial claim. Setting attachment content to |
@andris9 How is that possible? The failing test was submitted and merged? That's all that was requested in order to progress this, it was done, no follow-up since then till yours an hour ago. |
This test did something else, so I removed it. Adding an attachment to Nodemailer with
|
Could you please try add an attachment that is 0kb in size? That's what caused the original issue for me. |
Tested with await transporter.sendMail(failingPayload) The initially provided test did not do it. |
I don't know how to do that. What I can tell you is that if you use NodeMailer and you try to attach a 0kb attachment, then you get the error I posted. If you can't work with that, then I guess people will just have to live with this deficiency. |
I tried all kinds of payloads to verify the initial claim but never managed to get an uncaught error. Without having a proper test case that I can use to verify this bug, I can only assume that the issue is in your own code, not in Nodemailer. |
I don't understand what was wrong with the test I submitted. As far as I can see it does exactly what you asked for. Perhaps you could explain what's wrong with it in terms more specific than |
The provided test case was something else. It set a null payload and expected that Nodemailer throws on this. There is no reason to throw, so the test case was not valid. What I need is a test case, where you call the |
Why is there no reason to throw? |
Empty attachment content is totally valid. It should only throw if the payload causes uncaught errors, and to prevent this, the payload should be handled in a way where the uncaught error is caught and returned. This test did not cause any uncaught errors and so there was no error to return. This does not mean that the bug does not exist. It very well might exist, but to handle it, I need a test case with |
Ok well I'm no longer on that contract so I can't help with that. All I know is that some users were accidentally generating 0kb file attachments and that when sending those the error I posted happened. As far as I could tell, the file was interrogated to produce the input to NodeMailer that I showed and when I ran that code it generated an uncatchable error which caused the entire app to break. To fix it I added in code before the NodeMailer call so that it would not attempt to process files with null content. It seems like at least one other person above, @bharathpanchak has experienced this, so perhaps they can help further. |
Sure, in any case, as soon as I get a reproducible test case that causes an uncaught error, I can fix the handling for it to catch it and return it as a regular error. Right now, there is nothing to fix as I don't have such a payload. |
@andris9 Here are my inputs.
My case is when I used type of content in attachment as object/array or type of html body as object/array(other than your specified formats string or an instance of Buffer or Uint8Array) Nodemailer is throwing an uncatchable error which is crashing my server. |
If you have a question why my inputs are like array or object, in my project I will take the inputs from users, they can give any format they want I can't restrict that but I want to show an error that your input format is wrong. I can add a filtering code before sending mail if there is no way you can handle this. |
Ok, now I see it. You are providing something that is a completely wrong data type. Attachments can be empty, strings, or Buffers. This is not attachment specific, and can only be fixed by adding proper input validation for Nodemailer for all input values, as you could probably trigger something similar if you set a Date object as a header key or use any other strange values instead of expected ones. I have no plans for generic input validation for now, so you need to fix your input types in your code. Make sure you only use values that match the documented types. |
The error:
Methods from my EmailController class:
sendMail will catch normal errors (e.g. misconfigured transporter) but if an attachment causes an error (e.g. an attachment with no content) then it does not get caught. By "no content" I mean e.g.
content: null
; for whichtypeof
would reportobject
.Conversation from #NodeMailer Discord Server channel:
geoidesic — Today at 7:41 PM
Well it's an attachment with no content. That's causing the error.
andrisreinman — Today at 7:42 PM
What is the type of that value? Is it an empty string or a buffer? Or something else?
geoidesic — Today at 7:42 PM
null type
andrisreinman — Today at 7:43 PM
Like that: content: null?
geoidesic — Today at 7:43 PM
Yup
If I do typeof it outputs object
andrisreinman — Today at 7:45 PM
Could you create a pull request with a failing test where you try to send an email with such an attachment and it fails? Once there is a test case, I could look into it and try to fix it.
Until then, try to send attachments that are either strings, buffers or streams. Nothing else is allowed. Nodemailer should reject such an email without trying to send it.
If it does bot reject that email, it’s a bug in input validation
I'm creating this ticket as a placeholder against which the PR can be created.
The text was updated successfully, but these errors were encountered: