Revert "sec: security patch for CVE-2024-51999"
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This reverts commit 2f64f68c37c64ae333e41ff38032d21860f22255.
authored by Ulises Gascon · committed by Jon Church · parent 4007ad1 · Browse files · 2 files·+3 added−90 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+3 added−90 removed
- tests:+2 added−89 removed
- other:+1 added−1 removed
Provenance
- Commit
697547c- Tree
05f1818- Author
Ulises Gascon <ulisesgascongonzalez@gmail.com>- Committer
Jon Church <me@jonchurch.com>- Parent
4007ad1
2 files changed+3 added−90 removed
modified:lib/utils.js+1 added-1 removed
264 unmodified lines265 */266 267 function parseExtendedQueryString(str) {268 return qs.parse(str, {269- plainObjects: true269+ allowPrototypes: true270 });271 }modified:test/req.query.js+2 added-89 removed
123456678927 unmodified lines3738394042434445464748495051525354555657414243442 unmodified lines4748495068697071727374757677787980818283515253544 unmodified lines5960616296979899100101102103104105106107636465662 unmodified lines69707172118119120121122123124125126127128129130131132133737475762 unmodified lines79808182144145146147148149150151152153154155156157158159838485863 unmodified lines90919293171949596979899100101179180181182183184185186187188102189103104105106'use strict'
var assert = require('node:assert')var express = require('../') , request = require('supertest');var qs = require('qs');
describe('req', function(){ describe('.query', function(){ it('should default to {}', function(done){27 unmodified lines request(app) .get('/?user.name=tj') .expect(200, '{"user.name":"tj"}', done); });
it('should not be able to access object prototype properties', function (done) { var app = createApp('extended', true);
request(app) .get('/?foo=yee') .expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done); });
it('should be able to use object prototype property names as keys', function (done) { var app = createApp('extended', true);
request(app) .get('/?hasOwnProperty=yee') .expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done); }); });
describe('when "query parser" is simple', function () { it('should not parse complex keys', function (done) {2 unmodified lines request(app) .get('/?user%5Bname%5D=tj') .expect(200, '{"user[name]":"tj"}', done); });
it('should not be able to access object prototype properties', function (done) { var app = createApp('simple', true);
request(app) .get('/?foo=yee') .expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done); });
it('should be able to use object prototype property names as keys', function (done) { var app = createApp('simple', true);
request(app) .get('/?hasOwnProperty=yee') .expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done); }); });
describe('when "query parser" is a function', function () { it('should parse using function', function (done) {4 unmodified lines request(app) .get('/?user%5Bname%5D=tj') .expect(200, '{"length":17}', done); });
// test exists to verify behavior for folks wishing to workaround our qs defaults it('should drop object prototype property names and be able to access object prototype properties', function (done) { var app = createApp( function (str) { return qs.parse(str) }, true);
request(app) .get('/?hasOwnProperty=biscuits') .expect(200, '{"query":{},"hasOwnProperty":false}', done); }); });
describe('when "query parser" disabled', function () { it('should not parse query', function (done) {2 unmodified lines request(app) .get('/?user%5Bname%5D=tj') .expect(200, '{}', done); });
it('should not be able to access object prototype properties', function (done) { var app = createApp('extended', true);
request(app) .get('/?foo=yee') .expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done); });
it('should be able to use object prototype property names as keys', function (done) { var app = createApp('extended', true);
request(app) .get('/?hasOwnProperty=yee') .expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done); }); });
describe('when "query parser" enabled', function () { it('should not parse complex keys', function (done) {2 unmodified lines request(app) .get('/?user%5Bname%5D=tj') .expect(200, '{"user[name]":"tj"}', done); });
it('should not be able to access object prototype properties', function (done) { var app = createApp('extended', true);
request(app) .get('/?foo=yee') .expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done); });
it('should be able to use object prototype property names as keys', function (done) { var app = createApp('extended', true);
request(app) .get('/?hasOwnProperty=yee') .expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done); }); });
describe('when "query parser" an unknown value', function () { it('should throw', function () {3 unmodified lines }); })})
function createApp(setting, isPrototypePropertyTest) {function createApp(setting) { var app = express();
if (setting !== undefined) { app.set('query parser', setting); }
app.use(function (req, res) { if(isPrototypePropertyTest) { try { var hasOwnProperty = req.query.hasOwnProperty('✨ express ✨'); res.send({ query: req.query, hasOwnProperty: hasOwnProperty }); } catch (error) { res.send({ query: req.query, error: error.toString() }); } } else { res.send(req.query); res.send(req.query); } });
return app;}