Added blacklist checks and rate limit logging
Needs testing
This commit is contained in:
9
rpg-docs/Model/Meta/Blacklist.js
Normal file
9
rpg-docs/Model/Meta/Blacklist.js
Normal file
@@ -0,0 +1,9 @@
|
||||
Blacklist = new Mongo.Collection("blacklist");
|
||||
|
||||
Schemas.Blacklist = new SimpleSchema({
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
Blacklist.attachSchema(Schemas.Blacklist);
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user