Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@iroomit/rate-limit-mongodb
Advanced tools
MongoDB store for the Node.js express-rate-limit package.
MongoDB store for the express-rate-limit Node.js middleware package, used at iROOMit.
This package was heavily inspired by 2do2go/rate-limit-mongo, but is not a direct fork. Development on 2do2go/rate-limit-mongo has been stalled for several years, and also relies on some dependencies that are unnecessary in modern Node.js.
This implementation is also written in TypeScript for improved IntelliSense in VSCode and improved compile-time error detection.
This package is tested as compatible for MongoDB driver version >= 5, and express-rate-limit version >= 6.
Although untested, it may work with older versions of the MongoDB driver.
Version 6 and up of the express-rate-limit package is a hard requirement.
npm install @iroomit/rate-limit-mongodb
or
yarn add @iroomit/rate-limit-mongodb
import RateLimit from 'express-rate-limit';
import MongoDBStore from '@iroomit/rate-limit-mongodb';
const limiter = new RateLimit({
store: new MongoDBStore({
uri: 'mongodb://127.0.0.1:27017/test_db',
user: 'mongouser',
password: 'mongopassword'
}),
max: 100,
windowMs: 15 * 60 * 1000
});
// apply to all requests
app.use(limiter);
The MongoDBStore
class can be configured using the following options, depending on whether you are passing a MongoDB URI to establish the connection with this library or directly passing a MongoDB collection.
These options apply regardless of whether you are passing a MongoDB URI or a MongoDB collection directly:
prefix
(optional):
"mongodb_rl_"
.resetExpireDateOnChange
(optional):
true
, will reset the expiration date of a key each time it is incremented or decremented.false
.createTtlIndex
(optional):
true
, will automatically create a TTL index on the expirationDate
field in the MongoDB collection.true
.These options are used if you are passing a MongoDB URI to connect to the database yourself. The collection
field should not be provided in this case.
uri
(required):
"mongodb://localhost:27017/rateLimitDB"
.collectionName
(optional):
"expressRateRecords"
.connectionOptions
(optional):
MongoClient
constructor.user
(optional):
password
(optional):
authSource
(optional):
These options are used if you are directly passing a MongoDB collection object to the MongoDBStore
constructor. The uri
field should not be provided in this case.
collection
(required):
Collection
instance where rate-limit records will be stored.The test suite can be run with Docker, by running:
docker-compose -f docker-compose.test.yml up
You may be able to run the test suite outside of Docker, however the mongodb-memory-server
package used in the test suite only runs on select operating systems. This is probably fine if you are using Windows or macOS, but may cause problems on Linux if your distribution is not supported.
By running the test suite in Docker, we ensure that all required dependencies are installed for the mongodb-memory-server
package.
FAQs
MongoDB store for the Node.js express-rate-limit package.
We found that @iroomit/rate-limit-mongodb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.