Skip to content

Commit 4fbd7f4

Browse files
committed
fix: dont allow nonmaster to update user's authData
1 parent c73874c commit 4fbd7f4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/RestWrite.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ RestWrite.prototype._validatePasswordRequirements = function () {
853853
}
854854
if (this.data.password.indexOf(results[0].username) >= 0)
855855
{ return Promise.reject(
856-
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
856+
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
857857
); }
858858
return Promise.resolve();
859859
});
@@ -880,16 +880,16 @@ RestWrite.prototype._validatePasswordHistory = function () {
880880
let oldPasswords = [];
881881
if (user._password_history)
882882
{ oldPasswords = _.take(
883-
user._password_history,
884-
this.config.passwordPolicy.maxPasswordHistory - 1
883+
user._password_history,
884+
this.config.passwordPolicy.maxPasswordHistory - 1
885885
); }
886886
oldPasswords.push(user.password);
887887
const newPassword = this.data.password;
888888
// compare the new password hash with all old password hashes
889889
const promises = oldPasswords.map(function (hash) {
890890
return passwordCrypto.compare(newPassword, hash).then(result => {
891891
if (result)
892-
// reject if there is a match
892+
// reject if there is a match
893893
{ return Promise.reject('REPEAT_PASSWORD'); }
894894
return Promise.resolve();
895895
});
@@ -901,12 +901,12 @@ RestWrite.prototype._validatePasswordHistory = function () {
901901
})
902902
.catch(err => {
903903
if (err === 'REPEAT_PASSWORD')
904-
// a match was found
904+
// a match was found
905905
{ return Promise.reject(
906-
new Parse.Error(
907-
Parse.Error.VALIDATION_ERROR,
908-
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
909-
)
906+
new Parse.Error(
907+
Parse.Error.VALIDATION_ERROR,
908+
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
909+
)
910910
); }
911911
throw err;
912912
});
@@ -1436,6 +1436,18 @@ RestWrite.prototype.runDatabaseOperation = function () {
14361436
`Cannot modify user ${this.query.objectId}.`
14371437
);
14381438
}
1439+
// Handle authData updates for _User class
1440+
if (this.className === '_User' && this.query && this.data.authData) {
1441+
if (!this.auth.isMaster && !this.auth.isMaintenance) {
1442+
// For non-master key requests, remove authData from the update
1443+
delete this.data.authData;
1444+
// If no other fields to update, return early
1445+
if (Object.keys(this.data).length === 0) {
1446+
this.response = { response: {} };
1447+
return Promise.resolve();
1448+
}
1449+
}
1450+
}
14391451

14401452
if (this.className === '_Product' && this.data.download) {
14411453
this.data.downloadName = this.data.download.name;

0 commit comments

Comments
 (0)