-
Notifications
You must be signed in to change notification settings - Fork 3
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
Define cypress-run github action #746
Conversation
GRAD2-2538 clean up
Grad2 2972
GRAD2-2751 fix for offshore school
GRAD2-2751 fix for offshore school at GRAD
|
session({ | ||
name: "grad_admin_cookie", | ||
secret: config.get("oidc:clientSecret"), | ||
resave: false, | ||
saveUninitialized: true, | ||
cookie: cookie, | ||
store: dbSession, | ||
}) |
Check failure
Code scanning / CodeQL
Missing CSRF middleware High
request handler
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to add CSRF protection middleware to the Express application. The lusca
package provides a convenient way to implement CSRF protection. We will install the lusca
package and use its CSRF middleware in the application.
- Install the
lusca
package. - Import the
lusca
package in thebackend/src/app.js
file. - Add the CSRF middleware to the Express application before defining any routes that handle state-changing requests.
-
Copy modified line R14 -
Copy modified line R114
@@ -13,2 +13,3 @@ | ||
const auth = require("./components/auth"); | ||
const lusca = require("lusca"); | ||
const bodyParser = require("body-parser"); | ||
@@ -112,2 +113,3 @@ | ||
); | ||
app.use(lusca.csrf()); | ||
// app.use(require('./routes/health-check').router); |
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"lusca": "^1.7.0" | ||
}, |
Package | Version | Security advisories |
lusca (npm) | 1.7.0 | None |
router.get( | ||
"*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the route handler. The best way to do this is by using the express-rate-limit
package, which allows us to easily set up rate limiting for our Express application. We will configure a rate limiter to limit the number of requests that can be made to the route within a specified time window.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in the file. - Configure a rate limiter with appropriate settings (e.g., maximum number of requests per time window).
- Apply the rate limiter to the route handler.
-
Copy modified lines R2-R3 -
Copy modified lines R17-R31
@@ -1,3 +1,4 @@ | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const express = require("express"); | ||
const rateLimit = require("express-rate-limit"); | ||
const router = express.Router(); | ||
@@ -15,10 +16,17 @@ | ||
); | ||
|
||
//Program Routes | ||
router.get( | ||
"*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getalgorithmRulesAPI | ||
); | ||
|
||
// 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 | ||
}); | ||
|
||
//Program Routes | ||
router.get( | ||
"*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getalgorithmRulesAPI | ||
); | ||
|
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the route handlers in the batch-router.js
file. The best way to do this is by using the express-rate-limit
middleware. This middleware allows us to set a maximum number of requests that can be made to the server within a specified time window. We will apply this middleware to all the routes defined in the batch-router.js
file to ensure that the application is protected against denial-of-service attacks.
We will need to:
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in thebatch-router.js
file. - Set up a rate limiter with appropriate configuration.
- Apply the rate limiter to all the routes in the
batch-router.js
file.
-
Copy modified lines R1-R15 -
Copy modified lines R24-R77
@@ -1,15 +1,16 @@ | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const config = require("../config/index"); | ||
const auth = require("../components/auth"); | ||
const roles = require("../components/roles"); | ||
const { | ||
errorResponse, | ||
getData, | ||
postData, | ||
deleteData, | ||
putData, | ||
} = require("../components/utils"); | ||
const { request } = require("../app"); | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const RateLimit = require("express-rate-limit"); | ||
const config = require("../config/index"); | ||
const auth = require("../components/auth"); | ||
const roles = require("../components/roles"); | ||
const { | ||
errorResponse, | ||
getData, | ||
postData, | ||
deleteData, | ||
putData, | ||
} = require("../components/utils"); | ||
const { request } = require("../app"); | ||
const isValidUiTokenWithStaffRoles = auth.isValidUiTokenWithRoles( | ||
@@ -22,46 +23,56 @@ | ||
); | ||
|
||
//Batch Routes | ||
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getBatchInfoAPI | ||
); | ||
router.post( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
postBatchInfoAPI | ||
); | ||
router.delete( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
deleteBatchInfoAPI | ||
); | ||
router.put( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
putBatchInfoAPI | ||
); | ||
|
||
async function getBatchInfoAPI(req, res) { | ||
const token = auth.getBackendToken(req); | ||
const version = req.version; | ||
try { | ||
const url = `${config.get("server:batchAPIURL")}/api/${version}/batch${ | ||
req.url | ||
}`; | ||
const data = await getData(token, url, req.session?.correlationID); | ||
return res.status(200).json(data); | ||
} catch (e) { | ||
if (e.data.message) { | ||
return errorResponse(res, e.data.message, e.status); | ||
} else { | ||
return errorResponse(res); | ||
} | ||
} | ||
} | ||
|
||
// 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 | ||
}); | ||
|
||
//Batch Routes | ||
router.get( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getBatchInfoAPI | ||
); | ||
router.post( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
postBatchInfoAPI | ||
); | ||
router.delete( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
deleteBatchInfoAPI | ||
); | ||
router.put( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
putBatchInfoAPI | ||
); | ||
|
||
async function getBatchInfoAPI(req, res) { | ||
const token = auth.getBackendToken(req); | ||
const version = req.version; | ||
try { | ||
const url = `${config.get("server:batchAPIURL")}/api/${version}/batch${ | ||
req.url | ||
}`; | ||
const data = await getData(token, url, req.session?.correlationID); | ||
return res.status(200).json(data); | ||
} catch (e) { | ||
if (e.data.message) { | ||
return errorResponse(res, e.data.message, e.status); | ||
} else { | ||
return errorResponse(res); | ||
} | ||
} | ||
} | ||
async function postBatchInfoAPI(req, res) { |
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.post( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the route handlers in the batch-router.js
file. The best way to do this is by using the express-rate-limit
middleware. This middleware allows us to set a maximum number of requests that can be made to the server within a specified time window. We will apply this middleware to all the routes in the batch-router.js
file to ensure that the application is protected against denial-of-service attacks.
We will:
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in thebatch-router.js
file. - Set up a rate limiter with appropriate configuration.
- Apply the rate limiter to all the routes in the
batch-router.js
file.
-
Copy modified lines R1-R15 -
Copy modified lines R24-R60
@@ -1,15 +1,16 @@ | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const config = require("../config/index"); | ||
const auth = require("../components/auth"); | ||
const roles = require("../components/roles"); | ||
const { | ||
errorResponse, | ||
getData, | ||
postData, | ||
deleteData, | ||
putData, | ||
} = require("../components/utils"); | ||
const { request } = require("../app"); | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const RateLimit = require('express-rate-limit'); | ||
const config = require("../config/index"); | ||
const auth = require("../components/auth"); | ||
const roles = require("../components/roles"); | ||
const { | ||
errorResponse, | ||
getData, | ||
postData, | ||
deleteData, | ||
putData, | ||
} = require("../components/utils"); | ||
const { request } = require("../app"); | ||
const isValidUiTokenWithStaffRoles = auth.isValidUiTokenWithRoles( | ||
@@ -22,29 +23,39 @@ | ||
); | ||
|
||
//Batch Routes | ||
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getBatchInfoAPI | ||
); | ||
router.post( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
postBatchInfoAPI | ||
); | ||
router.delete( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
deleteBatchInfoAPI | ||
); | ||
router.put( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
putBatchInfoAPI | ||
); | ||
|
||
|
||
// 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 | ||
}); | ||
|
||
//Batch Routes | ||
router.get( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getBatchInfoAPI | ||
); | ||
router.post( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
postBatchInfoAPI | ||
); | ||
router.delete( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
deleteBatchInfoAPI | ||
); | ||
router.put( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
putBatchInfoAPI | ||
); | ||
|
||
async function getBatchInfoAPI(req, res) { |
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.delete( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the routes in the batch-router.js
file. The best way to do this is by using the express-rate-limit
middleware. This middleware allows us to set a maximum number of requests that can be made to the server within a specified time window. We will apply this middleware to all the routes in the batch-router.js
file to ensure that they are protected against denial-of-service attacks.
We will need to:
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in thebatch-router.js
file. - Set up a rate limiter with appropriate configuration.
- Apply the rate limiter to the routes in the
batch-router.js
file.
-
Copy modified lines R1-R15 -
Copy modified lines R24-R56
@@ -1,15 +1,16 @@ | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const config = require("../config/index"); | ||
const auth = require("../components/auth"); | ||
const roles = require("../components/roles"); | ||
const { | ||
errorResponse, | ||
getData, | ||
postData, | ||
deleteData, | ||
putData, | ||
} = require("../components/utils"); | ||
const { request } = require("../app"); | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const RateLimit = require("express-rate-limit"); | ||
const config = require("../config/index"); | ||
const auth = require("../components/auth"); | ||
const roles = require("../components/roles"); | ||
const { | ||
errorResponse, | ||
getData, | ||
postData, | ||
deleteData, | ||
putData, | ||
} = require("../components/utils"); | ||
const { request } = require("../app"); | ||
const isValidUiTokenWithStaffRoles = auth.isValidUiTokenWithRoles( | ||
@@ -22,28 +23,35 @@ | ||
); | ||
|
||
//Batch Routes | ||
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getBatchInfoAPI | ||
); | ||
router.post( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
postBatchInfoAPI | ||
); | ||
router.delete( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
deleteBatchInfoAPI | ||
); | ||
router.put( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
putBatchInfoAPI | ||
); | ||
|
||
// 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 | ||
}); | ||
|
||
//Batch Routes | ||
router.use(limiter); | ||
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getBatchInfoAPI | ||
); | ||
router.post( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
postBatchInfoAPI | ||
); | ||
router.delete( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
deleteBatchInfoAPI | ||
); | ||
router.put( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
putBatchInfoAPI | ||
); | ||
|
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.get( | ||
"*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the route handlers in the provided code. The best way to achieve this is by using the express-rate-limit
middleware. This middleware allows us to set a maximum number of requests that a client can make within a specified time window. We will apply the rate limiter to the routes that perform authorization and interact with external APIs.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in the file. - Set up a rate limiter with appropriate configuration.
- Apply the rate limiter to the routes that need protection.
-
Copy modified line R4 -
Copy modified lines R24-R30 -
Copy modified line R33 -
Copy modified line R40
@@ -3,2 +3,3 @@ | ||
const router = express.Router(); | ||
const RateLimit = require("express-rate-limit"); | ||
const config = require("../config/index"); | ||
@@ -22,5 +23,12 @@ | ||
|
||
//Program Routes | ||
// 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 | ||
}); | ||
|
||
// Program Routes | ||
router.get( | ||
"*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
@@ -31,2 +39,3 @@ | ||
"*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), |
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.post( | ||
"*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the route handlers in the provided code. The best way to do this is by using the express-rate-limit
package, which allows us to easily set up and apply rate limiting middleware to the routes.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in the 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 perform expensive operations.
-
Copy modified line R4 -
Copy modified lines R24-R29 -
Copy modified line R33 -
Copy modified line R40
@@ -3,2 +3,3 @@ | ||
const router = express.Router(); | ||
const RateLimit = require("express-rate-limit"); | ||
const config = require("../config/index"); | ||
@@ -22,2 +23,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 | ||
}); | ||
|
||
//Program Routes | ||
@@ -25,2 +32,3 @@ | ||
"*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
@@ -31,2 +39,3 @@ | ||
"*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), |
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we need to introduce rate limiting to the route handler to prevent potential denial-of-service attacks. The best way to achieve this is by using the express-rate-limit
package, which allows us to set up rate limiting middleware easily.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in the file. - Set up a rate limiter with appropriate configuration (e.g., maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the specific route handler.
-
Copy modified lines R2-R3 -
Copy modified lines R17-R30
@@ -1,3 +1,4 @@ | ||
const passport = require("passport"); | ||
const express = require("express"); | ||
const express = require("express"); | ||
const RateLimit = require("express-rate-limit"); | ||
const router = express.Router(); | ||
@@ -15,9 +16,16 @@ | ||
); | ||
|
||
router.get( | ||
"/*", | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getStudentExamAPI | ||
); | ||
|
||
// 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( | ||
"/*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }, undefined), | ||
isValidUiTokenWithStaffRoles, | ||
getStudentExamAPI | ||
); | ||
|
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
router.get( | ||
"*", | ||
passport.authenticate("jwt", { session: false }), | ||
isValidUiTokenWithStaffRoles, |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 23 days ago
To fix the problem, we should introduce rate limiting to the route handler. The best way to do this is by using the express-rate-limit
package, which allows us to easily set up and apply rate limiting to our Express routes. We will configure a rate limiter to allow a maximum of 100 requests per 15 minutes and apply it to the route handler.
We need to:
- Install the
express-rate-limit
package. - Import the package in the file.
- Configure the rate limiter.
- Apply the rate limiter to the route handler.
-
Copy modified line R4 -
Copy modified lines R24-R29 -
Copy modified line R32
@@ -3,2 +3,3 @@ | ||
const router = express.Router(); | ||
const RateLimit = require("express-rate-limit"); | ||
const config = require("../config/index"); | ||
@@ -22,4 +23,11 @@ | ||
|
||
// 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( | ||
"*", | ||
limiter, | ||
passport.authenticate("jwt", { session: false }), |
-
Copy modified lines R57-R58
@@ -56,3 +56,4 @@ | ||
"winston": "^3.5.0", | ||
"winston-daily-rotate-file": "^4.5.0" | ||
"winston-daily-rotate-file": "^4.5.0", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |
No description provided.