@@ -51,47 +51,43 @@ const transformObjectACL = ({ ACL, ...result }) => {
51
51
return result ;
52
52
} ;
53
53
54
- const specialQuerykeys = [
55
- '$and' ,
56
- '$or' ,
57
- '$nor' ,
58
- '_rperm' ,
59
- '_wperm' ,
60
- '_perishable_token' ,
54
+ const specialQueryKeys = [ '$and' , '$or' , '$nor' , '_rperm' , '_wperm' ] ;
55
+ const specialMasterQueryKeys = [
56
+ ...specialQueryKeys ,
61
57
'_email_verify_token' ,
58
+ '_perishable_token' ,
59
+ '_tombstone' ,
62
60
'_email_verify_token_expires_at' ,
63
- '_account_lockout_expires_at' ,
64
61
'_failed_login_count' ,
62
+ '_account_lockout_expires_at' ,
63
+ '_password_changed_at' ,
64
+ '_password_history' ,
65
65
] ;
66
66
67
- const isSpecialQueryKey = key => {
68
- return specialQuerykeys . indexOf ( key ) >= 0 ;
69
- } ;
70
-
71
- const validateQuery = ( query : any ) : void => {
67
+ const validateQuery = ( query : any , isMaster : boolean , update : boolean ) : void => {
72
68
if ( query . ACL ) {
73
69
throw new Parse . Error ( Parse . Error . INVALID_QUERY , 'Cannot query on ACL.' ) ;
74
70
}
75
71
76
72
if ( query . $or ) {
77
73
if ( query . $or instanceof Array ) {
78
- query . $or . forEach ( validateQuery ) ;
74
+ query . $or . forEach ( value => validateQuery ( value , isMaster , update ) ) ;
79
75
} else {
80
76
throw new Parse . Error ( Parse . Error . INVALID_QUERY , 'Bad $or format - use an array value.' ) ;
81
77
}
82
78
}
83
79
84
80
if ( query . $and ) {
85
81
if ( query . $and instanceof Array ) {
86
- query . $and . forEach ( validateQuery ) ;
82
+ query . $and . forEach ( value => validateQuery ( value , isMaster , update ) ) ;
87
83
} else {
88
84
throw new Parse . Error ( Parse . Error . INVALID_QUERY , 'Bad $and format - use an array value.' ) ;
89
85
}
90
86
}
91
87
92
88
if ( query . $nor ) {
93
89
if ( query . $nor instanceof Array && query . $nor . length > 0 ) {
94
- query . $nor . forEach ( validateQuery ) ;
90
+ query . $nor . forEach ( value => validateQuery ( value , isMaster , update ) ) ;
95
91
} else {
96
92
throw new Parse . Error (
97
93
Parse . Error . INVALID_QUERY ,
@@ -111,7 +107,11 @@ const validateQuery = (query: any): void => {
111
107
}
112
108
}
113
109
}
114
- if ( ! isSpecialQueryKey ( key ) && ! key . match ( / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 _ \. ] * $ / ) ) {
110
+ if (
111
+ ! key . match ( / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 _ \. ] * $ / ) &&
112
+ ( ( ! specialQueryKeys . includes ( key ) && ! isMaster && ! update ) ||
113
+ ( update && isMaster && ! specialMasterQueryKeys . includes ( key ) ) )
114
+ ) {
115
115
throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , `Invalid key name: ${ key } ` ) ;
116
116
}
117
117
} ) ;
@@ -204,27 +204,25 @@ const filterSensitiveData = (
204
204
perms . protectedFields . temporaryKeys . forEach ( k => delete object [ k ] ) ;
205
205
}
206
206
207
- if (!isUserClass) {
208
- return object ;
207
+ if (isUserClass) {
208
+ object . password = object . _hashed_password ;
209
+ delete object . _hashed_password ;
210
+ delete object . sessionToken ;
209
211
}
210
212
211
- object.password = object._hashed_password;
212
- delete object._hashed_password;
213
+ if (isMaster) {
214
+ return object ;
215
+ }
213
216
214
- delete object.sessionToken;
217
+ for (const key in object) {
218
+ if ( key . charAt ( 0 ) === '_' ) {
219
+ delete object [ key ] ;
220
+ }
221
+ }
215
222
216
- if (isMaster ) {
223
+ if ( ! isUserClass ) {
217
224
return object ;
218
225
}
219
- delete object._email_verify_token;
220
- delete object._perishable_token;
221
- delete object._perishable_token_expires_at;
222
- delete object._tombstone;
223
- delete object._email_verify_token_expires_at;
224
- delete object._failed_login_count;
225
- delete object._account_lockout_expires_at;
226
- delete object._password_changed_at;
227
- delete object._password_history;
228
226
229
227
if (aclGroup.indexOf(object.objectId) > - 1 ) {
230
228
return object ;
@@ -513,7 +511,7 @@ class DatabaseController {
513
511
if ( acl ) {
514
512
query = addWriteACL ( query , acl ) ;
515
513
}
516
- validateQuery ( query ) ;
514
+ validateQuery ( query , isMaster , true ) ;
517
515
return schemaController
518
516
. getOneSchema ( className , true )
519
517
. catch ( error => {
@@ -759,7 +757,7 @@ class DatabaseController {
759
757
if ( acl ) {
760
758
query = addWriteACL ( query , acl ) ;
761
759
}
762
- validateQuery ( query ) ;
760
+ validateQuery ( query , isMaster , false ) ;
763
761
return schemaController
764
762
. getOneSchema ( className )
765
763
. catch ( error => {
@@ -1232,7 +1230,7 @@ class DatabaseController {
1232
1230
query = addReadACL ( query , aclGroup ) ;
1233
1231
}
1234
1232
}
1235
- validateQuery ( query ) ;
1233
+ validateQuery ( query , isMaster , false ) ;
1236
1234
if ( count ) {
1237
1235
if ( ! classExists ) {
1238
1236
return 0 ;
@@ -1744,7 +1742,7 @@ class DatabaseController {
1744
1742
return Promise . resolve ( response ) ;
1745
1743
}
1746
1744
1747
- static _validateQuery : any => void ;
1745
+ static _validateQuery : ( any , boolean , boolean ) => void ;
1748
1746
static filterSensitiveData : ( boolean , any [ ] , any , any , any , string , any [ ] , any ) => void ;
1749
1747
}
1750
1748
0 commit comments