Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Do not allow change avatars of another users without permission #13629

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/rocketchat-file-upload/server/lib/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { settings } from 'meteor/rocketchat:settings';
import * as Models from 'meteor/rocketchat:models';
import { FileUpload as _FileUpload } from '../../lib/FileUpload';
import { roomTypes } from 'meteor/rocketchat:utils';
import { hasPermission } from 'meteor/rocketchat:authorization';

const cookie = new Cookies();

Expand Down Expand Up @@ -86,6 +87,9 @@ export const FileUpload = Object.assign(_FileUpload, {
if (settings.get('Accounts_AvatarResize') !== true) {
return;
}
if (Meteor.userId() !== file.userId && !hasPermission(Meteor.userId(), 'edit-other-user-info')) {
throw new Meteor.Error('error-not-allowed', 'Change avatar is not allowed');
}

const tempFilePath = UploadFS.getTempFilePath(file._id);

Expand Down Expand Up @@ -207,6 +211,9 @@ export const FileUpload = Object.assign(_FileUpload, {
},

avatarsOnFinishUpload(file) {
if (Meteor.userId() !== file.userId && !hasPermission(Meteor.userId(), 'edit-other-user-info')) {
throw new Meteor.Error('error-not-allowed', 'Change avatar is not allowed');
}
// update file record to match user's username
const user = Models.Users.findOneById(file.userId);
const oldAvatar = Models.Avatars.findOneByName(user.username);
Expand Down