-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migration: added migration script for migrate old users status in new collections #2177
base: develop
Are you sure you want to change the base?
Conversation
@@ -35,4 +36,6 @@ | |||
router.patch("/:userId", authenticate, authorizeRoles([SUPERUSER]), validateUserStatus, updateUserStatus); | |||
router.delete("/:userId", authenticate, authorizeRoles([SUPERUSER]), deleteUserStatus); | |||
|
|||
router.post("/migrate", authenticate, authorizeRoles([SUPERUSER]), migrateUserStatusController); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
This route handler performs
authorization
This route handler performs
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will add a rate-limiting middleware to the Express application. We will use the express-rate-limit
package to limit the number of requests to the /migrate
endpoint. This will help prevent abuse and potential DoS attacks.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theroutes/userStatus.js
file. - Configure a rate limiter with appropriate settings (e.g., maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the
/migrate
route.
-
Copy modified line R2 -
Copy modified lines R26-R31 -
Copy modified line R46
@@ -1,2 +1,3 @@ | ||
const express = require("express"); | ||
const RateLimit = require("express-rate-limit"); | ||
const { | ||
@@ -24,2 +25,8 @@ | ||
|
||
// set up rate limiter: maximum of 100 requests per 15 minutes | ||
const limiter = RateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
router.get("/", validateGetQueryParams, getUserStatusControllers); | ||
@@ -38,3 +45,3 @@ | ||
|
||
router.post("/migrate", authenticate, authorizeRoles([SUPERUSER]), migrateUserStatusController); | ||
router.post("/migrate", limiter, authenticate, authorizeRoles([SUPERUSER]), migrateUserStatusController); | ||
|
-
Copy modified lines R40-R41
@@ -39,3 +39,4 @@ | ||
"rate-limiter-flexible": "5.0.3", | ||
"winston": "3.13.0" | ||
"winston": "3.13.0", | ||
"express-rate-limit": "^7.4.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.0 | None |
…ackend into migrate/user-status
Date:
Developer Name:
Issue Ticket Number
Description
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Test Coverage
Screenshot 1
Additional Notes