-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
ignore parts without names #71
base: main
Are you sure you want to change the base?
Conversation
What happens currently? |
Currently the field event is emitted aber fieldname is undefined. I think if you emit Error then the whole submitted form would be discarded. not sure Maybe the package consumers have some idea how they would handle those cases? @LinusU ? @dougwilson ? |
I would be okay with this 👍
Hmm, this will probably lead to some unwanted behaviour in Multer 😅 If Which will also try to read the |
@LinusU So if you want to ignore that invalid multipart data, you could after this PR do a ignoreUndefinedFieldnames: true and those invalid fields would be skipped and not throwing issues in multer as the field event would not be emitted as the field is not valid anyway. |
Yeah, I assumed that we had the problems in all current versions of Multer, but my wording didn't really communicate that 😅
I would prefer it if Multer could raise an |
Just for my curiosity: Is the Error-throwing a part of the multipart rfc or the multer spec? |
@Uzlopak RFC does not cover any part of error handling, and I don't think that Multer spec is a thing. I would say it's more of a good engineering practice, failing fast on data that clearly contradicts the specification. |
I am open for suggestions. I guess, we need to emit an Error and not throw? And secondly, what should be the useful information if we error? "Malformed Multipart Error"? |
Hmm, it seems like the current version also skips over parts that doesn't have a
I personally would prefer to fail fast on any data that isn't valid according to RFC7578. Since 1.0.0 is already released, it's up for interpretation wether making changes to adhere to the specification is breaking or not. One way forward could be to add a |
I am open to both approaches - keeping 1.0.0 as drop-in replacement for busboy, and following up with 2.0.0 which is way stricter about what it accepts, or introducing "strict" option in 1.1.0. |
Neat! As for Multer, I would prefer to use the strict version for Multers 2.0.0 release 🚀 |
As discussed, can we start throwing errors there? |
For clarification: |
Current |
@LinusU
Also please additional feedback by @kibertoad I would patch it right away if we agree on the technical spec |
I'm not a maintainer of this project btw. I'm a maintainer of Multer, a large user of this library. My personal recommendation would be:
You might however want to wait for an answer from one the maintainers |
I agree that we should be strict and throw an error for these cases, configuration doesn't seem necessary, as this case directly violates spec |
That is the reason why I ask you. As a consumer of this package, you have the better insights regarding the edge cases etc.. As you know we forked and refactored this, because of the bugs etc.. But I am happy to get reliable feedback from you to determine what the best direction is. So Thank you for the feedback ;).
Scratch that :). Ok, will apply the changes soon. |
I thought I answered here, but it seems I didnt. Well I have tested locally. What actually the issue is, that you can have something like a payload, where you have 10 parts. The first 9 parts are valid, and the 10th is invalid. We would then emit error. But we already piped the first 9 parts already somewhere. So there could be an issu. Or you have 10 parts and the first part is invalid. So we have to emit the error and skip all the other parts. This seems to be strange to me. But I have no idea except to emit an error and skip the following part streams. |
I really would like to resolve this. How should we move forward? |
I would implement this as the Setting |
@KhafraDev |
Anything that violates the spec should emit an error as fast as possible in my opinion Clearly the RFC says that a part MUST have a name value However, I also wonder why mscdex/busboy#244 was closed. Was it fixed afterward? |
@Uzlopak could you tell why? If emitting an error for a malformed part and continuing is not possible, it should throw |
I wouldn't expect a malformed formdata to parse successfully, this change seems correct. |
So we should throw an error if we have a part without a name, right? @gurgunday |
Yeah, the RFC says it must have it. |
I worked on this issue on the weekend. skipParts was actually avoiding one issue: When we are processing the data, we dont know if one of the later parts is invalid. This results in the problem, that we create valid file-streams/fields and then we have an invalid part. So we abort. But we will still have created file streams. So how should we properly handle these cases? |
I see, I guess it's because busboy is event based But in any case, throwing (or at least emitting an error and stopping) would still be more correct in implementations where the user doesn't see the events and just gets the complete body when parsing is completed successfully |
It is not recommendable to store everything in memory. Imagine, you process a huuuuuge file upload and second field is without a name. Thinking of @Jarred-Sumner s tweet today |
But isn’t that what happens when fetch formData is used in the browser for instance? I haven’t checked, just asking |
yes it is. |
originally mscdex/busboy#244 with more links of @faust64
Chocobozzz/PeerTube#4121
expressjs/multer#913
https://datatracker.ietf.org/doc/html/rfc7578#section-4.2
There is actually no way to handle a part without name gracefully.
I think, I would add the option ignoreEmptyFieldnames with default of false to have non-breaking change to legacy busboy.Any thoughts?
Checklist
npm run test
andnpm run benchmark
and the Code of conduct