Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ app.defaultConfiguration = function defaultConfiguration() {
this.enable('x-powered-by');
this.set('etag', 'weak');
this.set('env', env);
this.set('query parser', 'simple')
this.set('query parser', 'extended')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'query parser' changed to 'simple' in Express 5 (#3621) and I don't think reverting to 'extended' is planned.

this.set('query parser limit', 10000)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion any new limit setting should be the same as current one (1000 in this case).

this.set('subdomain offset', 2);
this.set('trust proxy', false);

Expand Down
7 changes: 7 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var fresh = require('fresh');
var parseRange = require('range-parser');
var parse = require('parseurl');
var proxyaddr = require('proxy-addr');
var utils = require('./utils');

/**
* Request prototype.
Expand Down Expand Up @@ -229,6 +230,7 @@ req.range = function range(size, options) {

defineGetter(req, 'query', function query(){
var queryparse = this.app.get('query parser fn');
var limit = this.app.get('query parser limit');

if (!queryparse) {
// parsing is disabled
Expand All @@ -237,6 +239,11 @@ defineGetter(req, 'query', function query(){

var querystring = parse(this).query;

// Pass limit to extended parser
if (queryparse === utils.parseExtendedQueryString) {
return queryparse(querystring, limit);
}

return queryparse(querystring);
});

Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ function createETagGenerator (options) {
* @private
*/

function parseExtendedQueryString(str) {
function parseExtendedQueryString(str, limit) {
return qs.parse(str, {
allowPrototypes: true
allowPrototypes: true,
parameterLimit: limit || 10000
});
}
exports.parseExtendedQueryString = parseExtendedQueryString;
4 changes: 2 additions & 2 deletions test/req.query.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ describe('req', function(){
.expect(200, '{}', done);
});

it('should default to parse simple keys', function (done) {
it('should default to parse extended keys', function (done) {
var app = createApp();

request(app)
.get('/?user[name]=tj')
.expect(200, '{"user[name]":"tj"}', done);
.expect(200, '{"user":{"name":"tj"}}', done);
});

describe('when "query parser" is extended', function () {
Expand Down