Skip to content

Commit 9fce6b3

Browse files
authored
Merge pull request #33 from pphatdev/alert-autofix-94
Potential fix for code scanning alert no. 94: Missing rate limiting
2 parents 69eafd2 + 26cf7f5 commit 9fce6b3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/routes/images.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Router } from 'express'
2+
import rateLimit from 'express-rate-limit'
23
import { authenticateToken } from '../middlewares/authenticate.js'
34
import { getImage, create, uploadSingle } from '../controllers/images.js'
45
import { Validation } from '../helpers/validator.js'
@@ -13,8 +14,14 @@ const imageRateLimiter = rateLimit({
1314
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
1415
})
1516

16-
export const ROUTE = Router()
17+
// Set up rate limiter: max 100 requests per 15 minutes per IP
18+
const limiter = rateLimit({
19+
windowMs: 15 * 60 * 1000, // 15 minutes
20+
max: 100, // limit each IP to 100 requests per windowMs
21+
})
1722

23+
export const ROUTE = Router()
24+
ROUTE.use(limiter)
1825
ROUTE.get("/", Validation.base.list, async (req, res) => {
1926
const response = await ImageModel.getData(req.query)
2027
res.send(response)

0 commit comments

Comments
 (0)