fix rate-limit.js module failing to block excessive requests
This commit is contained in:
parent
6bfe6a3947
commit
031f36759f
2 changed files with 5 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
|
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
|
|
||||||
|
|
@ -6,6 +7,7 @@ let action;
|
||||||
|
|
||||||
const updatePassword = (userId, newPassword) => {
|
const updatePassword = (userId, newPassword) => {
|
||||||
try {
|
try {
|
||||||
|
throw new Meteor.Error('500', 'Testing failures.');
|
||||||
Accounts.setPassword(userId, newPassword, { logout: false });
|
Accounts.setPassword(userId, newPassword, { logout: false });
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
action.reject(`[editProfile.updatePassword] ${exception}`);
|
action.reject(`[editProfile.updatePassword] ${exception}`);
|
||||||
|
|
@ -31,13 +33,12 @@ const editProfile = ({ userId, profile }, promise) => {
|
||||||
|
|
||||||
updateUser(userId, profile);
|
updateUser(userId, profile);
|
||||||
if (profile.password) updatePassword(userId, profile.password);
|
if (profile.password) updatePassword(userId, profile.password);
|
||||||
|
|
||||||
action.resolve();
|
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
action.reject(`[editProfile.handler] ${exception}`);
|
action.reject(`[editProfile.handler] ${exception}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default options =>
|
export default options =>
|
||||||
new Promise((resolve, reject) =>
|
new Promise((resolve, reject) =>
|
||||||
editProfile(options, { resolve, reject }));
|
editProfile(options, { resolve, reject }));
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,11 @@
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
|
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
|
||||||
import { _ } from 'meteor/underscore';
|
|
||||||
|
|
||||||
const fetchMethodNames = methods => _.pluck(methods, 'name');
|
|
||||||
|
|
||||||
const assignLimits = ({ methods, limit, timeRange }) => {
|
|
||||||
const methodNames = fetchMethodNames(methods);
|
|
||||||
|
|
||||||
|
export default ({ methods, limit, timeRange }) => {
|
||||||
if (Meteor.isServer) {
|
if (Meteor.isServer) {
|
||||||
DDPRateLimiter.addRule({
|
DDPRateLimiter.addRule({
|
||||||
name(name) { return _.contains(methodNames, name); },
|
name(name) { return methods.indexOf(name) > -1; },
|
||||||
connectionId() { return true; },
|
connectionId() { return true; },
|
||||||
}, limit, timeRange);
|
}, limit, timeRange);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function rateLimit(options) { return assignLimits(options); }
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue