Skip to content

Commit

Permalink
Fixing maxBodyLength enforcement (#3786)
Browse files Browse the repository at this point in the history
* Adding request body length validation on HTTP adapter

* Removing error code assertion on HTTP's body length support test

 * Removed due to the error being thrown by axios itself now, instead of follow-redirects

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
PauloRSF and jasonsaayman committed Dec 23, 2021
1 parent 962f9ab commit c00c4dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/adapters/http.js
Expand Up @@ -101,6 +101,10 @@ module.exports = function httpAdapter(config) {
));
}

if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
return reject(createError('Request body larger than maxBodyLength limit', config));
}

// Add Content-Length header if data exists
if (!headerNames['content-length']) {
headers['Content-Length'] = data.length;
Expand Down
1 change: 0 additions & 1 deletion test/unit/adapters/http.js
Expand Up @@ -456,7 +456,6 @@ describe('supports http with nodejs', function () {
setTimeout(function () {
assert.equal(success, false, 'request should not succeed');
assert.equal(failure, true, 'request should fail');
assert.equal(error.code, 'ERR_FR_MAX_BODY_LENGTH_EXCEEDED');
assert.equal(error.message, 'Request body larger than maxBodyLength limit');
done();
}, 100);
Expand Down

0 comments on commit c00c4dd

Please sign in to comment.