-
Notifications
You must be signed in to change notification settings - Fork 204
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
Migrate backend to ESM #959
Conversation
const router = Router(); | ||
|
||
router.get("/:monitorId", getChecks); | ||
router.post("/:monitorId", verifyOwnership(Monitor, "monitorId"), createCheck); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
a database access
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce a rate-limiting middleware using the express-rate-limit
package. This middleware will limit the number of requests to the routes that perform database access, specifically the POST and DELETE routes that use the verifyOwnership
middleware.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in theServer/routes/checkRoute.js
file. - Configure the rate limiter to allow a maximum of 100 requests per 15 minutes.
- Apply the rate limiter to the POST and DELETE routes that use the
verifyOwnership
middleware.
-
Copy modified line R2 -
Copy modified lines R17-R21 -
Copy modified line R23 -
Copy modified line R26
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -15,6 +16,12 @@ | ||
|
||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
router.get("/:monitorId", getChecks); | ||
router.post("/:monitorId", verifyOwnership(Monitor, "monitorId"), createCheck); | ||
router.post("/:monitorId", limiter, verifyOwnership(Monitor, "monitorId"), createCheck); | ||
router.delete( | ||
"/:monitorId", | ||
limiter, | ||
verifyOwnership(Monitor, "monitorId"), |
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
isAllowed(["admin", "superadmin"]), | ||
checkController.updateChecksTTL | ||
); | ||
router.put("/team/ttl", isAllowed(["admin", "superadmin"]), updateChecksTTL); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce rate limiting to the route handler on line 32. We will use the express-rate-limit
package to set up a rate limiter and apply it to the specific route. This will ensure that the route is protected against excessive requests, mitigating the risk of DoS attacks.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theServer/routes/checkRoute.js
file. - Set up a rate limiter with appropriate configuration (e.g., maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the route handler on line 32.
-
Copy modified line R2 -
Copy modified lines R17-R21 -
Copy modified line R38
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -15,2 +16,7 @@ | ||
|
||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
router.get("/:monitorId", getChecks); | ||
@@ -31,3 +37,3 @@ | ||
|
||
router.put("/team/ttl", isAllowed(["admin", "superadmin"]), updateChecksTTL); | ||
router.put("/team/ttl", limiter, isAllowed(["admin", "superadmin"]), updateChecksTTL); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
isAllowed(["admin", "superadmin"]), | ||
checkController.updateChecksTTL | ||
); | ||
router.put("/team/ttl", isAllowed(["admin", "superadmin"]), updateChecksTTL); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce a rate-limiting middleware using the express-rate-limit
package. This middleware will be applied to the updateChecksTTL
route to ensure that the number of requests to this endpoint is controlled, thereby mitigating the risk of denial-of-service attacks.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theServer/routes/checkRoute.js
file. - Configure a rate limiter with appropriate settings (e.g., a maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the
updateChecksTTL
route.
-
Copy modified line R2 -
Copy modified lines R17-R22 -
Copy modified line R39
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -15,2 +16,8 @@ | ||
|
||
// Configure rate limiter: maximum of 100 requests per 15 minutes | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
router.get("/:monitorId", getChecks); | ||
@@ -31,3 +38,3 @@ | ||
|
||
router.put("/team/ttl", isAllowed(["admin", "superadmin"]), updateChecksTTL); | ||
router.put("/team/ttl", limiter, isAllowed(["admin", "superadmin"]), updateChecksTTL); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
router.post("/", maintenanceWindowController.createMaintenanceWindows); | ||
const router = Router(); | ||
|
||
router.post("/", createMaintenanceWindows); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will use the express-rate-limit
package to add rate limiting to the createMaintenanceWindows
route. This will ensure that the endpoint is protected against excessive requests, which could otherwise lead to performance degradation or service unavailability.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theServer/routes/maintenanceWindowRoute.js
file. - Set up a rate limiter with appropriate configuration (e.g., a maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the
createMaintenanceWindows
route.
-
Copy modified line R2 -
Copy modified lines R16-R21
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import RateLimit from "express-rate-limit"; | ||
import { | ||
@@ -14,3 +15,8 @@ | ||
|
||
router.post("/", createMaintenanceWindows); | ||
const createMaintenanceWindowsLimiter = RateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
router.post("/", createMaintenanceWindowsLimiter, createMaintenanceWindows); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
); | ||
|
||
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId); | ||
router.get("/team/", getMaintenanceWindowsByTeamId); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the issue, we will introduce rate limiting to the Express application using the express-rate-limit
package. This will help prevent denial-of-service attacks by limiting the number of requests a client can make to the server within a specified time window. We will apply the rate limiter middleware to the specific route handler getMaintenanceWindowsByTeamId
.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in theServer/routes/maintenanceWindowRoute.js
file. - Configure the rate limiter with appropriate settings (e.g., maximum number of requests and time window).
- Apply the rate limiter middleware to the
getMaintenanceWindowsByTeamId
route.
-
Copy modified line R2 -
Copy modified lines R16-R21 -
Copy modified line R30
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -14,2 +15,8 @@ | ||
|
||
// Configure rate limiter: maximum of 100 requests per 15 minutes | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
router.post("/", createMaintenanceWindows); | ||
@@ -22,3 +29,3 @@ | ||
|
||
router.get("/team/", getMaintenanceWindowsByTeamId); | ||
router.get("/team/", limiter, getMaintenanceWindowsByTeamId); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
isAllowed(["admin", "superadmin"]), | ||
monitorController.addDemoMonitors | ||
); | ||
router.post("/demo", isAllowed(["admin", "superadmin"]), addDemoMonitors); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will add rate limiting to the route handler on line 40. We will use the express-rate-limit
package to set up a rate limiter and apply it to the specific route. This will help prevent denial-of-service attacks by limiting the number of requests that can be made to this endpoint within a specified time window.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theServer/routes/monitorRoute.js
file. - Set up a rate limiter with appropriate configuration (e.g., maximum number of requests per minute).
- Apply the rate limiter to the route handler on line 40.
-
Copy modified line R2 -
Copy modified lines R22-R26 -
Copy modified line R46
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -20,2 +21,7 @@ | ||
|
||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
router.get("/", getAllMonitors); | ||
@@ -39,3 +45,3 @@ | ||
|
||
router.post("/demo", isAllowed(["admin", "superadmin"]), addDemoMonitors); | ||
router.post("/demo", limiter, isAllowed(["admin", "superadmin"]), addDemoMonitors); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
isAllowed(["admin", "superadmin"]), | ||
monitorController.addDemoMonitors | ||
); | ||
router.post("/demo", isAllowed(["admin", "superadmin"]), addDemoMonitors); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce a rate-limiting middleware using the express-rate-limit
package. This middleware will be applied specifically to the addDemoMonitors
route to limit the number of requests that can be made to this endpoint within a specified time window.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theServer/routes/monitorRoute.js
file. - Configure the rate limiter with appropriate settings (e.g., a maximum of 5 requests per minute).
- Apply the rate limiter to the
addDemoMonitors
route.
-
Copy modified line R2 -
Copy modified lines R22-R26 -
Copy modified line R46
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -20,2 +21,7 @@ | ||
|
||
const demoMonitorLimiter = rateLimit({ | ||
windowMs: 1 * 60 * 1000, // 1 minute | ||
max: 5, // limit each IP to 5 requests per windowMs | ||
}); | ||
|
||
router.get("/", getAllMonitors); | ||
@@ -39,3 +45,3 @@ | ||
|
||
router.post("/demo", isAllowed(["admin", "superadmin"]), addDemoMonitors); | ||
router.post("/demo", isAllowed(["admin", "superadmin"]), demoMonitorLimiter, addDemoMonitors); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
|
||
module.exports = router; | ||
router.get("/", getAppSettings); | ||
router.put("/", isAllowed(["superadmin"]), updateAppSettings); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will add rate limiting to the updateAppSettings
route using the express-rate-limit
package. This will ensure that the route is protected against excessive requests, mitigating the risk of DoS attacks.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theServer/routes/settingsRoute.js
file. - Configure a rate limiter with appropriate settings (e.g., a maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the
updateAppSettings
route.
-
Copy modified line R2 -
Copy modified lines R11-R16 -
Copy modified line R18
@@ -1,2 +1,3 @@ | ||
import { Router } from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { | ||
@@ -9,4 +10,10 @@ | ||
|
||
// Configure rate limiter: maximum of 100 requests per 15 minutes | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
router.get("/", getAppSettings); | ||
router.put("/", isAllowed(["superadmin"]), updateAppSettings); | ||
router.put("/", isAllowed(["superadmin"]), limiter, updateAppSettings); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
|
||
//routes | ||
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce a rate-limiting middleware using the express-rate-limit
package. This middleware will be applied to the routes that use the verifyJWT
middleware to ensure that these routes are protected against DoS attacks. Specifically, we will:
- Install the
express-rate-limit
package. - Configure a rate limiter with appropriate settings.
- Apply the rate limiter to the routes that use the
verifyJWT
middleware.
-
Copy modified line R6 -
Copy modified lines R65-R70 -
Copy modified line R97 -
Copy modified lines R99-R102
@@ -5,2 +5,3 @@ | ||
import express from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import helmet from "helmet"; | ||
@@ -63,2 +64,8 @@ | ||
|
||
// Rate limiter middleware | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
// middlewares | ||
@@ -89,8 +96,8 @@ | ||
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/settings", limiter, verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", verifyJWT, queueRouter); | ||
app.use("/api/v1/monitors", limiter, verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", limiter, verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", limiter, verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", limiter, verifyJWT, queueRouter); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce a rate-limiting middleware using the express-rate-limit
package. This middleware will be applied to the routes that use the verifyJWT
middleware to ensure that these routes are protected against excessive requests. We will configure the rate limiter to allow a maximum of 100 requests per 15 minutes from a single IP address.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in theServer/index.js
file. - Configure the rate limiter with appropriate settings.
- Apply the rate limiter to the routes that use the
verifyJWT
middleware.
-
Copy modified line R4 -
Copy modified lines R64-R69 -
Copy modified line R96 -
Copy modified lines R98-R101
@@ -3,3 +3,3 @@ | ||
import swaggerUi from "swagger-ui-express"; | ||
|
||
import rateLimit from "express-rate-limit"; | ||
import express from "express"; | ||
@@ -63,2 +63,8 @@ | ||
|
||
// Rate limiter middleware | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
// middlewares | ||
@@ -89,8 +95,8 @@ | ||
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/settings", limiter, verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", verifyJWT, queueRouter); | ||
app.use("/api/v1/monitors", limiter, verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", limiter, verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", limiter, verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", limiter, verifyJWT, queueRouter); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we will introduce rate limiting to the routes that use the verifyJWT
middleware. We will use the express-rate-limit
package to achieve this. Specifically, we will:
- Install the
express-rate-limit
package. - Configure a rate limiter with appropriate settings.
- Apply the rate limiter to the routes that use the
verifyJWT
middleware.
-
Copy modified line R6 -
Copy modified lines R65-R70 -
Copy modified line R97 -
Copy modified lines R99-R102
@@ -5,2 +5,3 @@ | ||
import express from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import helmet from "helmet"; | ||
@@ -63,2 +64,8 @@ | ||
|
||
// Rate limiter configuration | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
// middlewares | ||
@@ -89,8 +96,8 @@ | ||
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/settings", limiter, verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", verifyJWT, queueRouter); | ||
app.use("/api/v1/monitors", limiter, verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", limiter, verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", limiter, verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", limiter, verifyJWT, queueRouter); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the issue, we will introduce rate limiting to the Express application using the express-rate-limit
package. This will involve the following steps:
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in theServer/index.js
file. - Set up a rate limiter with appropriate configuration (e.g., maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the routes that use the
verifyJWT
middleware.
-
Copy modified line R4 -
Copy modified lines R64-R69 -
Copy modified line R96 -
Copy modified lines R98-R101
@@ -3,3 +3,3 @@ | ||
import swaggerUi from "swagger-ui-express"; | ||
|
||
import RateLimit from "express-rate-limit"; | ||
import express from "express"; | ||
@@ -63,2 +63,8 @@ | ||
|
||
// Rate limiter setup | ||
const limiter = RateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
// middlewares | ||
@@ -89,8 +95,8 @@ | ||
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/settings", limiter, verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", verifyJWT, queueRouter); | ||
app.use("/api/v1/monitors", limiter, verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", limiter, verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", limiter, verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", limiter, verifyJWT, queueRouter); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", verifyJWT, queueRouter); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the issue, we will introduce rate limiting to the Express application using the express-rate-limit
package. This will involve the following steps:
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in theServer/index.js
file. - Configure a rate limiter with appropriate settings (e.g., a maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the routes that use the
verifyJWT
middleware.
-
Copy modified line R4 -
Copy modified lines R64-R69 -
Copy modified line R96 -
Copy modified lines R98-R101
@@ -3,3 +3,3 @@ | ||
import swaggerUi from "swagger-ui-express"; | ||
|
||
import RateLimit from "express-rate-limit"; | ||
import express from "express"; | ||
@@ -63,2 +63,8 @@ | ||
|
||
// Rate limiter configuration | ||
const limiter = RateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
// middlewares | ||
@@ -89,8 +95,8 @@ | ||
app.use("/api/v1/auth", authRouter); | ||
app.use("/api/v1/settings", verifyJWT, settingsRouter); | ||
app.use("/api/v1/settings", limiter, verifyJWT, settingsRouter); | ||
app.use("/api/v1/invite", inviteRouter); | ||
app.use("/api/v1/monitors", verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", verifyJWT, queueRouter); | ||
app.use("/api/v1/monitors", limiter, verifyJWT, monitorRouter); | ||
app.use("/api/v1/checks", limiter, verifyJWT, checkRouter); | ||
app.use("/api/v1/maintenance-window", limiter, verifyJWT, maintenanceWindowRouter); | ||
app.use("/api/v1/queue", limiter, verifyJWT, queueRouter); | ||
|
-
Copy modified lines R34-R35
@@ -33,3 +33,4 @@ | ||
"swagger-ui-express": "5.0.1", | ||
"winston": "^3.13.0" | ||
"winston": "^3.13.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
req = { | ||
params: { userId: "123" }, | ||
body: { password: "Password1!", newPassword: "Password2!" }, | ||
headers: { authorization: "Bearer token" }, |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
authorization header
beforeEach(() => { | ||
req = { | ||
headers: { | ||
authorization: "Bearer token", |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
authorization header
}); | ||
req = { | ||
headers: { | ||
authorization: "Bearer token", |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
authorization header
}); | ||
req = { | ||
headers: { | ||
authorization: "Bearer token", |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
authorization header
This looks like lots of code refactoring and formatting, tests are all running on my end as well, |
Thanks for checking it over, conflicts resovled and ready to go |
const error = new Error("jwt.sign error"); | ||
stub = sinon.stub(jwt, "sign").throws(error); | ||
const payload = { id: "123" }; | ||
const appSettings = { jwtSecret: "my_secret" }; |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
jwt key
|
||
it("should return a token if jwt.sign is successful and appSettings.jwtTTL is not defined", () => { | ||
const payload = { id: "123" }; | ||
const appSettings = { jwtSecret: "my_secret" }; |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
jwt key
|
||
it("should return a token if jwt.sign is successful and appSettings.jwtTTL is defined", () => { | ||
const payload = { id: "123" }; | ||
const appSettings = { jwtSecret: "my_secret", jwtTTL: "1s" }; |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
jwt key
|
||
it("should return a refresh token if jwt.sign is successful and appSettings.refreshTokenTTL is not defined", () => { | ||
const payload = {}; | ||
const appSettings = { refreshTokenSecret: "my_refresh_secret" }; |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
jwt key
it("should return a refresh token if jwt.sign is successful and appSettings.refreshTokenTTL is defined", () => { | ||
const payload = {}; | ||
const appSettings = { | ||
refreshTokenSecret: "my_refresh_secret", |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical test
jwt key
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces significant changes across both client and server components, primarily focusing on transitioning from CommonJS to ES6 module syntax. Key modifications include the addition of a new Mocha configuration file, updates to existing files for consistent formatting, and the introduction of new functions in various controllers. The Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
This PR migrates the project to use ESM. This is the offical standard of JavaScript and will afford us better compatability. It will also allow us to eventually do things like tree shaking and static analysis which we can use for optimization.