@@ -32,7 +32,7 @@ function RestWrite(config, auth, className, query, data, originalData) {
32
32
throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , 'objectId ' +
33
33
'is an invalid field name.' ) ;
34
34
}
35
-
35
+
36
36
// When the operation is complete, this.response may have several
37
37
// fields.
38
38
// response: the actual data to be returned
@@ -136,7 +136,7 @@ RestWrite.prototype.runBeforeTrigger = function() {
136
136
if ( this . response ) {
137
137
return ;
138
138
}
139
-
139
+
140
140
// Avoid doing any setup for triggers if there is no 'beforeSave' trigger for this class.
141
141
if ( ! triggers . triggerExists ( this . className , triggers . Types . beforeSave , this . config . applicationId ) ) {
142
142
return Promise . resolve ( ) ;
@@ -154,7 +154,7 @@ RestWrite.prototype.runBeforeTrigger = function() {
154
154
// This is an update for existing object.
155
155
originalObject = triggers . inflate ( extraData , this . originalData ) ;
156
156
}
157
- updatedObject . set ( Parse . _decode ( undefined , this . data ) ) ;
157
+ updatedObject . set ( this . sanitizedData ( ) ) ;
158
158
159
159
return Promise . resolve ( ) . then ( ( ) => {
160
160
return triggers . maybeRunTrigger ( triggers . Types . beforeSave , this . auth , updatedObject , originalObject , this . config . applicationId ) ;
@@ -254,14 +254,14 @@ RestWrite.prototype.findUsersWithAuthData = function(authData) {
254
254
} , [ ] ) . filter ( ( q ) => {
255
255
return typeof q !== undefined ;
256
256
} ) ;
257
-
257
+
258
258
let findPromise = Promise . resolve ( [ ] ) ;
259
259
if ( query . length > 0 ) {
260
260
findPromise = this . config . database . find (
261
261
this . className ,
262
262
{ '$or' : query } , { } )
263
263
}
264
-
264
+
265
265
return findPromise ;
266
266
}
267
267
@@ -276,9 +276,9 @@ RestWrite.prototype.handleAuthData = function(authData) {
276
276
throw new Parse . Error ( Parse . Error . ACCOUNT_ALREADY_LINKED ,
277
277
'this auth is already used' ) ;
278
278
}
279
-
279
+
280
280
this . storage [ 'authProvider' ] = Object . keys ( authData ) . join ( ',' ) ;
281
-
281
+
282
282
if ( results . length == 0 ) {
283
283
this . data . username = cryptoUtils . newToken ( ) ;
284
284
} else if ( ! this . query ) {
@@ -404,7 +404,7 @@ RestWrite.prototype.transformUser = function() {
404
404
405
405
// Handles any followup logic
406
406
RestWrite . prototype . handleFollowup = function ( ) {
407
-
407
+
408
408
if ( this . storage && this . storage [ 'clearSessions' ] ) {
409
409
var sessionQuery = {
410
410
user : {
@@ -417,7 +417,7 @@ RestWrite.prototype.handleFollowup = function() {
417
417
this . config . database . destroy ( '_Session' , sessionQuery )
418
418
. then ( this . handleFollowup . bind ( this ) ) ;
419
419
}
420
-
420
+
421
421
if ( this . storage && this . storage [ 'sendVerificationEmail' ] ) {
422
422
delete this . storage [ 'sendVerificationEmail' ] ;
423
423
// Fire and forget!
@@ -695,7 +695,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
695
695
throw new Parse . Error ( Parse . Error . SESSION_MISSING ,
696
696
'cannot modify user ' + this . query . objectId ) ;
697
697
}
698
-
698
+
699
699
if ( this . className === '_Product' && this . data . download ) {
700
700
this . data . downloadName = this . data . download . name ;
701
701
}
@@ -722,7 +722,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
722
722
ACL [ this . data . objectId ] = { read : true , write : true } ;
723
723
ACL [ '*' ] = { read : true , write : false } ;
724
724
this . data . ACL = ACL ;
725
- }
725
+ }
726
726
// Run a create
727
727
return this . config . database . create ( this . className , this . data , this . runOptions )
728
728
. then ( ( ) => {
@@ -770,7 +770,7 @@ RestWrite.prototype.runAfterTrigger = function() {
770
770
// Build the inflated object, different from beforeSave, originalData is not empty
771
771
// since developers can change data in the beforeSave.
772
772
let updatedObject = triggers . inflate ( extraData , this . originalData ) ;
773
- updatedObject . set ( Parse . _decode ( undefined , this . data ) ) ;
773
+ updatedObject . set ( this . sanitizedData ( ) ) ;
774
774
updatedObject . _handleSaveResponse ( this . response . response , this . response . status || 200 ) ;
775
775
776
776
triggers . maybeRunTrigger ( triggers . Types . afterSave , this . auth , updatedObject , originalObject , this . config . applicationId ) ;
@@ -789,5 +789,17 @@ RestWrite.prototype.objectId = function() {
789
789
return this . data . objectId || this . query . objectId ;
790
790
} ;
791
791
792
+ // Returns a copy of the data and delete bad keys (_auth_data, _hashed_password...)
793
+ RestWrite . prototype . sanitizedData = function ( ) {
794
+ let data = Object . keys ( this . data ) . reduce ( ( data , key ) => {
795
+ // Regexp comes from Parse.Object.prototype.validate
796
+ if ( ! ( / ^ [ A - Z a - z ] [ 0 - 9 A - Z a - z _ ] * $ / ) . test ( key ) ) {
797
+ delete data [ key ] ;
798
+ }
799
+ return data ;
800
+ } , deepcopy ( this . data ) ) ;
801
+ return Parse . _decode ( undefined , data ) ;
802
+ }
803
+
792
804
export default RestWrite ;
793
805
module . exports = RestWrite ;
0 commit comments