Skip to content

Commit 559205b

Browse files
committed
Lift no-query-ACL validation out of transformWhere
1 parent 66b8a84 commit 559205b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export class MongoStorageAdapter {
184184
deleteObjectsByQuery(className, query, validate, schema) {
185185
return this.adaptiveCollection(className)
186186
.then(collection => {
187+
if (query.ACL) {
188+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
189+
}
187190
let mongoWhere = transform.transformWhere(className, query, { validate }, schema);
188191
return collection.deleteMany(mongoWhere)
189192
})

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,17 @@ function transformQueryKeyValue(className, key, value, schema) {
170170
if (!(value instanceof Array)) {
171171
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
172172
}
173+
if (value.some(subQuery => subQuery.ACL)) {
174+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
175+
}
173176
return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
174177
case '$and':
175178
if (!(value instanceof Array)) {
176179
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
177180
}
181+
if (value.some(subQuery => subQuery.ACL)) {
182+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
183+
}
178184
return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
179185
default:
180186
// Other auth data
@@ -224,9 +230,6 @@ function transformQueryKeyValue(className, key, value, schema) {
224230
const specialQuerykeys = ['$and', '$or', '_rperm', '_wperm', '_perishable_token', '_email_verify_token'];
225231
function transformWhere(className, restWhere, { validate = true } = {}, schema) {
226232
let mongoWhere = {};
227-
if (restWhere['ACL']) {
228-
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
229-
}
230233
for (let restKey in restWhere) {
231234
if (validate && !specialQuerykeys.includes(restKey) && !restKey.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
232235
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${restKey}`);

src/Controllers/DatabaseController.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ DatabaseController.prototype.update = function(className, query, update, {
184184
throw error;
185185
})
186186
.then(parseFormatSchema => {
187+
if (query.ACL) {
188+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
189+
}
187190
var mongoWhere = this.transform.transformWhere(className, query, {validate: !this.skipValidation}, parseFormatSchema);
188191
mongoUpdate = this.transform.transformUpdate(
189192
schemaController,
@@ -668,6 +671,9 @@ DatabaseController.prototype.find = function(className, query, {
668671
if (!isMaster) {
669672
query = addReadACL(query, aclGroup);
670673
}
674+
if (query.ACL) {
675+
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
676+
}
671677
let mongoWhere = this.transform.transformWhere(className, query, {}, schema);
672678
if (count) {
673679
delete mongoOptions.limit;

0 commit comments

Comments
 (0)