Skip to content

Commit

Permalink
feat: set default body-parser limitation to 1mb (#3903)
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos authored and fengmk2 committed Oct 11, 2019
1 parent 5ddf07c commit bddf1e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ module.exports = appInfo => {
* @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
* @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
* @property {String} encoding - body's encoding type锛宒efault is utf8
* @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 100kb
* @property {String} jsonLimit - limit of the json body, default is 100kb
* @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb
* @property {String} jsonLimit - limit of the json body, default is 1mb
* @property {String} textLimit - limit of the text body, default is 1mb
* @property {Boolean} strict - when set to true, JSON parser will only accept arrays and objects. Default is true
* @property {Number} queryString.arrayLimit - urlencoded body array's max length, default is 100
* @property {Number} queryString.depth - urlencoded body object's max depth, default is 5
Expand All @@ -196,8 +197,9 @@ module.exports = appInfo => {
config.bodyParser = {
enable: true,
encoding: 'utf8',
formLimit: '100kb',
jsonLimit: '100kb',
formLimit: '1mb',
jsonLimit: '1mb',
textLimit: '1mb',
strict: true,
// @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
queryString: {
Expand Down
6 changes: 3 additions & 3 deletions test/app/middleware/body_parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ describe('test/app/middleware/body_parser.test.js', () => {
.expect(200, done);
});

it('should 413 when post json body over the limit', () => {
it('should 413 when post json body over the limit', done => {
app.mockCsrf();
return app.httpRequest()
app.httpRequest()
.post('/test/body_parser/user')
.send({ foo: 'a'.repeat(1024 * 200) })
.expect(/request entity too large, check bodyParser config/)
.expect(413);
.expect(413, done);
});

it('should disable body parser', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
exports.bodyParser = {
formLimit: '100kb',
jsonLimit: '100kb',
textLimit: '100kb',
queryString: {
arrayLimit: 5
}
Expand Down

0 comments on commit bddf1e1

Please sign in to comment.