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

Multer crashes when name attribute is absent in multipart #553

Closed
vwvw opened this issue Jan 30, 2018 · 3 comments
Closed

Multer crashes when name attribute is absent in multipart #553

vwvw opened this issue Jan 30, 2018 · 3 comments

Comments

@vwvw
Copy link

vwvw commented Jan 30, 2018

A multipart request without a 'name' attribute will produce an error and result with a crash of multer.
Here is an example of such a multipart request (every line break is a CRLF).

POST / HTTP/1.1
Host: localhost
content-type:multipart/form-data;boundary=abcde
Content-Length: 69

--abcde
Content-Disposition: form-data; nam="a"

data
--abcde-

Busboy will not detect the field name and return

fieldname = undefined
val = data

The crash occurs when multer call the append-field as it will try to access the length property of 'fieldname'.
Here is the stacktrace:

/home/user/node_modules/append-field/lib/parse-path.js:13
var len = key.length
^

TypeError: Cannot read property 'length' of undefined
at parsePath (/home/user/node_modules/append-field/lib/parse-path.js:13:17)
at appendField (/home/user/node_modules/append-field/index.js:5:15)
at Busboy. (/home/user/node_modules/multer/lib/make-middleware.js:93:7)
at Busboy.emit (events.js:159:13)
at Busboy.emit (/home/user/node_modules/busboy/lib/main.js:38:33)
at PartStream.onEnd (/home/user/node_modules/busboy/lib/types/multipart.js:261:15)
at PartStream.emit (events.js:164:20)
at endReadableNT (_stream_readable.js:1062:12)
at process._tickCallback (internal/process/next_tick.js:152:19)

It seems to me that this issue can be fixed by adding a check at line 91 in make-middleware.js. We check that the fieldname is not empty.

if (!fieldname) return abortWithCode('NO_NAME_ATTRIBUTE')

This way, we will return a 500 instead of crashing.

@vwvw vwvw closed this as completed Jan 30, 2018
@vwvw
Copy link
Author

vwvw commented Jan 30, 2018

(The issue was posted too quickly and closed by mistake)

@vwvw vwvw reopened this Jan 30, 2018
@vwvw vwvw changed the title Multer crash when name attribute is absent in multipart Multer crashes when name attribute is absent in multipart Jan 30, 2018
@LinusU
Copy link
Member

LinusU commented Jan 30, 2018

Good catch 👍

PR welcome 🚀

@mbsimonovic
Copy link

just re-discovered this bug (on v1.4.1):

curl -X POST "http://localhost:3000/upload"  -H "Content-Type: multipart/form-data; boundary=----------------------------4ebf00fbcf09" -d $'------------------------------4ebf00fbcf09\r\nContent-Disposition: form-data; name="file" filename="somefile.txt"\r\n\r\nsome content\r\n------------------------------4ebf00fbcf09--\r\n'
//results in:
  TypeError: Cannot read property 'length' of undefined
      at Busboy.<anonymous> (upload-api/node_modules/multer/lib/make-middleware.js:89:23)

It fails because the semicolon is missing, name="file" filename="somefile.txt" instead of name="file"; filename="somefile.txt"

Ilyaololo added a commit to Ilyaololo/multer that referenced this issue Feb 22, 2020
ZloeSabo added a commit to ZloeSabo/multer that referenced this issue Jun 29, 2020
Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined"
in underlying append-field library.

The current change allows getting a error from multer that makes it
possible to handle it in servers.
ZloeSabo added a commit to ZloeSabo/multer that referenced this issue Jun 29, 2020
Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined"
in the underlying append-field library.

The current change allows getting an error from multer that makes it
possible to handle it in servers.
ZloeSabo added a commit to ZloeSabo/multer that referenced this issue Jun 29, 2020
Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined"
in the underlying append-field library.

The current change allows getting an error from multer that makes it
possible to handle it in servers.
@LinusU LinusU closed this as completed in 055767b Dec 7, 2021
nevilm-lt pushed a commit to nevilm-lt/multer that referenced this issue Apr 21, 2022
Fixes expressjs#553

Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined" in the underlying append-field library.

The current change allows getting an error from Multer that makes it possible to handle it in servers.

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
nevilm-lt pushed a commit to nevilm-lt/multer that referenced this issue Apr 22, 2022
Fixes expressjs#553

Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined" in the underlying append-field library.

The current change allows getting an error from Multer that makes it possible to handle it in servers.

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
nevilm-lt pushed a commit to nevilm-lt/multer that referenced this issue Apr 22, 2022
Fixes expressjs#553

Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined" in the underlying append-field library.

The current change allows getting an error from Multer that makes it possible to handle it in servers.

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
himanshiLt pushed a commit to himanshiLt/multer that referenced this issue Apr 26, 2022
Fixes expressjs#553

Without this fix fields without a name result in a "TypeError: Cannot read property 'length' of undefined" in the underlying append-field library.

The current change allows getting an error from Multer that makes it possible to handle it in servers.

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants