Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit f589185

Browse files
committed
Fix CodeQL alert for rate limiting
1 parent 497724f commit f589185

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

server/package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"compression": "^1.7.4",
1111
"express": "^4.17.1",
12+
"express-rate-limit": "^8.1.0",
1213
"handlebars": "^4.7.8",
1314
"helmet": "^7.0.0"
1415
}

server/server.prod.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import http from 'node:http';
55
import express from 'express';
6+
import { rateLimit } from 'express-rate-limit';
67
import compression from 'compression';
78
import handlebars from 'handlebars';
89
import helmet from 'helmet';
@@ -23,6 +24,14 @@ app.use(helmet());
2324
app.use(compression());
2425
app.use(express.static(path.join(DIST_DIR, 'public')));
2526

27+
const limiter = rateLimit({
28+
windowMs: 5 * 60 * 1000,
29+
limit: 100,
30+
});
31+
32+
// Apply the rate limiting middleware to all requests.
33+
app.use(limiter);
34+
2635
app.get('*', (req, res, next) => {
2736
const buffer = fs.readFileSync(HTML_FILE);
2837
const template = handlebars.compile(buffer.toString('utf8'));

0 commit comments

Comments
 (0)