@@ -55,47 +55,43 @@ const transformObjectACL = ({ ACL, ...result }) => {
55
55
return result ;
56
56
} ;
57
57
58
- const specialQuerykeys = [
59
- '$and' ,
60
- '$or' ,
61
- '$nor' ,
62
- '_rperm' ,
63
- '_wperm' ,
64
- '_perishable_token' ,
58
+ const specialQueryKeys = [ '$and' , '$or' , '$nor' , '_rperm' , '_wperm' ] ;
59
+ const specialMasterQueryKeys = [
60
+ ...specialQueryKeys ,
65
61
'_email_verify_token' ,
62
+ '_perishable_token' ,
63
+ '_tombstone' ,
66
64
'_email_verify_token_expires_at' ,
67
- '_account_lockout_expires_at' ,
68
65
'_failed_login_count' ,
66
+ '_account_lockout_expires_at' ,
67
+ '_password_changed_at' ,
68
+ '_password_history' ,
69
69
] ;
70
70
71
- const isSpecialQueryKey = key => {
72
- return specialQuerykeys . indexOf ( key ) >= 0 ;
73
- } ;
74
-
75
- const validateQuery = ( query : any ) : void => {
71
+ const validateQuery = ( query : any , isMaster : boolean , update : boolean ) : void => {
76
72
if ( query . ACL ) {
77
73
throw new Parse . Error ( Parse . Error . INVALID_QUERY , 'Cannot query on ACL.' ) ;
78
74
}
79
75
80
76
if ( query . $or ) {
81
77
if ( query . $or instanceof Array ) {
82
- query . $or . forEach ( validateQuery ) ;
78
+ query . $or . forEach ( value => validateQuery ( value , isMaster , update ) ) ;
83
79
} else {
84
80
throw new Parse . Error ( Parse . Error . INVALID_QUERY , 'Bad $or format - use an array value.' ) ;
85
81
}
86
82
}
87
83
88
84
if ( query . $and ) {
89
85
if ( query . $and instanceof Array ) {
90
- query . $and . forEach ( validateQuery ) ;
86
+ query . $and . forEach ( value => validateQuery ( value , isMaster , update ) ) ;
91
87
} else {
92
88
throw new Parse . Error ( Parse . Error . INVALID_QUERY , 'Bad $and format - use an array value.' ) ;
93
89
}
94
90
}
95
91
96
92
if ( query . $nor ) {
97
93
if ( query . $nor instanceof Array && query . $nor . length > 0 ) {
98
- query . $nor . forEach ( validateQuery ) ;
94
+ query . $nor . forEach ( value => validateQuery ( value , isMaster , update ) ) ;
99
95
} else {
100
96
throw new Parse . Error (
101
97
Parse . Error . INVALID_QUERY ,
@@ -115,7 +111,11 @@ const validateQuery = (query: any): void => {
115
111
}
116
112
}
117
113
}
118
- if ( ! isSpecialQueryKey ( key ) && ! key . match ( / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 _ \. ] * $ / ) ) {
114
+ if (
115
+ ! key . match ( / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 _ \. ] * $ / ) &&
116
+ ( ( ! specialQueryKeys . includes ( key ) && ! isMaster && ! update ) ||
117
+ ( update && isMaster && ! specialMasterQueryKeys . includes ( key ) ) )
118
+ ) {
119
119
throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , `Invalid key name: ${ key } ` ) ;
120
120
}
121
121
} ) ;
@@ -208,27 +208,24 @@ const filterSensitiveData = (
208
208
perms . protectedFields . temporaryKeys . forEach ( k => delete object [ k ] ) ;
209
209
}
210
210
211
- if (!isUserClass) {
212
- return object ;
211
+ if (isUserClass) {
212
+ object . password = object . _hashed_password ;
213
+ delete object . _hashed_password ;
214
+ delete object . sessionToken ;
213
215
}
214
216
215
- object.password = object._hashed_password;
216
- delete object._hashed_password;
217
-
218
- delete object.sessionToken;
219
-
220
217
if (isMaster) {
221
218
return object ;
222
219
}
223
- delete object._email_verify_token;
224
- delete object._perishable_token;
225
- delete object._perishable_token_expires_at ;
226
- delete object._tombstone;
227
- delete object._email_verify_token_expires_at;
228
- delete object._failed_login_count;
229
- delete object._account_lockout_expires_at;
230
- delete object._password_changed_at ;
231
- delete object._password_history;
220
+ for (const key in object) {
221
+ if ( key . charAt ( 0 ) === '_' ) {
222
+ delete object [ key ] ;
223
+ }
224
+ }
225
+
226
+ if ( ! isUserClass ) {
227
+ return object ;
228
+ }
232
229
233
230
if (aclGroup.indexOf(object.objectId) > - 1 ) {
234
231
return object ;
@@ -515,7 +512,7 @@ class DatabaseController {
515
512
if ( acl ) {
516
513
query = addWriteACL ( query , acl ) ;
517
514
}
518
- validateQuery ( query ) ;
515
+ validateQuery ( query , isMaster , true ) ;
519
516
return schemaController
520
517
. getOneSchema ( className , true )
521
518
. catch ( error => {
@@ -761,7 +758,7 @@ class DatabaseController {
761
758
if ( acl ) {
762
759
query = addWriteACL ( query , acl ) ;
763
760
}
764
- validateQuery ( query ) ;
761
+ validateQuery ( query , isMaster , false ) ;
765
762
return schemaController
766
763
. getOneSchema ( className )
767
764
. catch ( error => {
@@ -1253,7 +1250,7 @@ class DatabaseController {
1253
1250
query = addReadACL ( query , aclGroup ) ;
1254
1251
}
1255
1252
}
1256
- validateQuery ( query ) ;
1253
+ validateQuery ( query , isMaster , false ) ;
1257
1254
if ( count ) {
1258
1255
if ( ! classExists ) {
1259
1256
return 0 ;
@@ -1809,7 +1806,7 @@ class DatabaseController {
1809
1806
return Promise . resolve ( response ) ;
1810
1807
}
1811
1808
1812
- static _validateQuery : any => void ;
1809
+ static _validateQuery : ( any , boolean , boolean ) => void ;
1813
1810
static filterSensitiveData : ( boolean , any [ ] , any , any , any , string , any [ ] , any ) => void ;
1814
1811
}
1815
1812
0 commit comments