sec: security patch for CVE-2024-51999
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Chris de Almeida · committed by Ulises Gascon · parent ed0ba3f · Browse files · 2 files·+90 added−3 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+90 added−3 removed
- tests:+89 added−2 removed
- other:+1 added−1 removed
Provenance
- Commit
2f64f68- Tree
dc332a2- Author
Chris de Almeida <ctcpip@users.noreply.github.com>- Committer
Ulises Gascon <ulisesgascongonzalez@gmail.com>- Parent
ed0ba3f
2 files changed+90 added−3 removed
modified:lib/utils.js+1 added-1 removed
264 unmodified lines265 */266 267 function parseExtendedQueryString(str) {268 return qs.parse(str, {269- allowPrototypes: true269+ plainObjects: true270 });271 }modified:test/req.query.js+89 added-2 removed
1234567891027 unmodified lines3839404142434445464748495051525354555657585960612 unmodified lines6465666768697071727374757677787980818283848586874 unmodified lines92939495969798991001011021031041051061071081091101112 unmodified lines1141151161171181191201211221231241251261271281291301311321331341351361372 unmodified lines1401411421431441451461471481491501511521531541551561571581591601611621633 unmodified lines16716816917094171172173174175176177178179180181182183184185186187102188189190191192193'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) {function createApp(setting, isPrototypePropertyTest) { 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;}