@@ -16456,4 +16456,86 @@ describe('Vulnerabilities', () => {
1645616456 });
1645716457 });
1645816458 });
16459+
16460+ describe('(GHSA-q5g6-5ggq-6g4h) Query with very large conditions', () => {
16461+ const auth = require('../lib/Auth');
16462+ const rest = require('../lib/rest');
16463+ // Error of a find in a class that clients cannot query; the request ends before the database
16464+ const findError = where => {
16465+ const config = Config.get(Parse.applicationId);
16466+ return rest.find(config, auth.nobody(config), 'Locked', where).catch(error => error);
16467+ };
16468+ // Conditions with the given number of objects or arrays nested in each other
16469+ const nested = {
16470+ objects: count => {
16471+ let where = {};
16472+ for (let i = 0; i < count; i++) {
16473+ where = { a: where };
16474+ }
16475+ return where;
16476+ },
16477+ arrays: count => {
16478+ let list = [];
16479+ for (let i = 1; i < count; i++) {
16480+ list = [list];
16481+ }
16482+ return { a: list };
16483+ },
16484+ };
16485+ const tooDeep = jasmine.objectContaining({
16486+ code: Parse.Error.INVALID_QUERY,
16487+ message: 'Query conditions are nested too deeply.',
16488+ });
16489+ const forbidden = jasmine.objectContaining({ code: Parse.Error.OPERATION_FORBIDDEN });
16490+
16491+ beforeEach(async () => {
16492+ const schema = new Parse.Schema('Locked');
16493+ schema.setCLP({ find: {} });
16494+ await schema.save();
16495+ });
16496+
16497+ it('does not keep a record of every condition that it searches', async () => {
16498+ const spies = [
16499+ [WeakSet, 'add'],
16500+ [WeakMap, 'set'],
16501+ [Set, 'add'],
16502+ [Map, 'set'],
16503+ ].map(([type, method]) => spyOn(type.prototype, method).and.callThrough());
16504+ // Collection entries added while a query with the given number of conditions is processed
16505+ const records = async count => {
16506+ spies.forEach(spy => spy.calls.reset());
16507+ const conditions = Array.from({ length: count }, (_, i) => ({
16508+ group: { $in: [[{ value: i }]] },
16509+ }));
16510+ const error = await findError({ $or: conditions });
16511+ const entries = spies.reduce((sum, spy) => sum + spy.calls.count(), 0);
16512+ expect(error).toEqual(forbidden);
16513+ return entries;
16514+ };
16515+ const few = await records(10);
16516+ const many = await records(1010);
16517+ expect(many - few).toBeLessThan(1000);
16518+ });
16519+
16520+ it('does not count conditions next to each other as nesting', async () => {
16521+ const values = Array.from({ length: 20000 }, () => [{ a: [{ b: 1 }] }]);
16522+ expect(await findError({ tags: { $in: values } })).toEqual(forbidden);
16523+ });
16524+
16525+ for (const [kind, conditions] of Object.entries(nested)) {
16526+ it(`searches ${kind} nested 10,000 deep`, async () => {
16527+ expect(await findError(conditions(10000))).toEqual(forbidden);
16528+ });
16529+
16530+ it(`rejects ${kind} nested deeper than 10,000`, async () => {
16531+ expect(await findError(conditions(10001))).toEqual(tooDeep);
16532+ });
16533+ }
16534+
16535+ it('rejects conditions that contain themselves', async () => {
16536+ const where = { name: 'a' };
16537+ where.self = where;
16538+ expect(await findError(where)).toEqual(tooDeep);
16539+ });
16540+ });
1645916541});
0 commit comments