-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix: create new annotationFile #2432
base: main
Are you sure you want to change the base?
Conversation
|
@@ -198,6 +200,8 @@ | |||
router.post(ApiRoutes.CONTROLLER, this.routesHandler.handleWriteControllerExt as RequestHandler); | |||
|
|||
router.get(ApiRoutes.CODE_EXT, this.routesHandler.handleGetControllerExtensionData as RequestHandler); | |||
|
|||
router.post(ApiRoutes.ANNOTATION_FILE, this.routesHandler.handleCreateAnnoationFile as RequestHandler); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
a file system access
This route handler performs
a file system access
This route handler performs
a file system access
This route handler performs
a file system access
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 1 month 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 route handler handleCreateAnnoationFile
to a reasonable number within a specified time window. This will help prevent potential DoS attacks by ensuring that the server can handle requests without being overwhelmed.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in the file. - Create a rate limiter with a specified window and maximum number of requests.
- Apply the rate limiter to the specific route handler
handleCreateAnnoationFile
.
-
Copy modified line R5 -
Copy modified lines R198-R202 -
Copy modified line R210
@@ -4,2 +4,3 @@ | ||
import type { NextFunction, Request, Response, Router, RequestHandler } from 'express'; | ||
import rateLimit from 'express-rate-limit'; | ||
|
||
@@ -196,2 +197,7 @@ | ||
addApis(router: Router): void { | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
router.get(ApiRoutes.FRAGMENT, this.routesHandler.handleReadAllFragments as RequestHandler); | ||
@@ -203,3 +209,3 @@ | ||
|
||
router.post(ApiRoutes.ANNOTATION_FILE, this.routesHandler.handleCreateAnnoationFile as RequestHandler); | ||
router.post(ApiRoutes.ANNOTATION_FILE, limiter, this.routesHandler.handleCreateAnnoationFile as RequestHandler); | ||
} |
-
Copy modified lines R54-R55
@@ -53,3 +53,4 @@ | ||
"sanitize-filename": "1.6.3", | ||
"uuid": "10.0.0" | ||
"uuid": "10.0.0", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
if (metadataPath?.settings?.localUri) {//v2 | ||
metadataUrl = `${appInfo.url}/${metadataPath.settings.localUri}`; | ||
} else if (metadataPath?.uri) { //v4 | ||
metadataUrl = `${appInfo.url}/${metadataPath.uri}$metadata`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to get metadata for all v2 apps i tested.
For one V4 app tested the request was failing. But the same request passes in CPE when baseUrl is localhost.
For discussing creation of new annotation file for CPE