auth0 / express-brute-mongo Goto Github PK
View Code? Open in Web Editor NEWMongoDB adapter for the express-brute middleware.
License: MIT License
MongoDB adapter for the express-brute middleware.
License: MIT License
I remember that the express-brute-mongo has the problem with express-brute
npm WARN [email protected] requires a peer of express-brute@~0.5.0 but none was installed.
I've set up the module and seems to be working fine, however I'm getting duplicate key errors:
errmsg: 'E11000 duplicate key error collection: mydb.ratelimits index: _id_ dup key: { : "G/IAnx1Agvj9X0JzMvChzHFl6jKU0ps4dnfVvJ+ZYTc=" }' } }
I've ensured the index to be set, this is my implementation:
var MongoStore = require('express-brute-mongo');
var MongoClient = require('mongodb').MongoClient;
var bruteStore = new MongoStore(function (ready) {
MongoClient.connect(process.env['DB_URL'], function (err, db) {
if (err) throw err;
db.collection('ratelimits').ensureIndex({expires: 1}, {expireAfterSeconds: 0});
ready(db.collection('ratelimits'));
});
});
This is the middleware I set up (same as defaults, but logging the dup key error):
var rateLimitMiddleware = new ExpressBrute(bruteStore, {
failCallback: function (req, res, next, nextValidRequestDate) {
var err = new Error('Too many attempts.');
err.status = 429;
next(err);
},
handleStoreError: function (error) {
console.log(error);
}
});
Any ideas?
I get this error:
Peer [email protected] wants express-brute@~0.4.2
since express-brute is at 0.5.0
In the Expire Documents section of README.md, should
db.my_api_limits_coll.ensureIndex({expires: 1}, {expires: 0});
be
db.my_api_limits_coll.ensureIndex({expires: 1}, {expireAfterSeconds: 0});
?
Sorry if this is a dumb question; I'm very new to MongoDB.
License contents should be updated to latest approved contents.
TypeError: Cannot read property 'findOne' of undefined
at [object Object].MongoStore.get (/root/idlebot/src/modules/idle/node_modules/express-brute-mongo/index.js:37:13)
at [object Object].<anonymous> (/root/idlebot/src/modules/idle/node_modules/express-brute/index.js:82:15)
at keyFunc (/root/idlebot/src/modules/idle/node_modules/express-brute/index.js:49:41)
at [object Object].<anonymous> (/root/idlebot/src/modules/idle/node_modules/express-brute/index.js:57:3)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/route.js:100:13)
at Route.dispatch (/root/idlebot/src/modules/idle/node_modules/express/lib/router/route.js:81:3)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:234:24
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:559:15
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:186:14)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at Function.proto.handle (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:165:3)
at router (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:34:12)
at Layer.handle [as handle_request] (/root/idlebot/src/modules/idle/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:270:13)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:312:12)
at /root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:295:3)
at next (/root/idlebot/src/modules/idle/node_modules/express/lib/router/index.js:189:10)
at /root/idlebot/src/modules/idle/node_modules/body-parser/lib/read.js:107:5
at IncomingMessage.onEnd (/root/idlebot/src/modules/idle/node_modules/body-parser/node_modules/raw-body/index.js:136:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.EventEmitter.emit (events.js:104:17)
at _stream_readable.js:898:16
at process._tickCallback (node.js:343:11)
TypeError: db.collection is not a function
at MongoClient.connect (/Users/USER/Sites/PROJECT/routers/v1/api.js:23:14)
at args.push (/Users/cesarguadarrama/Sites/PROJECT/node_modules/mongodb/lib/utils.js:404:72)
at /Users/USER/Sites/PROJECT/node_modules/mongodb/lib/mongo_client.js:255:5
at connectCallback (/Users/USER/Sites/PROJECT/node_modules/mongodb/lib/mongo_client.js:933:5)
at /Users/USER/Sites/PROJECT/node_modules/mongodb/lib/mongo_client.js:794:11
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
MongoDB version v3.4.2
Mongoose version 5.0.0-rc2
Node version v8.9.0
[UPDATE]: Seems to be a mongoose issue
$ npm install express-brute-mongo
npm ERR! peerinvalid The package express-brute does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants express-brute@~0.5.0
The latest version of express-brute is 0.6.0 : https://github.com/AdamPflug/express-brute
I guess you need to upgrade the package json to version 0.6.0, only after you have tested?
"peerDependencies": {
"express-brute": "~0.5.0"
},
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.