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

Corrupted multipart/form-data crashes a server #117

Open
AlexPikalov opened this issue Jan 4, 2018 · 0 comments
Open

Corrupted multipart/form-data crashes a server #117

AlexPikalov opened this issue Jan 4, 2018 · 0 comments

Comments

@AlexPikalov
Copy link

Steps for reproduction:

  1. create a route that consumes multipart/form-data with two parametes of type string and file (this is more or less what I had)

  2. start node server

  3. make a request via Postman or other http client. This request should contain modified Content-Length header with value that is less than a true one (length 1 is good for demonstration)

Actual result: server is crashed completely with status 7 and following error

Error: req.body must be provided for 'formData' parameters
    at Parameter.getValue (/Users/xxx/Projects/zzz/node_modules/sway/lib/types/parameter.js:147:15)
    at /Users/xxx/Projects/zzz/node_modules/swagger-node-runner/fittings/swagger_params_parser.js:40:44
    at Array.forEach (<anonymous>)
    at /Users/xxx/Projects/zzz/node_modules/swagger-node-runner/fittings/swagger_params_parser.js:39:46
    at finishedParseBody (/Users/xxx/Projects/zzz/node_modules/swagger-node-runner/fittings/swagger_params_parser.js:128:12)
    at /Users/xxx/Projects/zzz/node_modules/async/lib/async.js:726:13
    at /Users/xxx/Projects/zzz/node_modules/async/lib/async.js:52:16
    at /Users/xxx/Projects/zzz/node_modules/async/lib/async.js:269:32
    at /Users/xxx/Projects/zzz/node_modules/async/lib/async.js:44:16
    at /Users/xxx/Projects/zzz/node_modules/async/lib/async.js:723:17
npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! [email protected] start: `node ./src/index.js`
npm ERR! Exit status 7
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

As a quick fix I've wrapped value getting into try/catch, somethink like

try {
  req.swagger.operation.parameterObjects.forEach(function(parameter) {
    params[parameter.name] = parameter.getValue(req); // note: we do not check for errors here
   });

   next(null, params);
} catch (err) {
   next(err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant