Skip to content

Commit ea09213

Browse files
committed
lift query key validation out of transformWhere
1 parent 559205b commit ea09213

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const storageAdapterAllCollections = mongoAdapter => {
2525
});
2626
}
2727

28+
const specialQuerykeys = ['$and', '$or', '_rperm', '_wperm', '_perishable_token', '_email_verify_token'];
2829
export class MongoStorageAdapter {
2930
// Private
3031
_uri: string;
@@ -187,7 +188,10 @@ export class MongoStorageAdapter {
187188
if (query.ACL) {
188189
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
189190
}
190-
let mongoWhere = transform.transformWhere(className, query, { validate }, schema);
191+
if (validate && Object.keys(query).some(restKey => !specialQuerykeys.includes(restKey) && !restKey.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/))) {
192+
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${restKey}`);
193+
}
194+
let mongoWhere = transform.transformWhere(className, query, schema);
191195
return collection.deleteMany(mongoWhere)
192196
})
193197
.then(({ result }) => {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ function transformQueryKeyValue(className, key, value, schema) {
172172
}
173173
if (value.some(subQuery => subQuery.ACL)) {
174174
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
175+
Object.keys(subQuery).forEach(restKey => {
176+
if (!specialQuerykeys.includes(restKey) && !restKey.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
177+
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${restKey}`);
178+
}
179+
});
175180
}
176181
return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
177182
case '$and':
@@ -180,6 +185,11 @@ function transformQueryKeyValue(className, key, value, schema) {
180185
}
181186
if (value.some(subQuery => subQuery.ACL)) {
182187
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
188+
Object.keys(subQuery).forEach(restKey => {
189+
if (!specialQuerykeys.includes(restKey) && !restKey.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
190+
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${restKey}`);
191+
}
192+
});
183193
}
184194
return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
185195
default:

0 commit comments

Comments
 (0)