Skip to content

Commit 2a85138

Browse files
committed
fix Code scanning results / CodeQL
1 parent 724976b commit 2a85138

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

backend/common.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import PinoHttp from 'pino-http';
2+
import rateLimit from 'express-rate-limit';
23
import { handleDockerDesktopSubsitution } from './docker-desktop-substitution';
34
import { filters } from './request-filters';
45

@@ -142,9 +143,18 @@ export const makeHandleRequest = () => {
142143
};
143144
};
144145

146+
// Rate limiter: Max 100 requests per 1 minutes per IP
147+
const limiter = rateLimit({
148+
windowMs: 1 * 60 * 1000,
149+
max: 100,
150+
message: 'Too many requests from this IP, please try again later.',
151+
standardHeaders: true,
152+
legacyHeaders: false,
153+
});
154+
145155
export const serveStaticApp = (app, requestPath, directoryPath) => {
146156
app.use(requestPath, express.static(path.join(__dirname, directoryPath)));
147-
app.get(requestPath + '*splat', (_, res) =>
157+
app.get(requestPath + '*splat', limiter, (_, res) =>
148158
res.sendFile(path.join(__dirname + directoryPath + '/index.html')),
149159
);
150160
};

0 commit comments

Comments
 (0)