apigee-127 / swagger-tools

A Node.js and browser module that provides tooling around Swagger.
MIT License
702 stars 373 forks source link

curl -d '{}' /your/swagger/url/here causes a crash #504

Open MikeSandfordArundo opened 7 years ago

MikeSandfordArundo commented 7 years ago

I discovered this error and a co-worker did the sleuthing to track down the exact problem. It turns out that curl will default to application/x-www-form-urlencoded when you don't specify a content type. And that can cause a process to crash due to an unhandled exception (at least for us) deep in the bowels of things completely outside of our code.

What happens is that the url encoded data gets choked on right here: https://github.com/apigee-127/swagger-tools/blob/master/middleware/swagger-metadata.js#L206

He changed that "%s" to "%j" and no more problems.

MikeSandfordArundo commented 7 years ago

I've made a PR for these changes: https://github.com/apigee-127/swagger-tools/pull/505

MikeSandfordArundo commented 7 years ago

While driving this morning I realized that this issue is a little vague. The URL needs to be one that accepts POSTs because otherwise the debug message is circumvented, no further processing (and failing) takes place. It may also need to be running in debug mode (haven't verified yet).

whitlockjc commented 7 years ago

Thanks, I'll give it a peek.