Comparing version 1.3.5 to 1.4.0
@@ -6,2 +6,3 @@ const Buffer = require('buffer').Buffer | ||
const conlen = parseInt(req.headers['content-length'], 10) || 0 | ||
const type = req.headers['content-type'] | ||
if (conlen === 0) { | ||
@@ -23,8 +24,10 @@ return next() | ||
const data = body.join('') | ||
if (data) { | ||
if (data && type === 'application/json') { | ||
try { | ||
req.body = JSON.parse(body.join('')) | ||
req.body = JSON.parse(data) | ||
} catch (err) { | ||
return res.err(400, 'Payload is not valid JSON') | ||
} | ||
} else { | ||
req.body = data | ||
} | ||
@@ -31,0 +34,0 @@ next() |
@@ -0,1 +1,3 @@ | ||
const multipart = /^multipart\/form-data/ | ||
module.exports = function (maxSize) { | ||
@@ -6,3 +8,4 @@ return function restrictPost (req, res, next) { | ||
const size = req.headers['content-length'] | ||
if (type !== 'application/json') { | ||
if (type !== 'application/json' && !multipart.test(type)) { | ||
return res.err(415, `POST requests must be application/json not ${type}`) | ||
@@ -9,0 +12,0 @@ } |
{ | ||
"name": "take-five", | ||
"version": "1.3.5", | ||
"version": "1.4.0", | ||
"description": "Very minimal JSON-REST server", | ||
@@ -5,0 +5,0 @@ "main": "take-five.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13587
190
3