Skip to content

Commit

Permalink
[FIX] RocketChat.settings.get causing memory leak (sometimes) (#11487)
Browse files Browse the repository at this point in the history
<!-- INSTRUCTION: Your Pull Request name should start with one of the following tags -->
<!-- [NEW] For new features -->
<!-- [FIX] For bug fixes -->
<!-- [BREAK] For pull requests including breaking changes -->

<!-- INSTRUCTION: Inform the issue number that this PR closes, or remove the line below -->


<!-- INSTRUCTION: Link to a https://github.com/RocketChat/docs PR with added/updated documentation or an update to the missing/outdated documentation list, see https://rocket.chat/docs/contributing/documentation/  -->

<!-- INSTRUCTION: Tell us more about your PR with screen shots if you can -->
  • Loading branch information
ggazzo authored Jul 19, 2018
1 parent 7d30a8e commit 146837b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import _ from 'underscore';
import s from 'underscore.string';


let usernameBlackList = [];

const toRegExp = username => new RegExp(`^${ s.escapeRegExp(username).trim() }$`, 'i');

RocketChat.settings.get('Accounts_BlockedUsernameList', (key, value) => {
usernameBlackList = value.split(',').map(toRegExp);
});

const usernameIsBlocked = (username, usernameBlackList) => usernameBlackList.length
&& usernameBlackList.some(restrictedUsername => restrictedUsername.test(s.trim(s.escapeRegExp(username))));

RocketChat.checkUsernameAvailability = function(username) {
return RocketChat.settings.get('Accounts_BlockedUsernameList', function(key, value) {
const usernameBlackList = _.map(value.split(','), function(username) {
return username.trim();
});
if (usernameBlackList.length !== 0) {
if (usernameBlackList.every(restrictedUsername => {
const regex = new RegExp(`^${ s.escapeRegExp(restrictedUsername) }$`, 'i');
return !regex.test(s.trim(s.escapeRegExp(username)));
})) {
return !Meteor.users.findOne({
username: {
$regex: new RegExp(`^${ s.trim(s.escapeRegExp(username)) }$`, 'i')
}
});
}
return false;

if (usernameIsBlocked(username, usernameBlackList)) {
return false;
}

return !Meteor.users.findOne({
username: {
$regex: toRegExp(username)
}
});
}, { fields: { _id: 1 } });
};
16 changes: 8 additions & 8 deletions packages/rocketchat-livechat/imports/server/rest/upload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Busboy from 'busboy';
import filesize from 'filesize';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
let maxFileSize;
RocketChat.settings.get('FileUpload_MaxFileSize', function(key, value) {
try {
maxFileSize = parseInt(value);
} catch (e) {
maxFileSize = RocketChat.models.Settings.findOneById('FileUpload_MaxFileSize').packageValue;
}
});

RocketChat.API.v1.addRoute('livechat/upload/:rid', {
post() {
Expand Down Expand Up @@ -61,14 +69,6 @@ RocketChat.API.v1.addRoute('livechat/upload/:rid', {
});
}

const maxFileSize = RocketChat.settings.get('FileUpload_MaxFileSize', function(key, value) {
try {
return parseInt(value);
} catch (e) {
return RocketChat.models.Settings.findOneById('FileUpload_MaxFileSize').packageValue;
}
});

// -1 maxFileSize means there is no limit
if (maxFileSize >= -1 && file.fileBuffer.length > maxFileSize) {
return RocketChat.API.v1.failure({
Expand Down

0 comments on commit 146837b

Please sign in to comment.