Skip to content

Commit 9df5df3

Browse files
Potential fix for code scanning alert no. 5: Missing rate limiting
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 3e81ec4 commit 9df5df3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"cors": "^2.8.5",
3333
"dotenv": "^16.4.7",
3434
"express": "^4.21.2",
35-
"raw-body": "^3.0.0"
35+
"raw-body": "^3.0.0",
36+
"express-rate-limit": "^8.0.1"
3637
},
3738
"overrides": {
3839
"@types/express": "^5.0.0",

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BearerAuthMiddlewareOptions, requireBearerAuth } from "@modelcontextpro
22
import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js";
33
import cors from "cors";
44
import express from "express";
5+
import rateLimit from "express-rate-limit";
56
import path from "path";
67
import { fileURLToPath } from "url";
78
import { EverythingAuthProvider } from "./auth/provider.js";
@@ -15,6 +16,13 @@ import { logger } from "./utils/logger.js";
1516

1617
const app = express();
1718

19+
// Rate limiter for splash page
20+
const splashLimiter = rateLimit({
21+
windowMs: 15 * 60 * 1000, // 15 minutes
22+
max: 100, // limit each IP to 100 requests per windowMs
23+
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
24+
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
25+
});
1826
// Get the directory of the current module
1927
const __filename = fileURLToPath(import.meta.url);
2028
const __dirname = path.dirname(__filename);
@@ -168,7 +176,7 @@ app.get("/mcp-logo.png", (req, res) => {
168176
});
169177

170178
// Splash page
171-
app.get("/", (req, res) => {
179+
app.get("/", splashLimiter, (req, res) => {
172180
const splashPath = path.join(__dirname, "static", "index.html");
173181
res.sendFile(splashPath);
174182
});

0 commit comments

Comments
 (0)