-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Full revamp #1097
base: main
Are you sure you want to change the base?
Full revamp #1097
Conversation
Betree
commented
Feb 4, 2025
•
edited
Loading
edited
- Add ESLint
- Add prettier
- Get GraphQL types from schema
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
async (req: express.Request, res: express.Response) => { | ||
const { id } = req.params; | ||
const authorizationHeaders = authenticateRequest(req); | ||
const expense = await fetchExpenseInvoiceData(id, authorizationHeaders); | ||
await sendPDFResponse(res, ExpenseInvoice, { expense }); | ||
} |
Check failure
Code scanning / CodeQL
Missing rate limiting High
authorization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 17 hours 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
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 the specific route handler that is performing authorization and fetching data.
- Install the
express-rate-limit
package if it is not already installed. - Import the
express-rate-limit
package in theserver/routes/expenses.tsx
file. - Create a rate limiter with appropriate settings (e.g., maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the route handler.
-
Copy modified line R3 -
Copy modified lines R17-R21 -
Copy modified line R135
@@ -2,2 +2,3 @@ | ||
import express from "express"; | ||
import rateLimit from "express-rate-limit"; | ||
import { sendPDFResponse } from "../utils/pdf"; | ||
@@ -15,2 +16,7 @@ | ||
|
||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
|
||
async function fetchExpenseInvoiceData( | ||
@@ -128,2 +134,3 @@ | ||
"/:id/:filename.pdf", | ||
limiter, | ||
async (req: express.Request, res: express.Response) => { |
-
Copy modified lines R25-R26
@@ -24,3 +24,4 @@ | ||
"react-dom": "^19.0.0", | ||
"react-intl": "^7.1.5" | ||
"react-intl": "^7.1.5", | ||
"express-rate-limit": "^7.5.0" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.5.0 | None |