Added blacklist checks and rate limit logging

Needs testing
This commit is contained in:
Stefan Zermatten
2018-03-12 09:22:04 +02:00
parent e27211b24d
commit 164ba78c81
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
Blacklist = new Mongo.Collection("blacklist");
Schemas.Blacklist = new SimpleSchema({
userId: {
type: String,
},
});
Blacklist.attachSchema(Schemas.Blacklist);

View File

@@ -33,6 +33,7 @@ var ifKeyValid = function(apiKey, response, callback){
response.writeHead(403, "API key is invalid");
response.end();
} else if (isRateLimited(apiKey)){
console.log(`Rate limit hit by API key ${apiKey}`);
response.writeHead(429, "Too many requests");
response.end();
} else {
@@ -42,7 +43,10 @@ var ifKeyValid = function(apiKey, response, callback){
};
var isKeyValid = function(apiKey){
return !!Meteor.users.findOne({apiKey});
var user = Meteor.users.findOne({apiKey});
if (!user) return false;
var blackListed = Blacklist.findOne({userId: user._id});
return !blackListed;
};
var rateLimiter = new RateLimiter();